Repository: novus/nvd3 Branch: master Commit: 447cce8c180a Files: 190 Total size: 2.9 MB Directory structure: gitextract_tmwn_v_x/ ├── .eslintrc.json ├── .gitignore ├── .jshintrc ├── .travis.yml ├── GruntFile.js ├── ISSUE_TEMPLATE.md ├── LICENSE.md ├── README.md ├── bower.json ├── build/ │ ├── nv.d3.css │ └── nv.d3.js ├── composer.json ├── examples/ │ ├── TimeSeries.html │ ├── actual.json │ ├── boxPlot.html │ ├── boxPlotCustomModel.html │ ├── bullet.html │ ├── bulletChart.html │ ├── candlestick.html │ ├── candlestickChart.html │ ├── cumulativeLineChart.html │ ├── differenceChart.html │ ├── discreteBarChart.html │ ├── distroPlotChart.html │ ├── documentation.html │ ├── donutChart.html │ ├── forceDirected.html │ ├── furiousLegend.html │ ├── heatMap.html │ ├── historicalBar.html │ ├── historicalBarChart.html │ ├── index.html │ ├── legend.html │ ├── lib/ │ │ ├── colorbrewer.js │ │ └── stream_layers.js │ ├── line.html │ ├── lineChart.html │ ├── lineChartLogScale.html │ ├── lineChartSVGResize.html │ ├── linePlusBarChart.html │ ├── lineWithFocusChart.html │ ├── lineWithFocusChart_x2AxisLabel.html │ ├── monitoringChart.html │ ├── multiBarChart.html │ ├── multiBarChart2.html │ ├── multiBarHorizontalChart.html │ ├── multiChart.html │ ├── ohlc.html │ ├── ohlcChart.html │ ├── parallelCoordinates.html │ ├── parallelCoordinatesChart.html │ ├── pie.html │ ├── pieChart.html │ ├── predicted.json │ ├── sankeyChart.html │ ├── scatter.html │ ├── scatterChart.html │ ├── scatterPlusLineChart.html │ ├── site.html │ ├── sparkline.html │ ├── sparklinePlus.html │ ├── stackedArea.html │ ├── stackedAreaChart.html │ ├── stackedAreaWithFocusChart.html │ ├── stylesheets/ │ │ ├── pygment_trac.css │ │ └── styles.css │ ├── sunburst.html │ └── tooltip.html ├── index.html ├── meteor/ │ └── export.js ├── package.js ├── package.json ├── src/ │ ├── core.js │ ├── css/ │ │ ├── axis.css │ │ ├── bars.css │ │ ├── boxplot.css │ │ ├── bullet.css │ │ ├── candlestick.css │ │ ├── forceDirectedGraph.css │ │ ├── furiousLegend.css │ │ ├── lineplusbar.css │ │ ├── lines.css │ │ ├── main.css │ │ ├── ohlc.css │ │ ├── parallelcoordinates.css │ │ ├── pie.css │ │ ├── scatter.css │ │ ├── sparkline.css │ │ ├── stackedarea.css │ │ └── tooltip.css │ ├── dom.js │ ├── interactiveLayer.js │ ├── models/ │ │ ├── axis.js │ │ ├── boxPlot.js │ │ ├── boxPlotChart.js │ │ ├── bullet.js │ │ ├── bulletChart.js │ │ ├── candlestickBar.js │ │ ├── cumulativeLineChart.js │ │ ├── differenceChart.js │ │ ├── discreteBar.js │ │ ├── discreteBarChart.js │ │ ├── distribution.js │ │ ├── distroPlot.js │ │ ├── distroPlotChart.js │ │ ├── focus.js │ │ ├── forceDirectedGraph.js │ │ ├── furiousLegend.js │ │ ├── heatMap.js │ │ ├── heatMapChart.js │ │ ├── historicalBar.js │ │ ├── historicalBarChart.js │ │ ├── legend.js │ │ ├── line.js │ │ ├── lineChart.js │ │ ├── linePlusBarChart.js │ │ ├── multiBar.js │ │ ├── multiBarChart.js │ │ ├── multiBarHorizontal.js │ │ ├── multiBarHorizontalChart.js │ │ ├── multiChart.js │ │ ├── ohlcBar.js │ │ ├── parallelCoordinates.js │ │ ├── parallelCoordinatesChart.js │ │ ├── pie.js │ │ ├── pieChart.js │ │ ├── sankey.js │ │ ├── sankeyChart.js │ │ ├── scatter.js │ │ ├── scatterChart.js │ │ ├── sparkline.js │ │ ├── sparklinePlus.js │ │ ├── stackedArea.js │ │ ├── stackedAreaChart.js │ │ ├── sunburst.js │ │ └── sunburstChart.js │ ├── tooltip.js │ └── utils.js └── test/ ├── ScatterChartTest.html ├── bootstrapModalTest.html ├── boxPlotTest.html ├── cumulativeLineChart.html ├── lineChartTest.html ├── linePlusBarChart.html ├── linePlusBarWithFocusChart.html ├── lineWithFisheyeChart.html ├── lineWithFocusChart.html ├── lineWithFocusChartMissingData.html ├── mocha/ │ ├── axis.coffee │ ├── boxplot.coffee │ ├── bullet.coffee │ ├── core.coffee │ ├── cumulative-line.coffee │ ├── differenceChart.js │ ├── discretebar.coffee │ ├── distrochart.coffee │ ├── heatmap.coffee │ ├── historical-bar.coffee │ ├── legend.coffee │ ├── line.coffee │ ├── multibar-horizontal.coffee │ ├── multibar.coffee │ ├── pie.coffee │ ├── sankey.coffee │ ├── scatter.coffee │ ├── sparkline.coffee │ ├── stacked.coffee │ ├── sunburst.coffee │ ├── test-utils.coffee │ └── utils.coffee ├── multiBarChartTest.html ├── multiBarHorizontalChart.html ├── node/ │ ├── GruntFile.js │ ├── README.md │ ├── nodeTest.html │ ├── nodeTest.js │ └── package.json ├── pieChartTest.html ├── polylinearTest.html ├── realTimeChartTest.html ├── scatterPlusLineChart.html ├── scrollTest.html ├── scrollTest2.html ├── stackedAreaChartMissingData.html ├── stackedAreaChartTest.html ├── stream_layers.js ├── testScript.js ├── teststyle.css ├── tinytest/ │ └── nv-is-defined-test.js └── translateTest.html ================================================ FILE CONTENTS ================================================ ================================================ FILE: .eslintrc.json ================================================ { "env": { "browser": true, "node": true, "es6": true, "mocha": true }, "extends": "eslint:recommended", "parserOptions": { "sourceType": "module" }, "globals": { "nv": true, "d3": true }, "rules": { "indent": [ "error", 2 ], "linebreak-style": [ "error", "unix" ], "quotes": [ "error", "single" ], "object-curly-spacing": [ "error", "always" ], "prefer-arrow-callback": [ "never", { "allowNamedFunctions": true } ], "arrow-parens": [ "error", "always" ], "space-before-function-paren": ["error", { "anonymous": "never", "named": "never", "asyncArrow": "never" }], "semi": [ "error", "always" ], "comma-dangle": ["error", { "arrays": "never", "objects": "never", "imports": "never", "exports": "never", "functions": "ignore" }] } } ================================================ FILE: .gitignore ================================================ .idea *.swp *~ *.log .DS_Store* ehthumbs.db Icon? Thumbs.db node_modules bower_components coverage test-results.xml *.orig ================================================ FILE: .jshintrc ================================================ { "asi": true } ================================================ FILE: .travis.yml ================================================ language: node_js node_js: - "0.12" before_install: - "npm install -g bower" - "npm install -g grunt-cli" - "export DISPLAY=:99.0" - "sh -e /etc/init.d/xvfb start" # Meteor Tinytest support - "curl https://install.meteor.com | /bin/sh" - export PATH="$HOME/.meteor:$PATH" - "npm install -g spacejam" install: - "npm install" - "bower install" script: - "npm test" - "spacejam test-packages ./" ================================================ FILE: GruntFile.js ================================================ module.exports = function(grunt) { var _pkg = grunt.file.readJSON('package.json'); // allows autoprefixer to work on older node_js versions require('es6-promise').polyfill(); //Project configuration. grunt.initConfig({ pkg: _pkg, concat: { css: { options: { separator: '\n', banner: '/* nvd3 version ' + _pkg.version + ' (' + _pkg.url + ') ' + '<%= grunt.template.today("yyyy-mm-dd") %> */\n' }, src: [ 'src/css/*.css' ], dest: 'build/nv.d3.css' }, js: { options: { separator: '', banner: '/* nvd3 version ' + _pkg.version + ' (' + _pkg.url + ') ' + '<%= grunt.template.today("yyyy-mm-dd") %> */\n' + '(function(){\n', footer: '\nnv.version = "' + _pkg.version + '";\n})();', sourceMap: true, sourceMapName: 'build/nv.d3.js.map', sourceMapStyle: 'embed' }, src: [ 'src/core.js', 'src/dom.js', 'src/interactiveLayer.js', 'src/tooltip.js', 'src/utils.js', //Include all files in src/models 'src/models/*.js', // example to exclude files: '!src/models/excludeMe*' ], dest: 'build/nv.d3.js' } }, uglify: { options: { sourceMap: true, sourceMapIncludeSources : true, sourceMapIn : 'build/nv.d3.js.map', banner: '/* nvd3 version ' + _pkg.version + ' (' + _pkg.url + ') ' + '<%= grunt.template.today("yyyy-mm-dd") %> */\n' }, js: { files: { 'build/nv.d3.min.js': ['build/nv.d3.js'] } } }, replace: { version: { src: [ 'package.js' ], overwrite: true, replacements: [{ from: /(version?\s?=?\:?\s\')([\d\.]*)\'/gi, to: '$1' + _pkg.version + "'" }] } }, jshint: { foo: { src: "src/**/*.js" }, options: { jshintrc: '.jshintrc' } }, watch: { js: { files: ["src/**/*.js"], tasks: ['concat'] } }, copy: { css: { files: [ { src: 'src/nv.d3.css', dest: 'build/nv.d3.css' } ] } }, postcss: { options: { processors: [ require('autoprefixer')({ browsers: [ 'last 2 versions', 'last 3 iOS versions', 'last 2 safari versions', 'ie >= 9'] }) ] }, dist: { src: 'build/nv.d3.css' } }, cssmin: { options: { sourceMap: true }, dist: { files: { 'build/nv.d3.min.css' : ['build/nv.d3.css'] } } }, karma: { unit: { options: { logLevel: 'DEBUG', browsers: ['Firefox'], browserNoActivityTimeout: 60000, browserDisconnectTimeout: 60000, captureTimeout: 60000, frameworks: [ 'mocha', 'sinon-chai' ], reporters: [ 'spec', 'junit', 'coverage'], singleRun: true, preprocessors: { 'src/*.js': ['coverage'], 'src/models/*.js': ['coverage'], 'test/mocha/*.coffee': ['coffee'] }, files: [ 'bower_components/d3/d3.js', 'node_modules/moment/moment.js', 'src/*.js', 'src/models/*.js', 'test/mocha/*.coffee', 'https://cdn.rawgit.com/Kcnarf/d3-beeswarm/fbda9b54/build/d3-beeswarm.min.js', 'test/mocha/*.js' ], exclude: [ 'src/intro.js', 'src/outro.js', //Files we don't want to test. 'src/models/lineWith*', 'src/models/parallelCoordinates*', 'src/models/multiBarTime*', 'src/models/indented*', 'src/models/linePlus*', 'src/models/ohlcBar.js', 'src/models/candlestickBar.js' ] } } } }); grunt.loadNpmTasks('grunt-contrib-watch'); grunt.loadNpmTasks('grunt-contrib-concat'); grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-contrib-copy'); grunt.loadNpmTasks('grunt-postcss'); grunt.loadNpmTasks('grunt-contrib-cssmin'); grunt.loadNpmTasks('grunt-karma'); grunt.loadNpmTasks('grunt-text-replace'); grunt.registerTask('default', ['concat', 'copy', 'postcss', 'karma:unit']); grunt.registerTask('production', ['concat', 'uglify', 'copy', 'postcss', 'cssmin', 'replace']); grunt.registerTask('release', ['production']); grunt.registerTask('lint', ['jshint']); }; ================================================ FILE: ISSUE_TEMPLATE.md ================================================ PLEASE READ THIS BEFORE SUBMITTING A NEW ISSUE. ARE YOU ASKING FOR HELP? Please use Stack Overflow tag nvd3.js and include a link to a live, minimal example on jsfiddle / plunker. The live example should use the latest code for nvd3. Links are below: https://raw.githubusercontent.com/novus/nvd3/master/build/nv.d3.js https://raw.githubusercontent.com/novus/nvd3/master/build/nv.d3.css Supported D3 js version. v3.5.17 https://github.com/cdnjs/cdnjs/blob/master/ajax/libs/d3/3.5.17/d3.min.js ARE YOU REPORTING AN ISSUE? Please provide below information with the issue: NVD3 version used: Browser and OS used: Live Example: Jsfiddle / Plunker Expected Behaviour: Present Behaviour: Any more information regarding the issue: ================================================ FILE: LICENSE.md ================================================ ##nvd3.js License Copyright (c) 2011-2014 [Novus Partners, Inc.][novus] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. [novus]: https://www.novus.com/ ##d3.js License Copyright (c) 2012, Michael Bostock All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * The name Michael Bostock may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MICHAEL BOSTOCK BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ================================================ FILE: README.md ================================================ ## NVD3 - A reusable D3 charting library Inspired by the work of Mike Bostock's [Towards Reusable Charts](http://bost.ocks.org/mike/chart/), and supported by a combined effort of [Novus](http://www.novus.com) and the NVD3 community. [View Examples](http://nvd3-community.github.io/nvd3/) | [NEW Documentation!](http://nvd3-community.github.io/nvd3/examples/documentation.html) | Development build status: [![Build Status](https://travis-ci.org/novus/nvd3.svg?branch=master)](https://travis-ci.org/novus/nvd3) ## Usage Simply add the `nv.d3` assets to your project and include them in your HTML. ``` ``` * `nv.d3.js` should appear after `d3.js` is included. * Prefer minified assets (`.min`) for production. ### Dependencies NVD3 is recommended to go with [d3.js](http://d3js.org/) version 3.5.3 and later, but NOT d3 4.x yet. [version 3.5.17](https://github.com/d3/d3/releases/tag/v3.5.17) is the most recent d3 v3 release. **Minimum D3 version required: 3.4.4** For a D3v4 Version, see the work in progress at the [nvd3 organization](http://github.com/nvd3/nvd3) Along with `pieChart` options `padAngle` and `cornerRadius`, the interactive guideline tooltip now requires these later versions of D3 (3.4.4+, specifically, to get interactive tooltips). The interactive guide lines rely on the more recent `d3.bisector()` method which treats accessors taking two parameters (the second being the element index) as comparators (see [d3.bisector()](https://github.com/mbostock/d3/wiki/Arrays#d3_bisector)). ## Supported Browsers NVD3 runs best on WebKit based browsers. * Google Chrome: latest version * Opera 15+ (i.e. webkit version) * Safari: latest version * Firefox: latest version * Internet Explorer: 10+ ## Do we support D3 v4.x? No, we do not... we are very interested in taking this on but could use some help. Please let us know if you'd like to help make this a reality! :) ## Changelog **1.8.6** Changes: * Community bugfixes **1.8.5** Changes: * Community bugfixes * New force-directed graph **1.8.4** Changes: * Community bugfixes including tooltip fixes. **1.8.3** Changes: * Lots of community bugfixes * Added force-directed chart **1.8.2** Changes: * Lots of community bugfixes and a few extra minor features **1.8.1** Changes: * Tooltips were refactored - If you have customized your tooltips, note that you may need to adjust your custom functions as the data passed has changed format. See the new [tooltip options](https://nvd3-community.github.io/nvd3/examples/documentation.html#tooltip) for more details. * Added boxplot charts | [example](https://nvd3-community.github.io/nvd3/examples/boxPlot.html) * Added candlestick charts | [example](https://nvd3-community.github.io/nvd3/examples/candlestickChart.html) * Added extra donut chart abilities | [examples](https://nvd3-community.github.io/nvd3/examples/monitoringChart.html) * Added sunburst Charts | [example](https://nvd3-community.github.io/nvd3/examples/sunburst.html) * Time Series | [example](https://nvd3-community.github.io/nvd3/examples/TimeSeries.html) * Another legend format available | [example](https://nvd3-community.github.io/nvd3/examples/stackedAreaChart.html) * Lots of bug fixes (see closed issues) * (for all examples, see [here](https://nvd3-community.github.io/nvd3/)) **1.7.1** Changes: * Fixed axis.staggerLabels bug. * Fixed Karma unit tests. * Fixed chart test pages. * Merged in nvd3-community changes and development branch. **1.7.0** Changes: * Fixes around 20 small bugs. * Fixed the notorious slowness of line charts and scatter plots on chrome * Combined the scatterChart and scatterChartWithLines models * Combined the linePlusBarChart and linePlusBarChartWithFocus models. * renamed some of the options (see the new documentation for what options are available for each chart) * Completed the migration of the option functions to an object format which allows the generation of the documentation in an automated way. Not everything has a description yet, but check it out! * Added extra options to the donut charts based on features that will be in d3 3.5. The donut example page loads the latest d3 from their 3.5 branch so keep that in mind. * Added an example of the parallelCoordinates chart. * Fixed up the half-done OHLC bar chart, and made an example for it as well. **1.6.0** Changes: * includes about a dozen bug fixes and pull requests I fixed and merged in from the issues/pulls from the original project. * It also standardized all indention --- # Current development focus - Review outstanding pull requests and issues. - Try to find an easy way to actually document usage and all chart options. - Improve the testing framework. - Setup continuous integration. --- # Bugs Found a bug? Check out the latest from the `master` branch and make sure it's not already fixed first! If you don't see a related fix, please [open an issue](https://github.com/novus/nvd3/issues). --- # Optional dependencies Including [Fastdom](https://github.com/wilsonpage/fastdom) in your project can greatly increase the performance of the line chart (particularly in Firefox and Internet Explorer) by batching DOM read and write operations to avoid [layout thrashing](http://wilsonpage.co.uk/preventing-layout-thrashing/). NVD3 will take advantage of Fastdom if present. --- # Contributing If one of [the existing models](https://github.com/novus/nvd3/tree/master/src/models) doesn't meet your needs, fork the project, implement the model and an example using it, send us a pull request, for consideration for inclusion in the project. If you'd like to contribute consistently, show me what you've got with some good pull requests and you may get added to the nvd3-community org! ### A few rules for pull requests 1. Please commit to the `master` branch 2. Do NOT check in anything under the `build` directory, it clutters up the commit and just gets overwritten later. 3. All new features must come with unit test coverage 4. Bug fixes should come with unit tests that prove their fix If you want to test your changes using the example pages, you'll have to run `grunt production` to build the items into the `build` directory. You must do this before your changes show up in the examples, as they link to the build directory in order to properly show off the finished product. Please remember to NOT include the build files in your commit though, only include the source files you changed! ### Tips for Testing * Unit tests were written in Karma and Mocha. Follow instructions in **Building Latest** to get npm packages setup. This may not work on Windows machines. * Run `bower install` to get bower dependencies. * Run `grunt` to start the unit tests. * Also visually inspect the HTML pages in the **examples/ and test/ folders**. Make sure there are no glaring errors. * Novus now uses Travis CI for continuous integration. Visit [our travis build page](https://travis-ci.org/novus/nvd3/) to see the latest status. #### Meteor Tinytests * Any Meteor-specific features can be tested from the command line using `tinytest` and [Spacejam](https://www.npmjs.com/package/spacejam) * `spacejam` can be installed by running `npm install -g spacejam`. * Tinytests can then be executed by running `spacejam test-packages ./` from this project's root. --- ## Building latest 1. First clone the repository and checkout the `master` branch 2. make sure `nodejs` is installed via your system's package manager. 3. Install `grunt`, `grunt-cli`, and `bower`: `npm install -g grunt grunt-cli bower` > have node download nvd3's required modules with: `npm install` > build with: `grunt production` You should now have a `build` directory with the js and css files within. --- ================================================ FILE: bower.json ================================================ { "name": "nvd3", "homepage": "http://www.nvd3.org", "authors": [ "Bob Monteverde", "Tyler Wolf", "Robin Hu", "Frank Shao", "liquidpele" ], "description": "Re-usable charts and chart components for d3.", "main": [ "build/nv.d3.js", "build/nv.d3.css" ], "keywords": [ "d3", "visualization", "svg", "charts" ], "license": "Apache-2.0", "dependencies": { "d3": "^3.4.4" }, "ignore": [ "**/.*", "node_modules", "bower_components", "test", "src", "examples", "GruntFile.js", "*.html", "*.log", "*.xml", "*.json", "*.md" ] } ================================================ FILE: build/nv.d3.css ================================================ /* nvd3 version 1.8.6-dev (https://github.com/novus/nvd3) 2018-02-24 */ .nvd3 .nv-axis { pointer-events:none; opacity: 1; } .nvd3 .nv-axis path { fill: none; stroke: #000; stroke-opacity: .75; shape-rendering: crispEdges; } .nvd3 .nv-axis path.domain { stroke-opacity: .75; } .nvd3 .nv-axis.nv-x path.domain { stroke-opacity: 0; } .nvd3 .nv-axis line { fill: none; stroke: #e5e5e5; shape-rendering: crispEdges; } .nvd3 .nv-axis .zero line, /*this selector may not be necessary*/ .nvd3 .nv-axis line.zero { stroke-opacity: .75; } .nvd3 .nv-axis .nv-axisMaxMin text { font-weight: bold; } .nvd3 .x .nv-axis .nv-axisMaxMin text, .nvd3 .x2 .nv-axis .nv-axisMaxMin text, .nvd3 .x3 .nv-axis .nv-axisMaxMin text { text-anchor: middle; } .nvd3 .nv-axis.nv-disabled { opacity: 0; } .nvd3 .nv-bars rect { fill-opacity: .75; transition: fill-opacity 250ms linear; } .nvd3 .nv-bars rect.hover { fill-opacity: 1; } .nvd3 .nv-bars .hover rect { fill: lightblue; } .nvd3 .nv-bars text { fill: rgba(0,0,0,0); } .nvd3 .nv-bars .hover text { fill: rgba(0,0,0,1); } .nvd3 .nv-multibar .nv-groups rect, .nvd3 .nv-multibarHorizontal .nv-groups rect, .nvd3 .nv-discretebar .nv-groups rect { stroke-opacity: 0; transition: fill-opacity 250ms linear; } .nvd3 .nv-multibar .nv-groups rect:hover, .nvd3 .nv-multibarHorizontal .nv-groups rect:hover, .nvd3 .nv-candlestickBar .nv-ticks rect:hover, .nvd3 .nv-discretebar .nv-groups rect:hover { fill-opacity: 1; } .nvd3 .nv-discretebar .nv-groups text, .nvd3 .nv-multibarHorizontal .nv-groups text { font-weight: bold; fill: rgba(0,0,0,1); stroke: rgba(0,0,0,0); } /* boxplot CSS */ .nvd3 .nv-boxplot circle { fill-opacity: 0.5; } .nvd3 .nv-boxplot circle:hover { fill-opacity: 1; } .nvd3 .nv-boxplot rect:hover { fill-opacity: 1; } .nvd3 line.nv-boxplot-median { stroke: black; } .nv-boxplot-tick:hover { stroke-width: 2.5px; } /* bullet */ .nvd3.nv-bullet { font: 10px sans-serif; } .nvd3.nv-bullet .nv-measure { fill-opacity: .8; } .nvd3.nv-bullet .nv-measure:hover { fill-opacity: 1; } .nvd3.nv-bullet .nv-marker { stroke: #000; stroke-width: 2px; } .nvd3.nv-bullet .nv-markerTriangle { stroke: #000; fill: #fff; stroke-width: 1.5px; } .nvd3.nv-bullet .nv-markerLine { stroke: #000; stroke-width: 1.5px; } .nvd3.nv-bullet .nv-tick line { stroke: #666; stroke-width: .5px; } .nvd3.nv-bullet .nv-range.nv-s0 { fill: #eee; } .nvd3.nv-bullet .nv-range.nv-s1 { fill: #ddd; } .nvd3.nv-bullet .nv-range.nv-s2 { fill: #ccc; } .nvd3.nv-bullet .nv-title { font-size: 14px; font-weight: bold; } .nvd3.nv-bullet .nv-subtitle { fill: #999; } .nvd3.nv-bullet .nv-range { fill: #bababa; fill-opacity: .4; } .nvd3.nv-bullet .nv-range:hover { fill-opacity: .7; } .nvd3.nv-candlestickBar .nv-ticks .nv-tick { stroke-width: 1px; } .nvd3.nv-candlestickBar .nv-ticks .nv-tick.hover { stroke-width: 2px; } .nvd3.nv-candlestickBar .nv-ticks .nv-tick.positive rect { stroke: #2ca02c; fill: #2ca02c; } .nvd3.nv-candlestickBar .nv-ticks .nv-tick.negative rect { stroke: #d62728; fill: #d62728; } .with-transitions .nv-candlestickBar .nv-ticks .nv-tick { transition: stroke-width 250ms linear, stroke-opacity 250ms linear; } .nvd3.nv-candlestickBar .nv-ticks line { stroke: #333; } .nv-force-node { stroke: #fff; stroke-width: 1.5px; } .nv-force-link { stroke: #999; stroke-opacity: .6; } .nv-force-node text { stroke-width: 0px; } .nvd3 .nv-legend .nv-disabled rect { /*fill-opacity: 0;*/ } .nvd3 .nv-check-box .nv-box { fill-opacity:0; stroke-width:2; } .nvd3 .nv-check-box .nv-check { fill-opacity:0; stroke-width:4; } .nvd3 .nv-series.nv-disabled .nv-check-box .nv-check { fill-opacity:0; stroke-opacity:0; } .nvd3 .nv-controlsWrap .nv-legend .nv-check-box .nv-check { opacity: 0; } /* line plus bar */ .nvd3.nv-linePlusBar .nv-bar rect { fill-opacity: .75; } .nvd3.nv-linePlusBar .nv-bar rect:hover { fill-opacity: 1; } .nvd3 .nv-groups path.nv-line { fill: none; } .nvd3 .nv-groups path.nv-area { stroke: none; } .nvd3.nv-line .nvd3.nv-scatter .nv-groups .nv-point { fill-opacity: 0; stroke-opacity: 0; } .nvd3.nv-scatter.nv-single-point .nv-groups .nv-point { fill-opacity: .5 !important; stroke-opacity: .5 !important; } .with-transitions .nvd3 .nv-groups .nv-point { transition: stroke-width 250ms linear, stroke-opacity 250ms linear; } .nvd3.nv-scatter .nv-groups .nv-point.hover, .nvd3 .nv-groups .nv-point.hover { stroke-width: 7px; fill-opacity: .95 !important; stroke-opacity: .95 !important; } .nvd3 .nv-point-paths path { stroke: #aaa; stroke-opacity: 0; fill: #eee; fill-opacity: 0; } .nvd3 .nv-indexLine { cursor: ew-resize; } /******************** * SVG CSS */ /******************** Default CSS for an svg element nvd3 used */ svg.nvd3-svg { -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; display: block; width:100%; height:100%; } /******************** Box shadow and border radius styling */ .nvtooltip.with-3d-shadow, .with-3d-shadow .nvtooltip { box-shadow: 0 5px 10px rgba(0,0,0,.2); border-radius: 5px; } .nvd3 text { font: normal 12px Arial, sans-serif; } .nvd3 .title { font: bold 14px Arial, sans-serif; } .nvd3 .nv-background { fill: white; fill-opacity: 0; } .nvd3.nv-noData { font-size: 18px; font-weight: bold; } /********** * Brush */ .nv-brush .extent { fill-opacity: .125; shape-rendering: crispEdges; } .nv-brush .resize path { fill: #eee; stroke: #666; } /********** * Legend */ .nvd3 .nv-legend .nv-series { cursor: pointer; } .nvd3 .nv-legend .nv-disabled circle { fill-opacity: 0; } /* focus */ .nvd3 .nv-brush .extent { fill-opacity: 0 !important; } .nvd3 .nv-brushBackground rect { stroke: #000; stroke-width: .4; fill: #fff; fill-opacity: .7; } /********** * Print */ @media print { .nvd3 text { stroke-width: 0; fill-opacity: 1; } } .nvd3.nv-ohlcBar .nv-ticks .nv-tick { stroke-width: 1px; } .nvd3.nv-ohlcBar .nv-ticks .nv-tick.hover { stroke-width: 2px; } .nvd3.nv-ohlcBar .nv-ticks .nv-tick.positive { stroke: #2ca02c; } .nvd3.nv-ohlcBar .nv-ticks .nv-tick.negative { stroke: #d62728; } .nvd3 .background path { fill: none; stroke: #EEE; stroke-opacity: .4; shape-rendering: crispEdges; } .nvd3 .foreground path { fill: none; stroke-opacity: .7; } .nvd3 .nv-parallelCoordinates-brush .extent { fill: #fff; fill-opacity: .6; stroke: gray; shape-rendering: crispEdges; } .nvd3 .nv-parallelCoordinates .hover { fill-opacity: 1; stroke-width: 3px; } .nvd3 .missingValuesline line { fill: none; stroke: black; stroke-width: 1; stroke-opacity: 1; stroke-dasharray: 5, 5; } .nvd3.nv-pie path { stroke-opacity: 0; transition: fill-opacity 250ms linear, stroke-width 250ms linear, stroke-opacity 250ms linear; } .nvd3.nv-pie .nv-pie-title { font-size: 24px; fill: rgba(19, 196, 249, 0.59); } .nvd3.nv-pie .nv-slice text { stroke: #000; stroke-width: 0; } .nvd3.nv-pie path { stroke: #fff; stroke-width: 1px; stroke-opacity: 1; } .nvd3.nv-pie path { fill-opacity: .7; } .nvd3.nv-pie .hover path { fill-opacity: 1; } .nvd3.nv-pie .nv-label { pointer-events: none; } .nvd3.nv-pie .nv-label rect { fill-opacity: 0; stroke-opacity: 0; } /* scatter */ .nvd3 .nv-groups .nv-point.hover { stroke-width: 20px; stroke-opacity: .5; } .nvd3 .nv-scatter .nv-point.hover { fill-opacity: 1; } .nv-noninteractive { pointer-events: none; } .nv-distx, .nv-disty { pointer-events: none; } /* sparkline */ .nvd3.nv-sparkline path { fill: none; } .nvd3.nv-sparklineplus g.nv-hoverValue { pointer-events: none; } .nvd3.nv-sparklineplus .nv-hoverValue line { stroke: #333; stroke-width: 1.5px; } .nvd3.nv-sparklineplus, .nvd3.nv-sparklineplus g { pointer-events: all; } .nvd3 .nv-hoverArea { fill-opacity: 0; stroke-opacity: 0; } .nvd3.nv-sparklineplus .nv-xValue, .nvd3.nv-sparklineplus .nv-yValue { stroke-width: 0; font-size: .9em; font-weight: normal; } .nvd3.nv-sparklineplus .nv-yValue { stroke: #f66; } .nvd3.nv-sparklineplus .nv-maxValue { stroke: #2ca02c; fill: #2ca02c; } .nvd3.nv-sparklineplus .nv-minValue { stroke: #d62728; fill: #d62728; } .nvd3.nv-sparklineplus .nv-currentValue { font-weight: bold; font-size: 1.1em; } /* stacked area */ .nvd3.nv-stackedarea path.nv-area { fill-opacity: .7; stroke-opacity: 0; transition: fill-opacity 250ms linear, stroke-opacity 250ms linear; } .nvd3.nv-stackedarea path.nv-area.hover { fill-opacity: .9; } .nvd3.nv-stackedarea .nv-groups .nv-point { stroke-opacity: 0; fill-opacity: 0; } .nvtooltip { position: absolute; background-color: rgba(255,255,255,1.0); color: rgba(0,0,0,1.0); padding: 1px; border: 1px solid rgba(0,0,0,.2); z-index: 10000; display: block; font-family: Arial, sans-serif; font-size: 13px; text-align: left; pointer-events: none; white-space: nowrap; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } .nvtooltip { background: rgba(255,255,255, 0.8); border: 1px solid rgba(0,0,0,0.5); border-radius: 4px; } /*Give tooltips that old fade in transition by putting a "with-transitions" class on the container div. */ .nvtooltip.with-transitions, .with-transitions .nvtooltip { transition: opacity 50ms linear; transition-delay: 200ms; } .nvtooltip.x-nvtooltip, .nvtooltip.y-nvtooltip { padding: 8px; } .nvtooltip h3 { margin: 0; padding: 4px 14px; line-height: 18px; font-weight: normal; background-color: rgba(247,247,247,0.75); color: rgba(0,0,0,1.0); text-align: center; border-bottom: 1px solid #ebebeb; border-radius: 5px 5px 0 0; } .nvtooltip p { margin: 0; padding: 5px 14px; text-align: center; } .nvtooltip span { display: inline-block; margin: 2px 0; } .nvtooltip table { margin: 6px; border-spacing:0; } .nvtooltip table td { padding: 2px 9px 2px 0; vertical-align: middle; } .nvtooltip table td.key { font-weight: normal; } .nvtooltip table td.key.total { font-weight: bold; } .nvtooltip table td.value { text-align: right; font-weight: bold; } .nvtooltip table td.percent { color: darkgray; } .nvtooltip table tr.highlight td { padding: 1px 9px 1px 0; border-bottom-style: solid; border-bottom-width: 1px; border-top-style: solid; border-top-width: 1px; } .nvtooltip table td.legend-color-guide div { width: 8px; height: 8px; vertical-align: middle; } .nvtooltip table td.legend-color-guide div { width: 12px; height: 12px; border: 1px solid #999; } .nvtooltip .footer { padding: 3px; text-align: center; } .nvtooltip-pending-removal { pointer-events: none; display: none; } /**** Interactive Layer */ .nvd3 .nv-interactiveGuideLine { pointer-events:none; } .nvd3 line.nv-guideline { stroke: #ccc; } ================================================ FILE: build/nv.d3.js ================================================ /* nvd3 version 1.8.6-dev (https://github.com/novus/nvd3) 2018-02-24 */ (function(){ // set up main nv object var nv = {}; // the major global objects under the nv namespace nv.dev = false; //set false when in production nv.tooltip = nv.tooltip || {}; // For the tooltip system nv.utils = nv.utils || {}; // Utility subsystem nv.models = nv.models || {}; //stores all the possible models/components nv.charts = {}; //stores all the ready to use charts nv.logs = {}; //stores some statistics and potential error messages nv.dom = {}; //DOM manipulation functions // Node/CommonJS - require D3 if (typeof(module) !== 'undefined' && typeof(exports) !== 'undefined' && typeof(d3) == 'undefined') { d3 = require('d3'); } nv.dispatch = d3.dispatch('render_start', 'render_end'); // Function bind polyfill // Needed ONLY for phantomJS as it's missing until version 2.0 which is unreleased as of this comment // https://github.com/ariya/phantomjs/issues/10522 // http://kangax.github.io/compat-table/es5/#Function.prototype.bind // phantomJS is used for running the test suite if (!Function.prototype.bind) { Function.prototype.bind = function (oThis) { if (typeof this !== "function") { // closest thing possible to the ECMAScript 5 internal IsCallable function throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable"); } var aArgs = Array.prototype.slice.call(arguments, 1), fToBind = this, fNOP = function () {}, fBound = function () { return fToBind.apply(this instanceof fNOP && oThis ? this : oThis, aArgs.concat(Array.prototype.slice.call(arguments))); }; fNOP.prototype = this.prototype; fBound.prototype = new fNOP(); return fBound; }; } // Development render timers - disabled if dev = false if (nv.dev) { nv.dispatch.on('render_start', function(e) { nv.logs.startTime = +new Date(); }); nv.dispatch.on('render_end', function(e) { nv.logs.endTime = +new Date(); nv.logs.totalTime = nv.logs.endTime - nv.logs.startTime; nv.log('total', nv.logs.totalTime); // used for development, to keep track of graph generation times }); } // Logs all arguments, and returns the last so you can test things in place // Note: in IE8 console.log is an object not a function, and if modernizr is used // then calling Function.prototype.bind with with anything other than a function // causes a TypeError to be thrown. nv.log = function() { if (nv.dev && window.console && console.log && console.log.apply) console.log.apply(console, arguments); else if (nv.dev && window.console && typeof console.log == "function" && Function.prototype.bind) { var log = Function.prototype.bind.call(console.log, console); log.apply(console, arguments); } return arguments[arguments.length - 1]; }; // print console warning, should be used by deprecated functions nv.deprecated = function(name, info) { if (console && console.warn) { console.warn('nvd3 warning: `' + name + '` has been deprecated. ', info || ''); } }; // The nv.render function is used to queue up chart rendering // in non-blocking async functions. // When all queued charts are done rendering, nv.dispatch.render_end is invoked. nv.render = function render(step) { // number of graphs to generate in each timeout loop step = step || 1; nv.render.active = true; nv.dispatch.render_start(); var renderLoop = function() { var chart, graph; for (var i = 0; i < step && (graph = nv.render.queue[i]); i++) { chart = graph.generate(); if (typeof graph.callback == typeof(Function)) graph.callback(chart); } nv.render.queue.splice(0, i); if (nv.render.queue.length) { setTimeout(renderLoop); } else { nv.dispatch.render_end(); nv.render.active = false; } }; setTimeout(renderLoop); }; nv.render.active = false; nv.render.queue = []; /* Adds a chart to the async rendering queue. This method can take arguments in two forms: nv.addGraph({ generate: callback: }) or nv.addGraph(, ) The generate function should contain code that creates the NVD3 model, sets options on it, adds data to an SVG element, and invokes the chart model. The generate function should return the chart model. See examples/lineChart.html for a usage example. The callback function is optional, and it is called when the generate function completes. */ nv.addGraph = function(obj) { if (typeof arguments[0] === typeof(Function)) { obj = {generate: arguments[0], callback: arguments[1]}; } nv.render.queue.push(obj); if (!nv.render.active) { nv.render(); } }; // Node/CommonJS exports if (typeof(module) !== 'undefined' && typeof(exports) !== 'undefined') { module.exports = nv; } if (typeof(window) !== 'undefined') { window.nv = nv; } /* Facade for queueing DOM write operations * with Fastdom (https://github.com/wilsonpage/fastdom) * if available. * This could easily be extended to support alternate * implementations in the future. */ nv.dom.write = function(callback) { if (window.fastdom !== undefined) { return fastdom.mutate(callback); } return callback(); }; /* Facade for queueing DOM read operations * with Fastdom (https://github.com/wilsonpage/fastdom) * if available. * This could easily be extended to support alternate * implementations in the future. */ nv.dom.read = function(callback) { if (window.fastdom !== undefined) { return fastdom.measure(callback); } return callback(); }; /* Utility class to handle creation of an interactive layer. This places a rectangle on top of the chart. When you mouse move over it, it sends a dispatch containing the X-coordinate. It can also render a vertical line where the mouse is located. dispatch.elementMousemove is the important event to latch onto. It is fired whenever the mouse moves over the rectangle. The dispatch is given one object which contains the mouseX/Y location. It also has 'pointXValue', which is the conversion of mouseX to the x-axis scale. */ nv.interactiveGuideline = function() { "use strict"; var margin = { left: 0, top: 0 } //Pass the chart's top and left magins. Used to calculate the mouseX/Y. , width = null , height = null , xScale = d3.scale.linear() , dispatch = d3.dispatch('elementMousemove', 'elementMouseout', 'elementClick', 'elementDblclick', 'elementMouseDown', 'elementMouseUp') , showGuideLine = true , svgContainer = null // Must pass the chart's svg, we'll use its mousemove event. , tooltip = nv.models.tooltip() , isMSIE = window.ActiveXObject// Checkt if IE by looking for activeX. (excludes IE11) ; tooltip .duration(0) .hideDelay(0) .hidden(false); function layer(selection) { selection.each(function(data) { var container = d3.select(this); var availableWidth = (width || 960), availableHeight = (height || 400); var wrap = container.selectAll("g.nv-wrap.nv-interactiveLineLayer") .data([data]); var wrapEnter = wrap.enter() .append("g").attr("class", " nv-wrap nv-interactiveLineLayer"); wrapEnter.append("g").attr("class","nv-interactiveGuideLine"); if (!svgContainer) { return; } function mouseHandler() { var mouseX = d3.event.clientX - this.getBoundingClientRect().left; var mouseY = d3.event.clientY - this.getBoundingClientRect().top; var subtractMargin = true; var mouseOutAnyReason = false; if (isMSIE) { /* D3.js (or maybe SVG.getScreenCTM) has a nasty bug in Internet Explorer 10. d3.mouse() returns incorrect X,Y mouse coordinates when mouse moving over a rect in IE 10. However, d3.event.offsetX/Y also returns the mouse coordinates relative to the triggering . So we use offsetX/Y on IE. */ mouseX = d3.event.offsetX; mouseY = d3.event.offsetY; /* On IE, if you attach a mouse event listener to the container, it will actually trigger it for all the child elements (like , , etc). When this happens on IE, the offsetX/Y is set to where ever the child element is located. As a result, we do NOT need to subtract margins to figure out the mouse X/Y position under this scenario. Removing the line below *will* cause the interactive layer to not work right on IE. */ if(d3.event.target.tagName !== "svg") { subtractMargin = false; } if (d3.event.target.className.baseVal.match("nv-legend")) { mouseOutAnyReason = true; } } if(subtractMargin) { mouseX -= margin.left; mouseY -= margin.top; } /* If mouseX/Y is outside of the chart's bounds, trigger a mouseOut event. */ if (d3.event.type === 'mouseout' || mouseX < 0 || mouseY < 0 || mouseX > availableWidth || mouseY > availableHeight || (d3.event.relatedTarget && d3.event.relatedTarget.ownerSVGElement === undefined) || mouseOutAnyReason ) { if (isMSIE) { if (d3.event.relatedTarget && d3.event.relatedTarget.ownerSVGElement === undefined && (d3.event.relatedTarget.className === undefined || d3.event.relatedTarget.className.match(tooltip.nvPointerEventsClass))) { return; } } dispatch.elementMouseout({ mouseX: mouseX, mouseY: mouseY }); layer.renderGuideLine(null); //hide the guideline tooltip.hidden(true); return; } else { tooltip.hidden(false); } var scaleIsOrdinal = typeof xScale.rangeBands === 'function'; var pointXValue = undefined; // Ordinal scale has no invert method if (scaleIsOrdinal) { var elementIndex = d3.bisect(xScale.range(), mouseX) - 1; // Check if mouseX is in the range band if (xScale.range()[elementIndex] + xScale.rangeBand() >= mouseX) { pointXValue = xScale.domain()[d3.bisect(xScale.range(), mouseX) - 1]; } else { dispatch.elementMouseout({ mouseX: mouseX, mouseY: mouseY }); layer.renderGuideLine(null); //hide the guideline tooltip.hidden(true); return; } } else { pointXValue = xScale.invert(mouseX); } dispatch.elementMousemove({ mouseX: mouseX, mouseY: mouseY, pointXValue: pointXValue }); //If user double clicks the layer, fire a elementDblclick if (d3.event.type === "dblclick") { dispatch.elementDblclick({ mouseX: mouseX, mouseY: mouseY, pointXValue: pointXValue }); } // if user single clicks the layer, fire elementClick if (d3.event.type === 'click') { dispatch.elementClick({ mouseX: mouseX, mouseY: mouseY, pointXValue: pointXValue }); } // if user presses mouse down the layer, fire elementMouseDown if (d3.event.type === 'mousedown') { dispatch.elementMouseDown({ mouseX: mouseX, mouseY: mouseY, pointXValue: pointXValue }); } // if user presses mouse down the layer, fire elementMouseUp if (d3.event.type === 'mouseup') { dispatch.elementMouseUp({ mouseX: mouseX, mouseY: mouseY, pointXValue: pointXValue }); } } svgContainer .on("touchmove",mouseHandler) .on("mousemove",mouseHandler, true) .on("mouseout" ,mouseHandler,true) .on("mousedown" ,mouseHandler,true) .on("mouseup" ,mouseHandler,true) .on("dblclick" ,mouseHandler) .on("click", mouseHandler) ; layer.guideLine = null; //Draws a vertical guideline at the given X postion. layer.renderGuideLine = function(x) { if (!showGuideLine) return; if (layer.guideLine && layer.guideLine.attr("x1") === x) return; nv.dom.write(function() { var line = wrap.select(".nv-interactiveGuideLine") .selectAll("line") .data((x != null) ? [nv.utils.NaNtoZero(x)] : [], String); line.enter() .append("line") .attr("class", "nv-guideline") .attr("x1", function(d) { return d;}) .attr("x2", function(d) { return d;}) .attr("y1", availableHeight) .attr("y2",0); line.exit().remove(); }); } }); } layer.dispatch = dispatch; layer.tooltip = tooltip; layer.margin = function(_) { if (!arguments.length) return margin; margin.top = typeof _.top != 'undefined' ? _.top : margin.top; margin.left = typeof _.left != 'undefined' ? _.left : margin.left; return layer; }; layer.width = function(_) { if (!arguments.length) return width; width = _; return layer; }; layer.height = function(_) { if (!arguments.length) return height; height = _; return layer; }; layer.xScale = function(_) { if (!arguments.length) return xScale; xScale = _; return layer; }; layer.showGuideLine = function(_) { if (!arguments.length) return showGuideLine; showGuideLine = _; return layer; }; layer.svgContainer = function(_) { if (!arguments.length) return svgContainer; svgContainer = _; return layer; }; return layer; }; /* Utility class that uses d3.bisect to find the index in a given array, where a search value can be inserted. This is different from normal bisectLeft; this function finds the nearest index to insert the search value. For instance, lets say your array is [1,2,3,5,10,30], and you search for 28. Normal d3.bisectLeft will return 4, because 28 is inserted after the number 10. But interactiveBisect will return 5 because 28 is closer to 30 than 10. Unit tests can be found in: interactiveBisectTest.html Has the following known issues: * Will not work if the data points move backwards (ie, 10,9,8,7, etc) or if the data points are in random order. * Won't work if there are duplicate x coordinate values. */ nv.interactiveBisect = function (values, searchVal, xAccessor) { "use strict"; if (! (values instanceof Array)) { return null; } var _xAccessor; if (typeof xAccessor !== 'function') { _xAccessor = function(d) { return d.x; } } else { _xAccessor = xAccessor; } var _cmp = function(d, v) { // Accessors are no longer passed the index of the element along with // the element itself when invoked by d3.bisector. // // Starting at D3 v3.4.4, d3.bisector() started inspecting the // function passed to determine if it should consider it an accessor // or a comparator. This meant that accessors that take two arguments // (expecting an index as the second parameter) are treated as // comparators where the second argument is the search value against // which the first argument is compared. return _xAccessor(d) - v; }; var bisect = d3.bisector(_cmp).left; var index = d3.max([0, bisect(values,searchVal) - 1]); var currentValue = _xAccessor(values[index]); if (typeof currentValue === 'undefined') { currentValue = index; } if (currentValue === searchVal) { return index; //found exact match } var nextIndex = d3.min([index+1, values.length - 1]); var nextValue = _xAccessor(values[nextIndex]); if (typeof nextValue === 'undefined') { nextValue = nextIndex; } if (Math.abs(nextValue - searchVal) >= Math.abs(currentValue - searchVal)) { return index; } else { return nextIndex } }; /* Returns the index in the array "values" that is closest to searchVal. Only returns an index if searchVal is within some "threshold". Otherwise, returns null. */ nv.nearestValueIndex = function (values, searchVal, threshold) { "use strict"; var yDistMax = Infinity, indexToHighlight = null; values.forEach(function(d,i) { var delta = Math.abs(searchVal - d); if ( d != null && delta <= yDistMax && delta < threshold) { yDistMax = delta; indexToHighlight = i; } }); return indexToHighlight; }; /* Model which can be instantiated to handle tooltip rendering. Example usage: var tip = nv.models.tooltip().gravity('w').distance(23) .data(myDataObject); tip(); //just invoke the returned function to render tooltip. */ nv.models.tooltip = function() { "use strict"; /* Tooltip data. If data is given in the proper format, a consistent tooltip is generated. Example Format of data: { key: "Date", value: "August 2009", series: [ {key: "Series 1", value: "Value 1", color: "#000"}, {key: "Series 2", value: "Value 2", color: "#00f"} ] } */ var id = "nvtooltip-" + Math.floor(Math.random() * 100000) // Generates a unique id when you create a new tooltip() object. , data = null , gravity = 'w' // Can be 'n','s','e','w'. Determines how tooltip is positioned. , distance = 25 // Distance to offset tooltip from the mouse location. , snapDistance = 0 // Tolerance allowed before tooltip is moved from its current position (creates 'snapping' effect) , classes = null // Attaches additional CSS classes to the tooltip DIV that is created. , hidden = true // Start off hidden, toggle with hide/show functions below. , hideDelay = 200 // Delay (in ms) before the tooltip hides after calling hide(). , tooltip = null // d3 select of the tooltip div. , lastPosition = { left: null, top: null } // Last position the tooltip was in. , enabled = true // True -> tooltips are rendered. False -> don't render tooltips. , duration = 100 // Tooltip movement duration, in ms. , headerEnabled = true // If is to show the tooltip header. , nvPointerEventsClass = "nv-pointer-events-none" // CSS class to specify whether element should not have mouse events. ; // Format function for the tooltip values column. // d is value, // i is series index // p is point containing the value var valueFormatter = function(d, i, p) { return d; }; // Format function for the tooltip header value. var headerFormatter = function(d) { return d; }; var keyFormatter = function(d, i) { return d; }; // By default, the tooltip model renders a beautiful table inside a DIV, returned as HTML // You can override this function if a custom tooltip is desired. For instance, you could directly manipulate // the DOM by accessing elem and returning false. var contentGenerator = function(d, elem) { if (d === null) { return ''; } var table = d3.select(document.createElement("table")); if (headerEnabled) { var theadEnter = table.selectAll("thead") .data([d]) .enter().append("thead"); theadEnter.append("tr") .append("td") .attr("colspan", 3) .append("strong") .classed("x-value", true) .html(headerFormatter(d.value)); } var tbodyEnter = table.selectAll("tbody") .data([d]) .enter().append("tbody"); var trowEnter = tbodyEnter.selectAll("tr") .data(function(p) { return p.series}) .enter() .append("tr") .classed("highlight", function(p) { return p.highlight}); trowEnter.append("td") .classed("legend-color-guide",true) .append("div") .style("background-color", function(p) { return p.color}); trowEnter.append("td") .classed("key",true) .classed("total",function(p) { return !!p.total}) .html(function(p, i) { return keyFormatter(p.key, i)}); trowEnter.append("td") .classed("value",true) .html(function(p, i) { return valueFormatter(p.value, i, p) }); trowEnter.filter(function (p,i) { return p.percent !== undefined }).append("td") .classed("percent", true) .html(function(p, i) { return "(" + d3.format('%')(p.percent) + ")" }); trowEnter.selectAll("td").each(function(p) { if (p.highlight) { var opacityScale = d3.scale.linear().domain([0,1]).range(["#fff",p.color]); var opacity = 0.6; d3.select(this) .style("border-bottom-color", opacityScale(opacity)) .style("border-top-color", opacityScale(opacity)) ; } }); var html = table.node().outerHTML; if (d.footer !== undefined) html += ""; return html; }; /* Function that returns the position (relative to the viewport/document.body) the tooltip should be placed in. Should return: { left: , top: } */ var position = function() { var pos = { left: d3.event !== null ? d3.event.clientX : 0, top: d3.event !== null ? d3.event.clientY : 0 }; if(getComputedStyle(document.body).transform != 'none') { // Take the offset into account, as now the tooltip is relative // to document.body. var client = document.body.getBoundingClientRect(); pos.left -= client.left; pos.top -= client.top; } return pos; }; var dataSeriesExists = function(d) { if (d && d.series) { if (nv.utils.isArray(d.series)) { return true; } // if object, it's okay just convert to array of the object if (nv.utils.isObject(d.series)) { d.series = [d.series]; return true; } } return false; }; // Calculates the gravity offset of the tooltip. Parameter is position of tooltip // relative to the viewport. var calcGravityOffset = function(pos) { var height = tooltip.node().offsetHeight, width = tooltip.node().offsetWidth, clientWidth = document.documentElement.clientWidth, // Don't want scrollbars. clientHeight = document.documentElement.clientHeight, // Don't want scrollbars. left, top, tmp; // calculate position based on gravity switch (gravity) { case 'e': left = - width - distance; top = - (height / 2); if(pos.left + left < 0) left = distance; if((tmp = pos.top + top) < 0) top -= tmp; if((tmp = pos.top + top + height) > clientHeight) top -= tmp - clientHeight; break; case 'w': left = distance; top = - (height / 2); if (pos.left + left + width > clientWidth) left = - width - distance; if ((tmp = pos.top + top) < 0) top -= tmp; if ((tmp = pos.top + top + height) > clientHeight) top -= tmp - clientHeight; break; case 'n': left = - (width / 2) - 5; // - 5 is an approximation of the mouse's height. top = distance; if (pos.top + top + height > clientHeight) top = - height - distance; if ((tmp = pos.left + left) < 0) left -= tmp; if ((tmp = pos.left + left + width) > clientWidth) left -= tmp - clientWidth; break; case 's': left = - (width / 2); top = - height - distance; if (pos.top + top < 0) top = distance; if ((tmp = pos.left + left) < 0) left -= tmp; if ((tmp = pos.left + left + width) > clientWidth) left -= tmp - clientWidth; break; case 'center': left = - (width / 2); top = - (height / 2); break; default: left = 0; top = 0; break; } return { 'left': left, 'top': top }; }; /* Positions the tooltip in the correct place, as given by the position() function. */ var positionTooltip = function() { nv.dom.read(function() { var pos = position(), gravityOffset = calcGravityOffset(pos), left = pos.left + gravityOffset.left, top = pos.top + gravityOffset.top; // delay hiding a bit to avoid flickering if (hidden) { tooltip .interrupt() .transition() .delay(hideDelay) .duration(0) .style('opacity', 0); } else { // using tooltip.style('transform') returns values un-usable for tween var old_translate = 'translate(' + lastPosition.left + 'px, ' + lastPosition.top + 'px)'; var new_translate = 'translate(' + Math.round(left) + 'px, ' + Math.round(top) + 'px)'; var translateInterpolator = d3.interpolateString(old_translate, new_translate); var is_hidden = tooltip.style('opacity') < 0.1; tooltip .interrupt() // cancel running transitions .transition() .duration(is_hidden ? 0 : duration) // using tween since some versions of d3 can't auto-tween a translate on a div .styleTween('transform', function (d) { return translateInterpolator; }, 'important') // Safari has its own `-webkit-transform` and does not support `transform` .styleTween('-webkit-transform', function (d) { return translateInterpolator; }) .style('-ms-transform', new_translate) .style('opacity', 1); } lastPosition.left = left; lastPosition.top = top; }); }; // Creates new tooltip container, or uses existing one on DOM. function initTooltip() { if (!tooltip || !tooltip.node()) { // Create new tooltip div if it doesn't exist on DOM. var data = [1]; tooltip = d3.select(document.body).selectAll('#'+id).data(data); tooltip.enter().append('div') .attr("class", "nvtooltip " + (classes ? classes : "xy-tooltip")) .attr("id", id) .style("top", 0).style("left", 0) .style('opacity', 0) .style('position', 'absolute') .selectAll("div, table, td, tr").classed(nvPointerEventsClass, true) .classed(nvPointerEventsClass, true); tooltip.exit().remove() } } // Draw the tooltip onto the DOM. function nvtooltip() { if (!enabled) return; if (!dataSeriesExists(data)) return; nv.dom.write(function () { initTooltip(); // Generate data and set it into tooltip. // Bonus - If you override contentGenerator and return false, you can use something like // Angular, React or Knockout to bind the data for your tooltip directly to the DOM. var newContent = contentGenerator(data, tooltip.node()); if (newContent) { tooltip.node().innerHTML = newContent; } positionTooltip(); }); return nvtooltip; } nvtooltip.nvPointerEventsClass = nvPointerEventsClass; nvtooltip.options = nv.utils.optionsFunc.bind(nvtooltip); nvtooltip._options = Object.create({}, { // simple read/write options duration: {get: function(){return duration;}, set: function(_){duration=_;}}, gravity: {get: function(){return gravity;}, set: function(_){gravity=_;}}, distance: {get: function(){return distance;}, set: function(_){distance=_;}}, snapDistance: {get: function(){return snapDistance;}, set: function(_){snapDistance=_;}}, classes: {get: function(){return classes;}, set: function(_){classes=_;}}, enabled: {get: function(){return enabled;}, set: function(_){enabled=_;}}, hideDelay: {get: function(){return hideDelay;}, set: function(_){hideDelay=_;}}, contentGenerator: {get: function(){return contentGenerator;}, set: function(_){contentGenerator=_;}}, valueFormatter: {get: function(){return valueFormatter;}, set: function(_){valueFormatter=_;}}, headerFormatter: {get: function(){return headerFormatter;}, set: function(_){headerFormatter=_;}}, keyFormatter: {get: function(){return keyFormatter;}, set: function(_){keyFormatter=_;}}, headerEnabled: {get: function(){return headerEnabled;}, set: function(_){headerEnabled=_;}}, position: {get: function(){return position;}, set: function(_){position=_;}}, // Deprecated options chartContainer: {get: function(){return document.body;}, set: function(_){ // deprecated after 1.8.3 nv.deprecated('chartContainer', 'feature removed after 1.8.3'); }}, fixedTop: {get: function(){return null;}, set: function(_){ // deprecated after 1.8.1 nv.deprecated('fixedTop', 'feature removed after 1.8.1'); }}, offset: {get: function(){return {left: 0, top: 0};}, set: function(_){ // deprecated after 1.8.1 nv.deprecated('offset', 'use chart.tooltip.distance() instead'); }}, // options with extra logic hidden: {get: function(){return hidden;}, set: function(_){ if (hidden != _) { hidden = !!_; nvtooltip(); } }}, data: {get: function(){return data;}, set: function(_){ // if showing a single data point, adjust data format with that if (_.point) { _.value = _.point.x; _.series = _.series || {}; _.series.value = _.point.y; _.series.color = _.point.color || _.series.color; } data = _; }}, // read only properties node: {get: function(){return tooltip.node();}, set: function(_){}}, id: {get: function(){return id;}, set: function(_){}} }); nv.utils.initOptions(nvtooltip); return nvtooltip; }; /* Gets the browser window size Returns object with height and width properties */ nv.utils.windowSize = function() { // Sane defaults var size = {width: 640, height: 480}; // Most recent browsers use if (window.innerWidth && window.innerHeight) { size.width = window.innerWidth; size.height = window.innerHeight; return (size); } // IE can use depending on mode it is in if (document.compatMode=='CSS1Compat' && document.documentElement && document.documentElement.offsetWidth ) { size.width = document.documentElement.offsetWidth; size.height = document.documentElement.offsetHeight; return (size); } // Earlier IE uses Doc.body if (document.body && document.body.offsetWidth) { size.width = document.body.offsetWidth; size.height = document.body.offsetHeight; return (size); } return (size); }; /* handle dumb browser quirks... isinstance breaks if you use frames typeof returns 'object' for null, NaN is a number, etc. */ nv.utils.isArray = Array.isArray; nv.utils.isObject = function(a) { return a !== null && typeof a === 'object'; }; nv.utils.isFunction = function(a) { return typeof a === 'function'; }; nv.utils.isDate = function(a) { return toString.call(a) === '[object Date]'; }; nv.utils.isNumber = function(a) { return !isNaN(a) && typeof a === 'number'; }; /* Binds callback function to run when window is resized */ nv.utils.windowResize = function(handler) { if (window.addEventListener) { window.addEventListener('resize', handler); } else { nv.log("ERROR: Failed to bind to window.resize with: ", handler); } // return object with clear function to remove the single added callback. return { callback: handler, clear: function() { window.removeEventListener('resize', handler); } } }; /* Backwards compatible way to implement more d3-like coloring of graphs. Can take in nothing, an array, or a function/scale To use a normal scale, get the range and pass that because we must be able to take two arguments and use the index to keep backward compatibility */ nv.utils.getColor = function(color) { //if you pass in nothing, get default colors back if (color === undefined) { return nv.utils.defaultColor(); //if passed an array, turn it into a color scale } else if(nv.utils.isArray(color)) { var color_scale = d3.scale.ordinal().range(color); return function(d, i) { var key = i === undefined ? d : i; return d.color || color_scale(key); }; //if passed a function or scale, return it, or whatever it may be //external libs, such as angularjs-nvd3-directives use this } else { //can't really help it if someone passes rubbish as color return color; } }; /* Default color chooser uses a color scale of 20 colors from D3 https://github.com/mbostock/d3/wiki/Ordinal-Scales#categorical-colors */ nv.utils.defaultColor = function() { // get range of the scale so we'll turn it into our own function. return nv.utils.getColor(d3.scale.category20().range()); }; /* Returns a color function that takes the result of 'getKey' for each series and looks for a corresponding color from the dictionary */ nv.utils.customTheme = function(dictionary, getKey, defaultColors) { // use default series.key if getKey is undefined getKey = getKey || function(series) { return series.key }; defaultColors = defaultColors || d3.scale.category20().range(); // start at end of default color list and walk back to index 0 var defIndex = defaultColors.length; return function(series, index) { var key = getKey(series); if (nv.utils.isFunction(dictionary[key])) { return dictionary[key](); } else if (dictionary[key] !== undefined) { return dictionary[key]; } else { // no match in dictionary, use a default color if (!defIndex) { // used all the default colors, start over defIndex = defaultColors.length; } defIndex = defIndex - 1; return defaultColors[defIndex]; } }; }; /* From the PJAX example on d3js.org, while this is not really directly needed it's a very cool method for doing pjax, I may expand upon it a little bit, open to suggestions on anything that may be useful */ nv.utils.pjax = function(links, content) { var load = function(href) { d3.html(href, function(fragment) { var target = d3.select(content).node(); target.parentNode.replaceChild( d3.select(fragment).select(content).node(), target); nv.utils.pjax(links, content); }); }; d3.selectAll(links).on("click", function() { history.pushState(this.href, this.textContent, this.href); load(this.href); d3.event.preventDefault(); }); d3.select(window).on("popstate", function() { if (d3.event.state) { load(d3.event.state); } }); }; /* For when we want to approximate the width in pixels for an SVG:text element. Most common instance is when the element is in a display:none; container. Forumla is : text.length * font-size * constant_factor */ nv.utils.calcApproxTextWidth = function (svgTextElem) { if (nv.utils.isFunction(svgTextElem.style) && nv.utils.isFunction(svgTextElem.text)) { var fontSize = parseInt(svgTextElem.style("font-size").replace("px",""), 10); var textLength = svgTextElem.text().length; return nv.utils.NaNtoZero(textLength * fontSize * 0.5); } return 0; }; /* Numbers that are undefined, null or NaN, convert them to zeros. */ nv.utils.NaNtoZero = function(n) { if (!nv.utils.isNumber(n) || isNaN(n) || n === null || n === Infinity || n === -Infinity) { return 0; } return n; }; /* Add a way to watch for d3 transition ends to d3 */ d3.selection.prototype.watchTransition = function(renderWatch){ var args = [this].concat([].slice.call(arguments, 1)); return renderWatch.transition.apply(renderWatch, args); }; /* Helper object to watch when d3 has rendered something */ nv.utils.renderWatch = function(dispatch, duration) { if (!(this instanceof nv.utils.renderWatch)) { return new nv.utils.renderWatch(dispatch, duration); } var _duration = duration !== undefined ? duration : 250; var renderStack = []; var self = this; this.models = function(models) { models = [].slice.call(arguments, 0); models.forEach(function(model){ model.__rendered = false; (function(m){ m.dispatch.on('renderEnd', function(arg){ m.__rendered = true; self.renderEnd('model'); }); })(model); if (renderStack.indexOf(model) < 0) { renderStack.push(model); } }); return this; }; this.reset = function(duration) { if (duration !== undefined) { _duration = duration; } renderStack = []; }; this.transition = function(selection, args, duration) { args = arguments.length > 1 ? [].slice.call(arguments, 1) : []; if (args.length > 1) { duration = args.pop(); } else { duration = _duration !== undefined ? _duration : 250; } selection.__rendered = false; if (renderStack.indexOf(selection) < 0) { renderStack.push(selection); } if (duration === 0) { selection.__rendered = true; selection.delay = function() { return this; }; selection.duration = function() { return this; }; return selection; } else { if (selection.length === 0) { selection.__rendered = true; } else if (selection.every( function(d){ return !d.length; } )) { selection.__rendered = true; } else { selection.__rendered = false; } var n = 0; return selection .transition() .duration(duration) .each(function(){ ++n; }) .each('end', function(d, i) { if (--n === 0) { selection.__rendered = true; self.renderEnd.apply(this, args); } }); } }; this.renderEnd = function() { if (renderStack.every( function(d){ return d.__rendered; } )) { renderStack.forEach( function(d){ d.__rendered = false; }); dispatch.renderEnd.apply(this, arguments); } } }; /* Takes multiple objects and combines them into the first one (dst) example: nv.utils.deepExtend({a: 1}, {a: 2, b: 3}, {c: 4}); gives: {a: 2, b: 3, c: 4} */ nv.utils.deepExtend = function(dst){ var sources = arguments.length > 1 ? [].slice.call(arguments, 1) : []; sources.forEach(function(source) { for (var key in source) { var isArray = nv.utils.isArray(dst[key]); var isObject = nv.utils.isObject(dst[key]); var srcObj = nv.utils.isObject(source[key]); if (isObject && !isArray && srcObj) { nv.utils.deepExtend(dst[key], source[key]); } else { dst[key] = source[key]; } } }); }; /* state utility object, used to track d3 states in the models */ nv.utils.state = function(){ if (!(this instanceof nv.utils.state)) { return new nv.utils.state(); } var state = {}; var _self = this; var _setState = function(){}; var _getState = function(){ return {}; }; var init = null; var changed = null; this.dispatch = d3.dispatch('change', 'set'); this.dispatch.on('set', function(state){ _setState(state, true); }); this.getter = function(fn){ _getState = fn; return this; }; this.setter = function(fn, callback) { if (!callback) { callback = function(){}; } _setState = function(state, update){ fn(state); if (update) { callback(); } }; return this; }; this.init = function(state){ init = init || {}; nv.utils.deepExtend(init, state); }; var _set = function(){ var settings = _getState(); if (JSON.stringify(settings) === JSON.stringify(state)) { return false; } for (var key in settings) { if (state[key] === undefined) { state[key] = {}; } state[key] = settings[key]; changed = true; } return true; }; this.update = function(){ if (init) { _setState(init, false); init = null; } if (_set.call(this)) { this.dispatch.change(state); } }; }; /* Snippet of code you can insert into each nv.models.* to give you the ability to do things like: chart.options({ showXAxis: true, tooltips: true }); To enable in the chart: chart.options = nv.utils.optionsFunc.bind(chart); */ nv.utils.optionsFunc = function(args) { if (args) { d3.map(args).forEach((function(key,value) { if (nv.utils.isFunction(this[key])) { this[key](value); } }).bind(this)); } return this; }; /* numTicks: requested number of ticks data: the chart data returns the number of ticks to actually use on X axis, based on chart data to avoid duplicate ticks with the same value */ nv.utils.calcTicksX = function(numTicks, data) { // find max number of values from all data streams var numValues = 1; var i = 0; for (i; i < data.length; i += 1) { var stream_len = data[i] && data[i].values ? data[i].values.length : 0; numValues = stream_len > numValues ? stream_len : numValues; } nv.log("Requested number of ticks: ", numTicks); nv.log("Calculated max values to be: ", numValues); // make sure we don't have more ticks than values to avoid duplicates numTicks = numTicks > numValues ? numTicks = numValues - 1 : numTicks; // make sure we have at least one tick numTicks = numTicks < 1 ? 1 : numTicks; // make sure it's an integer numTicks = Math.floor(numTicks); nv.log("Calculating tick count as: ", numTicks); return numTicks; }; /* returns number of ticks to actually use on Y axis, based on chart data */ nv.utils.calcTicksY = function(numTicks, data) { // currently uses the same logic but we can adjust here if needed later return nv.utils.calcTicksX(numTicks, data); }; /* Add a particular option from an options object onto chart Options exposed on a chart are a getter/setter function that returns chart on set to mimic typical d3 option chaining, e.g. svg.option1('a').option2('b'); option objects should be generated via Object.create() to provide the option of manipulating data via get/set functions. */ nv.utils.initOption = function(chart, name) { // if it's a call option, just call it directly, otherwise do get/set if (chart._calls && chart._calls[name]) { chart[name] = chart._calls[name]; } else { chart[name] = function (_) { if (!arguments.length) return chart._options[name]; chart._overrides[name] = true; chart._options[name] = _; return chart; }; // calling the option as _option will ignore if set by option already // so nvd3 can set options internally but the stop if set manually chart['_' + name] = function(_) { if (!arguments.length) return chart._options[name]; if (!chart._overrides[name]) { chart._options[name] = _; } return chart; } } }; /* Add all options in an options object to the chart */ nv.utils.initOptions = function(chart) { chart._overrides = chart._overrides || {}; var ops = Object.getOwnPropertyNames(chart._options || {}); var calls = Object.getOwnPropertyNames(chart._calls || {}); ops = ops.concat(calls); for (var i in ops) { nv.utils.initOption(chart, ops[i]); } }; /* Inherit options from a D3 object d3.rebind makes calling the function on target actually call it on source Also use _d3options so we can track what we inherit for documentation and chained inheritance */ nv.utils.inheritOptionsD3 = function(target, d3_source, oplist) { target._d3options = oplist.concat(target._d3options || []); // Find unique d3 options (string) and update d3options target._d3options = (target._d3options || []).filter(function(item, i, ar){ return ar.indexOf(item) === i; }); oplist.unshift(d3_source); oplist.unshift(target); d3.rebind.apply(this, oplist); }; /* Remove duplicates from an array */ nv.utils.arrayUnique = function(a) { return a.sort().filter(function(item, pos) { return !pos || item != a[pos - 1]; }); }; /* Keeps a list of custom symbols to draw from in addition to d3.svg.symbol Necessary since d3 doesn't let you extend its list -_- Add new symbols by doing nv.utils.symbols.set('name', function(size){...}); */ nv.utils.symbolMap = d3.map(); /* Replaces d3.svg.symbol so that we can look both there and our own map */ nv.utils.symbol = function() { var type, size = 64; function symbol(d,i) { var t = type.call(this,d,i); var s = size.call(this,d,i); if (d3.svg.symbolTypes.indexOf(t) !== -1) { return d3.svg.symbol().type(t).size(s)(); } else { return nv.utils.symbolMap.get(t)(s); } } symbol.type = function(_) { if (!arguments.length) return type; type = d3.functor(_); return symbol; }; symbol.size = function(_) { if (!arguments.length) return size; size = d3.functor(_); return symbol; }; return symbol; }; /* Inherit option getter/setter functions from source to target d3.rebind makes calling the function on target actually call it on source Also track via _inherited and _d3options so we can track what we inherit for documentation generation purposes and chained inheritance */ nv.utils.inheritOptions = function(target, source) { // inherit all the things var ops = Object.getOwnPropertyNames(source._options || {}); var calls = Object.getOwnPropertyNames(source._calls || {}); var inherited = source._inherited || []; var d3ops = source._d3options || []; var args = ops.concat(calls).concat(inherited).concat(d3ops); args.unshift(source); args.unshift(target); d3.rebind.apply(this, args); // pass along the lists to keep track of them, don't allow duplicates target._inherited = nv.utils.arrayUnique(ops.concat(calls).concat(inherited).concat(ops).concat(target._inherited || [])); target._d3options = nv.utils.arrayUnique(d3ops.concat(target._d3options || [])); }; /* Runs common initialize code on the svg before the chart builds */ nv.utils.initSVG = function(svg) { svg.classed({'nvd3-svg':true}); }; /* Sanitize and provide default for the container height. */ nv.utils.sanitizeHeight = function(height, container) { return (height || parseInt(container.style('height'), 10) || 400); }; /* Sanitize and provide default for the container width. */ nv.utils.sanitizeWidth = function(width, container) { return (width || parseInt(container.style('width'), 10) || 960); }; /* Calculate the available height for a chart. */ nv.utils.availableHeight = function(height, container, margin) { return Math.max(0,nv.utils.sanitizeHeight(height, container) - margin.top - margin.bottom); }; /* Calculate the available width for a chart. */ nv.utils.availableWidth = function(width, container, margin) { return Math.max(0,nv.utils.sanitizeWidth(width, container) - margin.left - margin.right); }; /* Clear any rendered chart components and display a chart's 'noData' message */ nv.utils.noData = function(chart, container) { var opt = chart.options(), margin = opt.margin(), noData = opt.noData(), data = (noData == null) ? ["No Data Available."] : [noData], height = nv.utils.availableHeight(null, container, margin), width = nv.utils.availableWidth(null, container, margin), x = margin.left + width/2, y = margin.top + height/2; //Remove any previously created chart components container.selectAll('g').remove(); var noDataText = container.selectAll('.nv-noData').data(data); noDataText.enter().append('text') .attr('class', 'nvd3 nv-noData') .attr('dy', '-.7em') .style('text-anchor', 'middle'); noDataText .attr('x', x) .attr('y', y) .text(function(t){ return t; }); }; /* Wrap long labels. */ nv.utils.wrapTicks = function (text, width) { text.each(function() { var text = d3.select(this), words = text.text().split(/\s+/).reverse(), word, line = [], lineNumber = 0, lineHeight = 1.1, y = text.attr("y"), dy = parseFloat(text.attr("dy")), tspan = text.text(null).append("tspan").attr("x", 0).attr("y", y).attr("dy", dy + "em"); while (word = words.pop()) { line.push(word); tspan.text(line.join(" ")); if (tspan.node().getComputedTextLength() > width) { line.pop(); tspan.text(line.join(" ")); line = [word]; tspan = text.append("tspan").attr("x", 0).attr("y", y).attr("dy", ++lineNumber * lineHeight + dy + "em").text(word); } } }); }; /* Check equality of 2 array */ nv.utils.arrayEquals = function (array1, array2) { if (array1 === array2) return true; if (!array1 || !array2) return false; // compare lengths - can save a lot of time if (array1.length != array2.length) return false; for (var i = 0, l = array1.length; i < l; i++) { // Check if we have nested arrays if (array1[i] instanceof Array && array2[i] instanceof Array) { // recurse into the nested arrays if (!nv.arrayEquals(array1[i], array2[i])) return false; } else if (array1[i] != array2[i]) { // Warning - two different object instances will never be equal: {x:20} != {x:20} return false; } } return true; }; /* Check if a point within an arc */ nv.utils.pointIsInArc = function(pt, ptData, d3Arc) { // Center of the arc is assumed to be 0,0 // (pt.x, pt.y) are assumed to be relative to the center var r1 = d3Arc.innerRadius()(ptData), // Note: Using the innerRadius r2 = d3Arc.outerRadius()(ptData), theta1 = d3Arc.startAngle()(ptData), theta2 = d3Arc.endAngle()(ptData); var dist = pt.x * pt.x + pt.y * pt.y, angle = Math.atan2(pt.x, -pt.y); // Note: different coordinate system. angle = (angle < 0) ? (angle + Math.PI * 2) : angle; return (r1 * r1 <= dist) && (dist <= r2 * r2) && (theta1 <= angle) && (angle <= theta2); }; nv.models.axis = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var axis = d3.svg.axis(); var scale = d3.scale.linear(); var margin = {top: 0, right: 0, bottom: 0, left: 0} , width = 75 //only used for tickLabel currently , height = 60 //only used for tickLabel currently , axisLabelText = null , showMaxMin = true //TODO: showMaxMin should be disabled on all ordinal scaled axes , rotateLabels = 0 , rotateYLabel = true , staggerLabels = false , isOrdinal = false , ticks = null , axisLabelDistance = 0 , fontSize = undefined , duration = 250 , dispatch = d3.dispatch('renderEnd') , tickFormatMaxMin ; axis .scale(scale) .orient('bottom') .tickFormat(function(d) { return d }) ; //============================================================ // Private Variables //------------------------------------------------------------ var scale0; var renderWatch = nv.utils.renderWatch(dispatch, duration); function chart(selection) { renderWatch.reset(); selection.each(function(data) { var container = d3.select(this); nv.utils.initSVG(container); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-axis').data([data]); var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-axis'); var gEnter = wrapEnter.append('g'); var g = wrap.select('g'); if (ticks !== null) axis.ticks(ticks); else if (axis.orient() == 'top' || axis.orient() == 'bottom') axis.ticks(Math.abs(scale.range()[1] - scale.range()[0]) / 100); //TODO: consider calculating width/height based on whether or not label is added, for reference in charts using this component g.watchTransition(renderWatch, 'axis').call(axis); scale0 = scale0 || axis.scale(); var fmt = axis.tickFormat(); if (fmt == null) { fmt = scale0.tickFormat(); } var axisLabel = g.selectAll('text.nv-axislabel') .data([axisLabelText || null]); axisLabel.exit().remove(); //only skip when fontSize is undefined so it can be cleared with a null or blank string if (fontSize !== undefined) { g.selectAll('g').select("text").style('font-size', fontSize); } var xLabelMargin; var axisMaxMin; var w; switch (axis.orient()) { case 'top': axisLabel.enter().append('text').attr('class', 'nv-axislabel'); w = 0; if (scale.range().length === 1) { w = isOrdinal ? scale.range()[0] * 2 + scale.rangeBand() : 0; } else if (scale.range().length === 2) { w = isOrdinal ? scale.range()[0] + scale.range()[1] + scale.rangeBand() : scale.range()[1]; } else if ( scale.range().length > 2){ w = scale.range()[scale.range().length-1]+(scale.range()[1]-scale.range()[0]); }; axisLabel .attr('text-anchor', 'middle') .attr('y', 0) .attr('x', w/2); if (showMaxMin) { axisMaxMin = wrap.selectAll('g.nv-axisMaxMin') .data(scale.domain()); axisMaxMin.enter().append('g').attr('class',function(d,i){ return ['nv-axisMaxMin','nv-axisMaxMin-x',(i == 0 ? 'nv-axisMin-x':'nv-axisMax-x')].join(' ') }).append('text'); axisMaxMin.exit().remove(); axisMaxMin .attr('transform', function(d,i) { return 'translate(' + nv.utils.NaNtoZero(scale(d)) + ',0)' }) .select('text') .attr('dy', '-0.5em') .attr('y', -axis.tickPadding()) .attr('text-anchor', 'middle') .text(function(d,i) { var formatter = tickFormatMaxMin || fmt; var v = formatter(d); return ('' + v).match('NaN') ? '' : v; }); axisMaxMin.watchTransition(renderWatch, 'min-max top') .attr('transform', function(d,i) { return 'translate(' + nv.utils.NaNtoZero(scale.range()[i]) + ',0)' }); } break; case 'bottom': xLabelMargin = axisLabelDistance + 36; var maxTextWidth = 30; var textHeight = 0; var xTicks = g.selectAll('g').select("text"); var rotateLabelsRule = ''; if (rotateLabels%360) { //Reset transform on ticks so textHeight can be calculated correctly xTicks.attr('transform', ''); //Calculate the longest xTick width xTicks.each(function(d,i){ var box = this.getBoundingClientRect(); var width = box.width; textHeight = box.height; if(width > maxTextWidth) maxTextWidth = width; }); rotateLabelsRule = 'rotate(' + rotateLabels + ' 0,' + (textHeight/2 + axis.tickPadding()) + ')'; //Convert to radians before calculating sin. Add 30 to margin for healthy padding. var sin = Math.abs(Math.sin(rotateLabels*Math.PI/180)); xLabelMargin = (sin ? sin*maxTextWidth : maxTextWidth)+30; //Rotate all xTicks xTicks .attr('transform', rotateLabelsRule) .style('text-anchor', rotateLabels%360 > 0 ? 'start' : 'end'); } else { if (staggerLabels) { xTicks .attr('transform', function(d,i) { return 'translate(0,' + (i % 2 == 0 ? '0' : '12') + ')' }); } else { xTicks.attr('transform', "translate(0,0)"); } } axisLabel.enter().append('text').attr('class', 'nv-axislabel'); w = 0; if (scale.range().length === 1) { w = isOrdinal ? scale.range()[0] * 2 + scale.rangeBand() : 0; } else if (scale.range().length === 2) { w = isOrdinal ? scale.range()[0] + scale.range()[1] + scale.rangeBand() : scale.range()[1]; } else if ( scale.range().length > 2){ w = scale.range()[scale.range().length-1]+(scale.range()[1]-scale.range()[0]); }; axisLabel .attr('text-anchor', 'middle') .attr('y', xLabelMargin) .attr('x', w/2); if (showMaxMin) { //if (showMaxMin && !isOrdinal) { axisMaxMin = wrap.selectAll('g.nv-axisMaxMin') //.data(scale.domain()) .data([scale.domain()[0], scale.domain()[scale.domain().length - 1]]); axisMaxMin.enter().append('g').attr('class',function(d,i){ return ['nv-axisMaxMin','nv-axisMaxMin-x',(i == 0 ? 'nv-axisMin-x':'nv-axisMax-x')].join(' ') }).append('text'); axisMaxMin.exit().remove(); axisMaxMin .attr('transform', function(d,i) { return 'translate(' + nv.utils.NaNtoZero((scale(d) + (isOrdinal ? scale.rangeBand() / 2 : 0))) + ',0)' }) .select('text') .attr('dy', '.71em') .attr('y', axis.tickPadding()) .attr('transform', rotateLabelsRule) .style('text-anchor', rotateLabels ? (rotateLabels%360 > 0 ? 'start' : 'end') : 'middle') .text(function(d,i) { var formatter = tickFormatMaxMin || fmt; var v = formatter(d); return ('' + v).match('NaN') ? '' : v; }); axisMaxMin.watchTransition(renderWatch, 'min-max bottom') .attr('transform', function(d,i) { return 'translate(' + nv.utils.NaNtoZero((scale(d) + (isOrdinal ? scale.rangeBand() / 2 : 0))) + ',0)' }); } break; case 'right': axisLabel.enter().append('text').attr('class', 'nv-axislabel'); axisLabel .style('text-anchor', rotateYLabel ? 'middle' : 'begin') .attr('transform', rotateYLabel ? 'rotate(90)' : '') .attr('y', rotateYLabel ? (-Math.max(margin.right, width) + 12 - (axisLabelDistance || 0)) : -10) //TODO: consider calculating this based on largest tick width... OR at least expose this on chart .attr('x', rotateYLabel ? (d3.max(scale.range()) / 2) : axis.tickPadding()); if (showMaxMin) { axisMaxMin = wrap.selectAll('g.nv-axisMaxMin') .data(scale.domain()); axisMaxMin.enter().append('g').attr('class',function(d,i){ return ['nv-axisMaxMin','nv-axisMaxMin-y',(i == 0 ? 'nv-axisMin-y':'nv-axisMax-y')].join(' ') }).append('text') .style('opacity', 0); axisMaxMin.exit().remove(); axisMaxMin .attr('transform', function(d,i) { return 'translate(0,' + nv.utils.NaNtoZero(scale(d)) + ')' }) .select('text') .attr('dy', '.32em') .attr('y', 0) .attr('x', axis.tickPadding()) .style('text-anchor', 'start') .text(function(d, i) { var formatter = tickFormatMaxMin || fmt; var v = formatter(d); return ('' + v).match('NaN') ? '' : v; }); axisMaxMin.watchTransition(renderWatch, 'min-max right') .attr('transform', function(d,i) { return 'translate(0,' + nv.utils.NaNtoZero(scale.range()[i]) + ')' }) .select('text') .style('opacity', 1); } break; case 'left': /* //For dynamically placing the label. Can be used with dynamically-sized chart axis margins var yTicks = g.selectAll('g').select("text"); yTicks.each(function(d,i){ var labelPadding = this.getBoundingClientRect().width + axis.tickPadding() + 16; if(labelPadding > width) width = labelPadding; }); */ axisLabel.enter().append('text').attr('class', 'nv-axislabel'); axisLabel .style('text-anchor', rotateYLabel ? 'middle' : 'end') .attr('transform', rotateYLabel ? 'rotate(-90)' : '') .attr('y', rotateYLabel ? (-Math.max(margin.left, width) + 25 - (axisLabelDistance || 0)) : -10) .attr('x', rotateYLabel ? (-d3.max(scale.range()) / 2) : -axis.tickPadding()); if (showMaxMin) { axisMaxMin = wrap.selectAll('g.nv-axisMaxMin') .data(scale.domain()); axisMaxMin.enter().append('g').attr('class',function(d,i){ return ['nv-axisMaxMin','nv-axisMaxMin-y',(i == 0 ? 'nv-axisMin-y':'nv-axisMax-y')].join(' ') }).append('text') .style('opacity', 0); axisMaxMin.exit().remove(); axisMaxMin .attr('transform', function(d,i) { return 'translate(0,' + nv.utils.NaNtoZero(scale0(d)) + ')' }) .select('text') .attr('dy', '.32em') .attr('y', 0) .attr('x', -axis.tickPadding()) .attr('text-anchor', 'end') .text(function(d,i) { var formatter = tickFormatMaxMin || fmt; var v = formatter(d); return ('' + v).match('NaN') ? '' : v; }); axisMaxMin.watchTransition(renderWatch, 'min-max right') .attr('transform', function(d,i) { return 'translate(0,' + nv.utils.NaNtoZero(scale.range()[i]) + ')' }) .select('text') .style('opacity', 1); } break; } axisLabel.text(function(d) { return d }); if (showMaxMin && (axis.orient() === 'left' || axis.orient() === 'right')) { //check if max and min overlap other values, if so, hide the values that overlap g.selectAll('g') // the g's wrapping each tick .each(function(d,i) { d3.select(this).select('text').attr('opacity', 1); if (scale(d) < scale.range()[1] + 10 || scale(d) > scale.range()[0] - 10) { // 10 is assuming text height is 16... if d is 0, leave it! if (d > 1e-10 || d < -1e-10) // accounts for minor floating point errors... though could be problematic if the scale is EXTREMELY SMALL d3.select(this).attr('opacity', 0); d3.select(this).select('text').attr('opacity', 0); // Don't remove the ZERO line!! } }); //if Max and Min = 0 only show min, Issue #281 if (scale.domain()[0] == scale.domain()[1] && scale.domain()[0] == 0) { wrap.selectAll('g.nv-axisMaxMin').style('opacity', function (d, i) { return !i ? 1 : 0 }); } } if (showMaxMin && (axis.orient() === 'top' || axis.orient() === 'bottom')) { var maxMinRange = []; wrap.selectAll('g.nv-axisMaxMin') .each(function(d,i) { try { if (i) // i== 1, max position maxMinRange.push(scale(d) - this.getBoundingClientRect().width - 4); //assuming the max and min labels are as wide as the next tick (with an extra 4 pixels just in case) else // i==0, min position maxMinRange.push(scale(d) + this.getBoundingClientRect().width + 4) }catch (err) { if (i) // i== 1, max position maxMinRange.push(scale(d) - 4); //assuming the max and min labels are as wide as the next tick (with an extra 4 pixels just in case) else // i==0, min position maxMinRange.push(scale(d) + 4); } }); // the g's wrapping each tick g.selectAll('g').each(function(d, i) { if (scale(d) < maxMinRange[0] || scale(d) > maxMinRange[1]) { if (d > 1e-10 || d < -1e-10) // accounts for minor floating point errors... though could be problematic if the scale is EXTREMELY SMALL d3.select(this).remove(); else d3.select(this).select('text').remove(); // Don't remove the ZERO line!! } }); } //Highlight zero tick line g.selectAll('.tick') .filter(function (d) { /* The filter needs to return only ticks at or near zero. Numbers like 0.00001 need to count as zero as well, and the arithmetic trick below solves that. */ return !parseFloat(Math.round(d * 100000) / 1000000) && (d !== undefined) }) .classed('zero', true); //store old scales for use in transitions on update scale0 = scale.copy(); }); renderWatch.renderEnd('axis immediate'); return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ // expose chart's sub-components chart.axis = axis; chart.dispatch = dispatch; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values axisLabelDistance: {get: function(){return axisLabelDistance;}, set: function(_){axisLabelDistance=_;}}, staggerLabels: {get: function(){return staggerLabels;}, set: function(_){staggerLabels=_;}}, rotateLabels: {get: function(){return rotateLabels;}, set: function(_){rotateLabels=_;}}, rotateYLabel: {get: function(){return rotateYLabel;}, set: function(_){rotateYLabel=_;}}, showMaxMin: {get: function(){return showMaxMin;}, set: function(_){showMaxMin=_;}}, axisLabel: {get: function(){return axisLabelText;}, set: function(_){axisLabelText=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, ticks: {get: function(){return ticks;}, set: function(_){ticks=_;}}, width: {get: function(){return width;}, set: function(_){width=_;}}, fontSize: {get: function(){return fontSize;}, set: function(_){fontSize=_;}}, tickFormatMaxMin: {get: function(){return tickFormatMaxMin;}, set: function(_){tickFormatMaxMin=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, duration: {get: function(){return duration;}, set: function(_){ duration=_; renderWatch.reset(duration); }}, scale: {get: function(){return scale;}, set: function(_){ scale = _; axis.scale(scale); isOrdinal = typeof scale.rangeBands === 'function'; nv.utils.inheritOptionsD3(chart, scale, ['domain', 'range', 'rangeBand', 'rangeBands']); }} }); nv.utils.initOptions(chart); nv.utils.inheritOptionsD3(chart, axis, ['orient', 'tickValues', 'tickSubdivide', 'tickSize', 'tickPadding', 'tickFormat']); nv.utils.inheritOptionsD3(chart, scale, ['domain', 'range', 'rangeBand', 'rangeBands']); return chart; }; nv.models.boxPlot = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 0, right: 0, bottom: 0, left: 0}, width = 960, height = 500, id = Math.floor(Math.random() * 10000), // Create semi-unique ID in case user doesn't select one xScale = d3.scale.ordinal(), yScale = d3.scale.linear(), getX = function(d) { return d.label }, // Default data model selectors. getQ1 = function(d) { return d.values.Q1 }, getQ2 = function(d) { return d.values.Q2 }, getQ3 = function(d) { return d.values.Q3 }, getWl = function(d) { return d.values.whisker_low }, getWh = function(d) { return d.values.whisker_high }, getColor = function(d) { return d.color }, getOlItems = function(d) { return d.values.outliers }, getOlValue = function(d, i, j) { return d }, getOlLabel = function(d, i, j) { return d }, getOlColor = function(d, i, j) { return undefined }, color = nv.utils.defaultColor(), container = null, xDomain, xRange, yDomain, yRange, dispatch = d3.dispatch('elementMouseover', 'elementMouseout', 'elementMousemove', 'renderEnd'), duration = 250, maxBoxWidth = null; //============================================================ // Private Variables //------------------------------------------------------------ var xScale0, yScale0; var renderWatch = nv.utils.renderWatch(dispatch, duration); function chart(selection) { renderWatch.reset(); selection.each(function(data) { var availableWidth = width - margin.left - margin.right, availableHeight = height - margin.top - margin.bottom; container = d3.select(this); nv.utils.initSVG(container); // Setup Scales xScale.domain(xDomain || data.map(function(d,i) { return getX(d,i); })) .rangeBands(xRange || [0, availableWidth], 0.1); // if we know yDomain, no need to calculate var yData = [] if (!yDomain) { // (y-range is based on quartiles, whiskers and outliers) var values = [], yMin, yMax; data.forEach(function (d, i) { var q1 = getQ1(d), q3 = getQ3(d), wl = getWl(d), wh = getWh(d); var olItems = getOlItems(d); if (olItems) { olItems.forEach(function (e, i) { values.push(getOlValue(e, i, undefined)); }); } if (wl) { values.push(wl) } if (q1) { values.push(q1) } if (q3) { values.push(q3) } if (wh) { values.push(wh) } }); yMin = d3.min(values); yMax = d3.max(values); yData = [ yMin, yMax ] ; } yScale.domain(yDomain || yData); yScale.range(yRange || [availableHeight, 0]); //store old scales if they exist xScale0 = xScale0 || xScale; yScale0 = yScale0 || yScale.copy().range([yScale(0),yScale(0)]); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap').data([data]); var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); var boxplots = wrap.selectAll('.nv-boxplot').data(function(d) { return d }); var boxEnter = boxplots.enter().append('g').style('stroke-opacity', 1e-6).style('fill-opacity', 1e-6); boxplots .attr('class', 'nv-boxplot') .attr('transform', function(d,i,j) { return 'translate(' + (xScale(getX(d,i)) + xScale.rangeBand() * 0.05) + ', 0)'; }) .classed('hover', function(d) { return d.hover }); boxplots .watchTransition(renderWatch, 'nv-boxplot: boxplots') .style('stroke-opacity', 1) .style('fill-opacity', 0.75) .delay(function(d,i) { return i * duration / data.length }) .attr('transform', function(d,i) { return 'translate(' + (xScale(getX(d,i)) + xScale.rangeBand() * 0.05) + ', 0)'; }); boxplots.exit().remove(); // ----- add the SVG elements for each boxPlot ----- // conditionally append whisker lines boxEnter.each(function(d,i) { var box = d3.select(this); [getWl, getWh].forEach(function (f) { if (f(d) !== undefined && f(d) !== null) { var key = (f === getWl) ? 'low' : 'high'; box.append('line') .style('stroke', getColor(d) || color(d,i)) .attr('class', 'nv-boxplot-whisker nv-boxplot-' + key); box.append('line') .style('stroke', getColor(d) || color(d,i)) .attr('class', 'nv-boxplot-tick nv-boxplot-' + key); } }); }); var box_width = function() { return (maxBoxWidth === null ? xScale.rangeBand() * 0.9 : Math.min(75, xScale.rangeBand() * 0.9)); }; var box_left = function() { return xScale.rangeBand() * 0.45 - box_width()/2; }; var box_right = function() { return xScale.rangeBand() * 0.45 + box_width()/2; }; // update whisker lines and ticks [getWl, getWh].forEach(function (f) { var key = (f === getWl) ? 'low' : 'high'; var endpoint = (f === getWl) ? getQ1 : getQ3; boxplots.select('line.nv-boxplot-whisker.nv-boxplot-' + key) .watchTransition(renderWatch, 'nv-boxplot: boxplots') .attr('x1', xScale.rangeBand() * 0.45 ) .attr('y1', function(d,i) { return yScale(f(d)); }) .attr('x2', xScale.rangeBand() * 0.45 ) .attr('y2', function(d,i) { return yScale(endpoint(d)); }); boxplots.select('line.nv-boxplot-tick.nv-boxplot-' + key) .watchTransition(renderWatch, 'nv-boxplot: boxplots') .attr('x1', box_left ) .attr('y1', function(d,i) { return yScale(f(d)); }) .attr('x2', box_right ) .attr('y2', function(d,i) { return yScale(f(d)); }); }); [getWl, getWh].forEach(function (f) { var key = (f === getWl) ? 'low' : 'high'; boxEnter.selectAll('.nv-boxplot-' + key) .on('mouseover', function(d,i,j) { d3.select(this).classed('hover', true); dispatch.elementMouseover({ series: { key: f(d), color: getColor(d) || color(d,j) }, e: d3.event }); }) .on('mouseout', function(d,i,j) { d3.select(this).classed('hover', false); dispatch.elementMouseout({ series: { key: f(d), color: getColor(d) || color(d,j) }, e: d3.event }); }) .on('mousemove', function(d,i) { dispatch.elementMousemove({e: d3.event}); }); }); // boxes boxEnter.append('rect') .attr('class', 'nv-boxplot-box') // tooltip events .on('mouseover', function(d,i) { d3.select(this).classed('hover', true); dispatch.elementMouseover({ key: getX(d), value: getX(d), series: [ { key: 'Q3', value: getQ3(d), color: getColor(d) || color(d,i) }, { key: 'Q2', value: getQ2(d), color: getColor(d) || color(d,i) }, { key: 'Q1', value: getQ1(d), color: getColor(d) || color(d,i) } ], data: d, index: i, e: d3.event }); }) .on('mouseout', function(d,i) { d3.select(this).classed('hover', false); dispatch.elementMouseout({ key: getX(d), value: getX(d), series: [ { key: 'Q3', value: getQ3(d), color: getColor(d) || color(d,i) }, { key: 'Q2', value: getQ2(d), color: getColor(d) || color(d,i) }, { key: 'Q1', value: getQ1(d), color: getColor(d) || color(d,i) } ], data: d, index: i, e: d3.event }); }) .on('mousemove', function(d,i) { dispatch.elementMousemove({e: d3.event}); }); // box transitions boxplots.select('rect.nv-boxplot-box') .watchTransition(renderWatch, 'nv-boxplot: boxes') .attr('y', function(d,i) { return yScale(getQ3(d)); }) .attr('width', box_width) .attr('x', box_left ) .attr('height', function(d,i) { return Math.abs(yScale(getQ3(d)) - yScale(getQ1(d))) || 1 }) .style('fill', function(d,i) { return getColor(d) || color(d,i) }) .style('stroke', function(d,i) { return getColor(d) || color(d,i) }); // median line boxEnter.append('line').attr('class', 'nv-boxplot-median'); boxplots.select('line.nv-boxplot-median') .watchTransition(renderWatch, 'nv-boxplot: boxplots line') .attr('x1', box_left) .attr('y1', function(d,i) { return yScale(getQ2(d)); }) .attr('x2', box_right) .attr('y2', function(d,i) { return yScale(getQ2(d)); }); // outliers var outliers = boxplots.selectAll('.nv-boxplot-outlier').data(function(d) { return getOlItems(d) || []; }); outliers.enter().append('circle') .style('fill', function(d,i,j) { return getOlColor(d,i,j) || color(d,j) }) .style('stroke', function(d,i,j) { return getOlColor(d,i,j) || color(d,j) }) .style('z-index', 9000) .on('mouseover', function(d,i,j) { d3.select(this).classed('hover', true); dispatch.elementMouseover({ series: { key: getOlLabel(d,i,j), color: getOlColor(d,i,j) || color(d,j) }, e: d3.event }); }) .on('mouseout', function(d,i,j) { d3.select(this).classed('hover', false); dispatch.elementMouseout({ series: { key: getOlLabel(d,i,j), color: getOlColor(d,i,j) || color(d,j) }, e: d3.event }); }) .on('mousemove', function(d,i) { dispatch.elementMousemove({e: d3.event}); }); outliers.attr('class', 'nv-boxplot-outlier'); outliers .watchTransition(renderWatch, 'nv-boxplot: nv-boxplot-outlier') .attr('cx', xScale.rangeBand() * 0.45) .attr('cy', function(d,i,j) { return yScale(getOlValue(d,i,j)); }) .attr('r', '3'); outliers.exit().remove(); //store old scales for use in transitions on update xScale0 = xScale.copy(); yScale0 = yScale.copy(); }); renderWatch.renderEnd('nv-boxplot immediate'); return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.dispatch = dispatch; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, maxBoxWidth: {get: function(){return maxBoxWidth;}, set: function(_){maxBoxWidth=_;}}, x: {get: function(){return getX;}, set: function(_){getX=_;}}, q1: {get: function(){return getQ1;}, set: function(_){getQ1=_;}}, q2: {get: function(){return getQ2;}, set: function(_){getQ2=_;}}, q3: {get: function(){return getQ3;}, set: function(_){getQ3=_;}}, wl: {get: function(){return getWl;}, set: function(_){getWl=_;}}, wh: {get: function(){return getWh;}, set: function(_){getWh=_;}}, itemColor: {get: function(){return getColor;}, set: function(_){getColor=_;}}, outliers: {get: function(){return getOlItems;}, set: function(_){getOlItems=_;}}, outlierValue: {get: function(){return getOlValue;}, set: function(_){getOlValue=_;}}, outlierLabel: {get: function(){return getOlLabel;}, set: function(_){getOlLabel=_;}}, outlierColor: {get: function(){return getOlColor;}, set: function(_){getOlColor=_;}}, xScale: {get: function(){return xScale;}, set: function(_){xScale=_;}}, yScale: {get: function(){return yScale;}, set: function(_){yScale=_;}}, xDomain: {get: function(){return xDomain;}, set: function(_){xDomain=_;}}, yDomain: {get: function(){return yDomain;}, set: function(_){yDomain=_;}}, xRange: {get: function(){return xRange;}, set: function(_){xRange=_;}}, yRange: {get: function(){return yRange;}, set: function(_){yRange=_;}}, id: {get: function(){return id;}, set: function(_){id=_;}}, // rectClass: {get: function(){return rectClass;}, set: function(_){rectClass=_;}}, y: { get: function() { console.warn('BoxPlot \'y\' chart option is deprecated. Please use model overrides instead.'); return {}; }, set: function(_) { console.warn('BoxPlot \'y\' chart option is deprecated. Please use model overrides instead.'); } }, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; renderWatch.reset(duration); }} }); nv.utils.initOptions(chart); return chart; }; nv.models.boxPlotChart = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var boxplot = nv.models.boxPlot(), xAxis = nv.models.axis(), yAxis = nv.models.axis(); var margin = {top: 15, right: 10, bottom: 50, left: 60}, width = null, height = null, color = nv.utils.getColor(), showXAxis = true, showYAxis = true, rightAlignYAxis = false, staggerLabels = false, tooltip = nv.models.tooltip(), x, y, noData = 'No Data Available.', dispatch = d3.dispatch('beforeUpdate', 'renderEnd'), duration = 250; xAxis .orient('bottom') .showMaxMin(false) .tickFormat(function(d) { return d }) ; yAxis .orient((rightAlignYAxis) ? 'right' : 'left') .tickFormat(d3.format(',.1f')) ; tooltip.duration(0); //============================================================ // Private Variables //------------------------------------------------------------ var renderWatch = nv.utils.renderWatch(dispatch, duration); function chart(selection) { renderWatch.reset(); renderWatch.models(boxplot); if (showXAxis) renderWatch.models(xAxis); if (showYAxis) renderWatch.models(yAxis); selection.each(function(data) { var container = d3.select(this), that = this; nv.utils.initSVG(container); var availableWidth = (width || parseInt(container.style('width')) || 960) - margin.left - margin.right; var availableHeight = (height || parseInt(container.style('height')) || 400) - margin.top - margin.bottom; chart.update = function() { dispatch.beforeUpdate(); container.transition().duration(duration).call(chart); }; chart.container = this; // TODO still need to find a way to validate quartile data presence using boxPlot callbacks. // Display No Data message if there's nothing to show. (quartiles required at minimum). if (!data || !data.length) { var noDataText = container.selectAll('.nv-noData').data([noData]); noDataText.enter().append('text') .attr('class', 'nvd3 nv-noData') .attr('dy', '-.7em') .style('text-anchor', 'middle'); noDataText .attr('x', margin.left + availableWidth / 2) .attr('y', margin.top + availableHeight / 2) .text(function(d) { return d }); return chart; } else { container.selectAll('.nv-noData').remove(); } // Setup Scales x = boxplot.xScale(); y = boxplot.yScale().clamp(true); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-boxPlotWithAxes').data([data]); var gEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-boxPlotWithAxes').append('g'); var defsEnter = gEnter.append('defs'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-x nv-axis'); gEnter.append('g').attr('class', 'nv-y nv-axis') .append('g').attr('class', 'nv-zeroLine') .append('line'); gEnter.append('g').attr('class', 'nv-barsWrap'); g.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); if (rightAlignYAxis) { g.select('.nv-y.nv-axis') .attr('transform', 'translate(' + availableWidth + ',0)'); } // Main Chart Component(s) boxplot.width(availableWidth).height(availableHeight); var barsWrap = g.select('.nv-barsWrap') .datum(data.filter(function(d) { return !d.disabled })) barsWrap.transition().call(boxplot); defsEnter.append('clipPath') .attr('id', 'nv-x-label-clip-' + boxplot.id()) .append('rect'); g.select('#nv-x-label-clip-' + boxplot.id() + ' rect') .attr('width', x.rangeBand() * (staggerLabels ? 2 : 1)) .attr('height', 16) .attr('x', -x.rangeBand() / (staggerLabels ? 1 : 2 )); // Setup Axes if (showXAxis) { xAxis .scale(x) .ticks( nv.utils.calcTicksX(availableWidth/100, data) ) .tickSize(-availableHeight, 0); g.select('.nv-x.nv-axis').attr('transform', 'translate(0,' + y.range()[0] + ')'); g.select('.nv-x.nv-axis').call(xAxis); var xTicks = g.select('.nv-x.nv-axis').selectAll('g'); if (staggerLabels) { xTicks .selectAll('text') .attr('transform', function(d,i,j) { return 'translate(0,' + (j % 2 === 0 ? '5' : '17') + ')' }) } } if (showYAxis) { yAxis .scale(y) .ticks( Math.floor(availableHeight/36) ) // can't use nv.utils.calcTicksY with Object data .tickSize( -availableWidth, 0); g.select('.nv-y.nv-axis').call(yAxis); } // Zero line g.select('.nv-zeroLine line') .attr('x1',0) .attr('x2',availableWidth) .attr('y1', y(0)) .attr('y2', y(0)) ; //============================================================ // Event Handling/Dispatching (in chart's scope) //------------------------------------------------------------ }); renderWatch.renderEnd('nv-boxplot chart immediate'); return chart; } //============================================================ // Event Handling/Dispatching (out of chart's scope) //------------------------------------------------------------ boxplot.dispatch.on('elementMouseover.tooltip', function(evt) { tooltip.data(evt).hidden(false); }); boxplot.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.data(evt).hidden(true); }); boxplot.dispatch.on('elementMousemove.tooltip', function(evt) { tooltip(); }); //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.dispatch = dispatch; chart.boxplot = boxplot; chart.xAxis = xAxis; chart.yAxis = yAxis; chart.tooltip = tooltip; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, staggerLabels: {get: function(){return staggerLabels;}, set: function(_){staggerLabels=_;}}, showXAxis: {get: function(){return showXAxis;}, set: function(_){showXAxis=_;}}, showYAxis: {get: function(){return showYAxis;}, set: function(_){showYAxis=_;}}, tooltipContent: {get: function(){return tooltip;}, set: function(_){tooltip=_;}}, noData: {get: function(){return noData;}, set: function(_){noData=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; renderWatch.reset(duration); boxplot.duration(duration); xAxis.duration(duration); yAxis.duration(duration); }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); boxplot.color(color); }}, rightAlignYAxis: {get: function(){return rightAlignYAxis;}, set: function(_){ rightAlignYAxis = _; yAxis.orient( (_) ? 'right' : 'left'); }} }); nv.utils.inheritOptions(chart, boxplot); nv.utils.initOptions(chart); return chart; } // Chart design based on the recommendations of Stephen Few. Implementation // based on the work of Clint Ivy, Jamie Love, and Jason Davies. // http://projects.instantcognition.com/protovis/bulletchart/ nv.models.bullet = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 0, right: 0, bottom: 0, left: 0} , orient = 'left' // TODO top & bottom , reverse = false , ranges = function(d) { return d.ranges } , markers = function(d) { return d.markers ? d.markers : [] } , markerLines = function(d) { return d.markerLines ? d.markerLines : [0] } , measures = function(d) { return d.measures } , rangeLabels = function(d) { return d.rangeLabels ? d.rangeLabels : [] } , markerLabels = function(d) { return d.markerLabels ? d.markerLabels : [] } , markerLineLabels = function(d) { return d.markerLineLabels ? d.markerLineLabels : [] } , measureLabels = function(d) { return d.measureLabels ? d.measureLabels : [] } , forceX = [0] // List of numbers to Force into the X scale (ie. 0, or a max / min, etc.) , width = 380 , height = 30 , container = null , tickFormat = null , color = nv.utils.getColor(['#1f77b4']) , dispatch = d3.dispatch('elementMouseover', 'elementMouseout', 'elementMousemove') , defaultRangeLabels = ["Maximum", "Mean", "Minimum"] , legacyRangeClassNames = ["Max", "Avg", "Min"] , duration = 1000 ; function sortLabels(labels, values){ var lz = labels.slice(); labels.sort(function(a, b){ var iA = lz.indexOf(a); var iB = lz.indexOf(b); return d3.descending(values[iA], values[iB]); }); }; function chart(selection) { selection.each(function(d, i) { var availableWidth = width - margin.left - margin.right, availableHeight = height - margin.top - margin.bottom; container = d3.select(this); nv.utils.initSVG(container); var rangez = ranges.call(this, d, i).slice(), markerz = markers.call(this, d, i).slice(), markerLinez = markerLines.call(this, d, i).slice(), measurez = measures.call(this, d, i).slice(), rangeLabelz = rangeLabels.call(this, d, i).slice(), markerLabelz = markerLabels.call(this, d, i).slice(), markerLineLabelz = markerLineLabels.call(this, d, i).slice(), measureLabelz = measureLabels.call(this, d, i).slice(); // Sort labels according to their sorted values sortLabels(rangeLabelz, rangez); sortLabels(markerLabelz, markerz); sortLabels(markerLineLabelz, markerLinez); sortLabels(measureLabelz, measurez); // sort values descending rangez.sort(d3.descending); markerz.sort(d3.descending); markerLinez.sort(d3.descending); measurez.sort(d3.descending); // Setup Scales // Compute the new x-scale. var x1 = d3.scale.linear() .domain( d3.extent(d3.merge([forceX, rangez])) ) .range(reverse ? [availableWidth, 0] : [0, availableWidth]); // Retrieve the old x-scale, if this is an update. var x0 = this.__chart__ || d3.scale.linear() .domain([0, Infinity]) .range(x1.range()); // Stash the new scale. this.__chart__ = x1; var rangeMin = d3.min(rangez), //rangez[2] rangeMax = d3.max(rangez), //rangez[0] rangeAvg = rangez[1]; // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-bullet').data([d]); var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-bullet'); var gEnter = wrapEnter.append('g'); var g = wrap.select('g'); for(var i=0,il=rangez.length; i getClose(d, i) ? 'nv-tick negative' : 'nv-tick positive') + ' nv-tick-' + j + '-' + i}); var lines = tickGroups.append('line') .attr('class', 'nv-candlestick-lines') .attr('transform', function(d, i) { return 'translate(' + x(getX(d, i)) + ',0)'; }) .attr('x1', 0) .attr('y1', function(d, i) { return y(getHigh(d, i)); }) .attr('x2', 0) .attr('y2', function(d, i) { return y(getLow(d, i)); }); var rects = tickGroups.append('rect') .attr('class', 'nv-candlestick-rects nv-bars') .attr('transform', function(d, i) { return 'translate(' + (x(getX(d, i)) - barWidth/2) + ',' + (y(getY(d, i)) - (getOpen(d, i) > getClose(d, i) ? (y(getClose(d, i)) - y(getOpen(d, i))) : 0)) + ')'; }) .attr('x', 0) .attr('y', 0) .attr('width', barWidth) .attr('height', function(d, i) { var open = getOpen(d, i); var close = getClose(d, i); return open > close ? y(close) - y(open) : y(open) - y(close); }); ticks.select('.nv-candlestick-lines').transition() .attr('transform', function(d, i) { return 'translate(' + x(getX(d, i)) + ',0)'; }) .attr('x1', 0) .attr('y1', function(d, i) { return y(getHigh(d, i)); }) .attr('x2', 0) .attr('y2', function(d, i) { return y(getLow(d, i)); }); ticks.select('.nv-candlestick-rects').transition() .attr('transform', function(d, i) { return 'translate(' + (x(getX(d, i)) - barWidth/2) + ',' + (y(getY(d, i)) - (getOpen(d, i) > getClose(d, i) ? (y(getClose(d, i)) - y(getOpen(d, i))) : 0)) + ')'; }) .attr('x', 0) .attr('y', 0) .attr('width', barWidth) .attr('height', function(d, i) { var open = getOpen(d, i); var close = getClose(d, i); return open > close ? y(close) - y(open) : y(open) - y(close); }); }); return chart; } //Create methods to allow outside functions to highlight a specific bar. chart.highlightPoint = function(pointIndex, isHoverOver) { chart.clearHighlights(); container.select(".nv-candlestickBar .nv-tick-0-" + pointIndex) .classed("hover", isHoverOver) ; }; chart.clearHighlights = function() { container.select(".nv-candlestickBar .nv-tick.hover") .classed("hover", false) ; }; //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.dispatch = dispatch; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, xScale: {get: function(){return x;}, set: function(_){x=_;}}, yScale: {get: function(){return y;}, set: function(_){y=_;}}, xDomain: {get: function(){return xDomain;}, set: function(_){xDomain=_;}}, yDomain: {get: function(){return yDomain;}, set: function(_){yDomain=_;}}, xRange: {get: function(){return xRange;}, set: function(_){xRange=_;}}, yRange: {get: function(){return yRange;}, set: function(_){yRange=_;}}, forceX: {get: function(){return forceX;}, set: function(_){forceX=_;}}, forceY: {get: function(){return forceY;}, set: function(_){forceY=_;}}, padData: {get: function(){return padData;}, set: function(_){padData=_;}}, clipEdge: {get: function(){return clipEdge;}, set: function(_){clipEdge=_;}}, id: {get: function(){return id;}, set: function(_){id=_;}}, interactive: {get: function(){return interactive;}, set: function(_){interactive=_;}}, x: {get: function(){return getX;}, set: function(_){getX=_;}}, y: {get: function(){return getY;}, set: function(_){getY=_;}}, open: {get: function(){return getOpen();}, set: function(_){getOpen=_;}}, close: {get: function(){return getClose();}, set: function(_){getClose=_;}}, high: {get: function(){return getHigh;}, set: function(_){getHigh=_;}}, low: {get: function(){return getLow;}, set: function(_){getLow=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top != undefined ? _.top : margin.top; margin.right = _.right != undefined ? _.right : margin.right; margin.bottom = _.bottom != undefined ? _.bottom : margin.bottom; margin.left = _.left != undefined ? _.left : margin.left; }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); }} }); nv.utils.initOptions(chart); return chart; }; nv.models.cumulativeLineChart = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var lines = nv.models.line() , xAxis = nv.models.axis() , yAxis = nv.models.axis() , legend = nv.models.legend() , controls = nv.models.legend() , interactiveLayer = nv.interactiveGuideline() , tooltip = nv.models.tooltip() ; var margin = {top: 30, right: 30, bottom: 50, left: 60} , marginTop = null , color = nv.utils.defaultColor() , width = null , height = null , showLegend = true , showXAxis = true , showYAxis = true , rightAlignYAxis = false , showControls = true , useInteractiveGuideline = false , rescaleY = true , x //can be accessed via chart.xScale() , y //can be accessed via chart.yScale() , id = lines.id() , state = nv.utils.state() , defaultState = null , noData = null , average = function(d) { return d.average } , dispatch = d3.dispatch('stateChange', 'changeState', 'renderEnd') , transitionDuration = 250 , duration = 250 , noErrorCheck = false //if set to TRUE, will bypass an error check in the indexify function. ; state.index = 0; state.rescaleY = rescaleY; xAxis.orient('bottom').tickPadding(7); yAxis.orient((rightAlignYAxis) ? 'right' : 'left'); tooltip.valueFormatter(function(d, i) { return yAxis.tickFormat()(d, i); }).headerFormatter(function(d, i) { return xAxis.tickFormat()(d, i); }); controls.updateState(false); //============================================================ // Private Variables //------------------------------------------------------------ var dx = d3.scale.linear() , index = {i: 0, x: 0} , renderWatch = nv.utils.renderWatch(dispatch, duration) , currentYDomain ; var stateGetter = function(data) { return function(){ return { active: data.map(function(d) { return !d.disabled }), index: index.i, rescaleY: rescaleY }; } }; var stateSetter = function(data) { return function(state) { if (state.index !== undefined) index.i = state.index; if (state.rescaleY !== undefined) rescaleY = state.rescaleY; if (state.active !== undefined) data.forEach(function(series,i) { series.disabled = !state.active[i]; }); } }; function chart(selection) { renderWatch.reset(); renderWatch.models(lines); if (showXAxis) renderWatch.models(xAxis); if (showYAxis) renderWatch.models(yAxis); selection.each(function(data) { var container = d3.select(this); nv.utils.initSVG(container); container.classed('nv-chart-' + id, true); var that = this; var availableWidth = nv.utils.availableWidth(width, container, margin), availableHeight = nv.utils.availableHeight(height, container, margin); chart.update = function() { if (duration === 0) container.call(chart); else container.transition().duration(duration).call(chart) }; chart.container = this; state .setter(stateSetter(data), chart.update) .getter(stateGetter(data)) .update(); // DEPRECATED set state.disableddisabled state.disabled = data.map(function(d) { return !!d.disabled }); if (!defaultState) { var key; defaultState = {}; for (key in state) { if (state[key] instanceof Array) defaultState[key] = state[key].slice(0); else defaultState[key] = state[key]; } } var indexDrag = d3.behavior.drag() .on('dragstart', dragStart) .on('drag', dragMove) .on('dragend', dragEnd); function dragStart(d,i) { d3.select(chart.container) .style('cursor', 'ew-resize'); } function dragMove(d,i) { index.x = d3.event.x; index.i = Math.round(dx.invert(index.x)); updateZero(); } function dragEnd(d,i) { d3.select(chart.container) .style('cursor', 'auto'); // update state and send stateChange with new index state.index = index.i; dispatch.stateChange(state); } // Display No Data message if there's nothing to show. if (!data || !data.length || !data.filter(function(d) { return d.values.length }).length) { nv.utils.noData(chart, container) return chart; } else { container.selectAll('.nv-noData').remove(); } // Setup Scales x = lines.xScale(); y = lines.yScale(); dx.domain([0, data[0].values.length - 1]) //Assumes all series have same length .range([0, availableWidth]) .clamp(true); var data = indexify(index.i, data); // initialize the starting yDomain for the not-rescale case after indexify (to have calculated point.display) if (typeof(currentYDomain) === "undefined") { currentYDomain = getCurrentYDomain(data); } if (!rescaleY) { lines.yDomain(currentYDomain); lines.clipEdge(true); } else { lines.yDomain(null); } // Setup containers and skeleton of chart var interactivePointerEvents = (useInteractiveGuideline) ? "none" : "all"; var wrap = container.selectAll('g.nv-wrap.nv-cumulativeLine').data([data]); var gEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-cumulativeLine').append('g'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-interactive'); gEnter.append('g').attr('class', 'nv-x nv-axis').style("pointer-events","none"); gEnter.append('g').attr('class', 'nv-y nv-axis'); gEnter.append('g').attr('class', 'nv-background'); gEnter.append('g').attr('class', 'nv-linesWrap').style("pointer-events",interactivePointerEvents); gEnter.append('g').attr('class', 'nv-avgLinesWrap').style("pointer-events","none"); gEnter.append('g').attr('class', 'nv-legendWrap'); gEnter.append('g').attr('class', 'nv-controlsWrap'); // Legend if (!showLegend) { g.select('.nv-legendWrap').selectAll('*').remove(); } else { legend.width(availableWidth); g.select('.nv-legendWrap') .datum(data) .call(legend); if (!marginTop && legend.height() !== margin.top) { margin.top = legend.height(); availableHeight = nv.utils.availableHeight(height, container, margin); } g.select('.nv-legendWrap') .attr('transform', 'translate(0,' + (-margin.top) +')') } // Controls if (!showControls) { g.select('.nv-controlsWrap').selectAll('*').remove(); } else { var controlsData = [ { key: 'Re-scale y-axis', disabled: !rescaleY } ]; controls .width(140) .color(['#444', '#444', '#444']) .rightAlign(false) .margin({top: 5, right: 0, bottom: 5, left: 20}) ; g.select('.nv-controlsWrap') .datum(controlsData) .attr('transform', 'translate(0,' + (-margin.top) +')') .call(controls); } wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); if (rightAlignYAxis) { g.select(".nv-y.nv-axis") .attr("transform", "translate(" + availableWidth + ",0)"); } // Show error if index point value is 0 (division by zero avoided) var tempDisabled = data.filter(function(d) { return d.tempDisabled }); wrap.select('.tempDisabled').remove(); //clean-up and prevent duplicates if (tempDisabled.length) { wrap.append('text').attr('class', 'tempDisabled') .attr('x', availableWidth / 2) .attr('y', '-.71em') .style('text-anchor', 'end') .text(tempDisabled.map(function(d) { return d.key }).join(', ') + ' values cannot be calculated for this time period.'); } //Set up interactive layer if (useInteractiveGuideline) { interactiveLayer .width(availableWidth) .height(availableHeight) .margin({left:margin.left,top:margin.top}) .svgContainer(container) .xScale(x); wrap.select(".nv-interactive").call(interactiveLayer); } gEnter.select('.nv-background') .append('rect'); g.select('.nv-background rect') .attr('width', availableWidth) .attr('height', availableHeight); lines //.x(function(d) { return d.x }) .y(function(d) { return d.display.y }) .width(availableWidth) .height(availableHeight) .color(data.map(function(d,i) { return d.color || color(d, i); }).filter(function(d,i) { return !data[i].disabled && !data[i].tempDisabled; })); var linesWrap = g.select('.nv-linesWrap') .datum(data.filter(function(d) { return !d.disabled && !d.tempDisabled })); linesWrap.call(lines); //Store a series index number in the data array. data.forEach(function(d,i) { d.seriesIndex = i; }); var avgLineData = data.filter(function(d) { return !d.disabled && !!average(d); }); var avgLines = g.select(".nv-avgLinesWrap").selectAll("line") .data(avgLineData, function(d) { return d.key; }); var getAvgLineY = function(d) { //If average lines go off the svg element, clamp them to the svg bounds. var yVal = y(average(d)); if (yVal < 0) return 0; if (yVal > availableHeight) return availableHeight; return yVal; }; avgLines.enter() .append('line') .style('stroke-width',2) .style('stroke-dasharray','10,10') .style('stroke',function (d,i) { return lines.color()(d,d.seriesIndex); }) .attr('x1',0) .attr('x2',availableWidth) .attr('y1', getAvgLineY) .attr('y2', getAvgLineY); avgLines .style('stroke-opacity',function(d){ //If average lines go offscreen, make them transparent var yVal = y(average(d)); if (yVal < 0 || yVal > availableHeight) return 0; return 1; }) .attr('x1',0) .attr('x2',availableWidth) .attr('y1', getAvgLineY) .attr('y2', getAvgLineY); avgLines.exit().remove(); //Create index line var indexLine = linesWrap.selectAll('.nv-indexLine') .data([index]); indexLine.enter().append('rect').attr('class', 'nv-indexLine') .attr('width', 3) .attr('x', -2) .attr('fill', 'red') .attr('fill-opacity', .5) .style("pointer-events","all") .call(indexDrag); indexLine .attr('transform', function(d) { return 'translate(' + dx(d.i) + ',0)' }) .attr('height', availableHeight); // Setup Axes if (showXAxis) { xAxis .scale(x) ._ticks( nv.utils.calcTicksX(availableWidth/70, data) ) .tickSize(-availableHeight, 0); g.select('.nv-x.nv-axis') .attr('transform', 'translate(0,' + y.range()[0] + ')'); g.select('.nv-x.nv-axis') .call(xAxis); } if (showYAxis) { yAxis .scale(y) ._ticks( nv.utils.calcTicksY(availableHeight/36, data) ) .tickSize( -availableWidth, 0); g.select('.nv-y.nv-axis') .call(yAxis); } //============================================================ // Event Handling/Dispatching (in chart's scope) //------------------------------------------------------------ function updateZero() { indexLine .data([index]); //When dragging the index line, turn off line transitions. // Then turn them back on when done dragging. var oldDuration = chart.duration(); chart.duration(0); chart.update(); chart.duration(oldDuration); } g.select('.nv-background rect') .on('click', function() { index.x = d3.mouse(this)[0]; index.i = Math.round(dx.invert(index.x)); // update state and send stateChange with new index state.index = index.i; dispatch.stateChange(state); updateZero(); }); lines.dispatch.on('elementClick', function(e) { index.i = e.pointIndex; index.x = dx(index.i); // update state and send stateChange with new index state.index = index.i; dispatch.stateChange(state); updateZero(); }); controls.dispatch.on('legendClick', function(d,i) { d.disabled = !d.disabled; rescaleY = !d.disabled; state.rescaleY = rescaleY; if (!rescaleY) { currentYDomain = getCurrentYDomain(data); // rescale is turned off, so set the currentYDomain } dispatch.stateChange(state); chart.update(); }); legend.dispatch.on('stateChange', function(newState) { for (var key in newState) state[key] = newState[key]; dispatch.stateChange(state); chart.update(); }); interactiveLayer.dispatch.on('elementMousemove', function(e) { lines.clearHighlights(); var singlePoint, pointIndex, pointXLocation, allData = []; data .filter(function(series, i) { series.seriesIndex = i; return !(series.disabled || series.tempDisabled); }) .forEach(function(series,i) { pointIndex = nv.interactiveBisect(series.values, e.pointXValue, chart.x()); lines.highlightPoint(i, pointIndex, true); var point = series.values[pointIndex]; if (typeof point === 'undefined') return; if (typeof singlePoint === 'undefined') singlePoint = point; if (typeof pointXLocation === 'undefined') pointXLocation = chart.xScale()(chart.x()(point,pointIndex)); allData.push({ key: series.key, value: chart.y()(point, pointIndex), color: color(series,series.seriesIndex) }); }); //Highlight the tooltip entry based on which point the mouse is closest to. if (allData.length > 2) { var yValue = chart.yScale().invert(e.mouseY); var domainExtent = Math.abs(chart.yScale().domain()[0] - chart.yScale().domain()[1]); var threshold = 0.03 * domainExtent; var indexToHighlight = nv.nearestValueIndex(allData.map(function(d){return d.value}),yValue,threshold); if (indexToHighlight !== null) allData[indexToHighlight].highlight = true; } var xValue = xAxis.tickFormat()(chart.x()(singlePoint,pointIndex), pointIndex); interactiveLayer.tooltip .valueFormatter(function(d,i) { return yAxis.tickFormat()(d); }) .data( { value: xValue, series: allData } )(); interactiveLayer.renderGuideLine(pointXLocation); }); interactiveLayer.dispatch.on("elementMouseout",function(e) { lines.clearHighlights(); }); // Update chart from a state object passed to event handler dispatch.on('changeState', function(e) { if (typeof e.disabled !== 'undefined') { data.forEach(function(series,i) { series.disabled = e.disabled[i]; }); state.disabled = e.disabled; } if (typeof e.index !== 'undefined') { index.i = e.index; index.x = dx(index.i); state.index = e.index; indexLine .data([index]); } if (typeof e.rescaleY !== 'undefined') { rescaleY = e.rescaleY; } chart.update(); }); }); renderWatch.renderEnd('cumulativeLineChart immediate'); return chart; } //============================================================ // Event Handling/Dispatching (out of chart's scope) //------------------------------------------------------------ lines.dispatch.on('elementMouseover.tooltip', function(evt) { var point = { x: chart.x()(evt.point), y: chart.y()(evt.point), color: evt.point.color }; evt.point = point; tooltip.data(evt).hidden(false); }); lines.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true) }); //============================================================ // Functions //------------------------------------------------------------ var indexifyYGetter = null; /* Normalize the data according to an index point. */ function indexify(idx, data) { if (!indexifyYGetter) indexifyYGetter = lines.y(); return data.map(function(line, i) { if (!line.values) { return line; } var indexValue = line.values[idx]; if (indexValue == null) { return line; } var v = indexifyYGetter(indexValue, idx); // avoid divide by zero if (Math.abs(v) < 0.00001 && !noErrorCheck) { line.tempDisabled = true; return line; } line.tempDisabled = false; line.values = line.values.map(function(point, pointIndex) { point.display = {'y': (indexifyYGetter(point, pointIndex) - v) / v }; return point; }); return line; }) } function getCurrentYDomain(data) { var seriesDomains = data .filter(function(series) { return !(series.disabled || series.tempDisabled)}) .map(function(series,i) { return d3.extent(series.values, function (d) { return d.display.y }); }); return [ d3.min(seriesDomains, function(d) { return d[0] }), d3.max(seriesDomains, function(d) { return d[1] }) ]; } //============================================================ // Expose Public Variables //------------------------------------------------------------ // expose chart's sub-components chart.dispatch = dispatch; chart.lines = lines; chart.legend = legend; chart.controls = controls; chart.xAxis = xAxis; chart.yAxis = yAxis; chart.interactiveLayer = interactiveLayer; chart.state = state; chart.tooltip = tooltip; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, showControls: {get: function(){return showControls;}, set: function(_){showControls=_;}}, showLegend: {get: function(){return showLegend;}, set: function(_){showLegend=_;}}, average: {get: function(){return average;}, set: function(_){average=_;}}, defaultState: {get: function(){return defaultState;}, set: function(_){defaultState=_;}}, noData: {get: function(){return noData;}, set: function(_){noData=_;}}, showXAxis: {get: function(){return showXAxis;}, set: function(_){showXAxis=_;}}, showYAxis: {get: function(){return showYAxis;}, set: function(_){showYAxis=_;}}, noErrorCheck: {get: function(){return noErrorCheck;}, set: function(_){noErrorCheck=_;}}, // options that require extra logic in the setter rescaleY: {get: function(){return rescaleY;}, set: function(_){ rescaleY = _; chart.state.rescaleY = _; // also update state }}, margin: {get: function(){return margin;}, set: function(_){ if (_.top !== undefined) { margin.top = _.top; marginTop = _.top; } margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); legend.color(color); }}, useInteractiveGuideline: {get: function(){return useInteractiveGuideline;}, set: function(_){ useInteractiveGuideline = _; if (_ === true) { chart.interactive(false); chart.useVoronoi(false); } }}, rightAlignYAxis: {get: function(){return rightAlignYAxis;}, set: function(_){ rightAlignYAxis = _; yAxis.orient( (_) ? 'right' : 'left'); }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; lines.duration(duration); xAxis.duration(duration); yAxis.duration(duration); renderWatch.reset(duration); }} }); nv.utils.inheritOptions(chart, lines); nv.utils.initOptions(chart); return chart; }; //TODO: consider deprecating by adding necessary features to multiBar model nv.models.discreteBar = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 0, right: 0, bottom: 0, left: 0} , width = 960 , height = 500 , id = Math.floor(Math.random() * 10000) //Create semi-unique ID in case user doesn't select one , container , x = d3.scale.ordinal() , y = d3.scale.linear() , getX = function(d) { return d.x } , getY = function(d) { return d.y } , forceY = [0] // 0 is forced by default.. this makes sense for the majority of bar graphs... user can always do chart.forceY([]) to remove , color = nv.utils.defaultColor() , showValues = false , valueFormat = d3.format(',.2f') , xDomain , yDomain , xRange , yRange , dispatch = d3.dispatch('chartClick', 'elementClick', 'elementDblClick', 'elementMouseover', 'elementMouseout', 'elementMousemove', 'renderEnd') , rectClass = 'discreteBar' , duration = 250 ; //============================================================ // Private Variables //------------------------------------------------------------ var x0, y0; var renderWatch = nv.utils.renderWatch(dispatch, duration); function chart(selection) { renderWatch.reset(); selection.each(function(data) { var availableWidth = width - margin.left - margin.right, availableHeight = height - margin.top - margin.bottom; container = d3.select(this); nv.utils.initSVG(container); //add series index to each data point for reference data.forEach(function(series, i) { series.values.forEach(function(point) { point.series = i; }); }); // Setup Scales // remap and flatten the data for use in calculating the scales' domains var seriesData = (xDomain && yDomain) ? [] : // if we know xDomain and yDomain, no need to calculate data.map(function(d) { return d.values.map(function(d,i) { return { x: getX(d,i), y: getY(d,i), y0: d.y0 } }) }); x .domain(xDomain || d3.merge(seriesData).map(function(d) { return d.x })) .rangeBands(xRange || [0, availableWidth], .1); y .domain(yDomain || d3.extent(d3.merge(seriesData).map(function(d) { return d.y }).concat(forceY))); // If showValues, pad the Y axis range to account for label height if (showValues) y.range(yRange || [availableHeight - (y.domain()[0] < 0 ? 12 : 0), y.domain()[1] > 0 ? 12 : 0]); else y.range(yRange || [availableHeight, 0]); //store old scales if they exist x0 = x0 || x; y0 = y0 || y.copy().range([y(0),y(0)]); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-discretebar').data([data]); var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-discretebar'); var gEnter = wrapEnter.append('g'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-groups'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); //TODO: by definition, the discrete bar should not have multiple groups, will modify/remove later var groups = wrap.select('.nv-groups').selectAll('.nv-group') .data(function(d) { return d }, function(d) { return d.key }); groups.enter().append('g') .style('stroke-opacity', 1e-6) .style('fill-opacity', 1e-6); groups.exit() .watchTransition(renderWatch, 'discreteBar: exit groups') .style('stroke-opacity', 1e-6) .style('fill-opacity', 1e-6) .remove(); groups .attr('class', function(d,i) { return 'nv-group nv-series-' + i }) .classed('hover', function(d) { return d.hover }); groups .watchTransition(renderWatch, 'discreteBar: groups') .style('stroke-opacity', 1) .style('fill-opacity', .75); var bars = groups.selectAll('g.nv-bar') .data(function(d) { return d.values }); bars.exit().remove(); var barsEnter = bars.enter().append('g') .attr('transform', function(d,i,j) { return 'translate(' + (x(getX(d,i)) + x.rangeBand() * .05 ) + ', ' + y(0) + ')' }) .on('mouseover', function(d,i) { //TODO: figure out why j works above, but not here d3.select(this).classed('hover', true); dispatch.elementMouseover({ data: d, index: i, color: d3.select(this).style("fill") }); }) .on('mouseout', function(d,i) { d3.select(this).classed('hover', false); dispatch.elementMouseout({ data: d, index: i, color: d3.select(this).style("fill") }); }) .on('mousemove', function(d,i) { dispatch.elementMousemove({ data: d, index: i, color: d3.select(this).style("fill") }); }) .on('click', function(d,i) { var element = this; dispatch.elementClick({ data: d, index: i, color: d3.select(this).style("fill"), event: d3.event, element: element }); d3.event.stopPropagation(); }) .on('dblclick', function(d,i) { dispatch.elementDblClick({ data: d, index: i, color: d3.select(this).style("fill") }); d3.event.stopPropagation(); }); barsEnter.append('rect') .attr('height', 0) .attr('width', x.rangeBand() * .9 / data.length ) if (showValues) { barsEnter.append('text') .attr('text-anchor', 'middle') ; bars.select('text') .text(function(d,i) { return valueFormat(getY(d,i)) }) .watchTransition(renderWatch, 'discreteBar: bars text') .attr('x', x.rangeBand() * .9 / 2) .attr('y', function(d,i) { return getY(d,i) < 0 ? y(getY(d,i)) - y(0) + 12 : -4 }) ; } else { bars.selectAll('text').remove(); } bars .attr('class', function(d,i) { return getY(d,i) < 0 ? 'nv-bar negative' : 'nv-bar positive' }) .style('fill', function(d,i) { return d.color || color(d,i) }) .style('stroke', function(d,i) { return d.color || color(d,i) }) .select('rect') .attr('class', rectClass) .watchTransition(renderWatch, 'discreteBar: bars rect') .attr('width', x.rangeBand() * .9 / data.length); bars.watchTransition(renderWatch, 'discreteBar: bars') //.delay(function(d,i) { return i * 1200 / data[0].values.length }) .attr('transform', function(d,i) { var left = x(getX(d,i)) + x.rangeBand() * .05, top = getY(d,i) < 0 ? y(0) : y(0) - y(getY(d,i)) < 1 ? y(0) - 1 : //make 1 px positive bars show up above y=0 y(getY(d,i)); return 'translate(' + left + ', ' + top + ')' }) .select('rect') .attr('height', function(d,i) { return Math.max(Math.abs(y(getY(d,i)) - y(0)), 1) }); //store old scales for use in transitions on update x0 = x.copy(); y0 = y.copy(); }); renderWatch.renderEnd('discreteBar immediate'); return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.dispatch = dispatch; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, forceY: {get: function(){return forceY;}, set: function(_){forceY=_;}}, showValues: {get: function(){return showValues;}, set: function(_){showValues=_;}}, x: {get: function(){return getX;}, set: function(_){getX=_;}}, y: {get: function(){return getY;}, set: function(_){getY=_;}}, xScale: {get: function(){return x;}, set: function(_){x=_;}}, yScale: {get: function(){return y;}, set: function(_){y=_;}}, xDomain: {get: function(){return xDomain;}, set: function(_){xDomain=_;}}, yDomain: {get: function(){return yDomain;}, set: function(_){yDomain=_;}}, xRange: {get: function(){return xRange;}, set: function(_){xRange=_;}}, yRange: {get: function(){return yRange;}, set: function(_){yRange=_;}}, valueFormat: {get: function(){return valueFormat;}, set: function(_){valueFormat=_;}}, id: {get: function(){return id;}, set: function(_){id=_;}}, rectClass: {get: function(){return rectClass;}, set: function(_){rectClass=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; renderWatch.reset(duration); }} }); nv.utils.initOptions(chart); return chart; }; nv.models.discreteBarChart = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var discretebar = nv.models.discreteBar() , xAxis = nv.models.axis() , yAxis = nv.models.axis() , legend = nv.models.legend() , tooltip = nv.models.tooltip() ; var margin = {top: 15, right: 10, bottom: 50, left: 60} , marginTop = null , width = null , height = null , color = nv.utils.getColor() , showLegend = false , showXAxis = true , showYAxis = true , rightAlignYAxis = false , staggerLabels = false , wrapLabels = false , rotateLabels = 0 , x , y , noData = null , dispatch = d3.dispatch('beforeUpdate','renderEnd') , duration = 250 ; xAxis .orient('bottom') .showMaxMin(false) .tickFormat(function(d) { return d }) ; yAxis .orient((rightAlignYAxis) ? 'right' : 'left') .tickFormat(d3.format(',.1f')) ; tooltip .duration(0) .headerEnabled(false) .valueFormatter(function(d, i) { return yAxis.tickFormat()(d, i); }) .keyFormatter(function(d, i) { return xAxis.tickFormat()(d, i); }); //============================================================ // Private Variables //------------------------------------------------------------ var renderWatch = nv.utils.renderWatch(dispatch, duration); function chart(selection) { renderWatch.reset(); renderWatch.models(discretebar); if (showXAxis) renderWatch.models(xAxis); if (showYAxis) renderWatch.models(yAxis); selection.each(function(data) { var container = d3.select(this), that = this; nv.utils.initSVG(container); var availableWidth = nv.utils.availableWidth(width, container, margin), availableHeight = nv.utils.availableHeight(height, container, margin); chart.update = function() { dispatch.beforeUpdate(); container.transition().duration(duration).call(chart); }; chart.container = this; // Display No Data message if there's nothing to show. if (!data || !data.length || !data.filter(function(d) { return d.values.length }).length) { nv.utils.noData(chart, container); return chart; } else { container.selectAll('.nv-noData').remove(); } // Setup Scales x = discretebar.xScale(); y = discretebar.yScale().clamp(true); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-discreteBarWithAxes').data([data]); var gEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-discreteBarWithAxes').append('g'); var defsEnter = gEnter.append('defs'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-x nv-axis'); gEnter.append('g').attr('class', 'nv-y nv-axis') .append('g').attr('class', 'nv-zeroLine') .append('line'); gEnter.append('g').attr('class', 'nv-barsWrap'); gEnter.append('g').attr('class', 'nv-legendWrap'); g.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); // Legend if (!showLegend) { g.select('.nv-legendWrap').selectAll('*').remove(); } else { legend.width(availableWidth); g.select('.nv-legendWrap') .datum(data) .call(legend); if (!marginTop && legend.height() !== margin.top) { margin.top = legend.height(); availableHeight = nv.utils.availableHeight(height, container, margin); } wrap.select('.nv-legendWrap') .attr('transform', 'translate(0,' + (-margin.top) +')') } if (rightAlignYAxis) { g.select(".nv-y.nv-axis") .attr("transform", "translate(" + availableWidth + ",0)"); } // Main Chart Component(s) discretebar .width(availableWidth) .height(availableHeight); var barsWrap = g.select('.nv-barsWrap') .datum(data.filter(function(d) { return !d.disabled })); barsWrap.transition().call(discretebar); defsEnter.append('clipPath') .attr('id', 'nv-x-label-clip-' + discretebar.id()) .append('rect'); g.select('#nv-x-label-clip-' + discretebar.id() + ' rect') .attr('width', x.rangeBand() * (staggerLabels ? 2 : 1)) .attr('height', 16) .attr('x', -x.rangeBand() / (staggerLabels ? 1 : 2 )); // Setup Axes if (showXAxis) { xAxis .scale(x) ._ticks( nv.utils.calcTicksX(availableWidth/100, data) ) .tickSize(-availableHeight, 0); g.select('.nv-x.nv-axis') .attr('transform', 'translate(0,' + (y.range()[0] + ((discretebar.showValues() && y.domain()[0] < 0) ? 16 : 0)) + ')'); g.select('.nv-x.nv-axis').call(xAxis); var xTicks = g.select('.nv-x.nv-axis').selectAll('g'); if (staggerLabels) { xTicks .selectAll('text') .attr('transform', function(d,i,j) { return 'translate(0,' + (j % 2 == 0 ? '5' : '17') + ')' }) } if (rotateLabels) { xTicks .selectAll('.tick text') .attr('transform', 'rotate(' + rotateLabels + ' 0,0)') .style('text-anchor', rotateLabels > 0 ? 'start' : 'end'); } if (wrapLabels) { g.selectAll('.tick text') .call(nv.utils.wrapTicks, chart.xAxis.rangeBand()) } } if (showYAxis) { yAxis .scale(y) ._ticks( nv.utils.calcTicksY(availableHeight/36, data) ) .tickSize( -availableWidth, 0); g.select('.nv-y.nv-axis').call(yAxis); } // Zero line g.select(".nv-zeroLine line") .attr("x1",0) .attr("x2",(rightAlignYAxis) ? -availableWidth : availableWidth) .attr("y1", y(0)) .attr("y2", y(0)) ; }); renderWatch.renderEnd('discreteBar chart immediate'); return chart; } //============================================================ // Event Handling/Dispatching (out of chart's scope) //------------------------------------------------------------ discretebar.dispatch.on('elementMouseover.tooltip', function(evt) { evt['series'] = { key: chart.x()(evt.data), value: chart.y()(evt.data), color: evt.color }; tooltip.data(evt).hidden(false); }); discretebar.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true); }); discretebar.dispatch.on('elementMousemove.tooltip', function(evt) { tooltip(); }); //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.dispatch = dispatch; chart.discretebar = discretebar; chart.legend = legend; chart.xAxis = xAxis; chart.yAxis = yAxis; chart.tooltip = tooltip; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, showLegend: {get: function(){return showLegend;}, set: function(_){showLegend=_;}}, staggerLabels: {get: function(){return staggerLabels;}, set: function(_){staggerLabels=_;}}, rotateLabels: {get: function(){return rotateLabels;}, set: function(_){rotateLabels=_;}}, wrapLabels: {get: function(){return wrapLabels;}, set: function(_){wrapLabels=!!_;}}, showXAxis: {get: function(){return showXAxis;}, set: function(_){showXAxis=_;}}, showYAxis: {get: function(){return showYAxis;}, set: function(_){showYAxis=_;}}, noData: {get: function(){return noData;}, set: function(_){noData=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ if (_.top !== undefined) { margin.top = _.top; marginTop = _.top; } margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; renderWatch.reset(duration); discretebar.duration(duration); xAxis.duration(duration); yAxis.duration(duration); }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); discretebar.color(color); legend.color(color); }}, rightAlignYAxis: {get: function(){return rightAlignYAxis;}, set: function(_){ rightAlignYAxis = _; yAxis.orient( (_) ? 'right' : 'left'); }} }); nv.utils.inheritOptions(chart, discretebar); nv.utils.initOptions(chart); return chart; } nv.models.distribution = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 0, right: 0, bottom: 0, left: 0} , width = 400 //technically width or height depending on x or y.... , size = 8 , axis = 'x' // 'x' or 'y'... horizontal or vertical , getData = function(d) { return d[axis] } // defaults d.x or d.y , color = nv.utils.defaultColor() , scale = d3.scale.linear() , domain , duration = 250 , dispatch = d3.dispatch('renderEnd') ; //============================================================ //============================================================ // Private Variables //------------------------------------------------------------ var scale0; var renderWatch = nv.utils.renderWatch(dispatch, duration); //============================================================ function chart(selection) { renderWatch.reset(); selection.each(function(data) { var availableLength = width - (axis === 'x' ? margin.left + margin.right : margin.top + margin.bottom), naxis = axis == 'x' ? 'y' : 'x', container = d3.select(this); nv.utils.initSVG(container); //------------------------------------------------------------ // Setup Scales scale0 = scale0 || scale; //------------------------------------------------------------ //------------------------------------------------------------ // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-distribution').data([data]); var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-distribution'); var gEnter = wrapEnter.append('g'); var g = wrap.select('g'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')') //------------------------------------------------------------ var distWrap = g.selectAll('g.nv-dist') .data(function(d) { return d }, function(d) { return d.key }); distWrap.enter().append('g'); distWrap .attr('class', function(d,i) { return 'nv-dist nv-series-' + i }) .style('stroke', function(d,i) { return color(d, i) }); var dist = distWrap.selectAll('line.nv-dist' + axis) .data(function(d) { return d.values }) dist.enter().append('line') .attr(axis + '1', function(d,i) { return scale0(getData(d,i)) }) .attr(axis + '2', function(d,i) { return scale0(getData(d,i)) }) renderWatch.transition(distWrap.exit().selectAll('line.nv-dist' + axis), 'dist exit') // .transition() .attr(axis + '1', function(d,i) { return scale(getData(d,i)) }) .attr(axis + '2', function(d,i) { return scale(getData(d,i)) }) .style('stroke-opacity', 0) .remove(); dist .attr('class', function(d,i) { return 'nv-dist' + axis + ' nv-dist' + axis + '-' + i }) .attr(naxis + '1', 0) .attr(naxis + '2', size); renderWatch.transition(dist, 'dist') // .transition() .attr(axis + '1', function(d,i) { return scale(getData(d,i)) }) .attr(axis + '2', function(d,i) { return scale(getData(d,i)) }) scale0 = scale.copy(); }); renderWatch.renderEnd('distribution immediate'); return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.options = nv.utils.optionsFunc.bind(chart); chart.dispatch = dispatch; chart.margin = function(_) { if (!arguments.length) return margin; margin.top = typeof _.top != 'undefined' ? _.top : margin.top; margin.right = typeof _.right != 'undefined' ? _.right : margin.right; margin.bottom = typeof _.bottom != 'undefined' ? _.bottom : margin.bottom; margin.left = typeof _.left != 'undefined' ? _.left : margin.left; return chart; }; chart.width = function(_) { if (!arguments.length) return width; width = _; return chart; }; chart.axis = function(_) { if (!arguments.length) return axis; axis = _; return chart; }; chart.size = function(_) { if (!arguments.length) return size; size = _; return chart; }; chart.getData = function(_) { if (!arguments.length) return getData; getData = d3.functor(_); return chart; }; chart.scale = function(_) { if (!arguments.length) return scale; scale = _; return chart; }; chart.color = function(_) { if (!arguments.length) return color; color = nv.utils.getColor(_); return chart; }; chart.duration = function(_) { if (!arguments.length) return duration; duration = _; renderWatch.reset(duration); return chart; }; //============================================================ return chart; } nv.models.distroPlot = function() { "use strict"; // IMPROVEMENTS: // - cleanup tooltip to look like candlestick example (don't need color square for everything) // - extend y scale range to min/max data better visually // - tips of violins need to be cut off if very long // - transition from box to violin not great since box only has a few points, and violin has many - need to generate box with as many points as violin // - when providing colorGroup, should color boxes by either parent or child group category (e.g. isolator) //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 0, right: 0, bottom: 0, left: 0}, width = 960, height = 500, id = Math.floor(Math.random() * 10000), // Create semi-unique ID in case user doesn't select one xScale = d3.scale.ordinal(), yScale = d3.scale.linear(), getX = function(d) { return d.label }, // Default data model selectors. getY = function(d) { return d.value }, getColor = function(d) { return d.color }, getQ1 = function(d) { return d.values.q1 }, getQ2 = function(d) { return d.values.q2 }, getQ3 = function(d) { return d.values.q3 }, getNl = function(d) { return (centralTendency == 'mean' ? getMean(d) : getQ2(d)) - d.values.notch }, getNu = function(d) { return (centralTendency == 'mean' ? getMean(d) : getQ2(d)) + d.values.notch }, getMean = function(d) { return d.values.mean }, getWl = function(d) { return d.values.wl[whiskerDef] }, getWh = function(d) { return d.values.wu[whiskerDef] }, getMin = function(d) { return d.values.min }, getMax = function(d) { return d.values.max }, getDev = function(d) { return d.values.dev }, getValsObj = function(d) { return d.values.observations; }, getValsArr = function(d) { return d.values.observations.map(function(e) { return e.y }); }, plotType, // type of background: 'box', 'violin', 'none'/false - default: 'box' - 'none' will activate random scatter automatically observationType = false, // type of observations to show: 'random', 'swarm', 'line', 'centered' - default: false (don't show any observations, even if an outlier) whiskerDef = 'iqr', // type of whisker to render: 'iqr', 'minmax', 'stddev' - default: iqr hideWhiskers = false, notchBox = false, // bool whether to notch box colorGroup = false, // if specified, each x-category will be split into groups, each colored centralTendency = false, showOnlyOutliers = true, // show only outliers in box plot jitter = 0.7, // faction of that jitter should take up in 'random' observationType, must be in range [0,1]; see jitterX(), default 0.7 squash = true, // whether to remove the x-axis positions for empty data groups, default is true bandwidth = 'scott', // bandwidth for kde calculation, can be float or str, if str, must be one of scott or silverman clampViolin = true, // whether to clamp the "tails" of the violin; prevents long 0-density area resolution = 50, pointSize = 3, color = nv.utils.defaultColor(), container = null, xDomain, xRange, yDomain, yRange, dispatch = d3.dispatch('elementMouseover', 'elementMouseout', 'elementMousemove', 'renderEnd'), duration = 250, maxBoxWidth = null; //============================================================ // Helper Functions //------------------------------------------------------------ /* Returns the smaller of std(X, ddof=1) or normalized IQR(X) over axis 0. * * @param (list) x - input x formatted as a single list of values * * @return float * * Source: https://github.com/statsmodels/statsmodels/blob/master/statsmodels/nonparametric/bandwidths.py#L9 */ function select_sigma(x) { var sorted = x.sort(d3.ascending); // sort our dat var normalize = 1.349; var IQR = (d3.quantile(sorted, 0.75) - d3.quantile(sorted, 0.25))/normalize; // normalized IQR return d3.min([d3.deviation(sorted), IQR]); } /* Scott's Rule of Thumb Parameters ---------- x : array-like Array for which to get the bandwidth type : string The type of estimate to use, must be one of scott or silverman Returns ------- bw : float The estimate of the bandwidth Notes ----- Returns 1.059 * A * n ** (-1/5.) where :: A = min(std(x, ddof=1), IQR/1.349) IQR = np.subtract.reduce(np.percentile(x, [75,25])) References ---------- Scott, D.W. (1992) Multivariate Density Estimation: Theory, Practice, and Visualization. */ function calcBandwidth(x, type) { if (typeof type === 'undefined') type = 'scott'; // TODO: consider using https://github.com/jasondavies/science.js var A = select_sigma(x); var n = x.length; return type==='scott' ? Math.pow(1.059 * A * n, -0.2) : Math.pow(.9 * A * n, -0.2); } /* * Prep data for use with distroPlot by grouping data * by .x() option set by user and then calculating * count, sum, mean, q1, q2 (median), q3, lower whisker (wl) * upper whisker (wu), iqr, min, max, and standard dev. * * NOTE: preparing this data can be resource intensive, and * is therefore only run once on plot load. It can * manually be run by calling recalcData(). This should * be re-run any time the axis accessors are changed or * when bandwidth/resolution are updated. * * NOTE: this will also setup the individual vertical scales * for the violins. * * @param (list) dat - input data formatted as list of objects, * with an object key that must exist when accessed by getX() * * @return prepared data in the form for box plotType: * [{ * key : YY, * values: { * count: XX, * sum: XX, * mean: XX, * q1: XX, * q2: XX, * q3: XX, * wl: XX, * wu: XX, * iqr: XX, * min: XX, * max: XX, * dev: XX, * observations: [{y:XX,..},..], * key: XX, * kdeDat: XX, * notch: XX, * } * }, * ... * ] * for violin plotType: * [{ * key : YY, * values: { * original: [{y:XX,..},..] * } * }, * ... * ] * where YY are those keys in dat that define the * x-axis and which are defined by .x() */ function prepData(dat) { // helper function to calcuate the various boxplot stats function calcStats(g, xGroup) { // sort data by Y so we can calc quartiles var v = g.map(function(d) { if (colorGroup) allColorGroups.add(colorGroup(d)); // list of all colorGroups; used to set x-axis return getY(d); }).sort(d3.ascending); var q1 = d3.quantile(v, 0.25); var q3 = d3.quantile(v, 0.75); var iqr = q3 - q1; var upper = q3 + 1.5 * iqr; var lower = q1 - 1.5 * iqr; /* whisker definitions: * - iqr: also known as Tukey boxplot, the lowest datum still within 1.5 IQR of the lower quartile, and the highest datum still within 1.5 IQR of the upper quartile * - minmax: the minimum and maximum of all of the data * - sttdev: one standard deviation above and below the mean of the data * Note that the central tendency type (median or mean) does not impact the whisker location */ var wl = {iqr: d3.max([d3.min(v), d3.min(v.filter(function(d) {return d > lower}))]), minmax: d3.min(v), stddev: d3.mean(v) - d3.deviation(v)}; var wu = {iqr: d3.min([d3.max(v), d3.max(v.filter(function(d) {return d < upper}))]), minmax: d3.max(v), stddev: d3.mean(v) + d3.deviation(v)}; var median = d3.median(v); var mean = d3.mean(v); var observations = []; // d3-beeswarm library must be externally loaded if being used // https://github.com/Kcnarf/d3-beeswarm if (typeof d3.beeswarm !== 'undefined') { observations = d3.beeswarm() .data(g.map(function(e) { return getY(e); })) .radius(pointSize+1) .orientation('vertical') .side('symmetric') .distributeOn(function(e) { return yScale(e); }) .arrange() // add group info for tooltip observations.map(function(e,i) { e.key = xGroup; e.object_constancy = g[i].object_constancy; e.isOutlier = (e.datum < wl.iqr || e.datum > wu.iqr) // add isOulier meta for proper class assignment e.isOutlierStdDev = (e.datum < wl.stddev || e.datum > wu.stddev) // add isOulier meta for proper class assignment e.randX = Math.random() * jitter * (Math.floor(Math.random()*2) == 1 ? 1 : -1) // calculate random x-position only once for each point }) } else { v.forEach(function(e,i) { observations.push({ object_constancy: e.object_constancy, datum: e, key: xGroup, isOutlier: (e < wl.iqr || e > wu.iqr), // add isOulier meta for proper class assignment isOutlierStdDev: (e < wl.stddev || e > wu.stddev), // add isOulier meta for proper class assignment randX: Math.random() * jitter * (Math.floor(Math.random()*2) == 1 ? 1 : -1) }) }) } // calculate bandwidth if no number is provided if(isNaN(parseFloat(bandwidth))) { // if not is float var bandwidthCalc; if (['scott','silverman'].indexOf(bandwidth) != -1) { bandwidthCalc = calcBandwidth(v, bandwidth); } else { bandwidthCalc = calcBandwidth(v); // calculate with default 'scott' } } var kde = kernelDensityEstimator(eKernel(bandwidthCalc), yScale.ticks(resolution)); var kdeDat = clampViolin ? clampViolinKDE(kde(v), d3.extent(v)) : kde(v); // make a new vertical scale for each group var tmpScale = d3.scale.linear() .domain([0, d3.max(kdeDat, function (e) { return e.y;})]) .clamp(true); yVScale.push(tmpScale); var reformat = { count: v.length, num_outlier: observations.filter(function (e) { return e.isOutlier; }).length, sum: d3.sum(v), mean: mean, q1: q1, q2: median, q3: q3, wl: wl, wu: wu, iqr: iqr, min: d3.min(v), max: d3.max(v), dev: d3.deviation(v), observations: observations, key: xGroup, kde: kdeDat, notch: 1.57 * iqr / Math.sqrt(v.length), // notch distance from mean/median }; if (colorGroup) {reformatDatFlat.push({key: xGroup, values: reformat});} return reformat; } // assign a unique identifier for each point for object constancy // this makes updating data possible dat.forEach(function(d,i) { d.object_constancy = i + '_' + getY(d) + '_' + getX(d); }) // TODO not DRY // couldn't find a conditional way of doing the key() grouping var formatted; if (!colorGroup) { formatted = d3.nest() .key(function(d) { return getX(d); }) .rollup(function(v,i) { return calcStats(v); }) .entries(dat); } else { allColorGroups = d3.set() // reset var tmp = d3.nest() .key(function(d) { return getX(d); }) .key(function(d) { return colorGroup(d); }) .rollup(function(v) { return calcStats(v, getX(v[0])); }) .entries(dat); // generate a final list of all x & colorGroup combinations // this is used to properly set the x-axis domain allColorGroups = allColorGroups.values(); // convert from d3.set to list var xGroups = tmp.map(function(d) { return d.key; }); var allGroups = []; for (var i = 0; i < xGroups.length; i++) { for (var j = 0; j < allColorGroups.length; j++) { allGroups.push(xGroups[i] + '_' + allColorGroups[j]); } } allColorGroups = allGroups; // flatten the inner most level so that // the plot retains the same DOM structure // to allow for smooth updating between // all groups. formatted = []; tmp.forEach(function(d) { d.values.forEach(function(e) { e.key = d.key +'_'+e.key }) // generate a combo key so that each boxplot has a distinct x-position formatted.push.apply(formatted, d.values) }); } return formatted; } // https://bl.ocks.org/mbostock/4341954 function kernelDensityEstimator(kernel, X) { return function (sample) { return X.map(function(x) { var y = d3.mean(sample, function (v) {return kernel(x - v);}); return {x:x, y:y}; }); }; } /* * Limit whether the density extends past the extreme datapoints * of the violin. * * @param (list) kde - x & y kde cooridinates * @param (list) extent - min/max y-values used for clamping violing */ function clampViolinKDE(kde, extent) { // this handles the case when all the x-values are equal // which means no kde could be properly calculated // just return the kde data so we can continue plotting successfully if (extent[0] === extent[1]) return kde; var clamped = kde.reduce(function(res, d) { if (d.x >= extent[0] && d.x <= extent[1]) res.push(d); return res; },[]); // add the extreme data points back in if (extent[0] < clamped[0].x) clamped.unshift({x:extent[0], y:clamped[0].y}) if (extent[1] > clamped[clamped.length-1].x) clamped.push({x:extent[1], y:clamped[clamped.length-1].y}) return clamped; } // https://bl.ocks.org/mbostock/4341954 function eKernel(scale) { return function (u) { return Math.abs(u /= scale) <= 1 ? .75 * (1 - u * u) / scale : 0; }; } /** * Makes the svg polygon string for a boxplot in either a notched * or square version * * NOTE: this actually only draws the left half of the box, since * the shape is symmetric (and since this is how violins are drawn) * we can simply generate half the box and mirror it. * * @param boxLeft {float} - left position of box * @param notchLeft {float} - left position of notch * @param dat {obj} - box plot data that was run through prepDat, must contain * data for Q1, median, Q2, notch upper and notch lower * @returns {string} A string in the proper format for a svg polygon */ function makeNotchBox(boxLeft, notchLeft, boxCenter, dat) { var boxPoints; var y = centralTendency == 'mean' ? getMean(dat) : getQ2(dat); // if centralTendency is not specified, we still want to notch boxes on 'median' if (notchBox) { boxPoints = [ {x:boxCenter, y:yScale(getQ1(dat))}, {x:boxLeft, y:yScale(getQ1(dat))}, {x:boxLeft, y:yScale(getNl(dat))}, {x:notchLeft, y:yScale(y)}, {x:boxLeft, y:yScale(getNu(dat))}, {x:boxLeft, y:yScale(getQ3(dat))}, {x:boxCenter, y:yScale(getQ3(dat))}, ]; } else { boxPoints = [ {x:boxCenter, y:yScale(getQ1(dat))}, {x:boxLeft, y:yScale(getQ1(dat))}, {x:boxLeft, y:yScale(y)}, // repeated point so that transition between notched/regular more smooth {x:boxLeft, y:yScale(y)}, {x:boxLeft, y:yScale(y)}, // repeated point so that transition between notched/regular more smooth {x:boxLeft, y:yScale(getQ3(dat))}, {x:boxCenter, y:yScale(getQ3(dat))}, ]; } return boxPoints; } /** * Given an x-axis group, return the available color groups within it * provided that colorGroups is set, if not, x-axis group is returned */ function getAvailableColorGroups(x) { if (!colorGroup) return x; var tmp = reformatDat.find(function(d) { return d.key == x }); return tmp.values.map(function(d) { return d.key }).sort(d3.ascending); } // return true if point is an outlier function isOutlier(d) { return (whiskerDef == 'iqr' && d.isOutlier) || (whiskerDef == 'stddev' && d.isOutlierStdDev) } //============================================================ // Private Variables //------------------------------------------------------------ var allColorGroups = d3.set() var yVScale = [], reformatDat, reformatDatFlat = []; var renderWatch = nv.utils.renderWatch(dispatch, duration); var availableWidth, availableHeight; function chart(selection) { renderWatch.reset(); selection.each(function(data) { availableWidth = width - margin.left - margin.right, availableHeight = height - margin.top - margin.bottom; container = d3.select(this); nv.utils.initSVG(container); // Setup y-scale so that beeswarm layout can use it in prepData() yScale.domain(yDomain || d3.extent(data.map(function(d) { return getY(d)}))).nice() .range(yRange || [availableHeight, 0]); if (typeof reformatDat === 'undefined') reformatDat = prepData(data); // this prevents us from recalculating data all the time // Setup x-scale xScale.rangeBands(xRange || [0, availableWidth], 0.1) .domain(xDomain || (colorGroup && !squash) ? allColorGroups : reformatDat.map(function(d) { return d.key })) // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap').data([reformatDat]); var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap'); wrap.watchTransition(renderWatch, 'nv-wrap: wrap') .attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); var areaEnter, distroplots = wrap.selectAll('.nv-distroplot-x-group') .data(function(d) { return d; }); // rebind new data // we don't rebuild individual x-axis groups so that we can update transition them // however the data associated with each x-axis group needs to be updated // so we manually update it here distroplots.each(function(d,i) { d3.select(this).selectAll('line.nv-distroplot-middle').datum(d); }) areaEnter = distroplots.enter() .append('g') .attr('class', 'nv-distroplot-x-group') .style('stroke-opacity', 1e-6).style('fill-opacity', 1e-6) .style('fill', function(d,i) { return getColor(d) || color(d,i) }) .style('stroke', function(d,i) { return getColor(d) || color(d,i) }) distroplots.exit().remove(); var rangeBand = function() { return xScale.rangeBand() }; var areaWidth = function() { return d3.min([maxBoxWidth,rangeBand() * 0.9]); }; var areaCenter = function() { return areaWidth()/2; }; var areaLeft = function() { return areaCenter() - areaWidth()/2; }; var areaRight = function() { return areaCenter() + areaWidth()/2; }; var tickLeft = function() { return areaCenter() - areaWidth()/5; }; var tickRight = function() { return areaCenter() + areaWidth()/5; }; areaEnter.attr('transform', function(d) { return 'translate(' + (xScale(d.key) + (rangeBand() - areaWidth()) * 0.5) + ', 0)'; }); distroplots .watchTransition(renderWatch, 'nv-distroplot-x-group: distroplots') .style('stroke-opacity', 1) .style('fill-opacity', 0.5) .attr('transform', function(d) { return 'translate(' + (xScale(d.key) + (rangeBand() - areaWidth()) * 0.5) + ', 0)'; }); // set range for violin scale yVScale.map(function(d) { d.range([areaWidth()/2, 0]) }); // ----- add the SVG elements for each plot type ----- // scatter plot type if (!plotType) { showOnlyOutliers = false; // force all observations to be seen if (!observationType) observationType = 'random' } // conditionally append whisker lines areaEnter.each(function(d,i) { var box = d3.select(this); [getWl, getWh].forEach(function (f) { var key = (f === getWl) ? 'low' : 'high'; box.append('line') .style('opacity', function() { return !hideWhiskers ? '0' : '1' }) .attr('class', 'nv-distroplot-whisker nv-distroplot-' + key) box.append('line') .style('opacity', function() { return hideWhiskers ? '0' : '1' }) .attr('class', 'nv-distroplot-tick nv-distroplot-' + key) }); }); // update whisker lines and ticks [getWl, getWh].forEach(function (f) { var key = (f === getWl) ? 'low' : 'high'; var endpoint = (f === getWl) ? getQ1 : getQ3; distroplots.select('line.nv-distroplot-whisker.nv-distroplot-' + key) .watchTransition(renderWatch, 'nv-distroplot-x-group: distroplots') .attr('x1', areaCenter()) .attr('y1', function(d) { return plotType!='violin' ? yScale(f(d)) : yScale(getQ2(d)); }) .attr('x2', areaCenter()) .attr('y2', function(d) { return plotType=='box' ? yScale(endpoint(d)) : yScale(getQ2(d)); }) .style('opacity', function() { return hideWhiskers ? '0' : '1' }) distroplots.select('line.nv-distroplot-tick.nv-distroplot-' + key) .watchTransition(renderWatch, 'nv-distroplot-x-group: distroplots') .attr('x1', function(d) { return plotType!='violin' ? tickLeft() : areaCenter()} ) .attr('y1', function(d,i) { return plotType!='violin' ? yScale(f(d)) : yScale(getQ2(d)); }) .attr('x2', function(d) { return plotType!='violin' ? tickRight() : areaCenter()} ) .attr('y2', function(d,i) { return plotType!='violin' ? yScale(f(d)) : yScale(getQ2(d)); }) .style('opacity', function() { return hideWhiskers ? '0' : '1' }) }); [getWl, getWh].forEach(function (f) { var key = (f === getWl) ? 'low' : 'high'; areaEnter.selectAll('.nv-distroplot-' + key) .on('mouseover', function(d,i,j) { d3.select(this.parentNode).selectAll('line.nv-distroplot-'+key).classed('hover',true); dispatch.elementMouseover({ value: key == 'low' ? 'Lower whisker' : 'Upper whisker', series: { key: f(d).toFixed(2), color: getColor(d) || color(d,j) }, e: d3.event }); }) .on('mouseout', function(d,i,j) { d3.select(this.parentNode).selectAll('line.nv-distroplot-'+key).classed('hover',false); dispatch.elementMouseout({ value: key == 'low' ? 'Lower whisker' : 'Upper whisker', series: { key: f(d).toFixed(2), color: getColor(d) || color(d,j) }, e: d3.event }); }) .on('mousemove', function(d,i) { dispatch.elementMousemove({e: d3.event}); }); }); // setup boxes as 4 parts: left-area, left-line, right-area, right-line, // this way we can transition to a violin areaEnter.each(function(d,i) { var violin = d3.select(this); ['left','right'].forEach(function(side) { ['line','area'].forEach(function(d) { violin.append('path') .attr('class', 'nv-distribution-' + d + ' nv-distribution-' + side) .attr("transform", "rotate(90,0,0) translate(0," + (side == 'left' ? -areaWidth() : 0) + ")" + (side == 'left' ? '' : ' scale(1,-1)')); // rotate violin }) }) areaEnter.selectAll('.nv-distribution-line') .style('fill','none') areaEnter.selectAll('.nv-distribution-area') .style('stroke','none') .style('opacity',0.7) }); // transitions distroplots.each(function(d,i) { var violin = d3.select(this); var objData = plotType == 'box' ? makeNotchBox(areaLeft(), tickLeft(), areaCenter(), d) : d.values.kde; violin.selectAll('path') .datum(objData) var tmpScale = yVScale[i]; var interp = plotType=='box' ? 'linear' : 'basis'; if (plotType == 'box' || plotType == 'violin') { ['left','right'].forEach(function(side) { // line distroplots.selectAll('.nv-distribution-line.nv-distribution-' + side) //.watchTransition(renderWatch, 'nv-distribution-line: distroplots') // disable transition for now because it's jaring .attr("d", d3.svg.line() .x(function(e) { return plotType=='box' ? e.y : yScale(e.x); }) .y(function(e) { return plotType=='box' ? e.x : tmpScale(e.y) }) .interpolate(interp) ) .attr("transform", "rotate(90,0,0) translate(0," + (side == 'left' ? -areaWidth() : 0) + ")" + (side == 'left' ? '' : ' scale(1,-1)')) // rotate violin .style('opacity', !plotType ? '0' : '1'); // area distroplots.selectAll('.nv-distribution-area.nv-distribution-' + side) //.watchTransition(renderWatch, 'nv-distribution-line: distroplots') // disable transition for now because it's jaring .attr("d", d3.svg.area() .x(function(e) { return plotType=='box' ? e.y : yScale(e.x); }) .y(function(e) { return plotType=='box' ? e.x : tmpScale(e.y) }) .y0(areaWidth()/2) .interpolate(interp) ) .attr("transform", "rotate(90,0,0) translate(0," + (side == 'left' ? -areaWidth() : 0) + ")" + (side == 'left' ? '' : ' scale(1,-1)')) // rotate violin .style('opacity', !plotType ? '0' : '1'); }) } else { // scatter type, hide areas distroplots.selectAll('.nv-distribution-area') .watchTransition(renderWatch, 'nv-distribution-area: distroplots') .style('opacity', !plotType ? '0' : '1'); distroplots.selectAll('.nv-distribution-line') .watchTransition(renderWatch, 'nv-distribution-line: distroplots') .style('opacity', !plotType ? '0' : '1'); } }) // tooltip events distroplots.selectAll('path') .on('mouseover', function(d,i,j) { d = d3.select(this.parentNode).datum(); // grab data from parent g d3.select(this).classed('hover', true); dispatch.elementMouseover({ key: d.key, value: 'Group ' + d.key + ' stats', series: [ { key: 'max', value: getMax(d).toFixed(2), color: getColor(d) || color(d,j) }, { key: 'Q3', value: getQ3(d).toFixed(2), color: getColor(d) || color(d,j) }, { key: 'Q2', value: getQ2(d).toFixed(2), color: getColor(d) || color(d,j) }, { key: 'Q1', value: getQ1(d).toFixed(2), color: getColor(d) || color(d,j) }, { key: 'min', value: getMin(d).toFixed(2), color: getColor(d) || color(d,j) }, { key: 'mean', value: getMean(d).toFixed(2), color: getColor(d) || color(d,j) }, { key: 'std. dev.', value: getDev(d).toFixed(2), color: getColor(d) || color(d,j) }, { key: 'count', value: d.values.count, color: getColor(d) || color(d,j) }, { key: 'num. outliers', value: d.values.num_outlier, color: getColor(d) || color(d,j) }, ], data: d, index: i, e: d3.event }); }) .on('mouseout', function(d,i,j) { d3.select(this).classed('hover', false); d = d3.select(this.parentNode).datum(); // grab data from parent g dispatch.elementMouseout({ key: d.key, value: 'Group ' + d.key + ' stats', series: [ { key: 'max', value: getMax(d).toFixed(2), color: getColor(d) || color(d,j) }, { key: 'Q3', value: getQ3(d).toFixed(2), color: getColor(d) || color(d,j) }, { key: 'Q2', value: getQ2(d).toFixed(2), color: getColor(d) || color(d,j) }, { key: 'Q1', value: getQ1(d).toFixed(2), color: getColor(d) || color(d,j) }, { key: 'min', value: getMin(d).toFixed(2), color: getColor(d) || color(d,j) }, { key: 'mean', value: getMean(d).toFixed(2), color: getColor(d) || color(d,j) }, { key: 'std. dev.', value: getDev(d).toFixed(2), color: getColor(d) || color(d,j) }, { key: 'count', value: d.values.count, color: getColor(d) || color(d,j) }, { key: 'num. outliers', value: d.values.num_outlier, color: getColor(d) || color(d,j) }, ], data: d, index: i, e: d3.event }); }) .on('mousemove', function(d,i) { dispatch.elementMousemove({e: d3.event}); }); // median/mean line areaEnter.append('line') .attr('class', function(d) { return 'nv-distroplot-middle'}) distroplots.selectAll('line.nv-distroplot-middle') .watchTransition(renderWatch, 'nv-distroplot-x-group: distroplots line') .attr('x1', notchBox ? tickLeft : plotType != 'violin' ? areaLeft : tickLeft()) .attr('y1', function(d,i,j) { return centralTendency == 'mean' ? yScale(getMean(d)) : yScale(getQ2(d)); }) .attr('x2', notchBox ? tickRight : plotType != 'violin' ? areaRight : tickRight()) .attr('y2', function(d,i) { return centralTendency == 'mean' ? yScale(getMean(d)) : yScale(getQ2(d)); }) .style('opacity', centralTendency ? '1' : '0'); // tooltip distroplots.selectAll('.nv-distroplot-middle') .on('mouseover', function(d,i,j) { if (d3.select(this).style('opacity') == 0) return; // don't show tooltip for hidden lines var fillColor = d3.select(this.parentNode).style('fill'); // color set by parent g fill d3.select(this).classed('hover', true); dispatch.elementMouseover({ value: centralTendency == 'mean' ? 'Mean' : 'Median', series: { key: centralTendency == 'mean' ? getMean(d).toFixed(2) : getQ2(d).toFixed(2), color: fillColor }, e: d3.event }); }) .on('mouseout', function(d,i,j) { if (d3.select(this).style('opacity') == 0) return; // don't show tooltip for hidden lines d3.select(this).classed('hover', false); var fillColor = d3.select(this.parentNode).style('fill'); // color set by parent g fill dispatch.elementMouseout({ value: centralTendency == 'mean' ? 'Mean' : 'Median', series: { key: centralTendency == 'mean' ? getMean(d).toFixed(2) : getQ2(d).toFixed(2), color: fillColor }, e: d3.event }); }) .on('mousemove', function(d,i) { dispatch.elementMousemove({e: d3.event}); }); // setup observations // create DOMs even if not requested (and hide them), so that // we can do transitions on them var obsWrap = distroplots.selectAll('g.nv-distroplot-observation') .data(function(d) { return getValsObj(d) }, function(d) { return d.object_constancy; }); var obsGroup = obsWrap.enter() .append('g') .attr('class', 'nv-distroplot-observation') obsGroup.append('circle') .style({'opacity': 0}) obsGroup.append('line') .style('stroke-width', 1) .style({'stroke': d3.rgb(85, 85, 85), 'opacity': 0}) obsWrap.exit().remove(); obsWrap.attr('class', function(d) { return 'nv-distroplot-observation ' + (isOutlier(d) && plotType == 'box' ? 'nv-distroplot-outlier' : 'nv-distroplot-non-outlier')}) // transition observations if (observationType == 'line') { distroplots.selectAll('g.nv-distroplot-observation line') .watchTransition(renderWatch, 'nv-distrolot-x-group: nv-distoplot-observation') .attr("x1", tickLeft() + areaWidth()/4) .attr("x2", tickRight() - areaWidth()/4) .attr('y1', function(d) { return yScale(d.datum)}) .attr('y2', function(d) { return yScale(d.datum)}); } else { distroplots.selectAll('g.nv-distroplot-observation circle') .watchTransition(renderWatch, 'nv-distroplot: nv-distroplot-observation') .attr('cy', function(d) { return yScale(d.datum); }) .attr('r', pointSize); // NOTE: this update can be slow when re-sizing window when many point visible // TODO: filter selection down to only visible points, no need to update x-position // of the hidden points distroplots.selectAll('g.nv-distroplot-observation circle') .watchTransition(renderWatch, 'nv-distroplot: nv-distroplot-observation') .attr('cx', function(d) { return observationType == 'swarm' ? d.x + areaWidth()/2 : observationType == 'random' ? areaWidth()/2 + d.randX * areaWidth()/2 : areaWidth()/2; }) } // set opacity on outliers/non-outliers // any circle/line entering has opacity 0 if (observationType !== false) { // observationType is False when hidding all circle/lines if (!showOnlyOutliers) { // show all line/circle distroplots.selectAll(observationType== 'line' ? 'line':'circle') .watchTransition(renderWatch, 'nv-distroplot: nv-distroplot-observation') .style('opacity',1) } else { // show only outliers distroplots.selectAll('.nv-distroplot-outlier '+ (observationType== 'line' ? 'line':'circle')) .watchTransition(renderWatch, 'nv-distroplot: nv-distroplot-observation') .style('opacity',1) distroplots.selectAll('.nv-distroplot-non-outlier '+ (observationType== 'line' ? 'line':'circle')) .watchTransition(renderWatch, 'nv-distroplot: nv-distroplot-observation') .style('opacity',0) } } // hide all other observations distroplots.selectAll('.nv-distroplot-observation' + (observationType=='line'?' circle':' line')) .watchTransition(renderWatch, 'nv-distroplot: nv-distoplot-observation') .style('opacity',0) // tooltip events for observations distroplots.selectAll('.nv-distroplot-observation') .on('mouseover', function(d,i,j) { var pt = d3.select(this); if (showOnlyOutliers && plotType == 'box' && !isOutlier(d)) return; // don't show tooltip for hidden observation var fillColor = d3.select(this.parentNode).style('fill'); // color set by parent g fill pt.classed('hover', true); dispatch.elementMouseover({ value: (plotType == 'box' && isOutlier(d)) ? 'Outlier' : 'Observation', series: { key: d.datum.toFixed(2), color: fillColor }, e: d3.event }); }) .on('mouseout', function(d,i,j) { var pt = d3.select(this); var fillColor = d3.select(this.parentNode).style('fill'); // color set by parent g fill pt.classed('hover', false); dispatch.elementMouseout({ value: (plotType == 'box' && isOutlier(d)) ? 'Outlier' : 'Observation', series: { key: d.datum.toFixed(2), color: fillColor }, e: d3.event }); }) .on('mousemove', function(d,i) { dispatch.elementMousemove({e: d3.event}); }); }); renderWatch.renderEnd('nv-distroplot-x-group immediate'); return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.dispatch = dispatch; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, maxBoxWidth: {get: function(){return maxBoxWidth;}, set: function(_){maxBoxWidth=_;}}, x: {get: function(){return getX;}, set: function(_){getX=_;}}, y: {get: function(){return getY;}, set: function(_){getY=_;}}, plotType: {get: function(){return plotType;}, set: function(_){plotType=_;}}, // plotType of background: 'box', 'violin' - default: 'box' observationType: {get: function(){return observationType;}, set: function(_){observationType=_;}}, // type of observations to show: 'random', 'swarm', 'line', 'point' - default: false (don't show observations) whiskerDef: {get: function(){return whiskerDef;}, set: function(_){whiskerDef=_;}}, // type of whisker to render: 'iqr', 'minmax', 'stddev' - default: iqr notchBox: {get: function(){return notchBox;}, set: function(_){notchBox=_;}}, // bool whether to notch box hideWhiskers: {get: function(){return hideWhiskers;}, set: function(_){hideWhiskers=_;}}, colorGroup: {get: function(){return colorGroup;}, set: function(_){colorGroup=_;}}, // data key to use to set color group of each x-category - default: don't group centralTendency: {get: function(){return centralTendency;}, set: function(_){centralTendency=_;}}, // add a mean or median line to the data - default: don't show, must be one of 'mean' or 'median' bandwidth: {get: function(){return bandwidth;}, set: function(_){bandwidth=_;}}, // bandwidth for kde calculation, can be float or str, if str, must be one of scott or silverman clampViolin: {get: function(){return clampViolin;}, set: function(_){clampViolin=_;}}, resolution: {get: function(){return resolution;}, set: function(_){resolution=_;}}, // resolution for kde calculation, default 50 xScale: {get: function(){return xScale;}, set: function(_){xScale=_;}}, yScale: {get: function(){return yScale;}, set: function(_){yScale=_;}}, showOnlyOutliers: {get: function(){return showOnlyOutliers;}, set: function(_){showOnlyOutliers=_;}}, // show only outliers in box plot, default true jitter: {get: function(){return jitter;}, set: function(_){jitter=_;}}, // faction of that jitter should take up in 'random' observationType, must be in range [0,1]; see jitterX(), default 0.7 squash: {get: function(){return squash;}, set: function(_){squash=_;}}, // whether to squash sparse distribution of color groups towards middle of x-axis position pointSize: {get: function(){return pointSize;}, set: function(_){pointSize=_;}}, xDomain: {get: function(){return xDomain;}, set: function(_){xDomain=_;}}, yDomain: {get: function(){return yDomain;}, set: function(_){yDomain=_;}}, xRange: {get: function(){return xRange;}, set: function(_){xRange=_;}}, yRange: {get: function(){return yRange;}, set: function(_){yRange=_;}}, recalcData: {get: function() { reformatDat = prepData(container.datum()); } }, itemColor: {get: function(){return getColor;}, set: function(_){getColor=_;}}, id: {get: function(){return id;}, set: function(_){id=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; renderWatch.reset(duration); }} }); nv.utils.initOptions(chart); return chart; }; nv.models.distroPlotChart = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var distroplot = nv.models.distroPlot(), xAxis = nv.models.axis(), yAxis = nv.models.axis() var margin = {top: 25, right: 10, bottom: 40, left: 60}, width = null, height = null, color = nv.utils.getColor(), showXAxis = true, showYAxis = true, rightAlignYAxis = false, staggerLabels = false, xLabel = false, yLabel = false, tooltip = nv.models.tooltip(), x, y, noData = 'No Data Available.', dispatch = d3.dispatch('stateChange', 'beforeUpdate', 'renderEnd'), duration = 500; xAxis .orient('bottom') .showMaxMin(false) .tickFormat(function(d) { return d }) ; yAxis .orient((rightAlignYAxis) ? 'right' : 'left') .tickFormat(d3.format(',.1f')) ; tooltip.duration(0); //============================================================ // Private Variables //------------------------------------------------------------ var renderWatch = nv.utils.renderWatch(dispatch, duration); var colorGroup0, marginTop0 = margin.top, x0, y0, resolution0, bandwidth0, clampViolin0; var dataCache; // return true if data has changed somehow after // an .update() was called // works by comparing current data set to the // one previously cached // TODO - since we keep another version of the dataset // around for comparison, it doubles the memory usage :( function dataHasChanged(d) { if (arraysEqual(d, dataCache)) { return false; } else { dataCache = JSON.parse(JSON.stringify(d)) // deep copy return true; } } // return true if array of objects equivalent function arraysEqual(arr1, arr2) { if(arr1.length !== arr2.length) return false; for(var i = arr1.length; i--;) { if ('object_constancy' in arr1[i]) delete arr1[i].object_constancy if ('object_constancy' in arr2[i]) delete arr2[i].object_constancy if(!objectEquals(arr1[i], arr2[i])) { return false; } } return true; } // return true if objects are equivalent function objectEquals(a, b) { // Create arrays of property names var aProps = Object.getOwnPropertyNames(a); var bProps = Object.getOwnPropertyNames(b); // If number of properties is different, // objects are not equivalent if (aProps.length != bProps.length) { return false; } for (var i = 0; i < aProps.length; i++) { var propName = aProps[i]; // If values of same property are not equal, // objects are not equivalent if (a[propName] !== b[propName]) { return false; } } return true; } function chart(selection) { renderWatch.reset(); renderWatch.models(distroplot); if (showXAxis) renderWatch.models(xAxis); if (showYAxis) renderWatch.models(yAxis); selection.each(function(data) { var container = d3.select(this), that = this; nv.utils.initSVG(container); var availableWidth = (width || parseInt(container.style('width')) || 960) - margin.left - margin.right; var availableHeight = (height || parseInt(container.style('height')) || 400) - margin.top - margin.bottom; if (typeof dataCache === 'undefined') { dataCache = JSON.parse(JSON.stringify(data)) // deep copy } chart.update = function() { dispatch.beforeUpdate(); var opts = distroplot.options() if (colorGroup0 !== opts.colorGroup() || // recalc data when any of the axis accessors are changed x0 !== opts.x() || y0 !== opts.y() || bandwidth0 !== opts.bandwidth() || resolution0 !== opts.resolution() || clampViolin0 !== opts.clampViolin() || dataHasChanged(data) ) { distroplot.recalcData(); } container.transition().duration(duration).call(chart); }; chart.container = this; if (typeof d3.beeswarm !== 'function' && chart.options().observationType() == 'swarm') { var xPos = margin.left + availableWidth/2; noData = 'Please include the library https://github.com/Kcnarf/d3-beeswarm to use "swarm".' nv.utils.noData(chart, container); return chart; } else if (!data || !data.length) { nv.utils.noData(chart, container); return chart; } else { container.selectAll('.nv-noData').remove(); } // Setup Scales x = distroplot.xScale(); y = distroplot.yScale().clamp(true); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-distroPlot').data([data]); var gEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-distroPlot').append('g'); var defsEnter = gEnter.append('defs'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-x nv-axis'); gEnter.append('g').attr('class', 'nv-y nv-axis') .append('g').attr('class', 'nv-zeroLine') .append('line'); gEnter.append('g').attr('class', 'nv-distroWrap'); gEnter.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); g.watchTransition(renderWatch, 'nv-wrap: wrap') .attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); if (rightAlignYAxis) { g.select('.nv-y.nv-axis') .attr('transform', 'translate(' + availableWidth + ',0)'); } // Main Chart Component(s) distroplot.width(availableWidth).height(availableHeight); var distroWrap = g.select('.nv-distroWrap') .datum(data) distroWrap.transition().call(distroplot); defsEnter.append('clipPath') .attr('id', 'nv-x-label-clip-' + distroplot.id()) .append('rect'); g.select('#nv-x-label-clip-' + distroplot.id() + ' rect') .attr('width', x.rangeBand() * (staggerLabels ? 2 : 1)) .attr('height', 16) .attr('x', -x.rangeBand() / (staggerLabels ? 1 : 2 )); // Setup Axes if (showXAxis) { xAxis .scale(x) .ticks( nv.utils.calcTicksX(availableWidth/100, data) ) .tickSize(-availableHeight, 0); g.select('.nv-x.nv-axis').attr('transform', 'translate(0,' + y.range()[0] + ')') g.select('.nv-x.nv-axis').call(xAxis); //g.select('.nv-x.nv-axis').select('.nv-axislabel') // .style('font-size', d3.min([availableWidth * 0.05,20]) + 'px') var xTicks = g.select('.nv-x.nv-axis').selectAll('g'); if (staggerLabels) { xTicks .selectAll('text') .attr('transform', function(d,i,j) { return 'translate(0,' + (j % 2 === 0 ? '5' : '17') + ')' }) } } if (showYAxis) { yAxis .scale(y) .ticks( Math.floor(availableHeight/36) ) // can't use nv.utils.calcTicksY with Object data .tickSize( -availableWidth, 0); g.select('.nv-y.nv-axis').call(yAxis); //g.select('.nv-y.nv-axis').select('.nv-axislabel') // .style('font-size', d3.min([availableHeight * 0.05,20]) + 'px') } // Zero line on chart bottom g.select('.nv-zeroLine line') .attr('x1',0) .attr('x2',availableWidth) .attr('y1', y(0)) .attr('y2', y(0)) ; // store original values so that we can // call 'recalcData()' if needed colorGroup0 = distroplot.options().colorGroup(); x0 = distroplot.options().x(); y0 = distroplot.options().y(); bandwidth0 = distroplot.options().bandwidth(); resolution0 = distroplot.options().resolution(); clampViolin0 = distroplot.options().clampViolin(); //============================================================ // Event Handling/Dispatching (in chart's scope) //------------------------------------------------------------ }); renderWatch.renderEnd('nv-distroplot chart immediate'); return chart; } //============================================================ // Event Handling/Dispatching (out of chart's scope) //------------------------------------------------------------ distroplot.dispatch.on('elementMouseover.tooltip', function(evt) { tooltip.data(evt).hidden(false); }); distroplot.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.data(evt).hidden(true); }); distroplot.dispatch.on('elementMousemove.tooltip', function(evt) { tooltip(); }); //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.dispatch = dispatch; chart.distroplot = distroplot; chart.xAxis = xAxis; chart.yAxis = yAxis; chart.tooltip = tooltip; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, staggerLabels: {get: function(){return staggerLabels;}, set: function(_){staggerLabels=_;}}, showXAxis: {get: function(){return showXAxis;}, set: function(_){showXAxis=_;}}, showYAxis: {get: function(){return showYAxis;}, set: function(_){showYAxis=_;}}, tooltipContent: {get: function(){return tooltip;}, set: function(_){tooltip=_;}}, noData: {get: function(){return noData;}, set: function(_){noData=_;}}, defaultState: {get: function(){return defaultState;}, set: function(_){defaultState=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; renderWatch.reset(duration); distroplot.duration(duration); xAxis.duration(duration); yAxis.duration(duration); }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); distroplot.color(color); }}, rightAlignYAxis: {get: function(){return rightAlignYAxis;}, set: function(_){ rightAlignYAxis = _; yAxis.orient( (_) ? 'right' : 'left'); }}, xLabel: {get: function(){return xLabel;}, set: function(_){ xLabel=_; xAxis.axisLabel(xLabel); }}, yLabel: {get: function(){return yLabel;}, set: function(_){ yLabel=_; yAxis.axisLabel(yLabel); }}, }); nv.utils.inheritOptions(chart, distroplot); nv.utils.initOptions(chart); return chart; } nv.models.focus = function(content) { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var content = content || nv.models.line() , xAxis = nv.models.axis() , yAxis = nv.models.axis() , brush = d3.svg.brush() ; var margin = {top: 10, right: 0, bottom: 30, left: 0} , color = nv.utils.defaultColor() , width = null , height = 70 , showXAxis = true , showYAxis = false , rightAlignYAxis = false , ticks = null , x , y , brushExtent = null , duration = 250 , dispatch = d3.dispatch('brush', 'onBrush', 'renderEnd') , syncBrushing = true ; content.interactive(false); content.pointActive(function(d) { return false; }); //============================================================ // Private Variables //------------------------------------------------------------ var renderWatch = nv.utils.renderWatch(dispatch, duration); function chart(selection) { renderWatch.reset(); renderWatch.models(content); if (showXAxis) renderWatch.models(xAxis); if (showYAxis) renderWatch.models(yAxis); selection.each(function(data) { var container = d3.select(this); nv.utils.initSVG(container); var availableWidth = nv.utils.availableWidth(width, container, margin), availableHeight = height - margin.top - margin.bottom; chart.update = function() { if( duration === 0 ) { container.call( chart ); } else { container.transition().duration(duration).call(chart); } }; chart.container = this; // Setup Scales x = content.xScale(); y = content.yScale(); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-focus').data([data]); var gEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-focus').append('g'); var g = wrap.select('g'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); gEnter.append('g').attr('class', 'nv-background').append('rect'); gEnter.append('g').attr('class', 'nv-x nv-axis'); gEnter.append('g').attr('class', 'nv-y nv-axis'); gEnter.append('g').attr('class', 'nv-contentWrap'); gEnter.append('g').attr('class', 'nv-brushBackground'); gEnter.append('g').attr('class', 'nv-x nv-brush'); if (rightAlignYAxis) { g.select(".nv-y.nv-axis") .attr("transform", "translate(" + availableWidth + ",0)"); } g.select('.nv-background rect') .attr('width', availableWidth) .attr('height', availableHeight); content .width(availableWidth) .height(availableHeight) .color(data.map(function(d,i) { return d.color || color(d, i); }).filter(function(d,i) { return !data[i].disabled; })); var contentWrap = g.select('.nv-contentWrap') .datum(data.filter(function(d) { return !d.disabled; })); d3.transition(contentWrap).call(content); // Setup Brush brush .x(x) .on('brush', function() { onBrush(syncBrushing); }); brush.on('brushend', function () { if (!syncBrushing) { dispatch.onBrush(brush.empty() ? x.domain() : brush.extent()); } }); if (brushExtent) brush.extent(brushExtent); var brushBG = g.select('.nv-brushBackground').selectAll('g') .data([brushExtent || brush.extent()]); var brushBGenter = brushBG.enter() .append('g'); brushBGenter.append('rect') .attr('class', 'left') .attr('x', 0) .attr('y', 0) .attr('height', availableHeight); brushBGenter.append('rect') .attr('class', 'right') .attr('x', 0) .attr('y', 0) .attr('height', availableHeight); var gBrush = g.select('.nv-x.nv-brush') .call(brush); gBrush.selectAll('rect') .attr('height', availableHeight); gBrush.selectAll('.resize').append('path').attr('d', resizePath); onBrush(true); g.select('.nv-background rect') .attr('width', availableWidth) .attr('height', availableHeight); if (showXAxis) { xAxis.scale(x) ._ticks( nv.utils.calcTicksX(availableWidth/100, data) ) .tickSize(-availableHeight, 0); g.select('.nv-x.nv-axis') .attr('transform', 'translate(0,' + y.range()[0] + ')'); d3.transition(g.select('.nv-x.nv-axis')) .call(xAxis); } if (showYAxis) { yAxis .scale(y) ._ticks( nv.utils.calcTicksY(availableHeight/36, data) ) .tickSize( -availableWidth, 0); d3.transition(g.select('.nv-y.nv-axis')) .call(yAxis); } g.select('.nv-x.nv-axis') .attr('transform', 'translate(0,' + y.range()[0] + ')'); //============================================================ // Event Handling/Dispatching (in chart's scope) //------------------------------------------------------------ //============================================================ // Functions //------------------------------------------------------------ // Taken from crossfilter (http://square.github.com/crossfilter/) function resizePath(d) { var e = +(d == 'e'), x = e ? 1 : -1, y = availableHeight / 3; return 'M' + (0.5 * x) + ',' + y + 'A6,6 0 0 ' + e + ' ' + (6.5 * x) + ',' + (y + 6) + 'V' + (2 * y - 6) + 'A6,6 0 0 ' + e + ' ' + (0.5 * x) + ',' + (2 * y) + 'Z' + 'M' + (2.5 * x) + ',' + (y + 8) + 'V' + (2 * y - 8) + 'M' + (4.5 * x) + ',' + (y + 8) + 'V' + (2 * y - 8); } function updateBrushBG() { if (!brush.empty()) brush.extent(brushExtent); brushBG .data([brush.empty() ? x.domain() : brushExtent]) .each(function(d,i) { var leftWidth = x(d[0]) - x.range()[0], rightWidth = availableWidth - x(d[1]); d3.select(this).select('.left') .attr('width', leftWidth < 0 ? 0 : leftWidth); d3.select(this).select('.right') .attr('x', x(d[1])) .attr('width', rightWidth < 0 ? 0 : rightWidth); }); } function onBrush(shouldDispatch) { brushExtent = brush.empty() ? null : brush.extent(); var extent = brush.empty() ? x.domain() : brush.extent(); dispatch.brush({extent: extent, brush: brush}); updateBrushBG(); if (shouldDispatch) { dispatch.onBrush(extent); } } }); renderWatch.renderEnd('focus immediate'); return chart; } //============================================================ // Event Handling/Dispatching (out of chart's scope) //------------------------------------------------------------ //============================================================ // Expose Public Variables //------------------------------------------------------------ // expose chart's sub-components chart.dispatch = dispatch; chart.content = content; chart.brush = brush; chart.xAxis = xAxis; chart.yAxis = yAxis; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, showXAxis: {get: function(){return showXAxis;}, set: function(_){showXAxis=_;}}, showYAxis: {get: function(){return showYAxis;}, set: function(_){showYAxis=_;}}, brushExtent: {get: function(){return brushExtent;}, set: function(_){brushExtent=_;}}, syncBrushing: {get: function(){return syncBrushing;}, set: function(_){syncBrushing=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; renderWatch.reset(duration); content.duration(duration); xAxis.duration(duration); yAxis.duration(duration); }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); content.color(color); }}, interpolate: {get: function(){return content.interpolate();}, set: function(_){ content.interpolate(_); }}, xTickFormat: {get: function(){return xAxis.tickFormat();}, set: function(_){ xAxis.tickFormat(_); }}, yTickFormat: {get: function(){return yAxis.tickFormat();}, set: function(_){ yAxis.tickFormat(_); }}, x: {get: function(){return content.x();}, set: function(_){ content.x(_); }}, y: {get: function(){return content.y();}, set: function(_){ content.y(_); }}, rightAlignYAxis: {get: function(){return rightAlignYAxis;}, set: function(_){ rightAlignYAxis = _; yAxis.orient( rightAlignYAxis ? 'right' : 'left'); }} }); nv.utils.inheritOptions(chart, content); nv.utils.initOptions(chart); return chart; }; nv.models.forceDirectedGraph = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 2, right: 0, bottom: 2, left: 0} , width = 400 , height = 32 , container = null , dispatch = d3.dispatch('renderEnd') , color = nv.utils.getColor(['#000']) , tooltip = nv.models.tooltip() , noData = null // Force directed graph specific parameters [default values] , linkStrength = 0.1 , friction = 0.9 , linkDist = 30 , charge = -120 , gravity = 0.1 , theta = 0.8 , alpha = 0.1 , radius = 5 // These functions allow to add extra attributes to ndes and links ,nodeExtras = function(nodes) { /* Do nothing */ } ,linkExtras = function(links) { /* Do nothing */ } , getX=d3.functor(0.0) , getY=d3.functor(0.0) ; //============================================================ // Private Variables //------------------------------------------------------------ var renderWatch = nv.utils.renderWatch(dispatch); function chart(selection) { renderWatch.reset(); selection.each(function(data) { container = d3.select(this); nv.utils.initSVG(container); var availableWidth = nv.utils.availableWidth(width, container, margin), availableHeight = nv.utils.availableHeight(height, container, margin); container .attr("width", availableWidth) .attr("height", availableHeight); // Display No Data message if there's nothing to show. if (!data || !data.links || !data.nodes) { nv.utils.noData(chart, container) return chart; } else { container.selectAll('.nv-noData').remove(); } container.selectAll('*').remove(); // Collect names of all fields in the nodes var nodeFieldSet = new Set(); data.nodes.forEach(function(node) { var keys = Object.keys(node); keys.forEach(function(key) { nodeFieldSet.add(key); }); }); var force = d3.layout.force() .nodes(data.nodes) .links(data.links) .size([availableWidth, availableHeight]) .linkStrength(linkStrength) .friction(friction) .linkDistance(linkDist) .charge(charge) .gravity(gravity) .theta(theta) .alpha(alpha) .start(); var link = container.selectAll(".link") .data(data.links) .enter().append("line") .attr("class", "nv-force-link") .style("stroke-width", function(d) { return Math.sqrt(d.value); }); var node = container.selectAll(".node") .data(data.nodes) .enter() .append("g") .attr("class", "nv-force-node") .call(force.drag); node .append("circle") .attr("r", radius) .style("fill", function(d) { return color(d) } ) .on("mouseover", function(evt) { container.select('.nv-series-' + evt.seriesIndex + ' .nv-distx-' + evt.pointIndex) .attr('y1', evt.py); container.select('.nv-series-' + evt.seriesIndex + ' .nv-disty-' + evt.pointIndex) .attr('x2', evt.px); // Add 'series' object to var nodeColor = color(evt); evt.series = []; nodeFieldSet.forEach(function(field) { evt.series.push({ color: nodeColor, key: field, value: evt[field] }); }); tooltip.data(evt).hidden(false); }) .on("mouseout", function(d) { tooltip.hidden(true); }); tooltip.headerFormatter(function(d) {return "Node";}); // Apply extra attributes to nodes and links (if any) linkExtras(link); nodeExtras(node); force.on("tick", function() { link.attr("x1", function(d) { return d.source.x; }) .attr("y1", function(d) { return d.source.y; }) .attr("x2", function(d) { return d.target.x; }) .attr("y2", function(d) { return d.target.y; }); node.attr("transform", function(d) { return "translate(" + d.x + ", " + d.y + ")"; }); }); }); return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, // Force directed graph specific parameters linkStrength:{get: function(){return linkStrength;}, set: function(_){linkStrength=_;}}, friction: {get: function(){return friction;}, set: function(_){friction=_;}}, linkDist: {get: function(){return linkDist;}, set: function(_){linkDist=_;}}, charge: {get: function(){return charge;}, set: function(_){charge=_;}}, gravity: {get: function(){return gravity;}, set: function(_){gravity=_;}}, theta: {get: function(){return theta;}, set: function(_){theta=_;}}, alpha: {get: function(){return alpha;}, set: function(_){alpha=_;}}, radius: {get: function(){return radius;}, set: function(_){radius=_;}}, //functor options x: {get: function(){return getX;}, set: function(_){getX=d3.functor(_);}}, y: {get: function(){return getY;}, set: function(_){getY=d3.functor(_);}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); }}, noData: {get: function(){return noData;}, set: function(_){noData=_;}}, nodeExtras: {get: function(){return nodeExtras;}, set: function(_){ nodeExtras = _; }}, linkExtras: {get: function(){return linkExtras;}, set: function(_){ linkExtras = _; }} }); chart.dispatch = dispatch; chart.tooltip = tooltip; nv.utils.initOptions(chart); return chart; }; nv.models.furiousLegend = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 5, right: 0, bottom: 5, left: 0} , width = 400 , height = 20 , getKey = function(d) { return d.key } , keyFormatter = function (d) { return d } , color = nv.utils.getColor() , maxKeyLength = 20 //default value for key lengths , align = true , padding = 28 //define how much space between legend items. - recommend 32 for furious version , rightAlign = true , updateState = true //If true, legend will update data.disabled and trigger a 'stateChange' dispatch. , radioButtonMode = false //If true, clicking legend items will cause it to behave like a radio button. (only one can be selected at a time) , expanded = false , dispatch = d3.dispatch('legendClick', 'legendDblclick', 'legendMouseover', 'legendMouseout', 'stateChange') , vers = 'classic' //Options are "classic" and "furious" ; function chart(selection) { selection.each(function(data) { var availableWidth = width - margin.left - margin.right, container = d3.select(this); nv.utils.initSVG(container); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-legend').data([data]); var gEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-legend').append('g'); var g = wrap.select('g'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); var series = g.selectAll('.nv-series') .data(function(d) { if(vers != 'furious') return d; return d.filter(function(n) { return expanded ? true : !n.disengaged; }); }); var seriesEnter = series.enter().append('g').attr('class', 'nv-series') var seriesShape; if(vers == 'classic') { seriesEnter.append('circle') .style('stroke-width', 2) .attr('class','nv-legend-symbol') .attr('r', 5); seriesShape = series.select('circle'); } else if (vers == 'furious') { seriesEnter.append('rect') .style('stroke-width', 2) .attr('class','nv-legend-symbol') .attr('rx', 3) .attr('ry', 3); seriesShape = series.select('rect'); seriesEnter.append('g') .attr('class', 'nv-check-box') .property('innerHTML','') .attr('transform', 'translate(-10,-8)scale(0.5)'); var seriesCheckbox = series.select('.nv-check-box'); seriesCheckbox.each(function(d,i) { d3.select(this).selectAll('path') .attr('stroke', setTextColor(d,i)); }); } seriesEnter.append('text') .attr('text-anchor', 'start') .attr('class','nv-legend-text') .attr('dy', '.32em') .attr('dx', '8'); var seriesText = series.select('text.nv-legend-text'); series .on('mouseover', function(d,i) { dispatch.legendMouseover(d,i); //TODO: Make consistent with other event objects }) .on('mouseout', function(d,i) { dispatch.legendMouseout(d,i); }) .on('click', function(d,i) { dispatch.legendClick(d,i); // make sure we re-get data in case it was modified var data = series.data(); if (updateState) { if(vers =='classic') { if (radioButtonMode) { //Radio button mode: set every series to disabled, // and enable the clicked series. data.forEach(function(series) { series.disabled = true}); d.disabled = false; } else { d.disabled = !d.disabled; if (data.every(function(series) { return series.disabled})) { //the default behavior of NVD3 legends is, if every single series // is disabled, turn all series' back on. data.forEach(function(series) { series.disabled = false}); } } } else if(vers == 'furious') { if(expanded) { d.disengaged = !d.disengaged; d.userDisabled = d.userDisabled == undefined ? !!d.disabled : d.userDisabled; d.disabled = d.disengaged || d.userDisabled; } else if (!expanded) { d.disabled = !d.disabled; d.userDisabled = d.disabled; var engaged = data.filter(function(d) { return !d.disengaged; }); if (engaged.every(function(series) { return series.userDisabled })) { //the default behavior of NVD3 legends is, if every single series // is disabled, turn all series' back on. data.forEach(function(series) { series.disabled = series.userDisabled = false; }); } } } dispatch.stateChange({ disabled: data.map(function(d) { return !!d.disabled }), disengaged: data.map(function(d) { return !!d.disengaged }) }); } }) .on('dblclick', function(d,i) { if(vers == 'furious' && expanded) return; dispatch.legendDblclick(d,i); if (updateState) { // make sure we re-get data in case it was modified var data = series.data(); //the default behavior of NVD3 legends, when double clicking one, // is to set all other series' to false, and make the double clicked series enabled. data.forEach(function(series) { series.disabled = true; if(vers == 'furious') series.userDisabled = series.disabled; }); d.disabled = false; if(vers == 'furious') d.userDisabled = d.disabled; dispatch.stateChange({ disabled: data.map(function(d) { return !!d.disabled }) }); } }); series.classed('nv-disabled', function(d) { return d.userDisabled }); series.exit().remove(); seriesText .attr('fill', setTextColor) .text(function (d) { return keyFormatter(getKey(d)) }); //TODO: implement fixed-width and max-width options (max-width is especially useful with the align option) // NEW ALIGNING CODE, TODO: clean up var versPadding; switch(vers) { case 'furious' : versPadding = 23; break; case 'classic' : versPadding = 20; } if (align) { var seriesWidths = []; series.each(function(d,i) { var legendText; if (keyFormatter(getKey(d)) && keyFormatter(getKey(d)).length > maxKeyLength) { var trimmedKey = keyFormatter(getKey(d)).substring(0, maxKeyLength); legendText = d3.select(this).select('text').text(trimmedKey + "..."); d3.select(this).append("svg:title").text(keyFormatter(getKey(d))); } else { legendText = d3.select(this).select('text'); } var nodeTextLength; try { nodeTextLength = legendText.node().getComputedTextLength(); // If the legendText is display:none'd (nodeTextLength == 0), simulate an error so we approximate, instead if(nodeTextLength <= 0) throw Error(); } catch(e) { nodeTextLength = nv.utils.calcApproxTextWidth(legendText); } seriesWidths.push(nodeTextLength + padding); }); var seriesPerRow = 0; var legendWidth = 0; var columnWidths = []; while ( legendWidth < availableWidth && seriesPerRow < seriesWidths.length) { columnWidths[seriesPerRow] = seriesWidths[seriesPerRow]; legendWidth += seriesWidths[seriesPerRow++]; } if (seriesPerRow === 0) seriesPerRow = 1; //minimum of one series per row while ( legendWidth > availableWidth && seriesPerRow > 1 ) { columnWidths = []; seriesPerRow--; for (var k = 0; k < seriesWidths.length; k++) { if (seriesWidths[k] > (columnWidths[k % seriesPerRow] || 0) ) columnWidths[k % seriesPerRow] = seriesWidths[k]; } legendWidth = columnWidths.reduce(function(prev, cur, index, array) { return prev + cur; }); } var xPositions = []; for (var i = 0, curX = 0; i < seriesPerRow; i++) { xPositions[i] = curX; curX += columnWidths[i]; } series .attr('transform', function(d, i) { return 'translate(' + xPositions[i % seriesPerRow] + ',' + (5 + Math.floor(i / seriesPerRow) * versPadding) + ')'; }); //position legend as far right as possible within the total width if (rightAlign) { g.attr('transform', 'translate(' + (width - margin.right - legendWidth) + ',' + margin.top + ')'); } else { g.attr('transform', 'translate(0' + ',' + margin.top + ')'); } height = margin.top + margin.bottom + (Math.ceil(seriesWidths.length / seriesPerRow) * versPadding); } else { var ypos = 5, newxpos = 5, maxwidth = 0, xpos; series .attr('transform', function(d, i) { var length = d3.select(this).select('text').node().getComputedTextLength() + padding; xpos = newxpos; if (width < margin.left + margin.right + xpos + length) { newxpos = xpos = 5; ypos += versPadding; } newxpos += length; if (newxpos > maxwidth) maxwidth = newxpos; return 'translate(' + xpos + ',' + ypos + ')'; }); //position legend as far right as possible within the total width g.attr('transform', 'translate(' + (width - margin.right - maxwidth) + ',' + margin.top + ')'); height = margin.top + margin.bottom + ypos + 15; } if(vers == 'furious') { // Size rectangles after text is placed seriesShape .attr('width', function(d,i) { return seriesText[0][i].getComputedTextLength() + 27; }) .attr('height', 18) .attr('y', -9) .attr('x', -15) } seriesShape .style('fill', setBGColor) .style('stroke', function(d,i) { return d.color || color(d, i) }); }); function setTextColor(d,i) { if(vers != 'furious') return '#000'; if(expanded) { return d.disengaged ? color(d,i) : '#fff'; } else if (!expanded) { return !!d.disabled ? color(d,i) : '#fff'; } } function setBGColor(d,i) { if(expanded && vers == 'furious') { return d.disengaged ? '#fff' : color(d,i); } else { return !!d.disabled ? '#fff' : color(d,i); } } return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.dispatch = dispatch; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, key: {get: function(){return getKey;}, set: function(_){getKey=_;}}, keyFormatter: {get: function(){return keyFormatter;}, set: function(_){keyFormatter=_;}}, align: {get: function(){return align;}, set: function(_){align=_;}}, rightAlign: {get: function(){return rightAlign;}, set: function(_){rightAlign=_;}}, maxKeyLength: {get: function(){return maxKeyLength;}, set: function(_){maxKeyLength=_;}}, padding: {get: function(){return padding;}, set: function(_){padding=_;}}, updateState: {get: function(){return updateState;}, set: function(_){updateState=_;}}, radioButtonMode:{get: function(){return radioButtonMode;}, set: function(_){radioButtonMode=_;}}, expanded: {get: function(){return expanded;}, set: function(_){expanded=_;}}, vers: {get: function(){return vers;}, set: function(_){vers=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); }} }); nv.utils.initOptions(chart); return chart; }; /* Improvements: - consistenly apply no-hover classes to rect isntead of to containing g, see example CSS style for .no-hover rect, rect.no-hover - row/column order (user specified) or 'ascending' / 'descending' - I haven't tested for transitions between changing datasets */ nv.models.heatMap = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 0, right: 0, bottom: 0, left: 0} , width = 960 , height = 500 , id = Math.floor(Math.random() * 10000) //Create semi-unique ID in case user doesn't select one , container , xScale = d3.scale.ordinal() , yScale = d3.scale.ordinal() , colorScale = false , getX = function(d) { return d.x } , getY = function(d) { return d.y } , getCellValue = function(d) { return d.value } , showCellValues = true , cellValueFormat = function(d) { return typeof d === 'number' ? d.toFixed(0) : d } , cellAspectRatio = false // width / height of cell , cellRadius = 2 , cellBorderWidth = 4 // pixels between cells , normalize = false , highContrastText = true , xDomain , yDomain , xMetaColorScale = nv.utils.defaultColor() , yMetaColorScale = nv.utils.defaultColor() , missingDataColor = '#bcbcbc' , missingDataLabel = '' , metaOffset = 5 // spacing between meta rects and cells , xRange , yRange , xMeta , yMeta , colorRange , colorDomain , dispatch = d3.dispatch('chartClick', 'elementClick', 'elementDblClick', 'elementMouseover', 'elementMouseout', 'elementMousemove', 'renderEnd') , duration = 250 , xMetaHeight = function(d) { return cellHeight / 3 } , yMetaWidth = function(d) { return cellWidth / 3 } , showGrid = false ; //============================================================ // Aux helper function for heatmap //------------------------------------------------------------ // choose high contrast text color based on background // shameful steal: https://github.com/alexandersimoes/d3plus/blob/master/src/color/text.coffee function cellTextColor(bgColor) { if (highContrastText) { var rgbColor = d3.rgb(bgColor); var r = rgbColor.r; var g = rgbColor.g; var b = rgbColor.b; var yiq = (r * 299 + g * 587 + b * 114) / 1000; return yiq >= 128 ? "#404040" : "#EDEDED"; // dark text else light text } else { return 'black'; } } /* go through heatmap data and generate array of values * for each row/column or for entire dataset; for use in * calculating means/medians of data for normalizing * @param {str} axis - 'row', 'col' or null * * @returns {row/column index: [array of values for row/col]} * note that if axis is not specified, the return will be * {0: [all values in heatmap]} */ function getHeatmapValues(data, axis) { var vals = {}; data.forEach(function(cell, i) { if (axis == 'row') { if (!(getIY(cell) in vals)) vals[getIY(cell)] = []; vals[getIY(cell)].push(getCellValue(cell)); } else if (axis == 'col') { if (!(getIX(cell) in vals)) vals[getIX(cell)] = []; vals[getIX(cell)].push(getCellValue(cell)); } else if (axis == null) { // if calculating stat over entire dataset if (!(0 in vals)) vals[0] = []; vals[0].push(getCellValue(cell)); } }) return vals; } // calculate the median absolute deviation of the given array of data // https://en.wikipedia.org/wiki/Median_absolute_deviation // MAD = median(abs(Xi - median(X))) function mad(dat) { var med = d3.median(dat); var vals = dat.map(function(d) { return Math.abs(d - med); }) return d3.median(vals); } // set cell color based on cell value // depending on whether it should be normalized or not function cellColor(d) { var colorVal = normalize ? getNorm(d) : getCellValue(d); return (cellsAreNumeric() && !isNaN(colorVal) || typeof colorVal !== 'undefined') ? colorScale(colorVal) : missingDataColor; } // return the domain of the color data // if ordinal data is given for the cells, this will // return all possible cells values; otherwise it // returns the extent of the cell values // will take into account normalization if specified function getColorDomain() { if (cellsAreNumeric()) { // if cell values are numeric return normalize ? d3.extent(prepedData, function(d) { return getNorm(d); }) : d3.extent(uniqueColor); } else if (!cellsAreNumeric()) { // if cell values are ordinal return uniqueColor; } } // return true if cells are numeric // as opposed to categorical function cellsAreNumeric() { return typeof uniqueColor[0] === 'number'; } /* * Normalize input data * * normalize must be one of centerX, robustCenterX, centerScaleX, robustCenterScaleX, centerAll, * robustCenterAll, centerScaleAll, robustCenterScaleAll where X is either 'Row' or 'Column' * * - centerX: subtract row/column mean from cell * - centerAll: subtract mean of whole data set from cell * - centerScaleX: scale so that row/column has mean 0 and variance 1 (Z-score) * - centerScaleAll: scale by overall normalization factor so that the whole data set has mean 0 and variance 1 (Z-score) * - robustCenterX: subtract row/column median from cell * - robustCenterScaleX: subtract row/column median from cell and then scale row/column by median absolute deviation * - robustCenterAll: subtract median of whole data set from cell * - robustCenterScaleAll: subtract overall median from cell and scale by overall median absolute deviation */ function normalizeData(dat) { var normTypes = ['centerRow', 'robustCenterRow', 'centerScaleRow', 'robustCenterScaleRow', 'centerColumn', 'robustCenterColumn', 'centerScaleColumn', 'robustCenterScaleColumn', 'centerAll', 'robustCenterAll', 'centerScaleAll', 'robustCenterScaleAll']; if(normTypes.indexOf(normalize) != -1) { var xVals = Object.keys(uniqueX), yVals = Object.keys(uniqueY); // setup normalization options var scale = normalize.includes('Scale') ? true: false, agg = normalize.includes('robust') ? 'median': 'mean', axis = normalize.includes('Row') ? 'row' : normalize.includes('Column') ? 'col' : null, vals = getHeatmapValues(dat, axis); // calculate mean or median // calculate standard dev or median absolute deviation var stat = {}; var dev = {}; for (var key in vals) { stat[key] = agg == 'mean' ? d3.mean(vals[key]) : d3.median(vals[key]); if (scale) dev[key] = agg == 'mean' ? d3.deviation(vals[key]) : mad(vals[key]); } // do the normalizing dat.forEach(function(cell, i) { if (cellsAreNumeric()) { if (axis == 'row') { var key = getIY(cell); } else if (axis == 'col') { var key = getIX(cell); } else if (axis == null) { // if calculating stat over entire dataset var key = 0; } var normVal = getCellValue(cell) - stat[key]; if (scale) { cell._cellPos.norm = normVal / dev[key]; } else { cell._cellPos.norm = normVal; } } else { cell._cellPos.norm = getCellValue(cell); // if trying to normalize ordinal cells, just set norm to cell value } }) } else { normalize = false; // proper normalize option was not provided, disable it so heatmap still shows colors } return dat; } /* * Process incoming data for use with heatmap including: * - adding a unique key indexer to each data point (idx) * - getting a unique list of all x & y values * - generating a position index (x & y) for each data point * - sorting that data for correct traversal when generating rect * - generating placeholders for missing data * * In order to allow for the flexibility of the user providing either * categorical or quantitative data, we're going to position the cells * through indices that we increment based on previously seen data * this way we can use ordinal() axes even if the data is quantitative. * * When we generate the SVG elements, we assumes traversal occures from * top to bottom and from left to right. * * @param data {list} - input data organize as a list of objects * * @return - copy of input data with additional '_cellPos' key * formatted as {idx: XXX, ix, XXX, iy: XXX} * where idx is a global identifier; ix is an identifier * within each column, and iy is an identifier within * each row. */ function prepData(data) { // reinitialize uniqueX = {}, // {cell x value: ix index} uniqueY = {}, // {cell y value: iy index} uniqueColor = [], // [cell color value] uniqueXMeta = [], // [cell x metadata value] uniqueYMeta = [], // [cell y metadata value] uniqueCells = []; // [cell x,y values stored as array] var warnings = []; var sortedCells = {}; // {cell x values: {cell y value: cell data, ... }, ... } var ix = 0, iy = 0; // use these indices to position cell in x & y direction var combo, idx=0; data.forEach(function(cell) { var valX = getX(cell), valY = getY(cell), valColor = getCellValue(cell); // assemble list of unique values for each dimension if (!(valX in uniqueX)) { uniqueX[valX] = ix; ix++; sortedCells[valX] = {} if (typeof xMeta === 'function') uniqueXMeta.push(xMeta(cell)); } if (!(valY in uniqueY)) { uniqueY[valY] = iy; iy++; sortedCells[valX][valY] = {} if (typeof yMeta === 'function') uniqueYMeta.push(yMeta(cell)); } if (uniqueColor.indexOf(valColor) == -1) uniqueColor.push(valColor) // for each data point, we generate an object of data // needed to properly position each cell cell._cellPos = { idx: idx, ix: uniqueX[valX], iy: uniqueY[valY], } idx++; // keep track of row & column combinations we've already seen // this prevents the same cells from being generated when // the user hasn't provided proper data (one value for each // row & column). // if properly formatted data is not provided, only the first // row & column value is used (the rest are ignored) combo = [valX, valY]; if (!isArrayInArray(uniqueCells, combo)) { uniqueCells.push(combo) sortedCells[valX][valY] = cell; } else if (warnings.indexOf(valX + valY) == -1) { warnings.push(valX + valY); console.warn("The row/column position " + valX + "/" + valY + " has multiple values; ensure each cell has only a single value."); } }); uniqueColor = uniqueColor.sort() // check in sortedCells that each x has all the y's // if not, generate an empty placeholder // this will also sort all cells from left to right // and top to bottom var reformatData = []; Object.keys(uniqueY).forEach(function(j) { Object.keys(uniqueX).forEach(function(i) { var cellVal = sortedCells[i][j]; if (cellVal) { reformatData.push(cellVal); } else { var cellPos = { idx: idx, ix: uniqueX[i], iy: uniqueY[j], } idx++; reformatData.push({_cellPos: cellPos}); // empty cell placeholder } }) }) // normalize data is needed return normalize ? normalizeData(reformatData) : reformatData; } // https://stackoverflow.com/a/41661388/1153897 function isArrayInArray(arr, item){ var item_as_string = JSON.stringify(item); var contains = arr.some(function(ele){ return JSON.stringify(ele) === item_as_string; }); return contains; } function removeAllHoverClasses() { // remove all hover classes d3.selectAll('.cell-hover').classed('cell-hover', false); d3.selectAll('.no-hover').classed('no-hover', false); d3.selectAll('.row-hover').classed('row-hover', false); d3.selectAll('.column-hover').classed('column-hover', false); } // return the formatted cell value if it is // a number, otherwise return missingDataLabel var cellValueLabel = function(d) { var val = !normalize ? cellValueFormat(getCellValue(d)) : cellValueFormat(getNorm(d)); return (cellsAreNumeric() && !isNaN(val) || typeof val !== 'undefined') ? val : missingDataLabel; } // https://stackoverflow.com/a/16794116/1153897 // note this returns the obj keys function sortObjByVals(obj) { return Object.keys(obj).sort(function(a,b){return obj[a]-obj[b]}) } // https://stackoverflow.com/a/28191966/1153897 function getKeyByValue(object, value) { //return Object.keys(object).find(key => object[key] === value); return Object.keys(object).filter(function(key) {return object[key] === value})[0]; } //============================================================ // Private Variables //------------------------------------------------------------ var prepedData, cellHeight, cellWidth; var uniqueX = {}, uniqueY = {}, uniqueColor = []; var uniqueXMeta = [], uniqueYMeta = [], uniqueCells = [] var renderWatch = nv.utils.renderWatch(dispatch, duration); var RdYlBu = ["#a50026","#d73027","#f46d43","#fdae61","#fee090","#ffffbf","#e0f3f8","#abd9e9","#74add1","#4575b4","#313695"]; var getCellPos = function(d) { return d._cellPos; }; var getIX = function(d) { return getCellPos(d).ix; } // get the given cell's x index position var getIY = function(d) { return getCellPos(d).iy; } // get the given cell's y index position var getNorm = function(d) { return getCellPos(d).norm; } var getIdx = function(d) { return getCellPos(d).idx; } function chart(selection) { renderWatch.reset(); selection.each(function(data) { prepedData = prepData(data); var availableWidth = width - margin.left - margin.right, availableHeight = height - margin.top - margin.bottom; // available width/height set the cell dimenions unless // the aspect ratio is defined - in that case the cell // height is adjusted and availableHeight updated cellWidth = availableWidth / Object.keys(uniqueX).length; cellHeight = cellAspectRatio ? cellWidth / cellAspectRatio : availableHeight / Object.keys(uniqueY).length; if (cellAspectRatio) availableHeight = cellHeight * Object.keys(uniqueY).length - margin.top - margin.bottom; container = d3.select(this); nv.utils.initSVG(container); // Setup Scales xScale.domain(xDomain || sortObjByVals(uniqueX)) .rangeBands(xRange || [0, availableWidth-cellBorderWidth/2]); yScale.domain(yDomain || sortObjByVals(uniqueY)) .rangeBands(yRange || [0, availableHeight-cellBorderWidth/2]); colorScale = cellsAreNumeric() ? d3.scale.quantize() : d3.scale.ordinal(); colorScale.domain(colorDomain || getColorDomain()) .range(colorRange || RdYlBu); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-heatMapWrap').data([prepedData]); var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-heatMapWrap'); wrapEnter .append('g') .attr('class','cellWrap') wrap.watchTransition(renderWatch, 'nv-wrap: heatMapWrap') .attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); var gridWrap = wrapEnter .append('g') .attr('class','cellGrid') .style('opacity',1e-6) var gridLinesV = wrap.select('.cellGrid').selectAll('.gridLines.verticalGrid') .data(Object.values(uniqueX).concat([Object.values(uniqueX).length])) gridLinesV.enter() .append('line') .attr('class','gridLines verticalGrid') gridLinesV.exit() .remove() var gridLinesH = wrap.select('.cellGrid').selectAll('.gridLines.horizontalGrid') .data(Object.values(uniqueY).concat([Object.values(uniqueY).length])) gridLinesH.enter() .append('line') .attr('class','gridLines horizontalGrid') gridLinesH.exit() .remove() var cellWrap = wrap.select('.cellWrap') .selectAll(".nv-cell") .data(function(d) { return d; }, function(e) { return getIdx(e); }) var xMetaWrap = wrapEnter .append('g') .attr('class','xMetaWrap') .attr("transform", function() { return "translate(0," + (-xMetaHeight()-cellBorderWidth-metaOffset) + ")" }) var xMetas = wrap.select('.xMetaWrap').selectAll('.x-meta') .data(uniqueXMeta) var xMetaEnter = xMetas .enter() .append('rect') .attr('class','x-meta meta') .attr("width", cellWidth-cellBorderWidth) .attr("height", xMetaHeight()) .attr("transform", "translate(0,0)") .attr("fill", function(d) { return xMetaColorScale(d); }) var yMetaWrap = wrapEnter .append('g') .attr('class','yMetaWrap') .attr("transform", function(d,i) { return "translate(" + (-yMetaWidth()-cellBorderWidth-metaOffset) + ",0)" }) var yMetas = wrap.select('.yMetaWrap').selectAll('.y-meta') .data(uniqueYMeta) var yMetaEnter = yMetas .enter() .append('rect') .attr('class','y-meta meta') .attr("width", yMetaWidth()) .attr("height", cellHeight-cellBorderWidth) .attr("transform", function(d,i) { return "translate(0,0)" }) .attr("fill", function(d,i) { return yMetaColorScale(d); }) xMetas.exit().remove() yMetas.exit().remove() // CELLS var cellsEnter = cellWrap .enter() .append('g') .style('opacity', 1e-6) .attr("transform", function(d) { return "translate(0," + getIY(d) * cellHeight + ")" }) // enter all g's here for a sweep-right transition .attr('data-row', function(d) { return getIY(d) }) .attr('data-column', function(d) { return getIX(d) }); cellsEnter .append("rect") cellsEnter .append('text') .attr('text-anchor', 'middle') .attr("dy", 4) .attr("class","cell-text") // transition cell (rect) size cellWrap.selectAll('rect') .watchTransition(renderWatch, 'heatMap: rect') .attr("width", cellWidth-cellBorderWidth) .attr("height", cellHeight-cellBorderWidth) .attr('rx', cellRadius) .attr('ry', cellRadius) .style('stroke', function(d) { return cellColor(d) }) // transition cell (g) position, opacity and fill cellWrap .attr("class",function(d) { return isNaN(getCellValue(d)) ? 'nv-cell cell-missing' : 'nv-cell'}) .watchTransition(renderWatch, 'heatMap: cells') .style({ 'opacity': 1, 'fill': function(d) { return cellColor(d) }, }) .attr("transform", function(d) { return "translate(" + getIX(d) * cellWidth + "," + getIY(d) * cellHeight + ")" }) .attr("class",function(d) { return isNaN(getCellValue(d)) ? 'nv-cell cell-missing' : 'nv-cell'}) cellWrap.exit().remove(); // transition text position and fill cellWrap.selectAll('text') .watchTransition(renderWatch, 'heatMap: cells text') .text(function(d) { return cellValueLabel(d); }) .attr("x", function(d) { return (cellWidth-cellBorderWidth) / 2; }) .attr("y", function(d) { return (cellHeight-cellBorderWidth) / 2; }) .style("fill", function(d) { return cellTextColor(cellColor(d)) }) .style('opacity', function() { return showCellValues ? 1 : 0 }) // transition grid wrap.selectAll('.verticalGrid') .watchTransition(renderWatch, 'heatMap: gridLines') .attr('y1',0) .attr('y2',availableHeight-cellBorderWidth) .attr('x1',function(d) { return d*cellWidth-cellBorderWidth/2; }) .attr('x2',function(d) { return d*cellWidth-cellBorderWidth/2; }) var numHLines = Object.keys(uniqueY).length; wrap.selectAll('.horizontalGrid') .watchTransition(renderWatch, 'heatMap: gridLines') .attr('x1',function(d) { return (d == 0 || d == numHLines) ? -cellBorderWidth : 0 }) .attr('x2',function(d) { return (d == 0 || d == numHLines) ? availableWidth : availableWidth-cellBorderWidth}) .attr('y1',function(d) { return d*cellHeight-cellBorderWidth/2; }) .attr('y2',function(d) { return d*cellHeight-cellBorderWidth/2; }) wrap.select('.cellGrid') .watchTransition(renderWatch, 'heatMap: gridLines') .style({ 'stroke-width': cellBorderWidth, 'opacity': function() { return showGrid ? 1 : 1e-6 }, }) var xMetaRect = wrap.selectAll('.x-meta') var yMetaRect = wrap.selectAll('.y-meta') var allMetaRect = wrap.selectAll('.meta') // transition meta rect size xMetas .watchTransition(renderWatch, 'heatMap: xMetaRect') .attr("width", cellWidth-cellBorderWidth) .attr("height", xMetaHeight()) .attr("transform", function(d,i) { return "translate(" + (i * cellWidth) + ",0)" }) yMetas .watchTransition(renderWatch, 'heatMap: yMetaRect') .attr("width", yMetaWidth()) .attr("height", cellHeight-cellBorderWidth) .attr("transform", function(d,i) { return "translate(0," + (i * cellHeight) + ")" }) // transition position of meta wrap g & opacity wrap.select('.xMetaWrap') .watchTransition(renderWatch, 'heatMap: xMetaWrap') .attr("transform", function(d,i) { return "translate(0," + (-xMetaHeight()-cellBorderWidth-metaOffset) + ")" }) .style("opacity", function() { return xMeta !== false ? 1 : 0 }) wrap.select('.yMetaWrap') .watchTransition(renderWatch, 'heatMap: yMetaWrap') .attr("transform", function(d,i) { return "translate(" + (-yMetaWidth()-cellBorderWidth-metaOffset) + ",0)" }) .style("opacity", function() { return yMeta !== false ? 1 : 0 }) // TOOLTIPS cellWrap .on('mouseover', function(d,i) { var idx = getIdx(d); var ix = getIX(d); var iy = getIY(d); // set the proper classes for all cells // hover row gets class .row-hover // hover column gets class .column-hover // hover cell gets class .cell-hover // all remaining cells get class .no-hover d3.selectAll('.nv-cell').each(function(e) { if (idx == getIdx(e)) { d3.select(this).classed('cell-hover', true); d3.select(this).classed('no-hover', false); } else { d3.select(this).classed('no-hover', true); d3.select(this).classed('cell-hover', false); } if (ix == getIX(e)) { d3.select(this).classed('no-hover', false); d3.select(this).classed('column-hover', true); } if (iy == getIY(e)) { d3.select(this).classed('no-hover', false); d3.select(this).classed('row-hover', true); } }) // set hover classes for column metadata d3.selectAll('.x-meta').each(function(e, j) { if (j == ix) { d3.select(this).classed('cell-hover', true); d3.select(this).classed('no-hover', false); } else { d3.select(this).classed('no-hover', true); d3.select(this).classed('cell-hover', false); } }); // set hover class for row metadata d3.selectAll('.y-meta').each(function(e, j) { if (j == iy) { d3.select(this).classed('cell-hover', true); d3.select(this).classed('no-hover', false); } else { d3.select(this).classed('no-hover', true); d3.select(this).classed('cell-hover', false); } }); dispatch.elementMouseover({ value: getKeyByValue(uniqueX, ix) + ' & ' + getKeyByValue(uniqueY, iy), series: { value: cellValueLabel(d), color: d3.select(this).select('rect').style("fill") }, e: d3.event, }); }) .on('mouseout', function(d,i) { // allow tooltip to remain even when mouse is over the // space between the cell; // this prevents cells from "flashing" when transitioning // between cells var bBox = d3.select(this).select('rect').node().getBBox(); var coordinates = d3.mouse(d3.select('.nv-heatMap').node()); var x = coordinates[0]; var y = coordinates[1]; // we only trigger mouseout when mouse moves outside of // .nv-heatMap if (x + cellBorderWidth >= availableWidth || y + cellBorderWidth >= availableHeight || x < 0 || y < 0) { // remove all hover classes removeAllHoverClasses(); dispatch.elementMouseout({e: d3.event}); } }) .on('mousemove', function(d,i) { dispatch.elementMousemove({e: d3.event}); }) allMetaRect .on('mouseover', function(d,i) { // true if hovering over a row metadata rect var isColMeta = d3.select(this).attr('class').indexOf('x-meta') != -1 ? true : false; // apply proper .row-hover & .column-hover // classes to cells d3.selectAll('.nv-cell').each(function(e) { if (isColMeta && i == getIX(e)) { d3.select(this).classed('column-hover', true); d3.select(this).classed('no-hover', false); } else if (!isColMeta && i-uniqueXMeta.length == getIY(e)) { // since allMetaRect selects all the meta rects, the index for the y's will // be offset by the number of x rects. TODO - write seperate tooltip sections // for x meta rect & y meta rect d3.select(this).classed('row-hover', true); d3.select(this).classed('no-hover', false); } else { d3.select(this).classed('no-hover', true); d3.select(this).classed('column-hover', false); d3.select(this).classed('row-hover', false); } d3.select(this).classed('cell-hover', false); }) // apply proper .row-hover & .column-hover // classes to meta rects d3.selectAll('.meta').classed('no-hover', true); d3.select(this).classed('cell-hover', true); d3.select(this).classed('no-hover', false); dispatch.elementMouseover({ value: isColMeta ? 'Column meta' : 'Row meta', series: { value: d, color: d3.select(this).style('fill'), } }); }) .on('mouseout', function(d,i) { // true if hovering over a row metadata rect var isColMeta = d3.select(this).attr('class').indexOf('x-meta') != -1 ? true : false; // allow tooltip to remain even when mouse is over the // space between the cell; // this prevents cells from "flashing" when transitioning // between cells var bBox = d3.select(this).node().getBBox(); var coordinates = d3.mouse(d3.select(isColMeta ? '.xMetaWrap' : '.yMetaWrap').node()); var x = coordinates[0]; var y = coordinates[1]; if ( y < 0 || x < 0 || (isColMeta && x + cellBorderWidth >= availableWidth) || (!isColMeta && y + cellBorderWidth >= availableHeight) ) { // remove all hover classes removeAllHoverClasses(); dispatch.elementMouseout({e: d3.event}); } }) .on('mousemove', function(d,i) { dispatch.elementMousemove({e: d3.event}); }) }); renderWatch.renderEnd('heatMap immediate'); return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.dispatch = dispatch; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, showCellValues: {get: function(){return showCellValues;}, set: function(_){showCellValues=_;}}, x: {get: function(){return getX;}, set: function(_){getX=_;}}, // data attribute for horizontal axis y: {get: function(){return getY;}, set: function(_){getY=_;}}, // data attribute for vertical axis cellValue: {get: function(){return getCellValue;}, set: function(_){getCellValue=_;}}, // data attribute that sets cell value and color missingDataColor: {get: function(){return missingDataColor;}, set: function(_){missingDataColor=_;}}, missingDataLabel: {get: function(){return missingDataLabel;}, set: function(_){missingDataLabel=_;}}, xScale: {get: function(){return xScale;}, set: function(_){xScale=_;}}, yScale: {get: function(){return yScale;}, set: function(_){yScale=_;}}, colorScale: {get: function(){return colorScale;}, set: function(_){colorScale=_;}}, // scale to map cell values to colors xDomain: {get: function(){return xDomain;}, set: function(_){xDomain=_;}}, yDomain: {get: function(){return yDomain;}, set: function(_){yDomain=_;}}, xRange: {get: function(){return xRange;}, set: function(_){xRange=_;}}, yRange: {get: function(){return yRange;}, set: function(_){yRange=_;}}, colorRange: {get: function(){return colorRange;}, set: function(_){colorRange=_;}}, colorDomain: {get: function(){return colorDomain;}, set: function(_){colorDomain=_;}}, xMeta: {get: function(){return xMeta;}, set: function(_){xMeta=_;}}, yMeta: {get: function(){return yMeta;}, set: function(_){yMeta=_;}}, xMetaColorScale: {get: function(){return color;}, set: function(_){color = nv.utils.getColor(_);}}, yMetaColorScale: {get: function(){return color;}, set: function(_){color = nv.utils.getColor(_);}}, cellAspectRatio: {get: function(){return cellAspectRatio;}, set: function(_){cellAspectRatio=_;}}, // cell width / height cellRadius: {get: function(){return cellRadius;}, set: function(_){cellRadius=_;}}, // cell width / height cellHeight: {get: function(){return cellHeight;}}, // TODO - should not be exposed since we don't want user setting this cellWidth: {get: function(){return cellWidth;}}, // TODO - should not be exposed since we don't want user setting this normalize: {get: function(){return normalize;}, set: function(_){normalize=_;}}, cellBorderWidth: {get: function(){return cellBorderWidth;}, set: function(_){cellBorderWidth=_;}}, highContrastText: {get: function(){return highContrastText;}, set: function(_){highContrastText=_;}}, cellValueFormat: {get: function(){return cellValueFormat;}, set: function(_){cellValueFormat=_;}}, id: {get: function(){return id;}, set: function(_){id=_;}}, metaOffset: {get: function(){return metaOffset;}, set: function(_){metaOffset=_;}}, xMetaHeight: {get: function(){return xMetaHeight;}, set: function(_){xMetaHeight=_;}}, yMetaWidth: {get: function(){return yMetaWidth;}, set: function(_){yMetaWidth=_;}}, showGrid: {get: function(){return showGrid;}, set: function(_){showGrid=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; renderWatch.reset(duration); }} }); nv.utils.initOptions(chart); return chart; }; /* Heatmap Chart Type A heatmap is a graphical representation of data where the individual values contained in a matrix are represented as colors within cells. Furthermore, metadata can be associated with each of the matrix rows or columns. By grouping these rows/columns together by a given metadata value, data trends can be spotted. Format for input data should be: var data = [ {day: 'mo', hour: '1a', value: 16, timeperiod: 'early morning', weekperiod: 'week', category: 1}, {day: 'mo', hour: '2a', value: 20, timeperiod: 'early morning', weekperiod: 'week', category: 2}, {day: 'mo', hour: '3a', value: 0, timeperiod: 'early morning', weekperiod: 'week', category: 1}, ... ] where the keys 'day' and 'hour' specify the row/column of the heatmap, 'value' specifies the cell value and the keys 'timeperiod', 'weekperiod' and 'week' are extra metadata that can be associated with rows/columns. Options for chart: */ nv.models.heatMapChart = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var heatMap = nv.models.heatMap() , legend = nv.models.legend() , legendRowMeta = nv.models.legend() , legendColumnMeta = nv.models.legend() , tooltip = nv.models.tooltip() , xAxis = nv.models.axis() , yAxis = nv.models.axis() ; var margin = {top: 20, right: 10, bottom: 50, left: 60} , marginTop = null , width = null , height = null , color = nv.utils.getColor() , showLegend = true , staggerLabels = false , showXAxis = true , showYAxis = true , alignYAxis = 'left' , alignXAxis = 'top' , rotateLabels = 0 , title = false , x , y , noData = null , dispatch = d3.dispatch('beforeUpdate','renderEnd') , duration = 250 ; xAxis .orient(alignXAxis) .showMaxMin(false) .tickFormat(function(d) { return d }) ; yAxis .orient(alignYAxis) .showMaxMin(false) .tickFormat(function(d) { return d }) ; tooltip .duration(0) .headerEnabled(true) .keyFormatter(function(d, i) { return xAxis.tickFormat()(d, i); }) //============================================================ // Private Variables //------------------------------------------------------------ // https://bl.ocks.org/mbostock/4573883 // get max/min range for all the quantized cell values // returns an array where each element is [start,stop] // of color bin function quantizeLegendValues() { var e = heatMap.colorScale(), legendVals; if (typeof e.domain()[0] === 'string') { // if color scale is ordinal legendVals = e.domain(); } else { // if color scale is numeric legendVals = e.range().map(function(color) { var d = e.invertExtent(color); if (d[0] === null) d[0] = e.domain()[0]; if (d[1] === null) d[1] = e.domain()[1]; return d; }) } return legendVals } // return true if row metadata specified by user function hasRowMeta() { return typeof heatMap.yMeta() === 'function' } // return true if col metadata specified by user function hasColumnMeta() { return typeof heatMap.xMeta() === 'function' } var renderWatch = nv.utils.renderWatch(dispatch, duration); function chart(selection) { renderWatch.reset(); renderWatch.models(heatMap); renderWatch.models(xAxis); renderWatch.models(yAxis); selection.each(function(data) { var container = d3.select(this), that = this; nv.utils.initSVG(container); var availableWidth = nv.utils.availableWidth(width, container, margin), availableHeight = nv.utils.availableHeight(height, container, margin); chart.update = function() { dispatch.beforeUpdate(); container.transition().duration(duration).call(chart); }; chart.container = this; // Display No Data message if there's nothing to show. if (!data || !data.length) { nv.utils.noData(chart, container); return chart; } else { container.selectAll('.nv-noData').remove(); } // Setup Scales x = heatMap.xScale(); y = heatMap.yScale(); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap').data([data]); var gEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap').append('g'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-heatMap'); gEnter.append('g').attr('class', 'nv-legendWrap'); gEnter.append('g').attr('class', 'nv-x nv-axis'); gEnter.append('g').attr('class', 'nv-y nv-axis') g.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); heatMap .width(availableWidth) .height(availableHeight); var heatMapWrap = g.select('.nv-heatMap') .datum(data.filter(function(d) { return !d.disabled })); heatMapWrap.transition().call(heatMap); if (heatMap.cellAspectRatio()) { availableHeight = heatMap.cellHeight() * y.domain().length; heatMap.height(availableHeight); } // Setup Axes xAxis .scale(x) ._ticks( nv.utils.calcTicksX(availableWidth/100, data) ) .tickSize(-availableHeight, 0); var axisX = g.select('.nv-x.nv-axis') axisX.call(xAxis) .watchTransition(renderWatch, 'heatMap: axisX') .selectAll('.tick') .style('opacity', function() { return showXAxis ? 1 : 0 } ) var xTicks = axisX.selectAll('g'); xTicks .selectAll('.tick text') .attr('transform', function(d,i,j) { var rot = rotateLabels != 0 ? rotateLabels : '0'; var stagger = staggerLabels ? j % 2 == 0 ? '5' : '17' : '0'; return 'translate(0, ' + stagger + ') rotate(' + rot + ' 0,0)'; }) .style('text-anchor', rotateLabels > 0 ? 'start' : rotateLabels < 0 ? 'end' : 'middle'); // position text in center of meta rects var yPos = -5; if (hasColumnMeta()) { axisX.selectAll('text').style('text-anchor', 'middle') yPos = -heatMap.xMetaHeight()()/2 - heatMap.metaOffset() + 3; } // adjust position of axis based on presence of metadata group if (alignXAxis == 'bottom') { axisX .watchTransition(renderWatch, 'heatMap: axisX') .attr("transform", "translate(0," + (availableHeight - yPos) + ")"); if (heatMap.xMeta() !== false) { // if showing x metadata var pos = availableHeight+heatMap.metaOffset()+heatMap.cellBorderWidth() g.select('.xMetaWrap') .watchTransition(renderWatch, 'heatMap: xMetaWrap') .attr("transform", function(d,i) { return "translate(0," + pos + ")" }) } } else { axisX .watchTransition(renderWatch, 'heatMap: axisX') .attr("transform", "translate(0," + yPos + ")"); } yAxis .scale(y) ._ticks( nv.utils.calcTicksY(availableHeight/36, data) ) .tickSize( -availableWidth, 0); var axisY = g.select('.nv-y.nv-axis') axisY.call(yAxis) .watchTransition(renderWatch, 'heatMap: axisY') .selectAll('.tick') .style('opacity', function() { return showYAxis ? 1 : 0 } ) // position text in center of meta rects var xPos = -5; if (hasRowMeta()) { axisY.selectAll('text').style('text-anchor', 'middle') xPos = -heatMap.yMetaWidth()()/2 - heatMap.metaOffset(); } // adjust position of axis based on presence of metadata group if (alignYAxis == 'right') { axisY.attr("transform", "translate(" + (availableWidth - xPos) + ",0)"); if (heatMap.yMeta() !== false) { // if showing y meatdata var pos = availableWidth+heatMap.metaOffset()+heatMap.cellBorderWidth() g.select('.yMetaWrap') .watchTransition(renderWatch, 'heatMap: yMetaWrap') .attr("transform", function(d,i) { return "translate(" + pos + ",0)" }) } } else { axisY.attr("transform", "translate(" + xPos + ",0)"); } // Legend var legendWrap = g.select('.nv-legendWrap') legend .width(availableWidth) .color(heatMap.colorScale().range()) var legendVal = quantizeLegendValues().map(function(d) { if (Array.isArray(d)) { // if cell values are numeric return {key: d[0].toFixed(1) + " - " + d[1].toFixed(1)}; } else { // if cell values are ordinal return {key: d}; } }) legendWrap .datum(legendVal) .call(legend) .attr('transform', 'translate(0,' + (alignXAxis == 'top' ? availableHeight : -30) + ')'); // TODO: more intelligent offset (-30) when top aligning legend legendWrap .watchTransition(renderWatch, 'heatMap: nv-legendWrap') .style('opacity', function() { return showLegend ? 1 : 0 } ) }); // axis don't have a flag for disabling the zero line, so we do it manually d3.selectAll('.nv-axis').selectAll('line') .style('stroke-opacity', 0) d3.select('.nv-y').select('path.domain').remove() renderWatch.renderEnd('heatMap chart immediate'); return chart; } //============================================================ // Event Handling/Dispatching (out of chart's scope) //------------------------------------------------------------ heatMap.dispatch.on('elementMouseover.tooltip', function(evt) { tooltip.data(evt).hidden(false); }); heatMap.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true); }); heatMap.dispatch.on('elementMousemove.tooltip', function(evt) { tooltip(); }); //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.dispatch = dispatch; chart.heatMap = heatMap; chart.legend = legend; chart.xAxis = xAxis; chart.yAxis = yAxis; chart.tooltip = tooltip; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, showLegend: {get: function(){return showLegend;}, set: function(_){showLegend=_;}}, noData: {get: function(){return noData;}, set: function(_){noData=_;}}, showXAxis: {get: function(){return showXAxis;}, set: function(_){showXAxis=_;}}, showYAxis: {get: function(){return showYAxis;}, set: function(_){showYAxis=_;}}, staggerLabels: {get: function(){return staggerLabels;}, set: function(_){staggerLabels=_;}}, rotateLabels: {get: function(){return rotateLabels;}, set: function(_){rotateLabels=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ if (_.top !== undefined) { margin.top = _.top; marginTop = _.top; } margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; renderWatch.reset(duration); heatMap.duration(duration); xAxis.duration(duration); yAxis.duration(duration); }}, alignYAxis: {get: function(){return alignYAxis;}, set: function(_){ alignYAxis = _; yAxis.orient(_); }}, alignXAxis: {get: function(){return alignXAxis;}, set: function(_){ alignXAxis = _; xAxis.orient(_); }}, }); nv.utils.inheritOptions(chart, heatMap); nv.utils.initOptions(chart); return chart; } //TODO: consider deprecating and using multibar with single series for this nv.models.historicalBar = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 0, right: 0, bottom: 0, left: 0} , width = null , height = null , id = Math.floor(Math.random() * 10000) //Create semi-unique ID in case user doesn't select one , container = null , x = d3.scale.linear() , y = d3.scale.linear() , getX = function(d) { return d.x } , getY = function(d) { return d.y } , forceX = [] , forceY = [0] , padData = false , clipEdge = true , color = nv.utils.defaultColor() , xDomain , yDomain , xRange , yRange , dispatch = d3.dispatch('chartClick', 'elementClick', 'elementDblClick', 'elementMouseover', 'elementMouseout', 'elementMousemove', 'renderEnd') , interactive = true ; var renderWatch = nv.utils.renderWatch(dispatch, 0); function chart(selection) { selection.each(function(data) { renderWatch.reset(); container = d3.select(this); var availableWidth = nv.utils.availableWidth(width, container, margin), availableHeight = nv.utils.availableHeight(height, container, margin); nv.utils.initSVG(container); // Setup Scales x.domain(xDomain || d3.extent(data[0].values.map(getX).concat(forceX) )); if (padData) x.range(xRange || [availableWidth * .5 / data[0].values.length, availableWidth * (data[0].values.length - .5) / data[0].values.length ]); else x.range(xRange || [0, availableWidth]); y.domain(yDomain || d3.extent(data[0].values.map(getY).concat(forceY) )) .range(yRange || [availableHeight, 0]); // If scale's domain don't have a range, slightly adjust to make one... so a chart can show a single data point if (x.domain()[0] === x.domain()[1]) x.domain()[0] ? x.domain([x.domain()[0] - x.domain()[0] * 0.01, x.domain()[1] + x.domain()[1] * 0.01]) : x.domain([-1,1]); if (y.domain()[0] === y.domain()[1]) y.domain()[0] ? y.domain([y.domain()[0] + y.domain()[0] * 0.01, y.domain()[1] - y.domain()[1] * 0.01]) : y.domain([-1,1]); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-historicalBar-' + id).data([data[0].values]); var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-historicalBar-' + id); var defsEnter = wrapEnter.append('defs'); var gEnter = wrapEnter.append('g'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-bars'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); container .on('click', function(d,i) { dispatch.chartClick({ data: d, index: i, pos: d3.event, id: id }); }); defsEnter.append('clipPath') .attr('id', 'nv-chart-clip-path-' + id) .append('rect'); wrap.select('#nv-chart-clip-path-' + id + ' rect') .attr('width', availableWidth) .attr('height', availableHeight); g.attr('clip-path', clipEdge ? 'url(#nv-chart-clip-path-' + id + ')' : ''); var bars = wrap.select('.nv-bars').selectAll('.nv-bar') .data(function(d) { return d }, function(d,i) {return getX(d,i)}); bars.exit().remove(); bars.enter().append('rect') .attr('x', 0 ) .attr('y', function(d,i) { return nv.utils.NaNtoZero(y(Math.max(0, getY(d,i)))) }) .attr('height', function(d,i) { return nv.utils.NaNtoZero(Math.abs(y(getY(d,i)) - y(0))) }) .attr('transform', function(d,i) { return 'translate(' + (x(getX(d,i)) - availableWidth / data[0].values.length * .45) + ',0)'; }) .on('mouseover', function(d,i) { if (!interactive) return; d3.select(this).classed('hover', true); dispatch.elementMouseover({ data: d, index: i, color: d3.select(this).style("fill") }); }) .on('mouseout', function(d,i) { if (!interactive) return; d3.select(this).classed('hover', false); dispatch.elementMouseout({ data: d, index: i, color: d3.select(this).style("fill") }); }) .on('mousemove', function(d,i) { if (!interactive) return; dispatch.elementMousemove({ data: d, index: i, color: d3.select(this).style("fill") }); }) .on('click', function(d,i) { if (!interactive) return; var element = this; dispatch.elementClick({ data: d, index: i, color: d3.select(this).style("fill"), event: d3.event, element: element }); d3.event.stopPropagation(); }) .on('dblclick', function(d,i) { if (!interactive) return; dispatch.elementDblClick({ data: d, index: i, color: d3.select(this).style("fill") }); d3.event.stopPropagation(); }); bars .attr('fill', function(d,i) { return color(d, i); }) .attr('class', function(d,i,j) { return (getY(d,i) < 0 ? 'nv-bar negative' : 'nv-bar positive') + ' nv-bar-' + j + '-' + i }) .watchTransition(renderWatch, 'bars') .attr('transform', function(d,i) { return 'translate(' + (x(getX(d,i)) - availableWidth / data[0].values.length * .45) + ',0)'; }) //TODO: better width calculations that don't assume always uniform data spacing;w .attr('width', (availableWidth / data[0].values.length) * .9 ); bars.watchTransition(renderWatch, 'bars') .attr('y', function(d,i) { var rval = getY(d,i) < 0 ? y(0) : y(0) - y(getY(d,i)) < 1 ? y(0) - 1 : y(getY(d,i)); return nv.utils.NaNtoZero(rval); }) .attr('height', function(d,i) { return nv.utils.NaNtoZero(Math.max(Math.abs(y(getY(d,i)) - y(0)),1)) }); }); renderWatch.renderEnd('historicalBar immediate'); return chart; } //Create methods to allow outside functions to highlight a specific bar. chart.highlightPoint = function(pointIndex, isHoverOver) { container .select(".nv-bars .nv-bar-0-" + pointIndex) .classed("hover", isHoverOver) ; }; chart.clearHighlights = function() { container .select(".nv-bars .nv-bar.hover") .classed("hover", false) ; }; //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.dispatch = dispatch; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, forceX: {get: function(){return forceX;}, set: function(_){forceX=_;}}, forceY: {get: function(){return forceY;}, set: function(_){forceY=_;}}, padData: {get: function(){return padData;}, set: function(_){padData=_;}}, x: {get: function(){return getX;}, set: function(_){getX=_;}}, y: {get: function(){return getY;}, set: function(_){getY=_;}}, xScale: {get: function(){return x;}, set: function(_){x=_;}}, yScale: {get: function(){return y;}, set: function(_){y=_;}}, xDomain: {get: function(){return xDomain;}, set: function(_){xDomain=_;}}, yDomain: {get: function(){return yDomain;}, set: function(_){yDomain=_;}}, xRange: {get: function(){return xRange;}, set: function(_){xRange=_;}}, yRange: {get: function(){return yRange;}, set: function(_){yRange=_;}}, clipEdge: {get: function(){return clipEdge;}, set: function(_){clipEdge=_;}}, id: {get: function(){return id;}, set: function(_){id=_;}}, interactive: {get: function(){return interactive;}, set: function(_){interactive=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); }} }); nv.utils.initOptions(chart); return chart; }; nv.models.historicalBarChart = function(bar_model) { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var bars = bar_model || nv.models.historicalBar() , xAxis = nv.models.axis() , yAxis = nv.models.axis() , legend = nv.models.legend() , interactiveLayer = nv.interactiveGuideline() , tooltip = nv.models.tooltip() ; var margin = {top: 30, right: 90, bottom: 50, left: 90} , marginTop = null , color = nv.utils.defaultColor() , width = null , height = null , showLegend = false , showXAxis = true , showYAxis = true , rightAlignYAxis = false , useInteractiveGuideline = false , x , y , state = {} , defaultState = null , noData = null , dispatch = d3.dispatch('tooltipHide', 'stateChange', 'changeState', 'renderEnd') , transitionDuration = 250 ; xAxis.orient('bottom').tickPadding(7); yAxis.orient( (rightAlignYAxis) ? 'right' : 'left'); tooltip .duration(0) .headerEnabled(false) .valueFormatter(function(d, i) { return yAxis.tickFormat()(d, i); }) .headerFormatter(function(d, i) { return xAxis.tickFormat()(d, i); }); //============================================================ // Private Variables //------------------------------------------------------------ var renderWatch = nv.utils.renderWatch(dispatch, 0); function chart(selection) { selection.each(function(data) { renderWatch.reset(); renderWatch.models(bars); if (showXAxis) renderWatch.models(xAxis); if (showYAxis) renderWatch.models(yAxis); var container = d3.select(this), that = this; nv.utils.initSVG(container); var availableWidth = nv.utils.availableWidth(width, container, margin), availableHeight = nv.utils.availableHeight(height, container, margin); chart.update = function() { container.transition().duration(transitionDuration).call(chart) }; chart.container = this; //set state.disabled state.disabled = data.map(function(d) { return !!d.disabled }); if (!defaultState) { var key; defaultState = {}; for (key in state) { if (state[key] instanceof Array) defaultState[key] = state[key].slice(0); else defaultState[key] = state[key]; } } // Display noData message if there's nothing to show. if (!data || !data.length || !data.filter(function(d) { return d.values.length }).length) { nv.utils.noData(chart, container) return chart; } else { container.selectAll('.nv-noData').remove(); } // Setup Scales x = bars.xScale(); y = bars.yScale(); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-historicalBarChart').data([data]); var gEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-historicalBarChart').append('g'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-x nv-axis'); gEnter.append('g').attr('class', 'nv-y nv-axis'); gEnter.append('g').attr('class', 'nv-barsWrap'); gEnter.append('g').attr('class', 'nv-legendWrap'); gEnter.append('g').attr('class', 'nv-interactive'); // Legend if (!showLegend) { g.select('.nv-legendWrap').selectAll('*').remove(); } else { legend.width(availableWidth); g.select('.nv-legendWrap') .datum(data) .call(legend); if (!marginTop && legend.height() !== margin.top) { margin.top = legend.height(); availableHeight = nv.utils.availableHeight(height, container, margin); } wrap.select('.nv-legendWrap') .attr('transform', 'translate(0,' + (-margin.top) +')') } wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); if (rightAlignYAxis) { g.select(".nv-y.nv-axis") .attr("transform", "translate(" + availableWidth + ",0)"); } //Set up interactive layer if (useInteractiveGuideline) { interactiveLayer .width(availableWidth) .height(availableHeight) .margin({left:margin.left, top:margin.top}) .svgContainer(container) .xScale(x); wrap.select(".nv-interactive").call(interactiveLayer); } bars .width(availableWidth) .height(availableHeight) .color(data.map(function(d,i) { return d.color || color(d, i); }).filter(function(d,i) { return !data[i].disabled })); var barsWrap = g.select('.nv-barsWrap') .datum(data.filter(function(d) { return !d.disabled })); barsWrap.transition().call(bars); // Setup Axes if (showXAxis) { xAxis .scale(x) ._ticks( nv.utils.calcTicksX(availableWidth/100, data) ) .tickSize(-availableHeight, 0); g.select('.nv-x.nv-axis') .attr('transform', 'translate(0,' + y.range()[0] + ')'); g.select('.nv-x.nv-axis') .transition() .call(xAxis); } if (showYAxis) { yAxis .scale(y) ._ticks( nv.utils.calcTicksY(availableHeight/36, data) ) .tickSize( -availableWidth, 0); g.select('.nv-y.nv-axis') .transition() .call(yAxis); } //============================================================ // Event Handling/Dispatching (in chart's scope) //------------------------------------------------------------ interactiveLayer.dispatch.on('elementMousemove', function(e) { bars.clearHighlights(); var singlePoint, pointIndex, pointXLocation, allData = []; data .filter(function(series, i) { series.seriesIndex = i; return !series.disabled; }) .forEach(function(series,i) { pointIndex = nv.interactiveBisect(series.values, e.pointXValue, chart.x()); bars.highlightPoint(pointIndex,true); var point = series.values[pointIndex]; if (point === undefined) return; if (singlePoint === undefined) singlePoint = point; if (pointXLocation === undefined) pointXLocation = chart.xScale()(chart.x()(point,pointIndex)); allData.push({ key: series.key, value: chart.y()(point, pointIndex), color: color(series,series.seriesIndex), data: series.values[pointIndex] }); }); var xValue = xAxis.tickFormat()(chart.x()(singlePoint,pointIndex)); interactiveLayer.tooltip .valueFormatter(function(d,i) { return yAxis.tickFormat()(d); }) .data({ value: xValue, index: pointIndex, series: allData })(); interactiveLayer.renderGuideLine(pointXLocation); }); interactiveLayer.dispatch.on("elementMouseout",function(e) { dispatch.tooltipHide(); bars.clearHighlights(); }); legend.dispatch.on('legendClick', function(d,i) { d.disabled = !d.disabled; if (!data.filter(function(d) { return !d.disabled }).length) { data.map(function(d) { d.disabled = false; wrap.selectAll('.nv-series').classed('disabled', false); return d; }); } state.disabled = data.map(function(d) { return !!d.disabled }); dispatch.stateChange(state); selection.transition().call(chart); }); legend.dispatch.on('legendDblclick', function(d) { //Double clicking should always enable current series, and disabled all others. data.forEach(function(d) { d.disabled = true; }); d.disabled = false; state.disabled = data.map(function(d) { return !!d.disabled }); dispatch.stateChange(state); chart.update(); }); dispatch.on('changeState', function(e) { if (typeof e.disabled !== 'undefined') { data.forEach(function(series,i) { series.disabled = e.disabled[i]; }); state.disabled = e.disabled; } chart.update(); }); }); renderWatch.renderEnd('historicalBarChart immediate'); return chart; } //============================================================ // Event Handling/Dispatching (out of chart's scope) //------------------------------------------------------------ bars.dispatch.on('elementMouseover.tooltip', function(evt) { evt['series'] = { key: chart.x()(evt.data), value: chart.y()(evt.data), color: evt.color }; tooltip.data(evt).hidden(false); }); bars.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true); }); bars.dispatch.on('elementMousemove.tooltip', function(evt) { tooltip(); }); //============================================================ // Expose Public Variables //------------------------------------------------------------ // expose chart's sub-components chart.dispatch = dispatch; chart.bars = bars; chart.legend = legend; chart.xAxis = xAxis; chart.yAxis = yAxis; chart.interactiveLayer = interactiveLayer; chart.tooltip = tooltip; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, showLegend: {get: function(){return showLegend;}, set: function(_){showLegend=_;}}, showXAxis: {get: function(){return showXAxis;}, set: function(_){showXAxis=_;}}, showYAxis: {get: function(){return showYAxis;}, set: function(_){showYAxis=_;}}, defaultState: {get: function(){return defaultState;}, set: function(_){defaultState=_;}}, noData: {get: function(){return noData;}, set: function(_){noData=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ if (_.top !== undefined) { margin.top = _.top; marginTop = _.top; } margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); legend.color(color); bars.color(color); }}, duration: {get: function(){return transitionDuration;}, set: function(_){ transitionDuration=_; renderWatch.reset(transitionDuration); yAxis.duration(transitionDuration); xAxis.duration(transitionDuration); }}, rightAlignYAxis: {get: function(){return rightAlignYAxis;}, set: function(_){ rightAlignYAxis = _; yAxis.orient( (_) ? 'right' : 'left'); }}, useInteractiveGuideline: {get: function(){return useInteractiveGuideline;}, set: function(_){ useInteractiveGuideline = _; if (_ === true) { chart.interactive(false); } }} }); nv.utils.inheritOptions(chart, bars); nv.utils.initOptions(chart); return chart; }; // ohlcChart is just a historical chart with ohlc bars and some tweaks nv.models.ohlcBarChart = function() { var chart = nv.models.historicalBarChart(nv.models.ohlcBar()); // special default tooltip since we show multiple values per x chart.useInteractiveGuideline(true); chart.interactiveLayer.tooltip.contentGenerator(function(data) { // we assume only one series exists for this chart var d = data.series[0].data; // match line colors as defined in nv.d3.css var color = d.open < d.close ? "2ca02c" : "d62728"; return '' + '

' + data.value + '

' + '' + '' + '' + '' + '' + '
open:' + chart.yAxis.tickFormat()(d.open) + '
close:' + chart.yAxis.tickFormat()(d.close) + '
high' + chart.yAxis.tickFormat()(d.high) + '
low:' + chart.yAxis.tickFormat()(d.low) + '
'; }); return chart; }; // candlestickChart is just a historical chart with candlestick bars and some tweaks nv.models.candlestickBarChart = function() { var chart = nv.models.historicalBarChart(nv.models.candlestickBar()); // special default tooltip since we show multiple values per x chart.useInteractiveGuideline(true); chart.interactiveLayer.tooltip.contentGenerator(function(data) { // we assume only one series exists for this chart var d = data.series[0].data; // match line colors as defined in nv.d3.css var color = d.open < d.close ? "2ca02c" : "d62728"; return '' + '

' + data.value + '

' + '' + '' + '' + '' + '' + '
open:' + chart.yAxis.tickFormat()(d.open) + '
close:' + chart.yAxis.tickFormat()(d.close) + '
high' + chart.yAxis.tickFormat()(d.high) + '
low:' + chart.yAxis.tickFormat()(d.low) + '
'; }); return chart; }; nv.models.legend = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 5, right: 0, bottom: 5, left: 0} , width = 400 , height = 20 , getKey = function(d) { return d.key } , keyFormatter = function (d) { return d } , color = nv.utils.getColor() , maxKeyLength = 20 //default value for key lengths , align = true , padding = 32 //define how much space between legend items. - recommend 32 for furious version , rightAlign = true , updateState = true //If true, legend will update data.disabled and trigger a 'stateChange' dispatch. , enableDoubleClick = true //If true, legend will enable double click handling , radioButtonMode = false //If true, clicking legend items will cause it to behave like a radio button. (only one can be selected at a time) , expanded = false , dispatch = d3.dispatch('legendClick', 'legendDblclick', 'legendMouseover', 'legendMouseout', 'stateChange') , vers = 'classic' //Options are "classic" and "furious" ; function chart(selection) { selection.each(function(data) { var availableWidth = width - margin.left - margin.right, container = d3.select(this); nv.utils.initSVG(container); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-legend').data([data]); var gEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-legend').append('g'); var g = wrap.select('g'); if (rightAlign) wrap.attr('transform', 'translate(' + (- margin.right) + ',' + margin.top + ')'); else wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); var series = g.selectAll('.nv-series') .data(function(d) { if(vers != 'furious') return d; return d.filter(function(n) { return expanded ? true : !n.disengaged; }); }); var seriesEnter = series.enter().append('g').attr('class', 'nv-series'); var seriesShape; var versPadding; switch(vers) { case 'furious' : versPadding = 23; break; case 'classic' : versPadding = 20; } if(vers == 'classic') { seriesEnter.append('circle') .style('stroke-width', 2) .attr('class','nv-legend-symbol') .attr('r', 5); seriesShape = series.select('.nv-legend-symbol'); } else if (vers == 'furious') { seriesEnter.append('rect') .style('stroke-width', 2) .attr('class','nv-legend-symbol') .attr('rx', 3) .attr('ry', 3); seriesShape = series.select('.nv-legend-symbol'); seriesEnter.append('g') .attr('class', 'nv-check-box') .property('innerHTML','') .attr('transform', 'translate(-10,-8)scale(0.5)'); var seriesCheckbox = series.select('.nv-check-box'); seriesCheckbox.each(function(d,i) { d3.select(this).selectAll('path') .attr('stroke', setTextColor(d,i)); }); } seriesEnter.append('text') .attr('text-anchor', 'start') .attr('class','nv-legend-text') .attr('dy', '.32em') .attr('dx', '8'); var seriesText = series.select('text.nv-legend-text'); series .on('mouseover', function(d,i) { dispatch.legendMouseover(d,i); //TODO: Make consistent with other event objects }) .on('mouseout', function(d,i) { dispatch.legendMouseout(d,i); }) .on('click', function(d,i) { dispatch.legendClick(d,i); // make sure we re-get data in case it was modified var data = series.data(); if (updateState) { if(vers =='classic') { if (radioButtonMode) { //Radio button mode: set every series to disabled, // and enable the clicked series. data.forEach(function(series) { series.disabled = true}); d.disabled = false; } else { d.disabled = !d.disabled; if (data.every(function(series) { return series.disabled})) { //the default behavior of NVD3 legends is, if every single series // is disabled, turn all series' back on. data.forEach(function(series) { series.disabled = false}); } } } else if(vers == 'furious') { if(expanded) { d.disengaged = !d.disengaged; d.userDisabled = d.userDisabled == undefined ? !!d.disabled : d.userDisabled; d.disabled = d.disengaged || d.userDisabled; } else if (!expanded) { d.disabled = !d.disabled; d.userDisabled = d.disabled; var engaged = data.filter(function(d) { return !d.disengaged; }); if (engaged.every(function(series) { return series.userDisabled })) { //the default behavior of NVD3 legends is, if every single series // is disabled, turn all series' back on. data.forEach(function(series) { series.disabled = series.userDisabled = false; }); } } } dispatch.stateChange({ disabled: data.map(function(d) { return !!d.disabled }), disengaged: data.map(function(d) { return !!d.disengaged }) }); } }) .on('dblclick', function(d,i) { if (enableDoubleClick) { if (vers == 'furious' && expanded) return; dispatch.legendDblclick(d, i); if (updateState) { // make sure we re-get data in case it was modified var data = series.data(); //the default behavior of NVD3 legends, when double clicking one, // is to set all other series' to false, and make the double clicked series enabled. data.forEach(function (series) { series.disabled = true; if (vers == 'furious') series.userDisabled = series.disabled; }); d.disabled = false; if (vers == 'furious') d.userDisabled = d.disabled; dispatch.stateChange({ disabled: data.map(function (d) { return !!d.disabled }) }); } } }); series.classed('nv-disabled', function(d) { return d.userDisabled }); series.exit().remove(); seriesText .attr('fill', setTextColor) .text(function (d) { return keyFormatter(getKey(d)) }); //TODO: implement fixed-width and max-width options (max-width is especially useful with the align option) // NEW ALIGNING CODE, TODO: clean up var legendWidth = 0; if (align) { var seriesWidths = []; series.each(function(d,i) { var legendText; if (keyFormatter(getKey(d)) && keyFormatter(getKey(d)).length > maxKeyLength) { var trimmedKey = keyFormatter(getKey(d)).substring(0, maxKeyLength); legendText = d3.select(this).select('text').text(trimmedKey + "..."); d3.select(this).append("svg:title").text(keyFormatter(getKey(d))); } else { legendText = d3.select(this).select('text'); } var nodeTextLength; try { nodeTextLength = legendText.node().getComputedTextLength(); // If the legendText is display:none'd (nodeTextLength == 0), simulate an error so we approximate, instead if(nodeTextLength <= 0) throw Error(); } catch(e) { nodeTextLength = nv.utils.calcApproxTextWidth(legendText); } seriesWidths.push(nodeTextLength + padding); }); var seriesPerRow = 0; var columnWidths = []; legendWidth = 0; while ( legendWidth < availableWidth && seriesPerRow < seriesWidths.length) { columnWidths[seriesPerRow] = seriesWidths[seriesPerRow]; legendWidth += seriesWidths[seriesPerRow++]; } if (seriesPerRow === 0) seriesPerRow = 1; //minimum of one series per row while ( legendWidth > availableWidth && seriesPerRow > 1 ) { columnWidths = []; seriesPerRow--; for (var k = 0; k < seriesWidths.length; k++) { if (seriesWidths[k] > (columnWidths[k % seriesPerRow] || 0) ) columnWidths[k % seriesPerRow] = seriesWidths[k]; } legendWidth = columnWidths.reduce(function(prev, cur, index, array) { return prev + cur; }); } var xPositions = []; for (var i = 0, curX = 0; i < seriesPerRow; i++) { xPositions[i] = curX; curX += columnWidths[i]; } series .attr('transform', function(d, i) { return 'translate(' + xPositions[i % seriesPerRow] + ',' + (5 + Math.floor(i / seriesPerRow) * versPadding) + ')'; }); //position legend as far right as possible within the total width if (rightAlign) { g.attr('transform', 'translate(' + (width - margin.right - legendWidth) + ',' + margin.top + ')'); } else { g.attr('transform', 'translate(0' + ',' + margin.top + ')'); } height = margin.top + margin.bottom + (Math.ceil(seriesWidths.length / seriesPerRow) * versPadding); } else { var ypos = 5, newxpos = 5, maxwidth = 0, xpos; series .attr('transform', function(d, i) { var length = d3.select(this).select('text').node().getComputedTextLength() + padding; xpos = newxpos; if (width < margin.left + margin.right + xpos + length) { newxpos = xpos = 5; ypos += versPadding; } newxpos += length; if (newxpos > maxwidth) maxwidth = newxpos; if(legendWidth < xpos + maxwidth) { legendWidth = xpos + maxwidth; } return 'translate(' + xpos + ',' + ypos + ')'; }); //position legend as far right as possible within the total width g.attr('transform', 'translate(' + (width - margin.right - maxwidth) + ',' + margin.top + ')'); height = margin.top + margin.bottom + ypos + 15; } if(vers == 'furious') { // Size rectangles after text is placed seriesShape .attr('width', function(d,i) { return seriesText[0][i].getComputedTextLength() + 27; }) .attr('height', 18) .attr('y', -9) .attr('x', -15); // The background for the expanded legend (UI) gEnter.insert('rect',':first-child') .attr('class', 'nv-legend-bg') .attr('fill', '#eee') // .attr('stroke', '#444') .attr('opacity',0); var seriesBG = g.select('.nv-legend-bg'); seriesBG .transition().duration(300) .attr('x', -versPadding ) .attr('width', legendWidth + versPadding - 12) .attr('height', height + 10) .attr('y', -margin.top - 10) .attr('opacity', expanded ? 1 : 0); } seriesShape .style('fill', setBGColor) .style('fill-opacity', setBGOpacity) .style('stroke', setBGColor); }); function setTextColor(d,i) { if(vers != 'furious') return '#000'; if(expanded) { return d.disengaged ? '#000' : '#fff'; } else if (!expanded) { if(!d.color) d.color = color(d,i); return !!d.disabled ? d.color : '#fff'; } } function setBGColor(d,i) { if(expanded && vers == 'furious') { return d.disengaged ? '#eee' : d.color || color(d,i); } else { return d.color || color(d,i); } } function setBGOpacity(d,i) { if(expanded && vers == 'furious') { return 1; } else { return !!d.disabled ? 0 : 1; } } return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.dispatch = dispatch; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, key: {get: function(){return getKey;}, set: function(_){getKey=_;}}, keyFormatter: {get: function(){return keyFormatter;}, set: function(_){keyFormatter=_;}}, align: {get: function(){return align;}, set: function(_){align=_;}}, maxKeyLength: {get: function(){return maxKeyLength;}, set: function(_){maxKeyLength=_;}}, rightAlign: {get: function(){return rightAlign;}, set: function(_){rightAlign=_;}}, padding: {get: function(){return padding;}, set: function(_){padding=_;}}, updateState: {get: function(){return updateState;}, set: function(_){updateState=_;}}, enableDoubleClick: {get: function(){return enableDoubleClick;}, set: function(_){enableDoubleClick=_;}}, radioButtonMode:{get: function(){return radioButtonMode;}, set: function(_){radioButtonMode=_;}}, expanded: {get: function(){return expanded;}, set: function(_){expanded=_;}}, vers: {get: function(){return vers;}, set: function(_){vers=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); }} }); nv.utils.initOptions(chart); return chart; }; nv.models.line = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var scatter = nv.models.scatter() ; var margin = {top: 0, right: 0, bottom: 0, left: 0} , width = 960 , height = 500 , container = null , strokeWidth = 1.5 , color = nv.utils.defaultColor() // a function that returns a color , getX = function(d) { return d.x } // accessor to get the x value from a data point , getY = function(d) { return d.y } // accessor to get the y value from a data point , defined = function(d,i) { return !isNaN(getY(d,i)) && getY(d,i) !== null } // allows a line to be not continuous when it is not defined , isArea = function(d) { return d.area } // decides if a line is an area or just a line , clipEdge = false // if true, masks lines within x and y scale , x //can be accessed via chart.xScale() , y //can be accessed via chart.yScale() , interpolate = "linear" // controls the line interpolation , duration = 250 , dispatch = d3.dispatch('elementClick', 'elementMouseover', 'elementMouseout', 'renderEnd') ; scatter .pointSize(16) // default size .pointDomain([16,256]) //set to speed up calculation, needs to be unset if there is a custom size accessor ; //============================================================ //============================================================ // Private Variables //------------------------------------------------------------ var x0, y0 //used to store previous scales , renderWatch = nv.utils.renderWatch(dispatch, duration) ; //============================================================ function chart(selection) { renderWatch.reset(); renderWatch.models(scatter); selection.each(function(data) { container = d3.select(this); var availableWidth = nv.utils.availableWidth(width, container, margin), availableHeight = nv.utils.availableHeight(height, container, margin); nv.utils.initSVG(container); // Setup Scales x = scatter.xScale(); y = scatter.yScale(); x0 = x0 || x; y0 = y0 || y; // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-line').data([data]); var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-line'); var defsEnter = wrapEnter.append('defs'); var gEnter = wrapEnter.append('g'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-groups'); gEnter.append('g').attr('class', 'nv-scatterWrap'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); scatter .width(availableWidth) .height(availableHeight); var scatterWrap = wrap.select('.nv-scatterWrap'); scatterWrap.call(scatter); defsEnter.append('clipPath') .attr('id', 'nv-edge-clip-' + scatter.id()) .append('rect'); wrap.select('#nv-edge-clip-' + scatter.id() + ' rect') .attr('width', availableWidth) .attr('height', (availableHeight > 0) ? availableHeight : 0); g .attr('clip-path', clipEdge ? 'url(#nv-edge-clip-' + scatter.id() + ')' : ''); scatterWrap .attr('clip-path', clipEdge ? 'url(#nv-edge-clip-' + scatter.id() + ')' : ''); var groups = wrap.select('.nv-groups').selectAll('.nv-group') .data(function(d) { return d }, function(d) { return d.key }); groups.enter().append('g') .style('stroke-opacity', 1e-6) .style('stroke-width', function(d) { return d.strokeWidth || strokeWidth }) .style('fill-opacity', 1e-6); groups.exit().remove(); groups .attr('class', function(d,i) { return (d.classed || '') + ' nv-group nv-series-' + i; }) .classed('hover', function(d) { return d.hover }) .style('fill', function(d,i){ return color(d, i) }) .style('stroke', function(d,i){ return color(d, i)}); groups.watchTransition(renderWatch, 'line: groups') .style('stroke-opacity', 1) .style('fill-opacity', function(d) { return d.fillOpacity || .5}); var areaPaths = groups.selectAll('path.nv-area') .data(function(d) { return isArea(d) ? [d] : [] }); // this is done differently than lines because I need to check if series is an area areaPaths.enter().append('path') .attr('class', 'nv-area') .attr('d', function(d) { return d3.svg.area() .interpolate(interpolate) .defined(defined) .x(function(d,i) { return nv.utils.NaNtoZero(x0(getX(d,i))) }) .y0(function(d,i) { return nv.utils.NaNtoZero(y0(getY(d,i))) }) .y1(function(d,i) { return y0( y.domain()[0] <= 0 ? y.domain()[1] >= 0 ? 0 : y.domain()[1] : y.domain()[0] ) }) //.y1(function(d,i) { return y0(0) }) //assuming 0 is within y domain.. may need to tweak this .apply(this, [d.values]) }); groups.exit().selectAll('path.nv-area') .remove(); areaPaths.watchTransition(renderWatch, 'line: areaPaths') .attr('d', function(d) { return d3.svg.area() .interpolate(interpolate) .defined(defined) .x(function(d,i) { return nv.utils.NaNtoZero(x(getX(d,i))) }) .y0(function(d,i) { return nv.utils.NaNtoZero(y(getY(d,i))) }) .y1(function(d,i) { return y( y.domain()[0] <= 0 ? y.domain()[1] >= 0 ? 0 : y.domain()[1] : y.domain()[0] ) }) //.y1(function(d,i) { return y0(0) }) //assuming 0 is within y domain.. may need to tweak this .apply(this, [d.values]) }); var linePaths = groups.selectAll('path.nv-line') .data(function(d) { return [d.values] }); linePaths.enter().append('path') .attr('class', 'nv-line') .attr('d', d3.svg.line() .interpolate(interpolate) .defined(defined) .x(function(d,i) { return nv.utils.NaNtoZero(x0(getX(d,i))) }) .y(function(d,i) { return nv.utils.NaNtoZero(y0(getY(d,i))) }) ); linePaths.watchTransition(renderWatch, 'line: linePaths') .attr('d', d3.svg.line() .interpolate(interpolate) .defined(defined) .x(function(d,i) { return nv.utils.NaNtoZero(x(getX(d,i))) }) .y(function(d,i) { return nv.utils.NaNtoZero(y(getY(d,i))) }) ); //store old scales for use in transitions on update x0 = x.copy(); y0 = y.copy(); }); renderWatch.renderEnd('line immediate'); return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.dispatch = dispatch; chart.scatter = scatter; // Pass through events scatter.dispatch.on('elementClick', function(){ dispatch.elementClick.apply(this, arguments); }); scatter.dispatch.on('elementMouseover', function(){ dispatch.elementMouseover.apply(this, arguments); }); scatter.dispatch.on('elementMouseout', function(){ dispatch.elementMouseout.apply(this, arguments); }); chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, defined: {get: function(){return defined;}, set: function(_){defined=_;}}, interpolate: {get: function(){return interpolate;}, set: function(_){interpolate=_;}}, clipEdge: {get: function(){return clipEdge;}, set: function(_){clipEdge=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; renderWatch.reset(duration); scatter.duration(duration); }}, isArea: {get: function(){return isArea;}, set: function(_){ isArea = d3.functor(_); }}, x: {get: function(){return getX;}, set: function(_){ getX = _; scatter.x(_); }}, y: {get: function(){return getY;}, set: function(_){ getY = _; scatter.y(_); }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); scatter.color(color); }} }); nv.utils.inheritOptions(chart, scatter); nv.utils.initOptions(chart); return chart; }; nv.models.lineChart = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var lines = nv.models.line() , xAxis = nv.models.axis() , yAxis = nv.models.axis() , legend = nv.models.legend() , interactiveLayer = nv.interactiveGuideline() , tooltip = nv.models.tooltip() , focus = nv.models.focus(nv.models.line()) ; var margin = {top: 30, right: 20, bottom: 50, left: 60} , marginTop = null , color = nv.utils.defaultColor() , width = null , height = null , showLegend = true , legendPosition = 'top' , showXAxis = true , showYAxis = true , rightAlignYAxis = false , useInteractiveGuideline = false , x , y , focusEnable = false , state = nv.utils.state() , defaultState = null , noData = null , dispatch = d3.dispatch('stateChange', 'changeState', 'renderEnd') , duration = 250 ; // set options on sub-objects for this chart xAxis.orient('bottom').tickPadding(7); yAxis.orient(rightAlignYAxis ? 'right' : 'left'); lines.clipEdge(true).duration(0); tooltip.valueFormatter(function(d, i) { return yAxis.tickFormat()(d, i); }).headerFormatter(function(d, i) { return xAxis.tickFormat()(d, i); }); interactiveLayer.tooltip.valueFormatter(function(d, i) { return yAxis.tickFormat()(d, i); }).headerFormatter(function(d, i) { return xAxis.tickFormat()(d, i); }); //============================================================ // Private Variables //------------------------------------------------------------ var renderWatch = nv.utils.renderWatch(dispatch, duration); var stateGetter = function(data) { return function(){ return { active: data.map(function(d) { return !d.disabled; }) }; }; }; var stateSetter = function(data) { return function(state) { if (state.active !== undefined) data.forEach(function(series,i) { series.disabled = !state.active[i]; }); }; }; function chart(selection) { renderWatch.reset(); renderWatch.models(lines); if (showXAxis) renderWatch.models(xAxis); if (showYAxis) renderWatch.models(yAxis); selection.each(function(data) { var container = d3.select(this); nv.utils.initSVG(container); var availableWidth = nv.utils.availableWidth(width, container, margin), availableHeight = nv.utils.availableHeight(height, container, margin) - (focusEnable ? focus.height() : 0); chart.update = function() { if( duration === 0 ) { container.call( chart ); } else { container.transition().duration(duration).call(chart); } }; chart.container = this; state .setter(stateSetter(data), chart.update) .getter(stateGetter(data)) .update(); // DEPRECATED set state.disabled state.disabled = data.map(function(d) { return !!d.disabled; }); if (!defaultState) { var key; defaultState = {}; for (key in state) { if (state[key] instanceof Array) defaultState[key] = state[key].slice(0); else defaultState[key] = state[key]; } } // Display noData message if there's nothing to show. if (!data || !data.length || !data.filter(function(d) { return d.values.length; }).length) { nv.utils.noData(chart, container); return chart; } else { container.selectAll('.nv-noData').remove(); } /* Update `main' graph on brush update. */ focus.dispatch.on("onBrush", function(extent) { onBrush(extent); }); // Setup Scales x = lines.xScale(); y = lines.yScale(); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-lineChart').data([data]); var gEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-lineChart').append('g'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-legendWrap'); var focusEnter = gEnter.append('g').attr('class', 'nv-focus'); focusEnter.append('g').attr('class', 'nv-background').append('rect'); focusEnter.append('g').attr('class', 'nv-x nv-axis'); focusEnter.append('g').attr('class', 'nv-y nv-axis'); focusEnter.append('g').attr('class', 'nv-linesWrap'); focusEnter.append('g').attr('class', 'nv-interactive'); var contextEnter = gEnter.append('g').attr('class', 'nv-focusWrap'); // Legend if (!showLegend) { g.select('.nv-legendWrap').selectAll('*').remove(); } else { legend.width(availableWidth); g.select('.nv-legendWrap') .datum(data) .call(legend); if (legendPosition === 'bottom') { margin.bottom = xAxis.height() + legend.height(); availableHeight = nv.utils.availableHeight(height, container, margin); g.select('.nv-legendWrap') .attr('transform', 'translate(0,' + (availableHeight + xAxis.height()) +')'); } else if (legendPosition === 'top') { if (!marginTop && legend.height() !== margin.top) { margin.top = legend.height(); availableHeight = nv.utils.availableHeight(height, container, margin) - (focusEnable ? focus.height() : 0); } wrap.select('.nv-legendWrap') .attr('transform', 'translate(0,' + (-margin.top) +')'); } } wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); if (rightAlignYAxis) { g.select(".nv-y.nv-axis") .attr("transform", "translate(" + availableWidth + ",0)"); } //Set up interactive layer if (useInteractiveGuideline) { interactiveLayer .width(availableWidth) .height(availableHeight) .margin({left:margin.left, top:margin.top}) .svgContainer(container) .xScale(x); wrap.select(".nv-interactive").call(interactiveLayer); } g.select('.nv-focus .nv-background rect') .attr('width', availableWidth) .attr('height', availableHeight); lines .width(availableWidth) .height(availableHeight) .color(data.map(function(d,i) { return d.color || color(d, i); }).filter(function(d,i) { return !data[i].disabled; })); var linesWrap = g.select('.nv-linesWrap') .datum(data.filter(function(d) { return !d.disabled; })); // Setup Main (Focus) Axes if (showXAxis) { xAxis .scale(x) ._ticks(nv.utils.calcTicksX(availableWidth/100, data) ) .tickSize(-availableHeight, 0); } if (showYAxis) { yAxis .scale(y) ._ticks( nv.utils.calcTicksY(availableHeight/36, data) ) .tickSize( -availableWidth, 0); } //============================================================ // Update Axes //============================================================ function updateXAxis() { if(showXAxis) { g.select('.nv-focus .nv-x.nv-axis') .transition() .duration(duration) .call(xAxis) ; } } function updateYAxis() { if(showYAxis) { g.select('.nv-focus .nv-y.nv-axis') .transition() .duration(duration) .call(yAxis) ; } } g.select('.nv-focus .nv-x.nv-axis') .attr('transform', 'translate(0,' + availableHeight + ')'); //============================================================ // Update Focus //============================================================ if (!focusEnable && focus.brush.extent() === null) { linesWrap.transition().call(lines); updateXAxis(); updateYAxis(); } else { focus.width(availableWidth); g.select('.nv-focusWrap') .style('display', focusEnable ? 'initial' : 'none') .attr('transform', 'translate(0,' + ( availableHeight + margin.bottom + focus.margin().top) + ')') .call(focus); var extent = focus.brush.empty() ? focus.xDomain() : focus.brush.extent(); if (extent !== null) { onBrush(extent); } } //============================================================ // Event Handling/Dispatching (in chart's scope) //------------------------------------------------------------ legend.dispatch.on('stateChange', function(newState) { for (var key in newState) state[key] = newState[key]; dispatch.stateChange(state); chart.update(); }); interactiveLayer.dispatch.on('elementMousemove', function(e) { lines.clearHighlights(); var singlePoint, pointIndex, pointXLocation, allData = []; data .filter(function(series, i) { series.seriesIndex = i; return !series.disabled && !series.disableTooltip; }) .forEach(function(series,i) { var extent = focus.brush.extent() !== null ? (focus.brush.empty() ? focus.xScale().domain() : focus.brush.extent()) : x.domain(); var currentValues = series.values.filter(function(d,i) { // Checks if the x point is between the extents, handling case where extent[0] is greater than extent[1] // (e.g. x domain is manually set to reverse the x-axis) if(extent[0] <= extent[1]) { return lines.x()(d,i) >= extent[0] && lines.x()(d,i) <= extent[1]; } else { return lines.x()(d,i) >= extent[1] && lines.x()(d,i) <= extent[0]; } }); if (currentValues.length > 0) { pointIndex = nv.interactiveBisect(currentValues, e.pointXValue, lines.x()); var point = currentValues[pointIndex]; var pointYValue = chart.y()(point, pointIndex); if (pointYValue !== null) { lines.highlightPoint(i, series.values.indexOf(point), true); } if (point === undefined) return; if (singlePoint === undefined) singlePoint = point; if (pointXLocation === undefined) pointXLocation = chart.xScale()(chart.x()(point,pointIndex)); allData.push({ key: series.key, value: pointYValue, color: color(series,series.seriesIndex), data: point }); } }); //Highlight the tooltip entry based on which point the mouse is closest to. if (allData.length > 2) { var yValue = chart.yScale().invert(e.mouseY); var domainExtent = Math.abs(chart.yScale().domain()[0] - chart.yScale().domain()[1]); var threshold = 0.03 * domainExtent; var indexToHighlight = nv.nearestValueIndex(allData.map(function(d){return d.value;}),yValue,threshold); if (indexToHighlight !== null) allData[indexToHighlight].highlight = true; } var defaultValueFormatter = function(d,i) { return d == null ? "N/A" : yAxis.tickFormat()(d); }; if (typeof pointIndex !== 'undefined') { interactiveLayer.tooltip .valueFormatter(interactiveLayer.tooltip.valueFormatter() || defaultValueFormatter) .data({ value: chart.x()( singlePoint,pointIndex ), index: pointIndex, series: allData })(); interactiveLayer.renderGuideLine(pointXLocation); } }); interactiveLayer.dispatch.on('elementClick', function(e) { var pointXLocation, allData = []; data.filter(function(series, i) { series.seriesIndex = i; return !series.disabled; }).forEach(function(series) { var pointIndex = nv.interactiveBisect(series.values, e.pointXValue, chart.x()); var point = series.values[pointIndex]; if (typeof point === 'undefined') return; if (typeof pointXLocation === 'undefined') pointXLocation = chart.xScale()(chart.x()(point,pointIndex)); var yPos = chart.yScale()(chart.y()(point,pointIndex)); allData.push({ point: point, pointIndex: pointIndex, pos: [pointXLocation, yPos], seriesIndex: series.seriesIndex, series: series }); }); lines.dispatch.elementClick(allData); }); interactiveLayer.dispatch.on("elementMouseout",function(e) { lines.clearHighlights(); }); dispatch.on('changeState', function(e) { if (typeof e.disabled !== 'undefined' && data.length === e.disabled.length) { data.forEach(function(series,i) { series.disabled = e.disabled[i]; }); state.disabled = e.disabled; } chart.update(); }); //============================================================ // Functions //------------------------------------------------------------ // Taken from crossfilter (http://square.github.com/crossfilter/) function resizePath(d) { var e = +(d == 'e'), x = e ? 1 : -1, y = availableHeight / 3; return 'M' + (0.5 * x) + ',' + y + 'A6,6 0 0 ' + e + ' ' + (6.5 * x) + ',' + (y + 6) + 'V' + (2 * y - 6) + 'A6,6 0 0 ' + e + ' ' + (0.5 * x) + ',' + (2 * y) + 'Z' + 'M' + (2.5 * x) + ',' + (y + 8) + 'V' + (2 * y - 8) + 'M' + (4.5 * x) + ',' + (y + 8) + 'V' + (2 * y - 8); } function onBrush(extent) { // Update Main (Focus) var focusLinesWrap = g.select('.nv-focus .nv-linesWrap') .datum( data.filter(function(d) { return !d.disabled; }) .map(function(d,i) { return { key: d.key, area: d.area, classed: d.classed, values: d.values.filter(function(d,i) { return lines.x()(d,i) >= extent[0] && lines.x()(d,i) <= extent[1]; }), disableTooltip: d.disableTooltip }; }) ); focusLinesWrap.transition().duration(duration).call(lines); // Update Main (Focus) Axes updateXAxis(); updateYAxis(); } }); renderWatch.renderEnd('lineChart immediate'); return chart; } //============================================================ // Event Handling/Dispatching (out of chart's scope) //------------------------------------------------------------ lines.dispatch.on('elementMouseover.tooltip', function(evt) { if(!evt.series.disableTooltip){ tooltip.data(evt).hidden(false); } }); lines.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true); }); //============================================================ // Expose Public Variables //------------------------------------------------------------ // expose chart's sub-components chart.dispatch = dispatch; chart.lines = lines; chart.legend = legend; chart.focus = focus; chart.xAxis = xAxis; chart.x2Axis = focus.xAxis chart.yAxis = yAxis; chart.y2Axis = focus.yAxis chart.interactiveLayer = interactiveLayer; chart.tooltip = tooltip; chart.state = state; chart.dispatch = dispatch; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, showLegend: {get: function(){return showLegend;}, set: function(_){showLegend=_;}}, legendPosition: {get: function(){return legendPosition;}, set: function(_){legendPosition=_;}}, showXAxis: {get: function(){return showXAxis;}, set: function(_){showXAxis=_;}}, showYAxis: {get: function(){return showYAxis;}, set: function(_){showYAxis=_;}}, defaultState: {get: function(){return defaultState;}, set: function(_){defaultState=_;}}, noData: {get: function(){return noData;}, set: function(_){noData=_;}}, // Focus options, mostly passed onto focus model. focusEnable: {get: function(){return focusEnable;}, set: function(_){focusEnable=_;}}, focusHeight: {get: function(){return focus.height();}, set: function(_){focus.height(_);}}, focusShowAxisX: {get: function(){return focus.showXAxis();}, set: function(_){focus.showXAxis(_);}}, focusShowAxisY: {get: function(){return focus.showYAxis();}, set: function(_){focus.showYAxis(_);}}, brushExtent: {get: function(){return focus.brushExtent();}, set: function(_){focus.brushExtent(_);}}, // options that require extra logic in the setter focusMargin: {get: function(){return focus.margin}, set: function(_){ if (_.top !== undefined) { margin.top = _.top; marginTop = _.top; } focus.margin.right = _.right !== undefined ? _.right : focus.margin.right; focus.margin.bottom = _.bottom !== undefined ? _.bottom : focus.margin.bottom; focus.margin.left = _.left !== undefined ? _.left : focus.margin.left; }}, margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; renderWatch.reset(duration); lines.duration(duration); focus.duration(duration); xAxis.duration(duration); yAxis.duration(duration); }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); legend.color(color); lines.color(color); focus.color(color); }}, interpolate: {get: function(){return lines.interpolate();}, set: function(_){ lines.interpolate(_); focus.interpolate(_); }}, xTickFormat: {get: function(){return xAxis.tickFormat();}, set: function(_){ xAxis.tickFormat(_); focus.xTickFormat(_); }}, yTickFormat: {get: function(){return yAxis.tickFormat();}, set: function(_){ yAxis.tickFormat(_); focus.yTickFormat(_); }}, x: {get: function(){return lines.x();}, set: function(_){ lines.x(_); focus.x(_); }}, y: {get: function(){return lines.y();}, set: function(_){ lines.y(_); focus.y(_); }}, rightAlignYAxis: {get: function(){return rightAlignYAxis;}, set: function(_){ rightAlignYAxis = _; yAxis.orient( rightAlignYAxis ? 'right' : 'left'); }}, useInteractiveGuideline: {get: function(){return useInteractiveGuideline;}, set: function(_){ useInteractiveGuideline = _; if (useInteractiveGuideline) { lines.interactive(false); lines.useVoronoi(false); } }} }); nv.utils.inheritOptions(chart, lines); nv.utils.initOptions(chart); return chart; }; nv.models.lineWithFocusChart = function() { return nv.models.lineChart() .margin({ bottom: 30 }) .focusEnable( true ); }; nv.models.linePlusBarChart = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var lines = nv.models.line() , lines2 = nv.models.line() , bars = nv.models.historicalBar() , bars2 = nv.models.historicalBar() , xAxis = nv.models.axis() , x2Axis = nv.models.axis() , y1Axis = nv.models.axis() , y2Axis = nv.models.axis() , y3Axis = nv.models.axis() , y4Axis = nv.models.axis() , legend = nv.models.legend() , brush = d3.svg.brush() , tooltip = nv.models.tooltip() ; var margin = {top: 30, right: 30, bottom: 30, left: 60} , marginTop = null , margin2 = {top: 0, right: 30, bottom: 20, left: 60} , width = null , height = null , getX = function(d) { return d.x } , getY = function(d) { return d.y } , color = nv.utils.defaultColor() , showLegend = true , focusEnable = true , focusShowAxisY = false , focusShowAxisX = true , focusHeight = 50 , extent , brushExtent = null , x , x2 , y1 , y2 , y3 , y4 , noData = null , dispatch = d3.dispatch('brush', 'stateChange', 'changeState') , transitionDuration = 0 , state = nv.utils.state() , defaultState = null , legendLeftAxisHint = ' (left axis)' , legendRightAxisHint = ' (right axis)' , switchYAxisOrder = false ; lines.clipEdge(true); lines2.interactive(false); // We don't want any points emitted for the focus chart's scatter graph. lines2.pointActive(function(d) { return false }); xAxis.orient('bottom').tickPadding(5); y1Axis.orient('left'); y2Axis.orient('right'); x2Axis.orient('bottom').tickPadding(5); y3Axis.orient('left'); y4Axis.orient('right'); tooltip.headerEnabled(true).headerFormatter(function(d, i) { return xAxis.tickFormat()(d, i); }); //============================================================ // Private Variables //------------------------------------------------------------ var getBarsAxis = function() { return switchYAxisOrder ? { main: y2Axis, focus: y4Axis } : { main: y1Axis, focus: y3Axis } } var getLinesAxis = function() { return switchYAxisOrder ? { main: y1Axis, focus: y3Axis } : { main: y2Axis, focus: y4Axis } } var stateGetter = function(data) { return function(){ return { active: data.map(function(d) { return !d.disabled }) }; } }; var stateSetter = function(data) { return function(state) { if (state.active !== undefined) data.forEach(function(series,i) { series.disabled = !state.active[i]; }); } }; var allDisabled = function(data) { return data.every(function(series) { return series.disabled; }); } function chart(selection) { selection.each(function(data) { var container = d3.select(this), that = this; nv.utils.initSVG(container); var availableWidth = nv.utils.availableWidth(width, container, margin), availableHeight1 = nv.utils.availableHeight(height, container, margin) - (focusEnable ? focusHeight : 0), availableHeight2 = focusHeight - margin2.top - margin2.bottom; chart.update = function() { container.transition().duration(transitionDuration).call(chart); }; chart.container = this; state .setter(stateSetter(data), chart.update) .getter(stateGetter(data)) .update(); // DEPRECATED set state.disableddisabled state.disabled = data.map(function(d) { return !!d.disabled }); if (!defaultState) { var key; defaultState = {}; for (key in state) { if (state[key] instanceof Array) defaultState[key] = state[key].slice(0); else defaultState[key] = state[key]; } } // Display No Data message if there's nothing to show. if (!data || !data.length || !data.filter(function(d) { return d.values.length }).length) { nv.utils.noData(chart, container) return chart; } else { container.selectAll('.nv-noData').remove(); } // Setup Scales var dataBars = data.filter(function(d) { return !d.disabled && d.bar }); var dataLines = data.filter(function(d) { return !d.bar }); // removed the !d.disabled clause here to fix Issue #240 if (dataBars.length && !switchYAxisOrder) { x = bars.xScale(); } else { x = lines.xScale(); } x2 = x2Axis.scale(); // select the scales and series based on the position of the yAxis y1 = switchYAxisOrder ? lines.yScale() : bars.yScale(); y2 = switchYAxisOrder ? bars.yScale() : lines.yScale(); y3 = switchYAxisOrder ? lines2.yScale() : bars2.yScale(); y4 = switchYAxisOrder ? bars2.yScale() : lines2.yScale(); var series1 = data .filter(function(d) { return !d.disabled && (switchYAxisOrder ? !d.bar : d.bar) }) .map(function(d) { return d.values.map(function(d,i) { return { x: getX(d,i), y: getY(d,i) } }) }); var series2 = data .filter(function(d) { return !d.disabled && (switchYAxisOrder ? d.bar : !d.bar) }) .map(function(d) { return d.values.map(function(d,i) { return { x: getX(d,i), y: getY(d,i) } }) }); x.range([0, availableWidth]); x2 .domain(d3.extent(d3.merge(series1.concat(series2)), function(d) { return d.x } )) .range([0, availableWidth]); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-linePlusBar').data([data]); var gEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-linePlusBar').append('g'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-legendWrap'); // this is the main chart var focusEnter = gEnter.append('g').attr('class', 'nv-focus'); focusEnter.append('g').attr('class', 'nv-x nv-axis'); focusEnter.append('g').attr('class', 'nv-y1 nv-axis'); focusEnter.append('g').attr('class', 'nv-y2 nv-axis'); focusEnter.append('g').attr('class', 'nv-barsWrap'); focusEnter.append('g').attr('class', 'nv-linesWrap'); // context chart is where you can focus in var contextEnter = gEnter.append('g').attr('class', 'nv-context'); contextEnter.append('g').attr('class', 'nv-x nv-axis'); contextEnter.append('g').attr('class', 'nv-y1 nv-axis'); contextEnter.append('g').attr('class', 'nv-y2 nv-axis'); contextEnter.append('g').attr('class', 'nv-barsWrap'); contextEnter.append('g').attr('class', 'nv-linesWrap'); contextEnter.append('g').attr('class', 'nv-brushBackground'); contextEnter.append('g').attr('class', 'nv-x nv-brush'); //============================================================ // Legend //------------------------------------------------------------ if (!showLegend) { g.select('.nv-legendWrap').selectAll('*').remove(); } else { var legendWidth = legend.align() ? availableWidth / 2 : availableWidth; var legendXPosition = legend.align() ? legendWidth : 0; legend.width(legendWidth); g.select('.nv-legendWrap') .datum(data.map(function(series) { series.originalKey = series.originalKey === undefined ? series.key : series.originalKey; if(switchYAxisOrder) { series.key = series.originalKey + (series.bar ? legendRightAxisHint : legendLeftAxisHint); } else { series.key = series.originalKey + (series.bar ? legendLeftAxisHint : legendRightAxisHint); } return series; })) .call(legend); if (!marginTop && legend.height() !== margin.top) { margin.top = legend.height(); // FIXME: shouldn't this be "- (focusEnabled ? focusHeight : 0)"? availableHeight1 = nv.utils.availableHeight(height, container, margin) - focusHeight; } g.select('.nv-legendWrap') .attr('transform', 'translate(' + legendXPosition + ',' + (-margin.top) +')'); } wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); //============================================================ // Context chart (focus chart) components //------------------------------------------------------------ // hide or show the focus context chart g.select('.nv-context').style('display', focusEnable ? 'initial' : 'none'); bars2 .width(availableWidth) .height(availableHeight2) .color(data.map(function (d, i) { return d.color || color(d, i); }).filter(function (d, i) { return !data[i].disabled && data[i].bar })); lines2 .width(availableWidth) .height(availableHeight2) .color(data.map(function (d, i) { return d.color || color(d, i); }).filter(function (d, i) { return !data[i].disabled && !data[i].bar })); var bars2Wrap = g.select('.nv-context .nv-barsWrap') .datum(dataBars.length ? dataBars : [ {values: []} ]); var lines2Wrap = g.select('.nv-context .nv-linesWrap') .datum(allDisabled(dataLines) ? [{values: []}] : dataLines.filter(function(dataLine) { return !dataLine.disabled; })); g.select('.nv-context') .attr('transform', 'translate(0,' + ( availableHeight1 + margin.bottom + margin2.top) + ')'); bars2Wrap.transition().call(bars2); lines2Wrap.transition().call(lines2); // context (focus chart) axis controls if (focusShowAxisX) { x2Axis ._ticks( nv.utils.calcTicksX(availableWidth / 100, data)) .tickSize(-availableHeight2, 0); g.select('.nv-context .nv-x.nv-axis') .attr('transform', 'translate(0,' + y3.range()[0] + ')'); g.select('.nv-context .nv-x.nv-axis').transition() .call(x2Axis); } if (focusShowAxisY) { y3Axis .scale(y3) ._ticks( availableHeight2 / 36 ) .tickSize( -availableWidth, 0); y4Axis .scale(y4) ._ticks( availableHeight2 / 36 ) .tickSize(dataBars.length ? 0 : -availableWidth, 0); // Show the y2 rules only if y1 has none g.select('.nv-context .nv-y3.nv-axis') .style('opacity', dataBars.length ? 1 : 0) .attr('transform', 'translate(0,' + x2.range()[0] + ')'); g.select('.nv-context .nv-y2.nv-axis') .style('opacity', dataLines.length ? 1 : 0) .attr('transform', 'translate(' + x2.range()[1] + ',0)'); g.select('.nv-context .nv-y1.nv-axis').transition() .call(y3Axis); g.select('.nv-context .nv-y2.nv-axis').transition() .call(y4Axis); } // Setup Brush brush.x(x2).on('brush', onBrush); if (brushExtent) brush.extent(brushExtent); var brushBG = g.select('.nv-brushBackground').selectAll('g') .data([brushExtent || brush.extent()]); var brushBGenter = brushBG.enter() .append('g'); brushBGenter.append('rect') .attr('class', 'left') .attr('x', 0) .attr('y', 0) .attr('height', availableHeight2); brushBGenter.append('rect') .attr('class', 'right') .attr('x', 0) .attr('y', 0) .attr('height', availableHeight2); var gBrush = g.select('.nv-x.nv-brush') .call(brush); gBrush.selectAll('rect') //.attr('y', -5) .attr('height', availableHeight2); gBrush.selectAll('.resize').append('path').attr('d', resizePath); //============================================================ // Event Handling/Dispatching (in chart's scope) //------------------------------------------------------------ legend.dispatch.on('stateChange', function(newState) { for (var key in newState) state[key] = newState[key]; dispatch.stateChange(state); chart.update(); }); // Update chart from a state object passed to event handler dispatch.on('changeState', function(e) { if (typeof e.disabled !== 'undefined') { data.forEach(function(series,i) { series.disabled = e.disabled[i]; }); state.disabled = e.disabled; } chart.update(); }); //============================================================ // Functions //------------------------------------------------------------ // Taken from crossfilter (http://square.github.com/crossfilter/) function resizePath(d) { var e = +(d == 'e'), x = e ? 1 : -1, y = availableHeight2 / 3; return 'M' + (.5 * x) + ',' + y + 'A6,6 0 0 ' + e + ' ' + (6.5 * x) + ',' + (y + 6) + 'V' + (2 * y - 6) + 'A6,6 0 0 ' + e + ' ' + (.5 * x) + ',' + (2 * y) + 'Z' + 'M' + (2.5 * x) + ',' + (y + 8) + 'V' + (2 * y - 8) + 'M' + (4.5 * x) + ',' + (y + 8) + 'V' + (2 * y - 8); } function updateBrushBG() { if (!brush.empty()) brush.extent(brushExtent); brushBG .data([brush.empty() ? x2.domain() : brushExtent]) .each(function(d,i) { var leftWidth = x2(d[0]) - x2.range()[0], rightWidth = x2.range()[1] - x2(d[1]); d3.select(this).select('.left') .attr('width', leftWidth < 0 ? 0 : leftWidth); d3.select(this).select('.right') .attr('x', x2(d[1])) .attr('width', rightWidth < 0 ? 0 : rightWidth); }); } function onBrush() { brushExtent = brush.empty() ? null : brush.extent(); extent = brush.empty() ? x2.domain() : brush.extent(); dispatch.brush({extent: extent, brush: brush}); updateBrushBG(); // Prepare Main (Focus) Bars and Lines bars .width(availableWidth) .height(availableHeight1) .color(data.map(function(d,i) { return d.color || color(d, i); }).filter(function(d,i) { return !data[i].disabled && data[i].bar })); lines .width(availableWidth) .height(availableHeight1) .color(data.map(function(d,i) { return d.color || color(d, i); }).filter(function(d,i) { return !data[i].disabled && !data[i].bar })); var focusBarsWrap = g.select('.nv-focus .nv-barsWrap') .datum(!dataBars.length ? [{values:[]}] : dataBars .map(function(d,i) { return { key: d.key, values: d.values.filter(function(d,i) { return bars.x()(d,i) >= extent[0] && bars.x()(d,i) <= extent[1]; }) } }) ); var focusLinesWrap = g.select('.nv-focus .nv-linesWrap') .datum(allDisabled(dataLines) ? [{values:[]}] : dataLines .filter(function(dataLine) { return !dataLine.disabled; }) .map(function(d,i) { return { area: d.area, fillOpacity: d.fillOpacity, strokeWidth: d.strokeWidth, key: d.key, values: d.values.filter(function(d,i) { return lines.x()(d,i) >= extent[0] && lines.x()(d,i) <= extent[1]; }) } }) ); // Update Main (Focus) X Axis if (dataBars.length && !switchYAxisOrder) { x = bars.xScale(); } else { x = lines.xScale(); } xAxis .scale(x) ._ticks( nv.utils.calcTicksX(availableWidth/100, data) ) .tickSize(-availableHeight1, 0); xAxis.domain([Math.ceil(extent[0]), Math.floor(extent[1])]); g.select('.nv-x.nv-axis').transition().duration(transitionDuration) .call(xAxis); // Update Main (Focus) Bars and Lines focusBarsWrap.transition().duration(transitionDuration).call(bars); focusLinesWrap.transition().duration(transitionDuration).call(lines); // Setup and Update Main (Focus) Y Axes g.select('.nv-focus .nv-x.nv-axis') .attr('transform', 'translate(0,' + y1.range()[0] + ')'); y1Axis .scale(y1) ._ticks( nv.utils.calcTicksY(availableHeight1/36, data) ) .tickSize(-availableWidth, 0); y2Axis .scale(y2) ._ticks( nv.utils.calcTicksY(availableHeight1/36, data) ); // Show the y2 rules only if y1 has none if(!switchYAxisOrder) { y2Axis.tickSize(dataBars.length ? 0 : -availableWidth, 0); } else { y2Axis.tickSize(dataLines.length ? 0 : -availableWidth, 0); } // Calculate opacity of the axis var barsOpacity = dataBars.length ? 1 : 0; var linesOpacity = dataLines.length && !allDisabled(dataLines) ? 1 : 0; var y1Opacity = switchYAxisOrder ? linesOpacity : barsOpacity; var y2Opacity = switchYAxisOrder ? barsOpacity : linesOpacity; g.select('.nv-focus .nv-y1.nv-axis') .style('opacity', y1Opacity); g.select('.nv-focus .nv-y2.nv-axis') .style('opacity', y2Opacity) .attr('transform', 'translate(' + x.range()[1] + ',0)'); g.select('.nv-focus .nv-y1.nv-axis').transition().duration(transitionDuration) .call(y1Axis); g.select('.nv-focus .nv-y2.nv-axis').transition().duration(transitionDuration) .call(y2Axis); } onBrush(); }); return chart; } //============================================================ // Event Handling/Dispatching (out of chart's scope) //------------------------------------------------------------ lines.dispatch.on('elementMouseover.tooltip', function(evt) { tooltip .duration(100) .valueFormatter(function(d, i) { return getLinesAxis().main.tickFormat()(d, i); }) .data(evt) .hidden(false); }); lines.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true) }); bars.dispatch.on('elementMouseover.tooltip', function(evt) { evt.value = chart.x()(evt.data); evt['series'] = { value: chart.y()(evt.data), color: evt.color }; tooltip .duration(0) .valueFormatter(function(d, i) { return getBarsAxis().main.tickFormat()(d, i); }) .data(evt) .hidden(false); }); bars.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true); }); bars.dispatch.on('elementMousemove.tooltip', function(evt) { tooltip(); }); //============================================================ //============================================================ // Expose Public Variables //------------------------------------------------------------ // expose chart's sub-components chart.dispatch = dispatch; chart.legend = legend; chart.lines = lines; chart.lines2 = lines2; chart.bars = bars; chart.bars2 = bars2; chart.xAxis = xAxis; chart.x2Axis = x2Axis; chart.y1Axis = y1Axis; chart.y2Axis = y2Axis; chart.y3Axis = y3Axis; chart.y4Axis = y4Axis; chart.tooltip = tooltip; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, showLegend: {get: function(){return showLegend;}, set: function(_){showLegend=_;}}, brushExtent: {get: function(){return brushExtent;}, set: function(_){brushExtent=_;}}, noData: {get: function(){return noData;}, set: function(_){noData=_;}}, focusEnable: {get: function(){return focusEnable;}, set: function(_){focusEnable=_;}}, focusHeight: {get: function(){return focusHeight;}, set: function(_){focusHeight=_;}}, focusShowAxisX: {get: function(){return focusShowAxisX;}, set: function(_){focusShowAxisX=_;}}, focusShowAxisY: {get: function(){return focusShowAxisY;}, set: function(_){focusShowAxisY=_;}}, legendLeftAxisHint: {get: function(){return legendLeftAxisHint;}, set: function(_){legendLeftAxisHint=_;}}, legendRightAxisHint: {get: function(){return legendRightAxisHint;}, set: function(_){legendRightAxisHint=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ if (_.top !== undefined) { margin.top = _.top; marginTop = _.top; } margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, focusMargin: {get: function(){return margin2;}, set: function(_){ margin2.top = _.top !== undefined ? _.top : margin2.top; margin2.right = _.right !== undefined ? _.right : margin2.right; margin2.bottom = _.bottom !== undefined ? _.bottom : margin2.bottom; margin2.left = _.left !== undefined ? _.left : margin2.left; }}, duration: {get: function(){return transitionDuration;}, set: function(_){ transitionDuration = _; }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); legend.color(color); }}, x: {get: function(){return getX;}, set: function(_){ getX = _; lines.x(_); lines2.x(_); bars.x(_); bars2.x(_); }}, y: {get: function(){return getY;}, set: function(_){ getY = _; lines.y(_); lines2.y(_); bars.y(_); bars2.y(_); }}, switchYAxisOrder: {get: function(){return switchYAxisOrder;}, set: function(_){ // Switch the tick format for the yAxis if(switchYAxisOrder !== _) { var y1 = y1Axis; y1Axis = y2Axis; y2Axis = y1; var y3 = y3Axis; y3Axis = y4Axis; y4Axis = y3; } switchYAxisOrder=_; y1Axis.orient('left'); y2Axis.orient('right'); y3Axis.orient('left'); y4Axis.orient('right'); }} }); nv.utils.inheritOptions(chart, lines); nv.utils.initOptions(chart); return chart; }; nv.models.multiBar = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 0, right: 0, bottom: 0, left: 0} , width = 960 , height = 500 , x = d3.scale.ordinal() , y = d3.scale.linear() , id = Math.floor(Math.random() * 10000) //Create semi-unique ID in case user doesn't select one , container = null , getX = function(d) { return d.x } , getY = function(d) { return d.y } , forceY = [0] // 0 is forced by default.. this makes sense for the majority of bar graphs... user can always do chart.forceY([]) to remove , clipEdge = true , stacked = false , stackOffset = 'zero' // options include 'silhouette', 'wiggle', 'expand', 'zero', or a custom function , color = nv.utils.defaultColor() , hideable = false , barColor = null // adding the ability to set the color for each rather than the whole group , disabled // used in conjunction with barColor to communicate from multiBarHorizontalChart what series are disabled , duration = 500 , xDomain , yDomain , xRange , yRange , groupSpacing = 0.1 , fillOpacity = 0.75 , dispatch = d3.dispatch('chartClick', 'elementClick', 'elementDblClick', 'elementMouseover', 'elementMouseout', 'elementMousemove', 'renderEnd') ; //============================================================ // Private Variables //------------------------------------------------------------ var x0, y0 //used to store previous scales , renderWatch = nv.utils.renderWatch(dispatch, duration) ; var last_datalength = 0; function chart(selection) { renderWatch.reset(); selection.each(function(data) { var availableWidth = width - margin.left - margin.right, availableHeight = height - margin.top - margin.bottom; container = d3.select(this); nv.utils.initSVG(container); var nonStackableCount = 0; // This function defines the requirements for render complete var endFn = function(d, i) { if (d.series === data.length - 1 && i === data[0].values.length - 1) return true; return false; }; if(hideable && data.length) hideable = [{ values: data[0].values.map(function(d) { return { x: d.x, y: 0, series: d.series, size: 0.01 };} )}]; if (stacked) { var parsed = d3.layout.stack() .offset(stackOffset) .values(function(d){ return d.values }) .y(getY) (!data.length && hideable ? hideable : data); parsed.forEach(function(series, i){ // if series is non-stackable, use un-parsed data if (series.nonStackable) { data[i].nonStackableSeries = nonStackableCount++; parsed[i] = data[i]; } else { // don't stack this seires on top of the nonStackable seriees if (i > 0 && parsed[i - 1].nonStackable){ parsed[i].values.map(function(d,j){ d.y0 -= parsed[i - 1].values[j].y; d.y1 = d.y0 + d.y; }); } } }); data = parsed; } //add series index and key to each data point for reference data.forEach(function(series, i) { series.values.forEach(function(point) { point.series = i; point.key = series.key; }); }); // HACK for negative value stacking if (stacked && data.length > 0) { data[0].values.map(function(d,i) { var posBase = 0, negBase = 0; data.map(function(d, idx) { if (!data[idx].nonStackable) { var f = d.values[i] f.size = Math.abs(f.y); if (f.y<0) { f.y1 = negBase; negBase = negBase - f.size; } else { f.y1 = f.size + posBase; posBase = posBase + f.size; } } }); }); } // Setup Scales // remap and flatten the data for use in calculating the scales' domains var seriesData = (xDomain && yDomain) ? [] : // if we know xDomain and yDomain, no need to calculate data.map(function(d, idx) { return d.values.map(function(d,i) { return { x: getX(d,i), y: getY(d,i), y0: d.y0, y1: d.y1, idx:idx } }) }); x.domain(xDomain || d3.merge(seriesData).map(function(d) { return d.x })) .rangeBands(xRange || [0, availableWidth], groupSpacing); y.domain(yDomain || d3.extent(d3.merge(seriesData).map(function(d) { var domain = d.y; // increase the domain range if this series is stackable if (stacked && !data[d.idx].nonStackable) { if (d.y > 0){ domain = d.y1 } else { domain = d.y1 + d.y } } return domain; }).concat(forceY))) .range(yRange || [availableHeight, 0]); // If scale's domain don't have a range, slightly adjust to make one... so a chart can show a single data point if (x.domain()[0] === x.domain()[1]) x.domain()[0] ? x.domain([x.domain()[0] - x.domain()[0] * 0.01, x.domain()[1] + x.domain()[1] * 0.01]) : x.domain([-1,1]); if (y.domain()[0] === y.domain()[1]) y.domain()[0] ? y.domain([y.domain()[0] + y.domain()[0] * 0.01, y.domain()[1] - y.domain()[1] * 0.01]) : y.domain([-1,1]); x0 = x0 || x; y0 = y0 || y; // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-multibar').data([data]); var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-multibar'); var defsEnter = wrapEnter.append('defs'); var gEnter = wrapEnter.append('g'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-groups'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); defsEnter.append('clipPath') .attr('id', 'nv-edge-clip-' + id) .append('rect'); wrap.select('#nv-edge-clip-' + id + ' rect') .attr('width', availableWidth) .attr('height', availableHeight); g.attr('clip-path', clipEdge ? 'url(#nv-edge-clip-' + id + ')' : ''); var groups = wrap.select('.nv-groups').selectAll('.nv-group') .data(function(d) { return d }, function(d,i) { return i }); groups.enter().append('g') .style('stroke-opacity', 1e-6) .style('fill-opacity', 1e-6); var exitTransition = renderWatch .transition(groups.exit().selectAll('rect.nv-bar'), 'multibarExit', Math.min(100, duration)) .attr('y', function(d, i, j) { var yVal = y0(0) || 0; if (stacked) { if (data[d.series] && !data[d.series].nonStackable) { yVal = y0(d.y0); } } return yVal; }) .attr('height', 0) .remove(); if (exitTransition.delay) exitTransition.delay(function(d,i) { var delay = i * (duration / (last_datalength + 1)) - i; return delay; }); groups .attr('class', function(d,i) { return 'nv-group nv-series-' + i }) .classed('hover', function(d) { return d.hover }) .style('fill', function(d,i){ return color(d, i) }) .style('stroke', function(d,i){ return color(d, i) }); groups .style('stroke-opacity', 1) .style('fill-opacity', fillOpacity); var bars = groups.selectAll('rect.nv-bar') .data(function(d) { return (hideable && !data.length) ? hideable.values : d.values }); bars.exit().remove(); var barsEnter = bars.enter().append('rect') .attr('class', function(d,i) { return getY(d,i) < 0 ? 'nv-bar negative' : 'nv-bar positive'}) .attr('x', function(d,i,j) { return stacked && !data[j].nonStackable ? 0 : (j * x.rangeBand() / data.length ) }) .attr('y', function(d,i,j) { return y0(stacked && !data[j].nonStackable ? d.y0 : 0) || 0 }) .attr('height', 0) .attr('width', function(d,i,j) { return x.rangeBand() / (stacked && !data[j].nonStackable ? 1 : data.length) }) .attr('transform', function(d,i) { return 'translate(' + x(getX(d,i)) + ',0)'; }) ; bars .style('fill', function(d,i,j){ return color(d, j, i); }) .style('stroke', function(d,i,j){ return color(d, j, i); }) .on('mouseover', function(d,i,j) { d3.select(this).classed('hover', true); dispatch.elementMouseover({ data: d, index: i, series: data[j], color: d3.select(this).style("fill") }); }) .on('mouseout', function(d,i,j) { d3.select(this).classed('hover', false); dispatch.elementMouseout({ data: d, index: i, series: data[j], color: d3.select(this).style("fill") }); }) .on('mousemove', function(d,i,j) { dispatch.elementMousemove({ data: d, index: i, series: data[j], color: d3.select(this).style("fill") }); }) .on('click', function(d,i,j) { var element = this; dispatch.elementClick({ data: d, index: i, series: data[j], color: d3.select(this).style("fill"), event: d3.event, element: element }); d3.event.stopPropagation(); }) .on('dblclick', function(d,i,j) { dispatch.elementDblClick({ data: d, index: i, series: data[j], color: d3.select(this).style("fill") }); d3.event.stopPropagation(); }); bars .attr('class', function(d,i) { return getY(d,i) < 0 ? 'nv-bar negative' : 'nv-bar positive'}) .attr('transform', function(d,i) { return 'translate(' + x(getX(d,i)) + ',0)'; }) if (barColor) { if (!disabled) disabled = data.map(function() { return true }); bars .style('fill', function(d,i,j) { return d3.rgb(barColor(d,i)).darker( disabled.map(function(d,i) { return i }).filter(function(d,i){ return !disabled[i] })[j] ).toString(); }) .style('stroke', function(d,i,j) { return d3.rgb(barColor(d,i)).darker( disabled.map(function(d,i) { return i }).filter(function(d,i){ return !disabled[i] })[j] ).toString(); }); } var barSelection = bars.watchTransition(renderWatch, 'multibar', Math.min(250, duration)) .delay(function(d,i) { return i * duration / data[0].values.length; }); if (stacked){ barSelection .attr('y', function(d,i,j) { var yVal = 0; // if stackable, stack it on top of the previous series if (!data[j].nonStackable) { yVal = y(d.y1); } else { if (getY(d,i) < 0){ yVal = y(0); } else { if (y(0) - y(getY(d,i)) < -1){ yVal = y(0) - 1; } else { yVal = y(getY(d, i)) || 0; } } } return yVal; }) .attr('height', function(d,i,j) { if (!data[j].nonStackable) { return Math.max(Math.abs(y(d.y+d.y0) - y(d.y0)), 0); } else { return Math.max(Math.abs(y(getY(d,i)) - y(0)), 0) || 0; } }) .attr('x', function(d,i,j) { var width = 0; if (data[j].nonStackable) { width = d.series * x.rangeBand() / data.length; if (data.length !== nonStackableCount){ width = data[j].nonStackableSeries * x.rangeBand()/(nonStackableCount*2); } } return width; }) .attr('width', function(d,i,j){ if (!data[j].nonStackable) { return x.rangeBand(); } else { // if all series are nonStacable, take the full width var width = (x.rangeBand() / nonStackableCount); // otherwise, nonStackable graph will be only taking the half-width // of the x rangeBand if (data.length !== nonStackableCount) { width = x.rangeBand()/(nonStackableCount*2); } return width; } }); } else { barSelection .attr('x', function(d,i) { return d.series * x.rangeBand() / data.length; }) .attr('width', x.rangeBand() / data.length) .attr('y', function(d,i) { return getY(d,i) < 0 ? y(0) : y(0) - y(getY(d,i)) < 1 ? y(0) - 1 : y(getY(d,i)) || 0; }) .attr('height', function(d,i) { return Math.max(Math.abs(y(getY(d,i)) - y(0)),1) || 0; }); } //store old scales for use in transitions on update x0 = x.copy(); y0 = y.copy(); // keep track of the last data value length for transition calculations if (data[0] && data[0].values) { last_datalength = data[0].values.length; } }); renderWatch.renderEnd('multibar immediate'); return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.dispatch = dispatch; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, x: {get: function(){return getX;}, set: function(_){getX=_;}}, y: {get: function(){return getY;}, set: function(_){getY=_;}}, xScale: {get: function(){return x;}, set: function(_){x=_;}}, yScale: {get: function(){return y;}, set: function(_){y=_;}}, xDomain: {get: function(){return xDomain;}, set: function(_){xDomain=_;}}, yDomain: {get: function(){return yDomain;}, set: function(_){yDomain=_;}}, xRange: {get: function(){return xRange;}, set: function(_){xRange=_;}}, yRange: {get: function(){return yRange;}, set: function(_){yRange=_;}}, forceY: {get: function(){return forceY;}, set: function(_){forceY=_;}}, stacked: {get: function(){return stacked;}, set: function(_){stacked=_;}}, stackOffset: {get: function(){return stackOffset;}, set: function(_){stackOffset=_;}}, clipEdge: {get: function(){return clipEdge;}, set: function(_){clipEdge=_;}}, disabled: {get: function(){return disabled;}, set: function(_){disabled=_;}}, id: {get: function(){return id;}, set: function(_){id=_;}}, hideable: {get: function(){return hideable;}, set: function(_){hideable=_;}}, groupSpacing:{get: function(){return groupSpacing;}, set: function(_){groupSpacing=_;}}, fillOpacity: {get: function(){return fillOpacity;}, set: function(_){fillOpacity=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; renderWatch.reset(duration); }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); }}, barColor: {get: function(){return barColor;}, set: function(_){ barColor = _ ? nv.utils.getColor(_) : null; }} }); nv.utils.initOptions(chart); return chart; }; nv.models.multiBarChart = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var multibar = nv.models.multiBar() , xAxis = nv.models.axis() , yAxis = nv.models.axis() , interactiveLayer = nv.interactiveGuideline() , legend = nv.models.legend() , controls = nv.models.legend() , tooltip = nv.models.tooltip() ; var margin = {top: 30, right: 20, bottom: 50, left: 60} , marginTop = null , width = null , height = null , color = nv.utils.defaultColor() , showControls = true , controlLabels = {} , showLegend = true , legendPosition = null , showXAxis = true , showYAxis = true , rightAlignYAxis = false , reduceXTicks = true // if false a tick will show for every data point , staggerLabels = false , wrapLabels = false , rotateLabels = 0 , x //can be accessed via chart.xScale() , y //can be accessed via chart.yScale() , state = nv.utils.state() , defaultState = null , noData = null , dispatch = d3.dispatch('stateChange', 'changeState', 'renderEnd') , controlWidth = function() { return showControls ? 180 : 0 } , duration = 250 , useInteractiveGuideline = false ; state.stacked = false // DEPRECATED Maintained for backward compatibility multibar.stacked(false); xAxis .orient('bottom') .tickPadding(7) .showMaxMin(false) .tickFormat(function(d) { return d }) ; yAxis .orient((rightAlignYAxis) ? 'right' : 'left') .tickFormat(d3.format(',.1f')) ; tooltip .duration(0) .valueFormatter(function(d, i) { return yAxis.tickFormat()(d, i); }) .headerFormatter(function(d, i) { return xAxis.tickFormat()(d, i); }); interactiveLayer.tooltip .valueFormatter(function(d, i) { return d == null ? "N/A" : yAxis.tickFormat()(d, i); }) .headerFormatter(function(d, i) { return xAxis.tickFormat()(d, i); }); interactiveLayer.tooltip .valueFormatter(function (d, i) { return d == null ? "N/A" : yAxis.tickFormat()(d, i); }) .headerFormatter(function (d, i) { return xAxis.tickFormat()(d, i); }); interactiveLayer.tooltip .duration(0) .valueFormatter(function(d, i) { return yAxis.tickFormat()(d, i); }) .headerFormatter(function(d, i) { return xAxis.tickFormat()(d, i); }); controls.updateState(false); //============================================================ // Private Variables //------------------------------------------------------------ var renderWatch = nv.utils.renderWatch(dispatch); var stacked = false; var stateGetter = function(data) { return function(){ return { active: data.map(function(d) { return !d.disabled }), stacked: stacked }; } }; var stateSetter = function(data) { return function(state) { if (state.stacked !== undefined) stacked = state.stacked; if (state.active !== undefined) data.forEach(function(series,i) { series.disabled = !state.active[i]; }); } }; function chart(selection) { renderWatch.reset(); renderWatch.models(multibar); if (showXAxis) renderWatch.models(xAxis); if (showYAxis) renderWatch.models(yAxis); selection.each(function(data) { var container = d3.select(this), that = this; nv.utils.initSVG(container); var availableWidth = nv.utils.availableWidth(width, container, margin), availableHeight = nv.utils.availableHeight(height, container, margin); chart.update = function() { if (duration === 0) container.call(chart); else container.transition() .duration(duration) .call(chart); }; chart.container = this; state .setter(stateSetter(data), chart.update) .getter(stateGetter(data)) .update(); // DEPRECATED set state.disableddisabled state.disabled = data.map(function(d) { return !!d.disabled }); if (!defaultState) { var key; defaultState = {}; for (key in state) { if (state[key] instanceof Array) defaultState[key] = state[key].slice(0); else defaultState[key] = state[key]; } } // Display noData message if there's nothing to show. if (!data || !data.length || !data.filter(function(d) { return d.values.length }).length) { nv.utils.noData(chart, container) return chart; } else { container.selectAll('.nv-noData').remove(); } // Setup Scales x = multibar.xScale(); y = multibar.yScale(); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-multiBarWithLegend').data([data]); var gEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-multiBarWithLegend').append('g'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-x nv-axis'); gEnter.append('g').attr('class', 'nv-y nv-axis'); gEnter.append('g').attr('class', 'nv-barsWrap'); gEnter.append('g').attr('class', 'nv-legendWrap'); gEnter.append('g').attr('class', 'nv-controlsWrap'); gEnter.append('g').attr('class', 'nv-interactive'); // Legend if (!showLegend) { g.select('.nv-legendWrap').selectAll('*').remove(); } else { if (legendPosition === 'bottom') { legend.width(availableWidth - margin.right); g.select('.nv-legendWrap') .datum(data) .call(legend); margin.bottom = xAxis.height() + legend.height(); availableHeight = nv.utils.availableHeight(height, container, margin); g.select('.nv-legendWrap') .attr('transform', 'translate(0,' + (availableHeight + xAxis.height()) +')'); } else { legend.width(availableWidth - controlWidth()); g.select('.nv-legendWrap') .datum(data) .call(legend); if (!marginTop && legend.height() !== margin.top) { margin.top = legend.height(); availableHeight = nv.utils.availableHeight(height, container, margin); } g.select('.nv-legendWrap') .attr('transform', 'translate(' + controlWidth() + ',' + (-margin.top) +')'); } } // Controls if (!showControls) { g.select('.nv-controlsWrap').selectAll('*').remove(); } else { var controlsData = [ { key: controlLabels.grouped || 'Grouped', disabled: multibar.stacked() }, { key: controlLabels.stacked || 'Stacked', disabled: !multibar.stacked() } ]; controls.width(controlWidth()).color(['#444', '#444', '#444']); g.select('.nv-controlsWrap') .datum(controlsData) .attr('transform', 'translate(0,' + (-margin.top) +')') .call(controls); } wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); if (rightAlignYAxis) { g.select(".nv-y.nv-axis") .attr("transform", "translate(" + availableWidth + ",0)"); } // Main Chart Component(s) multibar .disabled(data.map(function(series) { return series.disabled })) .width(availableWidth) .height(availableHeight) .color(data.map(function(d,i) { return d.color || color(d, i); }).filter(function(d,i) { return !data[i].disabled })); var barsWrap = g.select('.nv-barsWrap') .datum(data.filter(function(d) { return !d.disabled })); barsWrap.call(multibar); // Setup Axes if (showXAxis) { xAxis .scale(x) ._ticks( nv.utils.calcTicksX(availableWidth/100, data) ) .tickSize(-availableHeight, 0); g.select('.nv-x.nv-axis') .attr('transform', 'translate(0,' + y.range()[0] + ')'); g.select('.nv-x.nv-axis') .call(xAxis); var xTicks = g.select('.nv-x.nv-axis > g').selectAll('g'); xTicks .selectAll('line, text') .style('opacity', 1) if (staggerLabels) { var getTranslate = function(x,y) { return "translate(" + x + "," + y + ")"; }; var staggerUp = 5, staggerDown = 17; //pixels to stagger by // Issue #140 xTicks .selectAll("text") .attr('transform', function(d,i,j) { return getTranslate(0, (j % 2 == 0 ? staggerUp : staggerDown)); }); var totalInBetweenTicks = d3.selectAll(".nv-x.nv-axis .nv-wrap g g text")[0].length; g.selectAll(".nv-x.nv-axis .nv-axisMaxMin text") .attr("transform", function(d,i) { return getTranslate(0, (i === 0 || totalInBetweenTicks % 2 !== 0) ? staggerDown : staggerUp); }); } if (wrapLabels) { g.selectAll('.tick text') .call(nv.utils.wrapTicks, chart.xAxis.rangeBand()) } if (reduceXTicks) xTicks .filter(function(d,i) { return i % Math.ceil(data[0].values.length / (availableWidth / 100)) !== 0; }) .selectAll('text, line') .style('opacity', 0); if(rotateLabels) xTicks .selectAll('.tick text') .attr('transform', 'rotate(' + rotateLabels + ' 0,0)') .style('text-anchor', rotateLabels > 0 ? 'start' : 'end'); g.select('.nv-x.nv-axis').selectAll('g.nv-axisMaxMin text') .style('opacity', 1); } if (showYAxis) { yAxis .scale(y) ._ticks( nv.utils.calcTicksY(availableHeight/36, data) ) .tickSize( -availableWidth, 0); g.select('.nv-y.nv-axis') .call(yAxis); } //Set up interactive layer if (useInteractiveGuideline) { interactiveLayer .width(availableWidth) .height(availableHeight) .margin({left:margin.left, top:margin.top}) .svgContainer(container) .xScale(x); wrap.select(".nv-interactive").call(interactiveLayer); } //============================================================ // Event Handling/Dispatching (in chart's scope) //------------------------------------------------------------ legend.dispatch.on('stateChange', function(newState) { for (var key in newState) state[key] = newState[key]; dispatch.stateChange(state); chart.update(); }); controls.dispatch.on('legendClick', function(d,i) { if (!d.disabled) return; controlsData = controlsData.map(function(s) { s.disabled = true; return s; }); d.disabled = false; switch (d.key) { case 'Grouped': case controlLabels.grouped: multibar.stacked(false); break; case 'Stacked': case controlLabels.stacked: multibar.stacked(true); break; } state.stacked = multibar.stacked(); dispatch.stateChange(state); chart.update(); }); // Update chart from a state object passed to event handler dispatch.on('changeState', function(e) { if (typeof e.disabled !== 'undefined') { data.forEach(function(series,i) { series.disabled = e.disabled[i]; }); state.disabled = e.disabled; } if (typeof e.stacked !== 'undefined') { multibar.stacked(e.stacked); state.stacked = e.stacked; stacked = e.stacked; } chart.update(); }); if (useInteractiveGuideline) { interactiveLayer.dispatch.on('elementMousemove', function(e) { if (e.pointXValue == undefined) return; var singlePoint, pointIndex, pointXLocation, xValue, allData = []; data .filter(function(series, i) { series.seriesIndex = i; return !series.disabled; }) .forEach(function(series,i) { pointIndex = x.domain().indexOf(e.pointXValue) var point = series.values[pointIndex]; if (point === undefined) return; xValue = point.x; if (singlePoint === undefined) singlePoint = point; if (pointXLocation === undefined) pointXLocation = e.mouseX allData.push({ key: series.key, value: chart.y()(point, pointIndex), color: color(series,series.seriesIndex), data: series.values[pointIndex] }); }); interactiveLayer.tooltip .data({ value: xValue, index: pointIndex, series: allData })(); interactiveLayer.renderGuideLine(pointXLocation); }); interactiveLayer.dispatch.on("elementMouseout",function(e) { interactiveLayer.tooltip.hidden(true); }); } else { multibar.dispatch.on('elementMouseover.tooltip', function(evt) { evt.value = chart.x()(evt.data); evt['series'] = { key: evt.data.key, value: chart.y()(evt.data), color: evt.color }; tooltip.data(evt).hidden(false); }); multibar.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true); }); multibar.dispatch.on('elementMousemove.tooltip', function(evt) { tooltip(); }); } }); renderWatch.renderEnd('multibarchart immediate'); return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ // expose chart's sub-components chart.dispatch = dispatch; chart.multibar = multibar; chart.legend = legend; chart.controls = controls; chart.xAxis = xAxis; chart.yAxis = yAxis; chart.state = state; chart.tooltip = tooltip; chart.interactiveLayer = interactiveLayer; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, showLegend: {get: function(){return showLegend;}, set: function(_){showLegend=_;}}, legendPosition: {get: function(){return legendPosition;}, set: function(_){legendPosition=_;}}, showControls: {get: function(){return showControls;}, set: function(_){showControls=_;}}, controlLabels: {get: function(){return controlLabels;}, set: function(_){controlLabels=_;}}, showXAxis: {get: function(){return showXAxis;}, set: function(_){showXAxis=_;}}, showYAxis: {get: function(){return showYAxis;}, set: function(_){showYAxis=_;}}, defaultState: {get: function(){return defaultState;}, set: function(_){defaultState=_;}}, noData: {get: function(){return noData;}, set: function(_){noData=_;}}, reduceXTicks: {get: function(){return reduceXTicks;}, set: function(_){reduceXTicks=_;}}, rotateLabels: {get: function(){return rotateLabels;}, set: function(_){rotateLabels=_;}}, staggerLabels: {get: function(){return staggerLabels;}, set: function(_){staggerLabels=_;}}, wrapLabels: {get: function(){return wrapLabels;}, set: function(_){wrapLabels=!!_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ if (_.top !== undefined) { margin.top = _.top; marginTop = _.top; } margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; multibar.duration(duration); xAxis.duration(duration); yAxis.duration(duration); renderWatch.reset(duration); }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); legend.color(color); }}, rightAlignYAxis: {get: function(){return rightAlignYAxis;}, set: function(_){ rightAlignYAxis = _; yAxis.orient( rightAlignYAxis ? 'right' : 'left'); }}, useInteractiveGuideline: {get: function(){return useInteractiveGuideline;}, set: function(_){ useInteractiveGuideline = _; }}, barColor: {get: function(){return multibar.barColor;}, set: function(_){ multibar.barColor(_); legend.color(function(d,i) {return d3.rgb('#ccc').darker(i * 1.5).toString();}) }} }); nv.utils.inheritOptions(chart, multibar); nv.utils.initOptions(chart); return chart; }; nv.models.multiBarHorizontal = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 0, right: 0, bottom: 0, left: 0} , width = 960 , height = 500 , id = Math.floor(Math.random() * 10000) //Create semi-unique ID in case user doesn't select one , container = null , x = d3.scale.ordinal() , y = d3.scale.linear() , getX = function(d) { return d.x } , getY = function(d) { return d.y } , getYerr = function(d) { return d.yErr } , forceY = [0] // 0 is forced by default.. this makes sense for the majority of bar graphs... user can always do chart.forceY([]) to remove , color = nv.utils.defaultColor() , barColor = null // adding the ability to set the color for each rather than the whole group , disabled // used in conjunction with barColor to communicate from multiBarHorizontalChart what series are disabled , stacked = false , showValues = false , showBarLabels = false , valuePadding = 60 , groupSpacing = 0.1 , fillOpacity = 0.75 , valueFormat = d3.format(',.2f') , delay = 1200 , xDomain , yDomain , xRange , yRange , duration = 250 , dispatch = d3.dispatch('chartClick', 'elementClick', 'elementDblClick', 'elementMouseover', 'elementMouseout', 'elementMousemove', 'renderEnd') ; //============================================================ // Private Variables //------------------------------------------------------------ var x0, y0; //used to store previous scales var renderWatch = nv.utils.renderWatch(dispatch, duration); function chart(selection) { renderWatch.reset(); selection.each(function(data) { var availableWidth = width - margin.left - margin.right, availableHeight = height - margin.top - margin.bottom; container = d3.select(this); nv.utils.initSVG(container); if (stacked) data = d3.layout.stack() .offset('zero') .values(function(d){ return d.values }) .y(getY) (data); //add series index and key to each data point for reference data.forEach(function(series, i) { series.values.forEach(function(point) { point.series = i; point.key = series.key; }); }); // HACK for negative value stacking if (stacked) data[0].values.map(function(d,i) { var posBase = 0, negBase = 0; data.map(function(d) { var f = d.values[i] f.size = Math.abs(f.y); if (f.y<0) { f.y1 = negBase - f.size; negBase = negBase - f.size; } else { f.y1 = posBase; posBase = posBase + f.size; } }); }); // Setup Scales // remap and flatten the data for use in calculating the scales' domains var seriesData = (xDomain && yDomain) ? [] : // if we know xDomain and yDomain, no need to calculate data.map(function(d) { return d.values.map(function(d,i) { return { x: getX(d,i), y: getY(d,i), y0: d.y0, y1: d.y1 } }) }); x.domain(xDomain || d3.merge(seriesData).map(function(d) { return d.x })) .rangeBands(xRange || [0, availableHeight], groupSpacing); y.domain(yDomain || d3.extent(d3.merge(seriesData).map(function(d) { return stacked ? (d.y > 0 ? d.y1 + d.y : d.y1 ) : d.y }).concat(forceY))) if (showValues && !stacked) y.range(yRange || [(y.domain()[0] < 0 ? valuePadding : 0), availableWidth - (y.domain()[1] > 0 ? valuePadding : 0) ]); else y.range(yRange || [0, availableWidth]); x0 = x0 || x; y0 = y0 || d3.scale.linear().domain(y.domain()).range([y(0),y(0)]); // Setup containers and skeleton of chart var wrap = d3.select(this).selectAll('g.nv-wrap.nv-multibarHorizontal').data([data]); var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-multibarHorizontal'); var defsEnter = wrapEnter.append('defs'); var gEnter = wrapEnter.append('g'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-groups'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); var groups = wrap.select('.nv-groups').selectAll('.nv-group') .data(function(d) { return d }, function(d,i) { return i }); groups.enter().append('g') .style('stroke-opacity', 1e-6) .style('fill-opacity', 1e-6); groups.exit().watchTransition(renderWatch, 'multibarhorizontal: exit groups') .style('stroke-opacity', 1e-6) .style('fill-opacity', 1e-6) .remove(); groups .attr('class', function(d,i) { return 'nv-group nv-series-' + i }) .classed('hover', function(d) { return d.hover }) .style('fill', function(d,i){ return color(d, i) }) .style('stroke', function(d,i){ return color(d, i) }); groups.watchTransition(renderWatch, 'multibarhorizontal: groups') .style('stroke-opacity', 1) .style('fill-opacity', fillOpacity); var bars = groups.selectAll('g.nv-bar') .data(function(d) { return d.values }); bars.exit().remove(); var barsEnter = bars.enter().append('g') .attr('transform', function(d,i,j) { return 'translate(' + y0(stacked ? d.y0 : 0) + ',' + (stacked ? 0 : (j * x.rangeBand() / data.length ) + x(getX(d,i))) + ')' }); barsEnter.append('rect') .attr('width', 0) .attr('height', x.rangeBand() / (stacked ? 1 : data.length) ) bars .on('mouseover', function(d,i) { //TODO: figure out why j works above, but not here d3.select(this).classed('hover', true); dispatch.elementMouseover({ data: d, index: i, color: d3.select(this).style("fill") }); }) .on('mouseout', function(d,i) { d3.select(this).classed('hover', false); dispatch.elementMouseout({ data: d, index: i, color: d3.select(this).style("fill") }); }) .on('mouseout', function(d,i) { dispatch.elementMouseout({ data: d, index: i, color: d3.select(this).style("fill") }); }) .on('mousemove', function(d,i) { dispatch.elementMousemove({ data: d, index: i, color: d3.select(this).style("fill") }); }) .on('click', function(d,i) { var element = this; dispatch.elementClick({ data: d, index: i, color: d3.select(this).style("fill"), event: d3.event, element: element }); d3.event.stopPropagation(); }) .on('dblclick', function(d,i) { dispatch.elementDblClick({ data: d, index: i, color: d3.select(this).style("fill") }); d3.event.stopPropagation(); }); if (getYerr(data[0],0)) { barsEnter.append('polyline'); bars.select('polyline') .attr('fill', 'none') .attr('points', function(d,i) { var xerr = getYerr(d,i) , mid = 0.8 * x.rangeBand() / ((stacked ? 1 : data.length) * 2); xerr = xerr.length ? xerr : [-Math.abs(xerr), Math.abs(xerr)]; xerr = xerr.map(function(e) { return y(e + ((getY(d,i) < 0) ? 0 : getY(d,i))) - y(0); }); var a = [[xerr[0],-mid], [xerr[0],mid], [xerr[0],0], [xerr[1],0], [xerr[1],-mid], [xerr[1],mid]]; return a.map(function (path) { return path.join(',') }).join(' '); }) .attr('transform', function(d,i) { var mid = x.rangeBand() / ((stacked ? 1 : data.length) * 2); return 'translate(0, ' + mid + ')'; }); } barsEnter.append('text'); if (showValues && !stacked) { bars.select('text') .attr('text-anchor', function(d,i) { return getY(d,i) < 0 ? 'end' : 'start' }) .attr('y', x.rangeBand() / (data.length * 2)) .attr('dy', '.32em') .text(function(d,i) { var t = valueFormat(getY(d,i)) , yerr = getYerr(d,i); if (yerr === undefined) return t; if (!yerr.length) return t + '±' + valueFormat(Math.abs(yerr)); return t + '+' + valueFormat(Math.abs(yerr[1])) + '-' + valueFormat(Math.abs(yerr[0])); }); bars.watchTransition(renderWatch, 'multibarhorizontal: bars') .select('text') .attr('x', function(d,i) { return getY(d,i) < 0 ? -4 : y(getY(d,i)) - y(0) + 4 }) } else { bars.selectAll('text').text(''); } if (showBarLabels && !stacked) { barsEnter.append('text').classed('nv-bar-label',true); bars.select('text.nv-bar-label') .attr('text-anchor', function(d,i) { return getY(d,i) < 0 ? 'start' : 'end' }) .attr('y', x.rangeBand() / (data.length * 2)) .attr('dy', '.32em') .text(function(d,i) { return getX(d,i) }); bars.watchTransition(renderWatch, 'multibarhorizontal: bars') .select('text.nv-bar-label') .attr('x', function(d,i) { return getY(d,i) < 0 ? y(0) - y(getY(d,i)) + 4 : -4 }); } else { bars.selectAll('text.nv-bar-label').text(''); } bars .attr('class', function(d,i) { return getY(d,i) < 0 ? 'nv-bar negative' : 'nv-bar positive'}) if (barColor) { if (!disabled) disabled = data.map(function() { return true }); bars .style('fill', function(d,i,j) { return d3.rgb(barColor(d,i)).darker( disabled.map(function(d,i) { return i }).filter(function(d,i){ return !disabled[i] })[j] ).toString(); }) .style('stroke', function(d,i,j) { return d3.rgb(barColor(d,i)).darker( disabled.map(function(d,i) { return i }).filter(function(d,i){ return !disabled[i] })[j] ).toString(); }); } if (stacked) bars.watchTransition(renderWatch, 'multibarhorizontal: bars') .attr('transform', function(d,i) { return 'translate(' + y(d.y1) + ',' + x(getX(d,i)) + ')' }) .select('rect') .attr('width', function(d,i) { return Math.abs(y(getY(d,i) + d.y0) - y(d.y0)) || 0 }) .attr('height', x.rangeBand() ); else bars.watchTransition(renderWatch, 'multibarhorizontal: bars') .attr('transform', function(d,i) { //TODO: stacked must be all positive or all negative, not both? return 'translate(' + (getY(d,i) < 0 ? y(getY(d,i)) : y(0)) + ',' + (d.series * x.rangeBand() / data.length + x(getX(d,i)) ) + ')' }) .select('rect') .attr('height', x.rangeBand() / data.length ) .attr('width', function(d,i) { return Math.max(Math.abs(y(getY(d,i)) - y(0)),1) || 0 }); //store old scales for use in transitions on update x0 = x.copy(); y0 = y.copy(); }); renderWatch.renderEnd('multibarHorizontal immediate'); return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.dispatch = dispatch; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, x: {get: function(){return getX;}, set: function(_){getX=_;}}, y: {get: function(){return getY;}, set: function(_){getY=_;}}, yErr: {get: function(){return getYerr;}, set: function(_){getYerr=_;}}, xScale: {get: function(){return x;}, set: function(_){x=_;}}, yScale: {get: function(){return y;}, set: function(_){y=_;}}, xDomain: {get: function(){return xDomain;}, set: function(_){xDomain=_;}}, yDomain: {get: function(){return yDomain;}, set: function(_){yDomain=_;}}, xRange: {get: function(){return xRange;}, set: function(_){xRange=_;}}, yRange: {get: function(){return yRange;}, set: function(_){yRange=_;}}, forceY: {get: function(){return forceY;}, set: function(_){forceY=_;}}, stacked: {get: function(){return stacked;}, set: function(_){stacked=_;}}, showValues: {get: function(){return showValues;}, set: function(_){showValues=_;}}, // this shows the group name, seems pointless? //showBarLabels: {get: function(){return showBarLabels;}, set: function(_){showBarLabels=_;}}, disabled: {get: function(){return disabled;}, set: function(_){disabled=_;}}, id: {get: function(){return id;}, set: function(_){id=_;}}, valueFormat: {get: function(){return valueFormat;}, set: function(_){valueFormat=_;}}, valuePadding: {get: function(){return valuePadding;}, set: function(_){valuePadding=_;}}, groupSpacing: {get: function(){return groupSpacing;}, set: function(_){groupSpacing=_;}}, fillOpacity: {get: function(){return fillOpacity;}, set: function(_){fillOpacity=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; renderWatch.reset(duration); }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); }}, barColor: {get: function(){return barColor;}, set: function(_){ barColor = _ ? nv.utils.getColor(_) : null; }} }); nv.utils.initOptions(chart); return chart; }; nv.models.multiBarHorizontalChart = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var multibar = nv.models.multiBarHorizontal() , xAxis = nv.models.axis() , yAxis = nv.models.axis() , legend = nv.models.legend().height(30) , controls = nv.models.legend().height(30) , tooltip = nv.models.tooltip() ; var margin = {top: 30, right: 20, bottom: 50, left: 60} , marginTop = null , width = null , height = null , color = nv.utils.defaultColor() , showControls = true , controlsPosition = 'top' , controlLabels = {} , showLegend = true , legendPosition = 'top' , showXAxis = true , showYAxis = true , stacked = false , x //can be accessed via chart.xScale() , y //can be accessed via chart.yScale() , state = nv.utils.state() , defaultState = null , noData = null , dispatch = d3.dispatch('stateChange', 'changeState','renderEnd') , controlWidth = function() { return showControls ? 180 : 0 } , duration = 250 ; state.stacked = false; // DEPRECATED Maintained for backward compatibility multibar.stacked(stacked); xAxis .orient('left') .tickPadding(5) .showMaxMin(false) .tickFormat(function(d) { return d }) ; yAxis .orient('bottom') .tickFormat(d3.format(',.1f')) ; tooltip .duration(0) .valueFormatter(function(d, i) { return yAxis.tickFormat()(d, i); }) .headerFormatter(function(d, i) { return xAxis.tickFormat()(d, i); }); controls.updateState(false); //============================================================ // Private Variables //------------------------------------------------------------ var stateGetter = function(data) { return function(){ return { active: data.map(function(d) { return !d.disabled }), stacked: stacked }; } }; var stateSetter = function(data) { return function(state) { if (state.stacked !== undefined) stacked = state.stacked; if (state.active !== undefined) data.forEach(function(series,i) { series.disabled = !state.active[i]; }); } }; var renderWatch = nv.utils.renderWatch(dispatch, duration); function chart(selection) { renderWatch.reset(); renderWatch.models(multibar); if (showXAxis) renderWatch.models(xAxis); if (showYAxis) renderWatch.models(yAxis); selection.each(function(data) { var container = d3.select(this), that = this; nv.utils.initSVG(container); var availableWidth = nv.utils.availableWidth(width, container, margin), availableHeight = nv.utils.availableHeight(height, container, margin); chart.update = function() { container.transition().duration(duration).call(chart) }; chart.container = this; stacked = multibar.stacked(); state .setter(stateSetter(data), chart.update) .getter(stateGetter(data)) .update(); // DEPRECATED set state.disableddisabled state.disabled = data.map(function(d) { return !!d.disabled }); if (!defaultState) { var key; defaultState = {}; for (key in state) { if (state[key] instanceof Array) defaultState[key] = state[key].slice(0); else defaultState[key] = state[key]; } } // Display No Data message if there's nothing to show. if (!data || !data.length || !data.filter(function(d) { return d.values.length }).length) { nv.utils.noData(chart, container) return chart; } else { container.selectAll('.nv-noData').remove(); } // Setup Scales x = multibar.xScale(); y = multibar.yScale().clamp(true); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-multiBarHorizontalChart').data([data]); var gEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-multiBarHorizontalChart').append('g'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-x nv-axis'); gEnter.append('g').attr('class', 'nv-y nv-axis') .append('g').attr('class', 'nv-zeroLine') .append('line'); gEnter.append('g').attr('class', 'nv-barsWrap'); gEnter.append('g').attr('class', 'nv-legendWrap'); gEnter.append('g').attr('class', 'nv-controlsWrap'); // Legend if (!showLegend) { g.select('.nv-legendWrap').selectAll('*').remove(); } else { legend.width(availableWidth - controlWidth()); g.select('.nv-legendWrap') .datum(data) .call(legend); if (legendPosition === 'bottom') { margin.bottom = xAxis.height() + legend.height(); availableHeight = nv.utils.availableHeight(height, container, margin); g.select('.nv-legendWrap') .attr('transform', 'translate(' + controlWidth() + ',' + (availableHeight + xAxis.height()) +')'); } else if (legendPosition === 'top') { if (!marginTop && legend.height() !== margin.top) { margin.top = legend.height(); availableHeight = nv.utils.availableHeight(height, container, margin); } g.select('.nv-legendWrap') .attr('transform', 'translate(' + controlWidth() + ',' + (-margin.top) +')'); } } // Controls if (!showControls) { g.select('.nv-controlsWrap').selectAll('*').remove(); } else { var controlsData = [ { key: controlLabels.grouped || 'Grouped', disabled: multibar.stacked() }, { key: controlLabels.stacked || 'Stacked', disabled: !multibar.stacked() } ]; controls.width(controlWidth()).color(['#444', '#444', '#444']); if (controlsPosition === 'bottom') { margin.bottom = xAxis.height() + legend.height(); availableHeight = nv.utils.availableHeight(height, container, margin); g.select('.nv-controlsWrap') .datum(controlsData) .attr('transform', 'translate(0,' + (availableHeight + xAxis.height()) +')') .call(controls); } else if (controlsPosition === 'top') { g.select('.nv-controlsWrap') .datum(controlsData) .attr('transform', 'translate(0,' + (-margin.top) +')') .call(controls); } } wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); // Main Chart Component(s) multibar .disabled(data.map(function(series) { return series.disabled })) .width(availableWidth) .height(availableHeight) .color(data.map(function(d,i) { return d.color || color(d, i); }).filter(function(d,i) { return !data[i].disabled })); var barsWrap = g.select('.nv-barsWrap') .datum(data.filter(function(d) { return !d.disabled })); barsWrap.transition().call(multibar); // Setup Axes if (showXAxis) { xAxis .scale(x) ._ticks( nv.utils.calcTicksY(availableHeight/24, data) ) .tickSize(-availableWidth, 0); g.select('.nv-x.nv-axis').call(xAxis); var xTicks = g.select('.nv-x.nv-axis').selectAll('g'); xTicks .selectAll('line, text'); } if (showYAxis) { yAxis .scale(y) ._ticks( nv.utils.calcTicksX(availableWidth/100, data) ) .tickSize( -availableHeight, 0); g.select('.nv-y.nv-axis') .attr('transform', 'translate(0,' + availableHeight + ')'); g.select('.nv-y.nv-axis').call(yAxis); } // Zero line g.select(".nv-zeroLine line") .attr("x1", y(0)) .attr("x2", y(0)) .attr("y1", 0) .attr("y2", -availableHeight) ; //============================================================ // Event Handling/Dispatching (in chart's scope) //------------------------------------------------------------ legend.dispatch.on('stateChange', function(newState) { for (var key in newState) state[key] = newState[key]; dispatch.stateChange(state); chart.update(); }); controls.dispatch.on('legendClick', function(d,i) { if (!d.disabled) return; controlsData = controlsData.map(function(s) { s.disabled = true; return s; }); d.disabled = false; switch (d.key) { case 'Grouped': case controlLabels.grouped: multibar.stacked(false); break; case 'Stacked': case controlLabels.stacked: multibar.stacked(true); break; } state.stacked = multibar.stacked(); dispatch.stateChange(state); stacked = multibar.stacked(); chart.update(); }); // Update chart from a state object passed to event handler dispatch.on('changeState', function(e) { if (typeof e.disabled !== 'undefined') { data.forEach(function(series,i) { series.disabled = e.disabled[i]; }); state.disabled = e.disabled; } if (typeof e.stacked !== 'undefined') { multibar.stacked(e.stacked); state.stacked = e.stacked; stacked = e.stacked; } chart.update(); }); }); renderWatch.renderEnd('multibar horizontal chart immediate'); return chart; } //============================================================ // Event Handling/Dispatching (out of chart's scope) //------------------------------------------------------------ multibar.dispatch.on('elementMouseover.tooltip', function(evt) { evt.value = chart.x()(evt.data); evt['series'] = { key: evt.data.key, value: chart.y()(evt.data), color: evt.color }; tooltip.data(evt).hidden(false); }); multibar.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true); }); multibar.dispatch.on('elementMousemove.tooltip', function(evt) { tooltip(); }); //============================================================ // Expose Public Variables //------------------------------------------------------------ // expose chart's sub-components chart.dispatch = dispatch; chart.multibar = multibar; chart.legend = legend; chart.controls = controls; chart.xAxis = xAxis; chart.yAxis = yAxis; chart.state = state; chart.tooltip = tooltip; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, showLegend: {get: function(){return showLegend;}, set: function(_){showLegend=_;}}, legendPosition: {get: function(){return legendPosition;}, set: function(_){legendPosition=_;}}, controlsPosition: {get: function(){return controlsPosition;}, set: function(_){controlsPosition=_;}}, showControls: {get: function(){return showControls;}, set: function(_){showControls=_;}}, controlLabels: {get: function(){return controlLabels;}, set: function(_){controlLabels=_;}}, showXAxis: {get: function(){return showXAxis;}, set: function(_){showXAxis=_;}}, showYAxis: {get: function(){return showYAxis;}, set: function(_){showYAxis=_;}}, defaultState: {get: function(){return defaultState;}, set: function(_){defaultState=_;}}, noData: {get: function(){return noData;}, set: function(_){noData=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ if (_.top !== undefined) { margin.top = _.top; marginTop = _.top; } margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; renderWatch.reset(duration); multibar.duration(duration); xAxis.duration(duration); yAxis.duration(duration); }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); legend.color(color); }}, barColor: {get: function(){return multibar.barColor;}, set: function(_){ multibar.barColor(_); legend.color(function(d,i) {return d3.rgb('#ccc').darker(i * 1.5).toString();}) }} }); nv.utils.inheritOptions(chart, multibar); nv.utils.initOptions(chart); return chart; }; nv.models.multiChart = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 30, right: 20, bottom: 50, left: 60}, marginTop = null, color = nv.utils.defaultColor(), width = null, height = null, showLegend = true, noData = null, yDomain1, yDomain2, getX = function(d) { return d.x }, getY = function(d) { return d.y}, interpolate = 'linear', useVoronoi = true, interactiveLayer = nv.interactiveGuideline(), useInteractiveGuideline = false, legendRightAxisHint = ' (right axis)', duration = 250 ; //============================================================ // Private Variables //------------------------------------------------------------ var x = d3.scale.linear(), yScale1 = d3.scale.linear(), yScale2 = d3.scale.linear(), lines1 = nv.models.line().yScale(yScale1).duration(duration), lines2 = nv.models.line().yScale(yScale2).duration(duration), scatters1 = nv.models.scatter().yScale(yScale1).duration(duration), scatters2 = nv.models.scatter().yScale(yScale2).duration(duration), bars1 = nv.models.multiBar().stacked(false).yScale(yScale1).duration(duration), bars2 = nv.models.multiBar().stacked(false).yScale(yScale2).duration(duration), stack1 = nv.models.stackedArea().yScale(yScale1).duration(duration), stack2 = nv.models.stackedArea().yScale(yScale2).duration(duration), xAxis = nv.models.axis().scale(x).orient('bottom').tickPadding(5).duration(duration), yAxis1 = nv.models.axis().scale(yScale1).orient('left').duration(duration), yAxis2 = nv.models.axis().scale(yScale2).orient('right').duration(duration), legend = nv.models.legend().height(30), tooltip = nv.models.tooltip(), dispatch = d3.dispatch(); var charts = [lines1, lines2, scatters1, scatters2, bars1, bars2, stack1, stack2]; function chart(selection) { selection.each(function(data) { var container = d3.select(this), that = this; nv.utils.initSVG(container); chart.update = function() { container.transition().call(chart); }; chart.container = this; var availableWidth = nv.utils.availableWidth(width, container, margin), availableHeight = nv.utils.availableHeight(height, container, margin); var dataLines1 = data.filter(function(d) {return d.type == 'line' && d.yAxis == 1}); var dataLines2 = data.filter(function(d) {return d.type == 'line' && d.yAxis == 2}); var dataScatters1 = data.filter(function(d) {return d.type == 'scatter' && d.yAxis == 1}); var dataScatters2 = data.filter(function(d) {return d.type == 'scatter' && d.yAxis == 2}); var dataBars1 = data.filter(function(d) {return d.type == 'bar' && d.yAxis == 1}); var dataBars2 = data.filter(function(d) {return d.type == 'bar' && d.yAxis == 2}); var dataStack1 = data.filter(function(d) {return d.type == 'area' && d.yAxis == 1}); var dataStack2 = data.filter(function(d) {return d.type == 'area' && d.yAxis == 2}); // Display noData message if there's nothing to show. if (!data || !data.length || !data.filter(function(d) { return d.values.length }).length) { nv.utils.noData(chart, container); return chart; } else { container.selectAll('.nv-noData').remove(); } var series1 = data.filter(function(d) {return !d.disabled && d.yAxis == 1}) .map(function(d) { return d.values.map(function(d,i) { return { x: getX(d), y: getY(d) } }) }); var series2 = data.filter(function(d) {return !d.disabled && d.yAxis == 2}) .map(function(d) { return d.values.map(function(d,i) { return { x: getX(d), y: getY(d) } }) }); x .domain(d3.extent(d3.merge(series1.concat(series2)), function(d) { return d.x })) .range([0, availableWidth]); var wrap = container.selectAll('g.wrap.multiChart').data([data]); var gEnter = wrap.enter().append('g').attr('class', 'wrap nvd3 multiChart').append('g'); gEnter.append('g').attr('class', 'nv-x nv-axis'); gEnter.append('g').attr('class', 'nv-y1 nv-axis'); gEnter.append('g').attr('class', 'nv-y2 nv-axis'); gEnter.append('g').attr('class', 'stack1Wrap'); gEnter.append('g').attr('class', 'stack2Wrap'); gEnter.append('g').attr('class', 'bars1Wrap'); gEnter.append('g').attr('class', 'bars2Wrap'); gEnter.append('g').attr('class', 'scatters1Wrap'); gEnter.append('g').attr('class', 'scatters2Wrap'); gEnter.append('g').attr('class', 'lines1Wrap'); gEnter.append('g').attr('class', 'lines2Wrap'); gEnter.append('g').attr('class', 'legendWrap'); gEnter.append('g').attr('class', 'nv-interactive'); var g = wrap.select('g'); var color_array = data.map(function(d,i) { return data[i].color || color(d, i); }); // Legend if (!showLegend) { g.select('.legendWrap').selectAll('*').remove(); } else { var legendWidth = legend.align() ? availableWidth / 2 : availableWidth; var legendXPosition = legend.align() ? legendWidth : 0; legend.width(legendWidth); legend.color(color_array); g.select('.legendWrap') .datum(data.map(function(series) { series.originalKey = series.originalKey === undefined ? series.key : series.originalKey; series.key = series.originalKey + (series.yAxis == 1 ? '' : legendRightAxisHint); return series; })) .call(legend); if (!marginTop && legend.height() !== margin.top) { margin.top = legend.height(); availableHeight = nv.utils.availableHeight(height, container, margin); } g.select('.legendWrap') .attr('transform', 'translate(' + legendXPosition + ',' + (-margin.top) +')'); } lines1 .width(availableWidth) .height(availableHeight) .interpolate(interpolate) .color(color_array.filter(function(d,i) { return !data[i].disabled && data[i].yAxis == 1 && data[i].type == 'line'})); lines2 .width(availableWidth) .height(availableHeight) .interpolate(interpolate) .color(color_array.filter(function(d,i) { return !data[i].disabled && data[i].yAxis == 2 && data[i].type == 'line'})); scatters1 .width(availableWidth) .height(availableHeight) .color(color_array.filter(function(d,i) { return !data[i].disabled && data[i].yAxis == 1 && data[i].type == 'scatter'})); scatters2 .width(availableWidth) .height(availableHeight) .color(color_array.filter(function(d,i) { return !data[i].disabled && data[i].yAxis == 2 && data[i].type == 'scatter'})); bars1 .width(availableWidth) .height(availableHeight) .color(color_array.filter(function(d,i) { return !data[i].disabled && data[i].yAxis == 1 && data[i].type == 'bar'})); bars2 .width(availableWidth) .height(availableHeight) .color(color_array.filter(function(d,i) { return !data[i].disabled && data[i].yAxis == 2 && data[i].type == 'bar'})); stack1 .width(availableWidth) .height(availableHeight) .interpolate(interpolate) .color(color_array.filter(function(d,i) { return !data[i].disabled && data[i].yAxis == 1 && data[i].type == 'area'})); stack2 .width(availableWidth) .height(availableHeight) .interpolate(interpolate) .color(color_array.filter(function(d,i) { return !data[i].disabled && data[i].yAxis == 2 && data[i].type == 'area'})); g.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); var lines1Wrap = g.select('.lines1Wrap') .datum(dataLines1.filter(function(d){return !d.disabled})); var scatters1Wrap = g.select('.scatters1Wrap') .datum(dataScatters1.filter(function(d){return !d.disabled})); var bars1Wrap = g.select('.bars1Wrap') .datum(dataBars1.filter(function(d){return !d.disabled})); var stack1Wrap = g.select('.stack1Wrap') .datum(dataStack1.filter(function(d){return !d.disabled})); var lines2Wrap = g.select('.lines2Wrap') .datum(dataLines2.filter(function(d){return !d.disabled})); var scatters2Wrap = g.select('.scatters2Wrap') .datum(dataScatters2.filter(function(d){return !d.disabled})); var bars2Wrap = g.select('.bars2Wrap') .datum(dataBars2.filter(function(d){return !d.disabled})); var stack2Wrap = g.select('.stack2Wrap') .datum(dataStack2.filter(function(d){return !d.disabled})); var extraValue1BarStacked = []; if (bars1.stacked() && dataBars1.length) { var extraValue1BarStacked = dataBars1.filter(function(d){return !d.disabled}).map(function(a){return a.values}); if (extraValue1BarStacked.length > 0) extraValue1BarStacked = extraValue1BarStacked.reduce(function(a,b){ return a.map(function(aVal,i){return {x: aVal.x, y: aVal.y + b[i].y}}) }); } if (dataBars1.length) { extraValue1BarStacked.push({x:0, y:0}); } var extraValue2BarStacked = []; if (bars2.stacked() && dataBars2.length) { var extraValue2BarStacked = dataBars2.filter(function(d){return !d.disabled}).map(function(a){return a.values}); if (extraValue2BarStacked.length > 0) extraValue2BarStacked = extraValue2BarStacked.reduce(function(a,b){ return a.map(function(aVal,i){return {x: aVal.x, y: aVal.y + b[i].y}}) }); } if (dataBars2.length) { extraValue2BarStacked.push({x:0, y:0}); } yScale1 .domain(yDomain1 || d3.extent(d3.merge(series1).concat(extraValue1BarStacked), function(d) { return d.y } )) .range([0, availableHeight]); yScale2 .domain(yDomain2 || d3.extent(d3.merge(series2).concat(extraValue2BarStacked), function(d) { return d.y } )) .range([0, availableHeight]); lines1.yDomain(yScale1.domain()); scatters1.yDomain(yScale1.domain()); bars1.yDomain(yScale1.domain()); stack1.yDomain(yScale1.domain()); lines2.yDomain(yScale2.domain()); scatters2.yDomain(yScale2.domain()); bars2.yDomain(yScale2.domain()); stack2.yDomain(yScale2.domain()); if(dataStack1.length){d3.transition(stack1Wrap).call(stack1);} if(dataStack2.length){d3.transition(stack2Wrap).call(stack2);} if(dataBars1.length){d3.transition(bars1Wrap).call(bars1);} if(dataBars2.length){d3.transition(bars2Wrap).call(bars2);} if(dataLines1.length){d3.transition(lines1Wrap).call(lines1);} if(dataLines2.length){d3.transition(lines2Wrap).call(lines2);} if(dataScatters1.length){d3.transition(scatters1Wrap).call(scatters1);} if(dataScatters2.length){d3.transition(scatters2Wrap).call(scatters2);} xAxis ._ticks( nv.utils.calcTicksX(availableWidth/100, data) ) .tickSize(-availableHeight, 0); g.select('.nv-x.nv-axis') .attr('transform', 'translate(0,' + availableHeight + ')'); d3.transition(g.select('.nv-x.nv-axis')) .call(xAxis); yAxis1 ._ticks( nv.utils.calcTicksY(availableHeight/36, data) ) .tickSize( -availableWidth, 0); d3.transition(g.select('.nv-y1.nv-axis')) .call(yAxis1); yAxis2 ._ticks( nv.utils.calcTicksY(availableHeight/36, data) ) .tickSize( -availableWidth, 0); d3.transition(g.select('.nv-y2.nv-axis')) .call(yAxis2); g.select('.nv-y1.nv-axis') .classed('nv-disabled', series1.length ? false : true) .attr('transform', 'translate(' + x.range()[0] + ',0)'); g.select('.nv-y2.nv-axis') .classed('nv-disabled', series2.length ? false : true) .attr('transform', 'translate(' + x.range()[1] + ',0)'); legend.dispatch.on('stateChange', function(newState) { chart.update(); }); if(useInteractiveGuideline){ interactiveLayer .width(availableWidth) .height(availableHeight) .margin({left:margin.left, top:margin.top}) .svgContainer(container) .xScale(x); wrap.select(".nv-interactive").call(interactiveLayer); } //============================================================ // Event Handling/Dispatching //------------------------------------------------------------ function mouseover_line(evt) { var yaxis = evt.series.yAxis === 2 ? yAxis2 : yAxis1; evt.value = evt.point.x; evt.series = { value: evt.point.y, color: evt.point.color, key: evt.series.key }; tooltip .duration(0) .headerFormatter(function(d, i) { return xAxis.tickFormat()(d, i); }) .valueFormatter(function(d, i) { return yaxis.tickFormat()(d, i); }) .data(evt) .hidden(false); } function mouseover_scatter(evt) { var yaxis = evt.series.yAxis === 2 ? yAxis2 : yAxis1; evt.value = evt.point.x; evt.series = { value: evt.point.y, color: evt.point.color, key: evt.series.key }; tooltip .duration(100) .headerFormatter(function(d, i) { return xAxis.tickFormat()(d, i); }) .valueFormatter(function(d, i) { return yaxis.tickFormat()(d, i); }) .data(evt) .hidden(false); } function mouseover_stack(evt) { var yaxis = evt.series.yAxis === 2 ? yAxis2 : yAxis1; evt.point['x'] = stack1.x()(evt.point); evt.point['y'] = stack1.y()(evt.point); tooltip .duration(0) .headerFormatter(function(d, i) { return xAxis.tickFormat()(d, i); }) .valueFormatter(function(d, i) { return yaxis.tickFormat()(d, i); }) .data(evt) .hidden(false); } function mouseover_bar(evt) { var yaxis = evt.series.yAxis === 2 ? yAxis2 : yAxis1; evt.value = bars1.x()(evt.data); evt['series'] = { value: bars1.y()(evt.data), color: evt.color, key: evt.data.key }; tooltip .duration(0) .headerFormatter(function(d, i) { return xAxis.tickFormat()(d, i); }) .valueFormatter(function(d, i) { return yaxis.tickFormat()(d, i); }) .data(evt) .hidden(false); } function clearHighlights() { for(var i=0, il=charts.length; i < il; i++){ var chart = charts[i]; try { chart.clearHighlights(); } catch(e){} } } function highlightPoint(serieIndex, pointIndex, b){ for(var i=0, il=charts.length; i < il; i++){ var chart = charts[i]; try { chart.highlightPoint(serieIndex, pointIndex, b); } catch(e){} } } if(useInteractiveGuideline){ interactiveLayer.dispatch.on('elementMousemove', function(e) { clearHighlights(); var singlePoint, pointIndex, pointXLocation, allData = []; data .filter(function(series, i) { series.seriesIndex = i; return !series.disabled; }) .forEach(function(series,i) { var extent = x.domain(); var currentValues = series.values.filter(function(d,i) { return chart.x()(d,i) >= extent[0] && chart.x()(d,i) <= extent[1]; }); pointIndex = nv.interactiveBisect(currentValues, e.pointXValue, chart.x()); var point = currentValues[pointIndex]; var pointYValue = chart.y()(point, pointIndex); if (pointYValue !== null) { highlightPoint(i, pointIndex, true); } if (point === undefined) return; if (singlePoint === undefined) singlePoint = point; if (pointXLocation === undefined) pointXLocation = x(chart.x()(point,pointIndex)); allData.push({ key: series.key, value: pointYValue, color: color(series,series.seriesIndex), data: point, yAxis: series.yAxis == 2 ? yAxis2 : yAxis1 }); }); var defaultValueFormatter = function(d,i) { var yAxis = allData[i].yAxis; return d == null ? "N/A" : yAxis.tickFormat()(d); }; interactiveLayer.tooltip .headerFormatter(function(d, i) { return xAxis.tickFormat()(d, i); }) .valueFormatter(interactiveLayer.tooltip.valueFormatter() || defaultValueFormatter) .data({ value: chart.x()( singlePoint,pointIndex ), index: pointIndex, series: allData })(); interactiveLayer.renderGuideLine(pointXLocation); }); interactiveLayer.dispatch.on("elementMouseout",function(e) { clearHighlights(); }); } else { lines1.dispatch.on('elementMouseover.tooltip', mouseover_line); lines2.dispatch.on('elementMouseover.tooltip', mouseover_line); lines1.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true) }); lines2.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true) }); scatters1.dispatch.on('elementMouseover.tooltip', mouseover_scatter); scatters2.dispatch.on('elementMouseover.tooltip', mouseover_scatter); scatters1.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true) }); scatters2.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true) }); stack1.dispatch.on('elementMouseover.tooltip', mouseover_stack); stack2.dispatch.on('elementMouseover.tooltip', mouseover_stack); stack1.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true) }); stack2.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true) }); bars1.dispatch.on('elementMouseover.tooltip', mouseover_bar); bars2.dispatch.on('elementMouseover.tooltip', mouseover_bar); bars1.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true); }); bars2.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true); }); bars1.dispatch.on('elementMousemove.tooltip', function(evt) { tooltip(); }); bars2.dispatch.on('elementMousemove.tooltip', function(evt) { tooltip(); }); } }); return chart; } //============================================================ // Global getters and setters //------------------------------------------------------------ chart.dispatch = dispatch; chart.legend = legend; chart.lines1 = lines1; chart.lines2 = lines2; chart.scatters1 = scatters1; chart.scatters2 = scatters2; chart.bars1 = bars1; chart.bars2 = bars2; chart.stack1 = stack1; chart.stack2 = stack2; chart.xAxis = xAxis; chart.yAxis1 = yAxis1; chart.yAxis2 = yAxis2; chart.tooltip = tooltip; chart.interactiveLayer = interactiveLayer; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, showLegend: {get: function(){return showLegend;}, set: function(_){showLegend=_;}}, xScale: {get: function(){return x;}, set: function(_){ x = _; xAxis.scale(x); }}, yDomain1: {get: function(){return yDomain1;}, set: function(_){yDomain1=_;}}, yDomain2: {get: function(){return yDomain2;}, set: function(_){yDomain2=_;}}, noData: {get: function(){return noData;}, set: function(_){noData=_;}}, interpolate: {get: function(){return interpolate;}, set: function(_){interpolate=_;}}, legendRightAxisHint: {get: function(){return legendRightAxisHint;}, set: function(_){legendRightAxisHint=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ if (_.top !== undefined) { margin.top = _.top; marginTop = _.top; } margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); }}, x: {get: function(){return getX;}, set: function(_){ getX = _; lines1.x(_); lines2.x(_); scatters1.x(_); scatters2.x(_); bars1.x(_); bars2.x(_); stack1.x(_); stack2.x(_); }}, y: {get: function(){return getY;}, set: function(_){ getY = _; lines1.y(_); lines2.y(_); scatters1.y(_); scatters2.y(_); stack1.y(_); stack2.y(_); bars1.y(_); bars2.y(_); }}, useVoronoi: {get: function(){return useVoronoi;}, set: function(_){ useVoronoi=_; lines1.useVoronoi(_); lines2.useVoronoi(_); stack1.useVoronoi(_); stack2.useVoronoi(_); }}, useInteractiveGuideline: {get: function(){return useInteractiveGuideline;}, set: function(_){ useInteractiveGuideline = _; if (useInteractiveGuideline) { lines1.interactive(false); lines1.useVoronoi(false); lines2.interactive(false); lines2.useVoronoi(false); stack1.interactive(false); stack1.useVoronoi(false); stack2.interactive(false); stack2.useVoronoi(false); scatters1.interactive(false); scatters2.interactive(false); } }}, duration: {get: function(){return duration;}, set: function(_) { duration = _; [lines1, lines2, stack1, stack2, scatters1, scatters2, xAxis, yAxis1, yAxis2].forEach(function(model){ model.duration(duration); }); }} }); nv.utils.initOptions(chart); return chart; }; nv.models.ohlcBar = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 0, right: 0, bottom: 0, left: 0} , width = null , height = null , id = Math.floor(Math.random() * 10000) //Create semi-unique ID in case user doesn't select one , container = null , x = d3.scale.linear() , y = d3.scale.linear() , getX = function(d) { return d.x } , getY = function(d) { return d.y } , getOpen = function(d) { return d.open } , getClose = function(d) { return d.close } , getHigh = function(d) { return d.high } , getLow = function(d) { return d.low } , forceX = [] , forceY = [] , padData = false // If true, adds half a data points width to front and back, for lining up a line chart with a bar chart , clipEdge = true , color = nv.utils.defaultColor() , interactive = false , xDomain , yDomain , xRange , yRange , dispatch = d3.dispatch('stateChange', 'changeState', 'renderEnd', 'chartClick', 'elementClick', 'elementDblClick', 'elementMouseover', 'elementMouseout', 'elementMousemove') ; //============================================================ // Private Variables //------------------------------------------------------------ function chart(selection) { selection.each(function(data) { container = d3.select(this); var availableWidth = nv.utils.availableWidth(width, container, margin), availableHeight = nv.utils.availableHeight(height, container, margin); nv.utils.initSVG(container); // ohlc bar width. var w = (availableWidth / data[0].values.length) * .9; // Setup Scales x.domain(xDomain || d3.extent(data[0].values.map(getX).concat(forceX) )); if (padData) x.range(xRange || [availableWidth * .5 / data[0].values.length, availableWidth * (data[0].values.length - .5) / data[0].values.length ]); else x.range(xRange || [5 + w/2, availableWidth - w/2 - 5]); y.domain(yDomain || [ d3.min(data[0].values.map(getLow).concat(forceY)), d3.max(data[0].values.map(getHigh).concat(forceY)) ] ).range(yRange || [availableHeight, 0]); // If scale's domain don't have a range, slightly adjust to make one... so a chart can show a single data point if (x.domain()[0] === x.domain()[1]) x.domain()[0] ? x.domain([x.domain()[0] - x.domain()[0] * 0.01, x.domain()[1] + x.domain()[1] * 0.01]) : x.domain([-1,1]); if (y.domain()[0] === y.domain()[1]) y.domain()[0] ? y.domain([y.domain()[0] + y.domain()[0] * 0.01, y.domain()[1] - y.domain()[1] * 0.01]) : y.domain([-1,1]); // Setup containers and skeleton of chart var wrap = d3.select(this).selectAll('g.nv-wrap.nv-ohlcBar').data([data[0].values]); var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-ohlcBar'); var defsEnter = wrapEnter.append('defs'); var gEnter = wrapEnter.append('g'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-ticks'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); container .on('click', function(d,i) { dispatch.chartClick({ data: d, index: i, pos: d3.event, id: id }); }); defsEnter.append('clipPath') .attr('id', 'nv-chart-clip-path-' + id) .append('rect'); wrap.select('#nv-chart-clip-path-' + id + ' rect') .attr('width', availableWidth) .attr('height', availableHeight); g .attr('clip-path', clipEdge ? 'url(#nv-chart-clip-path-' + id + ')' : ''); var ticks = wrap.select('.nv-ticks').selectAll('.nv-tick') .data(function(d) { return d }); ticks.exit().remove(); ticks.enter().append('path') .attr('class', function(d,i,j) { return (getOpen(d,i) > getClose(d,i) ? 'nv-tick negative' : 'nv-tick positive') + ' nv-tick-' + j + '-' + i }) .attr('d', function(d,i) { return 'm0,0l0,' + (y(getOpen(d,i)) - y(getHigh(d,i))) + 'l' + (-w/2) + ',0l' + (w/2) + ',0l0,' + (y(getLow(d,i)) - y(getOpen(d,i))) + 'l0,' + (y(getClose(d,i)) - y(getLow(d,i))) + 'l' + (w/2) + ',0l' + (-w/2) + ',0z'; }) .attr('transform', function(d,i) { return 'translate(' + x(getX(d,i)) + ',' + y(getHigh(d,i)) + ')'; }) .attr('fill', function(d,i) { return color[0]; }) .attr('stroke', function(d,i) { return color[0]; }) .attr('x', 0 ) .attr('y', function(d,i) { return y(Math.max(0, getY(d,i))) }) .attr('height', function(d,i) { return Math.abs(y(getY(d,i)) - y(0)) }); // the bar colors are controlled by CSS currently ticks.attr('class', function(d,i,j) { return (getOpen(d,i) > getClose(d,i) ? 'nv-tick negative' : 'nv-tick positive') + ' nv-tick-' + j + '-' + i; }); d3.transition(ticks) .attr('transform', function(d,i) { return 'translate(' + x(getX(d,i)) + ',' + y(getHigh(d,i)) + ')'; }) .attr('d', function(d,i) { var w = (availableWidth / data[0].values.length) * .9; return 'm0,0l0,' + (y(getOpen(d,i)) - y(getHigh(d,i))) + 'l' + (-w/2) + ',0l' + (w/2) + ',0l0,' + (y(getLow(d,i)) - y(getOpen(d,i))) + 'l0,' + (y(getClose(d,i)) - y(getLow(d,i))) + 'l' + (w/2) + ',0l' + (-w/2) + ',0z'; }); }); return chart; } //Create methods to allow outside functions to highlight a specific bar. chart.highlightPoint = function(pointIndex, isHoverOver) { chart.clearHighlights(); container.select(".nv-ohlcBar .nv-tick-0-" + pointIndex) .classed("hover", isHoverOver) ; }; chart.clearHighlights = function() { container.select(".nv-ohlcBar .nv-tick.hover") .classed("hover", false) ; }; //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.dispatch = dispatch; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, xScale: {get: function(){return x;}, set: function(_){x=_;}}, yScale: {get: function(){return y;}, set: function(_){y=_;}}, xDomain: {get: function(){return xDomain;}, set: function(_){xDomain=_;}}, yDomain: {get: function(){return yDomain;}, set: function(_){yDomain=_;}}, xRange: {get: function(){return xRange;}, set: function(_){xRange=_;}}, yRange: {get: function(){return yRange;}, set: function(_){yRange=_;}}, forceX: {get: function(){return forceX;}, set: function(_){forceX=_;}}, forceY: {get: function(){return forceY;}, set: function(_){forceY=_;}}, padData: {get: function(){return padData;}, set: function(_){padData=_;}}, clipEdge: {get: function(){return clipEdge;}, set: function(_){clipEdge=_;}}, id: {get: function(){return id;}, set: function(_){id=_;}}, interactive: {get: function(){return interactive;}, set: function(_){interactive=_;}}, x: {get: function(){return getX;}, set: function(_){getX=_;}}, y: {get: function(){return getY;}, set: function(_){getY=_;}}, open: {get: function(){return getOpen();}, set: function(_){getOpen=_;}}, close: {get: function(){return getClose();}, set: function(_){getClose=_;}}, high: {get: function(){return getHigh;}, set: function(_){getHigh=_;}}, low: {get: function(){return getLow;}, set: function(_){getLow=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top != undefined ? _.top : margin.top; margin.right = _.right != undefined ? _.right : margin.right; margin.bottom = _.bottom != undefined ? _.bottom : margin.bottom; margin.left = _.left != undefined ? _.left : margin.left; }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); }} }); nv.utils.initOptions(chart); return chart; }; // Code adapted from Jason Davies' "Parallel Coordinates" // http://bl.ocks.org/jasondavies/1341281 nv.models.parallelCoordinates = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 30, right: 0, bottom: 10, left: 0} , width = null , height = null , availableWidth = null , availableHeight = null , x = d3.scale.ordinal() , y = {} , undefinedValuesLabel = "undefined values" , dimensionData = [] , enabledDimensions = [] , dimensionNames = [] , displayBrush = true , color = nv.utils.defaultColor() , filters = [] , active = [] , dragging = [] , axisWithUndefinedValues = [] , lineTension = 1 , foreground , background , dimensions , line = d3.svg.line() , axis = d3.svg.axis() , dispatch = d3.dispatch('brushstart', 'brush', 'brushEnd', 'dimensionsOrder', "stateChange", 'elementClick', 'elementMouseover', 'elementMouseout', 'elementMousemove', 'renderEnd', 'activeChanged') ; //============================================================ // Private Variables //------------------------------------------------------------ var renderWatch = nv.utils.renderWatch(dispatch); function chart(selection) { renderWatch.reset(); selection.each(function(data) { var container = d3.select(this); availableWidth = nv.utils.availableWidth(width, container, margin); availableHeight = nv.utils.availableHeight(height, container, margin); nv.utils.initSVG(container); //Convert old data to new format (name, values) if (data[0].values === undefined) { var newData = []; data.forEach(function (d) { var val = {}; var key = Object.keys(d); key.forEach(function (k) { if (k !== "name") val[k] = d[k] }); newData.push({ key: d.name, values: val }); }); data = newData; } var dataValues = data.map(function (d) {return d.values}); if (active.length === 0) { active = data; }; //set all active before first brush call dimensionNames = dimensionData.sort(function (a, b) { return a.currentPosition - b.currentPosition; }).map(function (d) { return d.key }); enabledDimensions = dimensionData.filter(function (d) { return !d.disabled; }); // Setup Scales x.rangePoints([0, availableWidth], 1).domain(enabledDimensions.map(function (d) { return d.key; })); //Set as true if all values on an axis are missing. // Extract the list of dimensions and create a scale for each. var oldDomainMaxValue = {}; var displayMissingValuesline = false; var currentTicks = []; dimensionNames.forEach(function(d) { var extent = d3.extent(dataValues, function (p) { return +p[d]; }); var min = extent[0]; var max = extent[1]; var onlyUndefinedValues = false; //If there is no values to display on an axis, set the extent to 0 if (isNaN(min) || isNaN(max)) { onlyUndefinedValues = true; min = 0; max = 0; } //Scale axis if there is only one value if (min === max) { min = min - 1; max = max + 1; } var f = filters.filter(function (k) { return k.dimension == d; }); if (f.length !== 0) { //If there is only NaN values, keep the existing domain. if (onlyUndefinedValues) { min = y[d].domain()[0]; max = y[d].domain()[1]; } //If the brush extent is > max (< min), keep the extent value. else if (!f[0].hasOnlyNaN && displayBrush) { min = min > f[0].extent[0] ? f[0].extent[0] : min; max = max < f[0].extent[1] ? f[0].extent[1] : max; } //If there is NaN values brushed be sure the brush extent is on the domain. else if (f[0].hasNaN) { max = max < f[0].extent[1] ? f[0].extent[1] : max; oldDomainMaxValue[d] = y[d].domain()[1]; displayMissingValuesline = true; } } //Use 90% of (availableHeight - 12) for the axis range, 12 reprensenting the space necessary to display "undefined values" text. //The remaining 10% are used to display the missingValue line. y[d] = d3.scale.linear() .domain([min, max]) .range([(availableHeight - 12) * 0.9, 0]); axisWithUndefinedValues = []; y[d].brush = d3.svg.brush().y(y[d]).on('brushstart', brushstart).on('brush', brush).on('brushend', brushend); }); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-parallelCoordinates').data([data]); var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-parallelCoordinates'); var gEnter = wrapEnter.append('g'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-parallelCoordinates background'); gEnter.append('g').attr('class', 'nv-parallelCoordinates foreground'); gEnter.append('g').attr('class', 'nv-parallelCoordinates missingValuesline'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); line.interpolate('cardinal').tension(lineTension); axis.orient('left'); var axisDrag = d3.behavior.drag() .on('dragstart', dragStart) .on('drag', dragMove) .on('dragend', dragEnd); //Add missing value line at the bottom of the chart var missingValuesline, missingValueslineText; var step = x.range()[1] - x.range()[0]; step = isNaN(step) ? x.range()[0] : step; if (!isNaN(step)) { var lineData = [0 + step / 2, availableHeight - 12, availableWidth - step / 2, availableHeight - 12]; missingValuesline = wrap.select('.missingValuesline').selectAll('line').data([lineData]); missingValuesline.enter().append('line'); missingValuesline.exit().remove(); missingValuesline.attr("x1", function(d) { return d[0]; }) .attr("y1", function(d) { return d[1]; }) .attr("x2", function(d) { return d[2]; }) .attr("y2", function(d) { return d[3]; }); //Add the text "undefined values" under the missing value line missingValueslineText = wrap.select('.missingValuesline').selectAll('text').data([undefinedValuesLabel]); missingValueslineText.append('text').data([undefinedValuesLabel]); missingValueslineText.enter().append('text'); missingValueslineText.exit().remove(); missingValueslineText.attr("y", availableHeight) //To have the text right align with the missingValues line, substract 92 representing the text size. .attr("x", availableWidth - 92 - step / 2) .text(function(d) { return d; }); } // Add grey background lines for context. background = wrap.select('.background').selectAll('path').data(data); background.enter().append('path'); background.exit().remove(); background.attr('d', path); // Add blue foreground lines for focus. foreground = wrap.select('.foreground').selectAll('path').data(data); foreground.enter().append('path') foreground.exit().remove(); foreground.attr('d', path) .style("stroke-width", function (d, i) { if (isNaN(d.strokeWidth)) { d.strokeWidth = 1;} return d.strokeWidth;}) .attr('stroke', function (d, i) { return d.color || color(d, i); }); foreground.on("mouseover", function (d, i) { d3.select(this).classed('hover', true).style("stroke-width", d.strokeWidth + 2 + "px").style("stroke-opacity", 1); dispatch.elementMouseover({ label: d.name, color: d.color || color(d, i), values: d.values, dimensions: enabledDimensions }); }); foreground.on("mouseout", function (d, i) { d3.select(this).classed('hover', false).style("stroke-width", d.strokeWidth + "px").style("stroke-opacity", 0.7); dispatch.elementMouseout({ label: d.name, index: i }); }); foreground.on('mousemove', function (d, i) { dispatch.elementMousemove(); }); foreground.on('click', function (d) { dispatch.elementClick({ id: d.id }); }); // Add a group element for each dimension. dimensions = g.selectAll('.dimension').data(enabledDimensions); var dimensionsEnter = dimensions.enter().append('g').attr('class', 'nv-parallelCoordinates dimension'); dimensions.attr('transform', function(d) { return 'translate(' + x(d.key) + ',0)'; }); dimensionsEnter.append('g').attr('class', 'nv-axis'); // Add an axis and title. dimensionsEnter.append('text') .attr('class', 'nv-label') .style("cursor", "move") .attr('dy', '-1em') .attr('text-anchor', 'middle') .on("mouseover", function(d, i) { dispatch.elementMouseover({ label: d.tooltip || d.key, color: d.color }); }) .on("mouseout", function(d, i) { dispatch.elementMouseout({ label: d.tooltip }); }) .on('mousemove', function (d, i) { dispatch.elementMousemove(); }) .call(axisDrag); dimensionsEnter.append('g').attr('class', 'nv-brushBackground'); dimensions.exit().remove(); dimensions.select('.nv-label').text(function (d) { return d.key }); // Add and store a brush for each axis. restoreBrush(displayBrush); var actives = dimensionNames.filter(function (p) { return !y[p].brush.empty(); }), extents = actives.map(function (p) { return y[p].brush.extent(); }); var formerActive = active.slice(0); //Restore active values active = []; foreground.style("display", function (d) { var isActive = actives.every(function (p, i) { if ((isNaN(d.values[p]) || isNaN(parseFloat(d.values[p]))) && extents[i][0] == y[p].brush.y().domain()[0]) { return true; } return (extents[i][0] <= d.values[p] && d.values[p] <= extents[i][1]) && !isNaN(parseFloat(d.values[p])); }); if (isActive) active.push(d); return !isActive ? "none" : null; }); if (filters.length > 0 || !nv.utils.arrayEquals(active, formerActive)) { dispatch.activeChanged(active); } // Returns the path for a given data point. function path(d) { return line(enabledDimensions.map(function (p) { //If value if missing, put the value on the missing value line if (isNaN(d.values[p.key]) || isNaN(parseFloat(d.values[p.key])) || displayMissingValuesline) { var domain = y[p.key].domain(); var range = y[p.key].range(); var min = domain[0] - (domain[1] - domain[0]) / 9; //If it's not already the case, allow brush to select undefined values if (axisWithUndefinedValues.indexOf(p.key) < 0) { var newscale = d3.scale.linear().domain([min, domain[1]]).range([availableHeight - 12, range[1]]); y[p.key].brush.y(newscale); axisWithUndefinedValues.push(p.key); } if (isNaN(d.values[p.key]) || isNaN(parseFloat(d.values[p.key]))) { return [x(p.key), y[p.key](min)]; } } //If parallelCoordinate contain missing values show the missing values line otherwise, hide it. if (missingValuesline !== undefined) { if (axisWithUndefinedValues.length > 0 || displayMissingValuesline) { missingValuesline.style("display", "inline"); missingValueslineText.style("display", "inline"); } else { missingValuesline.style("display", "none"); missingValueslineText.style("display", "none"); } } return [x(p.key), y[p.key](d.values[p.key])]; })); } function restoreBrush(visible) { filters.forEach(function (f) { //If filter brushed NaN values, keep the brush on the bottom of the axis. var brushDomain = y[f.dimension].brush.y().domain(); if (f.hasOnlyNaN) { f.extent[1] = (y[f.dimension].domain()[1] - brushDomain[0]) * (f.extent[1] - f.extent[0]) / (oldDomainMaxValue[f.dimension] - f.extent[0]) + brushDomain[0]; } if (f.hasNaN) { f.extent[0] = brushDomain[0]; } if (visible) y[f.dimension].brush.extent(f.extent); }); dimensions.select('.nv-brushBackground') .each(function (d) { d3.select(this).call(y[d.key].brush); }) .selectAll('rect') .attr('x', -8) .attr('width', 16); updateTicks(); } // Handles a brush event, toggling the display of foreground lines. function brushstart() { //If brush aren't visible, show it before brushing again. if (displayBrush === false) { displayBrush = true; restoreBrush(true); } } // Handles a brush event, toggling the display of foreground lines. function brush() { actives = dimensionNames.filter(function (p) { return !y[p].brush.empty(); }); extents = actives.map(function(p) { return y[p].brush.extent(); }); filters = []; //erase current filters actives.forEach(function(d,i) { filters[i] = { dimension: d, extent: extents[i], hasNaN: false, hasOnlyNaN: false } }); active = []; //erase current active list foreground.style('display', function(d) { var isActive = actives.every(function(p, i) { if ((isNaN(d.values[p]) || isNaN(parseFloat(d.values[p]))) && extents[i][0] == y[p].brush.y().domain()[0]) return true; return (extents[i][0] <= d.values[p] && d.values[p] <= extents[i][1]) && !isNaN(parseFloat(d.values[p])); }); if (isActive) active.push(d); return isActive ? null : 'none'; }); updateTicks(); dispatch.brush({ filters: filters, active: active }); } function brushend() { var hasActiveBrush = actives.length > 0 ? true : false; filters.forEach(function (f) { if (f.extent[0] === y[f.dimension].brush.y().domain()[0] && axisWithUndefinedValues.indexOf(f.dimension) >= 0) f.hasNaN = true; if (f.extent[1] < y[f.dimension].domain()[0]) f.hasOnlyNaN = true; }); dispatch.brushEnd(active, hasActiveBrush); } function updateTicks() { dimensions.select('.nv-axis') .each(function (d, i) { var f = filters.filter(function (k) { return k.dimension == d.key; }); currentTicks[d.key] = y[d.key].domain(); //If brush are available, display brush extent if (f.length != 0 && displayBrush) { currentTicks[d.key] = []; if (f[0].extent[1] > y[d.key].domain()[0]) currentTicks[d.key] = [f[0].extent[1]]; if (f[0].extent[0] >= y[d.key].domain()[0]) currentTicks[d.key].push(f[0].extent[0]); } d3.select(this).call(axis.scale(y[d.key]).tickFormat(d.format).tickValues(currentTicks[d.key])); }); } function dragStart(d) { dragging[d.key] = this.parentNode.__origin__ = x(d.key); background.attr("visibility", "hidden"); } function dragMove(d) { dragging[d.key] = Math.min(availableWidth, Math.max(0, this.parentNode.__origin__ += d3.event.x)); foreground.attr("d", path); enabledDimensions.sort(function (a, b) { return dimensionPosition(a.key) - dimensionPosition(b.key); }); enabledDimensions.forEach(function (d, i) { return d.currentPosition = i; }); x.domain(enabledDimensions.map(function (d) { return d.key; })); dimensions.attr("transform", function(d) { return "translate(" + dimensionPosition(d.key) + ")"; }); } function dragEnd(d, i) { delete this.parentNode.__origin__; delete dragging[d.key]; d3.select(this.parentNode).attr("transform", "translate(" + x(d.key) + ")"); foreground .attr("d", path); background .attr("d", path) .attr("visibility", null); dispatch.dimensionsOrder(enabledDimensions); } function dimensionPosition(d) { var v = dragging[d]; return v == null ? x(d) : v; } }); return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.dispatch = dispatch; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width= _;}}, height: {get: function(){return height;}, set: function(_){height= _;}}, dimensionData: { get: function () { return dimensionData; }, set: function (_) { dimensionData = _; } }, displayBrush: { get: function () { return displayBrush; }, set: function (_) { displayBrush = _; } }, filters: { get: function () { return filters; }, set: function (_) { filters = _; } }, active: { get: function () { return active; }, set: function (_) { active = _; } }, lineTension: {get: function(){return lineTension;}, set: function(_){lineTension = _;}}, undefinedValuesLabel : {get: function(){return undefinedValuesLabel;}, set: function(_){undefinedValuesLabel=_;}}, // deprecated options dimensions: {get: function () { return dimensionData.map(function (d){return d.key}); }, set: function (_) { // deprecated after 1.8.1 nv.deprecated('dimensions', 'use dimensionData instead'); if (dimensionData.length === 0) { _.forEach(function (k) { dimensionData.push({ key: k }) }) } else { _.forEach(function (k, i) { dimensionData[i].key= k }) } }}, dimensionNames: {get: function () { return dimensionData.map(function (d){return d.key}); }, set: function (_) { // deprecated after 1.8.1 nv.deprecated('dimensionNames', 'use dimensionData instead'); dimensionNames = []; if (dimensionData.length === 0) { _.forEach(function (k) { dimensionData.push({ key: k }) }) } else { _.forEach(function (k, i) { dimensionData[i].key = k }) } }}, dimensionFormats: {get: function () { return dimensionData.map(function (d) { return d.format }); }, set: function (_) { // deprecated after 1.8.1 nv.deprecated('dimensionFormats', 'use dimensionData instead'); if (dimensionData.length === 0) { _.forEach(function (f) { dimensionData.push({ format: f }) }) } else { _.forEach(function (f, i) { dimensionData[i].format = f }) } }}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); }} }); nv.utils.initOptions(chart); return chart; }; nv.models.parallelCoordinatesChart = function () { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var parallelCoordinates = nv.models.parallelCoordinates() var legend = nv.models.legend() var tooltip = nv.models.tooltip(); var dimensionTooltip = nv.models.tooltip(); var margin = { top: 0, right: 0, bottom: 0, left: 0 } , marginTop = null , width = null , height = null , showLegend = true , color = nv.utils.defaultColor() , state = nv.utils.state() , dimensionData = [] , displayBrush = true , defaultState = null , noData = null , nanValue = "undefined" , dispatch = d3.dispatch('dimensionsOrder', 'brushEnd', 'stateChange', 'changeState', 'renderEnd') , controlWidth = function () { return showControls ? 180 : 0 } ; //============================================================ //============================================================ // Private Variables //------------------------------------------------------------ var renderWatch = nv.utils.renderWatch(dispatch); var stateGetter = function(data) { return function() { return { active: data.map(function(d) { return !d.disabled }) }; } }; var stateSetter = function(data) { return function(state) { if(state.active !== undefined) { data.forEach(function(series, i) { series.disabled = !state.active[i]; }); } } }; tooltip.contentGenerator(function(data) { var str = ''; if(data.series.length !== 0) { str = str + ''; data.series.forEach(function(d){ str = str + ''; }); str = str + ''; } str = str + '
' + data.key + '
' + d.key + '' + d.value + '
'; return str; }); //============================================================ // Chart function //------------------------------------------------------------ function chart(selection) { renderWatch.reset(); renderWatch.models(parallelCoordinates); selection.each(function(data) { var container = d3.select(this); nv.utils.initSVG(container); var that = this; var availableWidth = nv.utils.availableWidth(width, container, margin), availableHeight = nv.utils.availableHeight(height, container, margin); chart.update = function() { container.call(chart); }; chart.container = this; state.setter(stateSetter(dimensionData), chart.update) .getter(stateGetter(dimensionData)) .update(); //set state.disabled state.disabled = dimensionData.map(function (d) { return !!d.disabled }); //Keep dimensions position in memory dimensionData = dimensionData.map(function (d) {d.disabled = !!d.disabled; return d}); dimensionData.forEach(function (d, i) { d.originalPosition = isNaN(d.originalPosition) ? i : d.originalPosition; d.currentPosition = isNaN(d.currentPosition) ? i : d.currentPosition; }); if (!defaultState) { var key; defaultState = {}; for(key in state) { if(state[key] instanceof Array) defaultState[key] = state[key].slice(0); else defaultState[key] = state[key]; } } // Display No Data message if there's nothing to show. if(!data || !data.length) { nv.utils.noData(chart, container); return chart; } else { container.selectAll('.nv-noData').remove(); } //------------------------------------------------------------ // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-parallelCoordinatesChart').data([data]); var gEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-parallelCoordinatesChart').append('g'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-parallelCoordinatesWrap'); gEnter.append('g').attr('class', 'nv-legendWrap'); g.select("rect") .attr("width", availableWidth) .attr("height", (availableHeight > 0) ? availableHeight : 0); // Legend if (!showLegend) { g.select('.nv-legendWrap').selectAll('*').remove(); } else { legend.width(availableWidth) .color(function (d) { return "rgb(188,190,192)"; }); g.select('.nv-legendWrap') .datum(dimensionData.sort(function (a, b) { return a.originalPosition - b.originalPosition; })) .call(legend); if (!marginTop && legend.height() !== margin.top) { margin.top = legend.height(); availableHeight = nv.utils.availableHeight(height, container, margin); } wrap.select('.nv-legendWrap') .attr('transform', 'translate( 0 ,' + (-margin.top) + ')'); } wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); // Main Chart Component(s) parallelCoordinates .width(availableWidth) .height(availableHeight) .dimensionData(dimensionData) .displayBrush(displayBrush); var parallelCoordinatesWrap = g.select('.nv-parallelCoordinatesWrap ') .datum(data); parallelCoordinatesWrap.transition().call(parallelCoordinates); //============================================================ // Event Handling/Dispatching (in chart's scope) //------------------------------------------------------------ //Display reset brush button parallelCoordinates.dispatch.on('brushEnd', function (active, hasActiveBrush) { if (hasActiveBrush) { displayBrush = true; dispatch.brushEnd(active); } else { displayBrush = false; } }); legend.dispatch.on('stateChange', function(newState) { for(var key in newState) { state[key] = newState[key]; } dispatch.stateChange(state); chart.update(); }); //Update dimensions order and display reset sorting button parallelCoordinates.dispatch.on('dimensionsOrder', function (e) { dimensionData.sort(function (a, b) { return a.currentPosition - b.currentPosition; }); var isSorted = false; dimensionData.forEach(function (d, i) { d.currentPosition = i; if (d.currentPosition !== d.originalPosition) isSorted = true; }); dispatch.dimensionsOrder(dimensionData, isSorted); }); // Update chart from a state object passed to event handler dispatch.on('changeState', function (e) { if (typeof e.disabled !== 'undefined') { dimensionData.forEach(function (series, i) { series.disabled = e.disabled[i]; }); state.disabled = e.disabled; } chart.update(); }); }); renderWatch.renderEnd('parraleleCoordinateChart immediate'); return chart; } //============================================================ // Event Handling/Dispatching (out of chart's scope) //------------------------------------------------------------ parallelCoordinates.dispatch.on('elementMouseover.tooltip', function (evt) { var tp = { key: evt.label, color: evt.color, series: [] } if(evt.values){ Object.keys(evt.values).forEach(function (d) { var dim = evt.dimensions.filter(function (dd) {return dd.key === d;})[0]; if(dim){ var v; if (isNaN(evt.values[d]) || isNaN(parseFloat(evt.values[d]))) { v = nanValue; } else { v = dim.format(evt.values[d]); } tp.series.push({ idx: dim.currentPosition, key: d, value: v, color: dim.color }); } }); tp.series.sort(function(a,b) {return a.idx - b.idx}); } tooltip.data(tp).hidden(false); }); parallelCoordinates.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true) }); parallelCoordinates.dispatch.on('elementMousemove.tooltip', function () { tooltip(); }); //============================================================ // Expose Public Variables //------------------------------------------------------------ // expose chart's sub-components chart.dispatch = dispatch; chart.parallelCoordinates = parallelCoordinates; chart.legend = legend; chart.tooltip = tooltip; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: { get: function () { return width; }, set: function (_) { width = _; } }, height: { get: function () { return height; }, set: function (_) { height = _; } }, showLegend: { get: function () { return showLegend; }, set: function (_) { showLegend = _; } }, defaultState: { get: function () { return defaultState; }, set: function (_) { defaultState = _; } }, dimensionData: { get: function () { return dimensionData; }, set: function (_) { dimensionData = _; } }, displayBrush: { get: function () { return displayBrush; }, set: function (_) { displayBrush = _; } }, noData: { get: function () { return noData; }, set: function (_) { noData = _; } }, nanValue: { get: function () { return nanValue; }, set: function (_) { nanValue = _; } }, // options that require extra logic in the setter margin: { get: function () { return margin; }, set: function (_) { if (_.top !== undefined) { margin.top = _.top; marginTop = _.top; } margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; } }, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); legend.color(color); parallelCoordinates.color(color); }} }); nv.utils.inheritOptions(chart, parallelCoordinates); nv.utils.initOptions(chart); return chart; }; nv.models.pie = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 0, right: 0, bottom: 0, left: 0} , width = 500 , height = 500 , getX = function(d) { return d.x } , getY = function(d) { return d.y } , id = Math.floor(Math.random() * 10000) //Create semi-unique ID in case user doesn't select one , container = null , color = nv.utils.defaultColor() , valueFormat = d3.format(',.2f') , showLabels = true , labelsOutside = false , labelType = "key" , labelThreshold = .02 //if slice percentage is under this, don't show label , hideOverlapLabels = false //Hide labels that don't fit in slice , donut = false , title = false , growOnHover = true , titleOffset = 0 , labelSunbeamLayout = false , startAngle = false , padAngle = false , endAngle = false , cornerRadius = 0 , donutRatio = 0.5 , duration = 250 , arcsRadius = [] , dispatch = d3.dispatch('chartClick', 'elementClick', 'elementDblClick', 'elementMouseover', 'elementMouseout', 'elementMousemove', 'renderEnd') ; var arcs = []; var arcsOver = []; //============================================================ // chart function //------------------------------------------------------------ var renderWatch = nv.utils.renderWatch(dispatch); function chart(selection) { renderWatch.reset(); selection.each(function(data) { var availableWidth = width - margin.left - margin.right , availableHeight = height - margin.top - margin.bottom , radius = Math.min(availableWidth, availableHeight) / 2 , arcsRadiusOuter = [] , arcsRadiusInner = [] ; container = d3.select(this) if (arcsRadius.length === 0) { var outer = radius - radius / 10; var inner = donutRatio * radius; for (var i = 0; i < data[0].length; i++) { arcsRadiusOuter.push(outer); arcsRadiusInner.push(inner); } } else { if(growOnHover){ arcsRadiusOuter = arcsRadius.map(function (d) { return (d.outer - d.outer / 10) * radius; }); arcsRadiusInner = arcsRadius.map(function (d) { return (d.inner - d.inner / 10) * radius; }); donutRatio = d3.min(arcsRadius.map(function (d) { return (d.inner - d.inner / 10); })); } else { arcsRadiusOuter = arcsRadius.map(function (d) { return d.outer * radius; }); arcsRadiusInner = arcsRadius.map(function (d) { return d.inner * radius; }); donutRatio = d3.min(arcsRadius.map(function (d) { return d.inner; })); } } nv.utils.initSVG(container); // Setup containers and skeleton of chart var wrap = container.selectAll('.nv-wrap.nv-pie').data(data); var wrapEnter = wrap.enter().append('g').attr('class','nvd3 nv-wrap nv-pie nv-chart-' + id); var gEnter = wrapEnter.append('g'); var g = wrap.select('g'); var g_pie = gEnter.append('g').attr('class', 'nv-pie'); gEnter.append('g').attr('class', 'nv-pieLabels'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); g.select('.nv-pie').attr('transform', 'translate(' + availableWidth / 2 + ',' + availableHeight / 2 + ')'); g.select('.nv-pieLabels').attr('transform', 'translate(' + availableWidth / 2 + ',' + availableHeight / 2 + ')'); // container.on('click', function(d,i) { dispatch.chartClick({ data: d, index: i, pos: d3.event, id: id }); }); arcs = []; arcsOver = []; for (var i = 0; i < data[0].length; i++) { var arc = d3.svg.arc().outerRadius(arcsRadiusOuter[i]); var arcOver = d3.svg.arc().outerRadius(arcsRadiusOuter[i] + 5); if (startAngle !== false) { arc.startAngle(startAngle); arcOver.startAngle(startAngle); } if (endAngle !== false) { arc.endAngle(endAngle); arcOver.endAngle(endAngle); } if (donut) { arc.innerRadius(arcsRadiusInner[i]); arcOver.innerRadius(arcsRadiusInner[i]); } if (arc.cornerRadius && cornerRadius) { arc.cornerRadius(cornerRadius); arcOver.cornerRadius(cornerRadius); } arcs.push(arc); arcsOver.push(arcOver); } // Setup the Pie chart and choose the data element var pie = d3.layout.pie() .sort(null) .value(function(d) { return d.disabled ? 0 : getY(d) }); // padAngle added in d3 3.5 if (pie.padAngle && padAngle) { pie.padAngle(padAngle); } // if title is specified and donut, put it in the middle if (donut && title) { g_pie.append("text").attr('class', 'nv-pie-title'); wrap.select('.nv-pie-title') .style("text-anchor", "middle") .text(function (d) { return title; }) .style("font-size", (Math.min(availableWidth, availableHeight)) * donutRatio * 2 / (title.length + 2) + "px") .attr("dy", "0.35em") // trick to vertically center text .attr('transform', function(d, i) { return 'translate(0, '+ titleOffset + ')'; }); } var slices = wrap.select('.nv-pie').selectAll('.nv-slice').data(pie); var pieLabels = wrap.select('.nv-pieLabels').selectAll('.nv-label').data(pie); slices.exit().remove(); pieLabels.exit().remove(); var ae = slices.enter().append('g'); ae.attr('class', 'nv-slice'); ae.on('mouseover', function(d, i) { d3.select(this).classed('hover', true); if (growOnHover) { d3.select(this).select("path").transition() .duration(70) .attr("d", arcsOver[i]); } dispatch.elementMouseover({ data: d.data, index: i, color: d3.select(this).style("fill"), percent: (d.endAngle - d.startAngle) / (2 * Math.PI) }); }); ae.on('mouseout', function(d, i) { d3.select(this).classed('hover', false); if (growOnHover) { d3.select(this).select("path").transition() .duration(50) .attr("d", arcs[i]); } dispatch.elementMouseout({data: d.data, index: i}); }); ae.on('mousemove', function(d, i) { dispatch.elementMousemove({data: d.data, index: i}); }); ae.on('click', function(d, i) { var element = this; dispatch.elementClick({ data: d.data, index: i, color: d3.select(this).style("fill"), event: d3.event, element: element }); }); ae.on('dblclick', function(d, i) { dispatch.elementDblClick({ data: d.data, index: i, color: d3.select(this).style("fill") }); }); slices.attr('fill', function(d,i) { return color(d.data, i); }); slices.attr('stroke', function(d,i) { return color(d.data, i); }); var paths = ae.append('path').each(function(d) { this._current = d; }); slices.select('path') .transition() .duration(duration) .attr('d', function (d, i) { return arcs[i](d); }) .attrTween('d', arcTween); if (showLabels) { // This does the normal label var labelsArc = []; for (var i = 0; i < data[0].length; i++) { labelsArc.push(arcs[i]); if (labelsOutside) { if (donut) { labelsArc[i] = d3.svg.arc().outerRadius(arcs[i].outerRadius()); if (startAngle !== false) labelsArc[i].startAngle(startAngle); if (endAngle !== false) labelsArc[i].endAngle(endAngle); } } else if (!donut) { labelsArc[i].innerRadius(0); } } pieLabels.enter().append("g").classed("nv-label",true).each(function(d,i) { var group = d3.select(this); group.attr('transform', function (d, i) { if (labelSunbeamLayout) { d.outerRadius = arcsRadiusOuter[i] + 10; // Set Outer Coordinate d.innerRadius = arcsRadiusOuter[i] + 15; // Set Inner Coordinate var rotateAngle = (d.startAngle + d.endAngle) / 2 * (180 / Math.PI); if ((d.startAngle + d.endAngle) / 2 < Math.PI) { rotateAngle -= 90; } else { rotateAngle += 90; } return 'translate(' + labelsArc[i].centroid(d) + ') rotate(' + rotateAngle + ')'; } else { d.outerRadius = radius + 10; // Set Outer Coordinate d.innerRadius = radius + 15; // Set Inner Coordinate return 'translate(' + labelsArc[i].centroid(d) + ')' } }); group.append('rect') .style('stroke', '#fff') .style('fill', '#fff') .attr("rx", 3) .attr("ry", 3); group.append('text') .style('text-anchor', labelSunbeamLayout ? ((d.startAngle + d.endAngle) / 2 < Math.PI ? 'start' : 'end') : 'middle') //center the text on it's origin or begin/end if orthogonal aligned .style('fill', '#000') }); var labelLocationHash = {}; var avgHeight = 14; var avgWidth = 140; var createHashKey = function(coordinates) { return Math.floor(coordinates[0]/avgWidth) * avgWidth + ',' + Math.floor(coordinates[1]/avgHeight) * avgHeight; }; var getSlicePercentage = function(d) { return (d.endAngle - d.startAngle) / (2 * Math.PI); }; pieLabels.watchTransition(renderWatch, 'pie labels').attr('transform', function (d, i) { if (labelSunbeamLayout) { d.outerRadius = arcsRadiusOuter[i] + 10; // Set Outer Coordinate d.innerRadius = arcsRadiusOuter[i] + 15; // Set Inner Coordinate var rotateAngle = (d.startAngle + d.endAngle) / 2 * (180 / Math.PI); if ((d.startAngle + d.endAngle) / 2 < Math.PI) { rotateAngle -= 90; } else { rotateAngle += 90; } return 'translate(' + labelsArc[i].centroid(d) + ') rotate(' + rotateAngle + ')'; } else { d.outerRadius = radius + 10; // Set Outer Coordinate d.innerRadius = radius + 15; // Set Inner Coordinate /* Overlapping pie labels are not good. What this attempts to do is, prevent overlapping. Each label location is hashed, and if a hash collision occurs, we assume an overlap. Adjust the label's y-position to remove the overlap. */ var center = labelsArc[i].centroid(d); var percent = getSlicePercentage(d); if (d.value && percent >= labelThreshold) { var hashKey = createHashKey(center); if (labelLocationHash[hashKey]) { center[1] -= avgHeight; } labelLocationHash[createHashKey(center)] = true; } return 'translate(' + center + ')' } }); pieLabels.select(".nv-label text") .style('text-anchor', function(d,i) { //center the text on it's origin or begin/end if orthogonal aligned return labelSunbeamLayout ? ((d.startAngle + d.endAngle) / 2 < Math.PI ? 'start' : 'end') : 'middle'; }) .text(function(d, i) { var percent = getSlicePercentage(d); var label = ''; if (!d.value || percent < labelThreshold) return ''; if(typeof labelType === 'function') { label = labelType(d, i, { 'key': getX(d.data), 'value': getY(d.data), 'percent': valueFormat(percent) }); } else { switch (labelType) { case 'key': label = getX(d.data); break; case 'value': label = valueFormat(getY(d.data)); break; case 'percent': label = d3.format('%')(percent); break; } } return label; }) ; if (hideOverlapLabels) { pieLabels .each(function (d, i) { if (!this.getBBox) return; var bb = this.getBBox(), center = labelsArc[i].centroid(d); var topLeft = { x : center[0] + bb.x, y : center[1] + bb.y }; var topRight = { x : topLeft.x + bb.width, y : topLeft.y }; var bottomLeft = { x : topLeft.x, y : topLeft.y + bb.height }; var bottomRight = { x : topLeft.x + bb.width, y : topLeft.y + bb.height }; d.visible = nv.utils.pointIsInArc(topLeft, d, arc) && nv.utils.pointIsInArc(topRight, d, arc) && nv.utils.pointIsInArc(bottomLeft, d, arc) && nv.utils.pointIsInArc(bottomRight, d, arc); }) .style('display', function (d) { return d.visible ? null : 'none'; }) ; } } // Computes the angle of an arc, converting from radians to degrees. function angle(d) { var a = (d.startAngle + d.endAngle) * 90 / Math.PI - 90; return a > 90 ? a - 180 : a; } function arcTween(a, idx) { a.endAngle = isNaN(a.endAngle) ? 0 : a.endAngle; a.startAngle = isNaN(a.startAngle) ? 0 : a.startAngle; if (!donut) a.innerRadius = 0; var i = d3.interpolate(this._current, a); this._current = i(0); return function (t) { return arcs[idx](i(t)); }; } }); renderWatch.renderEnd('pie immediate'); return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.dispatch = dispatch; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values arcsRadius: { get: function () { return arcsRadius; }, set: function (_) { arcsRadius = _; } }, width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, showLabels: {get: function(){return showLabels;}, set: function(_){showLabels=_;}}, title: {get: function(){return title;}, set: function(_){title=_;}}, titleOffset: {get: function(){return titleOffset;}, set: function(_){titleOffset=_;}}, labelThreshold: {get: function(){return labelThreshold;}, set: function(_){labelThreshold=_;}}, hideOverlapLabels: {get: function(){return hideOverlapLabels;}, set: function(_){hideOverlapLabels=_;}}, valueFormat: {get: function(){return valueFormat;}, set: function(_){valueFormat=_;}}, x: {get: function(){return getX;}, set: function(_){getX=_;}}, id: {get: function(){return id;}, set: function(_){id=_;}}, endAngle: {get: function(){return endAngle;}, set: function(_){endAngle=_;}}, startAngle: {get: function(){return startAngle;}, set: function(_){startAngle=_;}}, padAngle: {get: function(){return padAngle;}, set: function(_){padAngle=_;}}, cornerRadius: {get: function(){return cornerRadius;}, set: function(_){cornerRadius=_;}}, donutRatio: {get: function(){return donutRatio;}, set: function(_){donutRatio=_;}}, labelsOutside: {get: function(){return labelsOutside;}, set: function(_){labelsOutside=_;}}, labelSunbeamLayout: {get: function(){return labelSunbeamLayout;}, set: function(_){labelSunbeamLayout=_;}}, donut: {get: function(){return donut;}, set: function(_){donut=_;}}, growOnHover: {get: function(){return growOnHover;}, set: function(_){growOnHover=_;}}, // depreciated after 1.7.1 pieLabelsOutside: {get: function(){return labelsOutside;}, set: function(_){ labelsOutside=_; nv.deprecated('pieLabelsOutside', 'use labelsOutside instead'); }}, // depreciated after 1.7.1 donutLabelsOutside: {get: function(){return labelsOutside;}, set: function(_){ labelsOutside=_; nv.deprecated('donutLabelsOutside', 'use labelsOutside instead'); }}, // deprecated after 1.7.1 labelFormat: {get: function(){ return valueFormat;}, set: function(_) { valueFormat=_; nv.deprecated('labelFormat','use valueFormat instead'); }}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = typeof _.top != 'undefined' ? _.top : margin.top; margin.right = typeof _.right != 'undefined' ? _.right : margin.right; margin.bottom = typeof _.bottom != 'undefined' ? _.bottom : margin.bottom; margin.left = typeof _.left != 'undefined' ? _.left : margin.left; }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; renderWatch.reset(duration); }}, y: {get: function(){return getY;}, set: function(_){ getY=d3.functor(_); }}, color: {get: function(){return color;}, set: function(_){ color=nv.utils.getColor(_); }}, labelType: {get: function(){return labelType;}, set: function(_){ labelType= _ || 'key'; }} }); nv.utils.initOptions(chart); return chart; }; nv.models.pieChart = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var pie = nv.models.pie(); var legend = nv.models.legend(); var tooltip = nv.models.tooltip(); var margin = {top: 30, right: 20, bottom: 20, left: 20} , marginTop = null , width = null , height = null , showTooltipPercent = false , showLegend = true , legendPosition = "top" , color = nv.utils.defaultColor() , state = nv.utils.state() , defaultState = null , noData = null , duration = 250 , dispatch = d3.dispatch('stateChange', 'changeState','renderEnd') ; tooltip .duration(0) .headerEnabled(false) .valueFormatter(function(d, i) { return pie.valueFormat()(d, i); }); //============================================================ // Private Variables //------------------------------------------------------------ var renderWatch = nv.utils.renderWatch(dispatch); var stateGetter = function(data) { return function(){ return { active: data.map(function(d) { return !d.disabled }) }; } }; var stateSetter = function(data) { return function(state) { if (state.active !== undefined) { data.forEach(function (series, i) { series.disabled = !state.active[i]; }); } } }; //============================================================ // Chart function //------------------------------------------------------------ function chart(selection) { renderWatch.reset(); renderWatch.models(pie); selection.each(function(data) { var container = d3.select(this); nv.utils.initSVG(container); var that = this; var availableWidth = nv.utils.availableWidth(width, container, margin), availableHeight = nv.utils.availableHeight(height, container, margin); chart.update = function() { container.transition().call(chart); }; chart.container = this; state.setter(stateSetter(data), chart.update) .getter(stateGetter(data)) .update(); //set state.disabled state.disabled = data.map(function(d) { return !!d.disabled }); if (!defaultState) { var key; defaultState = {}; for (key in state) { if (state[key] instanceof Array) defaultState[key] = state[key].slice(0); else defaultState[key] = state[key]; } } // Display No Data message if there's nothing to show. if (!data || !data.length) { nv.utils.noData(chart, container); return chart; } else { container.selectAll('.nv-noData').remove(); } // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-pieChart').data([data]); var gEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-pieChart').append('g'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-pieWrap'); gEnter.append('g').attr('class', 'nv-legendWrap'); // Legend if (!showLegend) { g.select('.nv-legendWrap').selectAll('*').remove(); } else { if (legendPosition === "top") { legend.width( availableWidth ).key(pie.x()); wrap.select('.nv-legendWrap') .datum(data) .call(legend); if (!marginTop && legend.height() !== margin.top) { margin.top = legend.height(); availableHeight = nv.utils.availableHeight(height, container, margin); } wrap.select('.nv-legendWrap') .attr('transform', 'translate(0,' + (-margin.top) +')'); } else if (legendPosition === "right") { var legendWidth = nv.models.legend().width(); if (availableWidth / 2 < legendWidth) { legendWidth = (availableWidth / 2) } legend.height(availableHeight).key(pie.x()); legend.width(legendWidth); availableWidth -= legend.width(); wrap.select('.nv-legendWrap') .datum(data) .call(legend) .attr('transform', 'translate(' + (availableWidth) +',0)'); } else if (legendPosition === "bottom") { legend.width( availableWidth ).key(pie.x()); wrap.select('.nv-legendWrap') .datum(data) .call(legend); margin.bottom = legend.height(); availableHeight = nv.utils.availableHeight(height, container, margin); wrap.select('.nv-legendWrap') .attr('transform', 'translate(0,' + availableHeight +')'); } } wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); // Main Chart Component(s) pie.width(availableWidth).height(availableHeight); var pieWrap = g.select('.nv-pieWrap').datum([data]); d3.transition(pieWrap).call(pie); //============================================================ // Event Handling/Dispatching (in chart's scope) //------------------------------------------------------------ legend.dispatch.on('stateChange', function(newState) { for (var key in newState) { state[key] = newState[key]; } dispatch.stateChange(state); chart.update(); }); // Update chart from a state object passed to event handler dispatch.on('changeState', function(e) { if (typeof e.disabled !== 'undefined') { data.forEach(function(series,i) { series.disabled = e.disabled[i]; }); state.disabled = e.disabled; } chart.update(); }); }); renderWatch.renderEnd('pieChart immediate'); return chart; } //============================================================ // Event Handling/Dispatching (out of chart's scope) //------------------------------------------------------------ pie.dispatch.on('elementMouseover.tooltip', function(evt) { evt['series'] = { key: chart.x()(evt.data), value: chart.y()(evt.data), color: evt.color, percent: evt.percent }; if (!showTooltipPercent) { delete evt.percent; delete evt.series.percent; } tooltip.data(evt).hidden(false); }); pie.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true); }); pie.dispatch.on('elementMousemove.tooltip', function(evt) { tooltip(); }); //============================================================ // Expose Public Variables //------------------------------------------------------------ // expose chart's sub-components chart.legend = legend; chart.dispatch = dispatch; chart.pie = pie; chart.tooltip = tooltip; chart.options = nv.utils.optionsFunc.bind(chart); // use Object get/set functionality to map between vars and chart functions chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, noData: {get: function(){return noData;}, set: function(_){noData=_;}}, showTooltipPercent: {get: function(){return showTooltipPercent;}, set: function(_){showTooltipPercent=_;}}, showLegend: {get: function(){return showLegend;}, set: function(_){showLegend=_;}}, legendPosition: {get: function(){return legendPosition;}, set: function(_){legendPosition=_;}}, defaultState: {get: function(){return defaultState;}, set: function(_){defaultState=_;}}, // options that require extra logic in the setter color: {get: function(){return color;}, set: function(_){ color = _; legend.color(color); pie.color(color); }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; renderWatch.reset(duration); pie.duration(duration); }}, margin: {get: function(){return margin;}, set: function(_){ if (_.top !== undefined) { margin.top = _.top; marginTop = _.top; } margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }} }); nv.utils.inheritOptions(chart, pie); nv.utils.initOptions(chart); return chart; }; nv.models.sankey = function() { 'use strict'; // Sources: // - https://bost.ocks.org/mike/sankey/ // - https://github.com/soxofaan/d3-plugin-captain-sankey //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var sankey = {}, nodeWidth = 24, nodePadding = 8, size = [1, 1], nodes = [], links = [], sinksRight = true; var layout = function(iterations) { computeNodeLinks(); computeNodeValues(); computeNodeBreadths(); computeNodeDepths(iterations); }; var relayout = function() { computeLinkDepths(); }; // SVG path data generator, to be used as 'd' attribute on 'path' element selection. var link = function() { var curvature = .5; function link(d) { var x0 = d.source.x + d.source.dx, x1 = d.target.x, xi = d3.interpolateNumber(x0, x1), x2 = xi(curvature), x3 = xi(1 - curvature), y0 = d.source.y + d.sy + d.dy / 2, y1 = d.target.y + d.ty + d.dy / 2; var linkPath = 'M' + x0 + ',' + y0 + 'C' + x2 + ',' + y0 + ' ' + x3 + ',' + y1 + ' ' + x1 + ',' + y1; return linkPath; } link.curvature = function(_) { if (!arguments.length) return curvature; curvature = +_; return link; }; return link; }; // Y-position of the middle of a node. var center = function(node) { return node.y + node.dy / 2; }; //============================================================ // Private Variables //------------------------------------------------------------ // Populate the sourceLinks and targetLinks for each node. // Also, if the source and target are not objects, assume they are indices. function computeNodeLinks() { nodes.forEach(function(node) { // Links that have this node as source. node.sourceLinks = []; // Links that have this node as target. node.targetLinks = []; }); links.forEach(function(link) { var source = link.source, target = link.target; if (typeof source === 'number') source = link.source = nodes[link.source]; if (typeof target === 'number') target = link.target = nodes[link.target]; source.sourceLinks.push(link); target.targetLinks.push(link); }); } // Compute the value (size) of each node by summing the associated links. function computeNodeValues() { nodes.forEach(function(node) { node.value = Math.max( d3.sum(node.sourceLinks, value), d3.sum(node.targetLinks, value) ); }); } // Iteratively assign the breadth (x-position) for each node. // Nodes are assigned the maximum breadth of incoming neighbors plus one; // nodes with no incoming links are assigned breadth zero, while // nodes with no outgoing links are assigned the maximum breadth. function computeNodeBreadths() { // var remainingNodes = nodes, nextNodes, x = 0; // Work from left to right. // Keep updating the breath (x-position) of nodes that are target of recently updated nodes. // while (remainingNodes.length && x < nodes.length) { nextNodes = []; remainingNodes.forEach(function(node) { node.x = x; node.dx = nodeWidth; node.sourceLinks.forEach(function(link) { if (nextNodes.indexOf(link.target) < 0) { nextNodes.push(link.target); } }); }); remainingNodes = nextNodes; ++x; // } // Optionally move pure sinks always to the right. if (sinksRight) { moveSinksRight(x); } scaleNodeBreadths((size[0] - nodeWidth) / (x - 1)); } function moveSourcesRight() { nodes.forEach(function(node) { if (!node.targetLinks.length) { node.x = d3.min(node.sourceLinks, function(d) { return d.target.x; }) - 1; } }); } function moveSinksRight(x) { nodes.forEach(function(node) { if (!node.sourceLinks.length) { node.x = x - 1; } }); } function scaleNodeBreadths(kx) { nodes.forEach(function(node) { node.x *= kx; }); } // Compute the depth (y-position) for each node. function computeNodeDepths(iterations) { // Group nodes by breath. var nodesByBreadth = d3.nest() .key(function(d) { return d.x; }) .sortKeys(d3.ascending) .entries(nodes) .map(function(d) { return d.values; }); // initializeNodeDepth(); resolveCollisions(); computeLinkDepths(); for (var alpha = 1; iterations > 0; --iterations) { relaxRightToLeft(alpha *= .99); resolveCollisions(); computeLinkDepths(); relaxLeftToRight(alpha); resolveCollisions(); computeLinkDepths(); } function initializeNodeDepth() { // Calculate vertical scaling factor. var ky = d3.min(nodesByBreadth, function(nodes) { return (size[1] - (nodes.length - 1) * nodePadding) / d3.sum(nodes, value); }); nodesByBreadth.forEach(function(nodes) { nodes.forEach(function(node, i) { node.y = i; node.dy = node.value * ky; }); }); links.forEach(function(link) { link.dy = link.value * ky; }); } function relaxLeftToRight(alpha) { nodesByBreadth.forEach(function(nodes, breadth) { nodes.forEach(function(node) { if (node.targetLinks.length) { // Value-weighted average of the y-position of source node centers linked to this node. var y = d3.sum(node.targetLinks, weightedSource) / d3.sum(node.targetLinks, value); node.y += (y - center(node)) * alpha; } }); }); function weightedSource(link) { return (link.source.y + link.sy + link.dy / 2) * link.value; } } function relaxRightToLeft(alpha) { nodesByBreadth.slice().reverse().forEach(function(nodes) { nodes.forEach(function(node) { if (node.sourceLinks.length) { // Value-weighted average of the y-positions of target nodes linked to this node. var y = d3.sum(node.sourceLinks, weightedTarget) / d3.sum(node.sourceLinks, value); node.y += (y - center(node)) * alpha; } }); }); function weightedTarget(link) { return (link.target.y + link.ty + link.dy / 2) * link.value; } } function resolveCollisions() { nodesByBreadth.forEach(function(nodes) { var node, dy, y0 = 0, n = nodes.length, i; // Push any overlapping nodes down. nodes.sort(ascendingDepth); for (i = 0; i < n; ++i) { node = nodes[i]; dy = y0 - node.y; if (dy > 0) node.y += dy; y0 = node.y + node.dy + nodePadding; } // If the bottommost node goes outside the bounds, push it back up. dy = y0 - nodePadding - size[1]; if (dy > 0) { y0 = node.y -= dy; // Push any overlapping nodes back up. for (i = n - 2; i >= 0; --i) { node = nodes[i]; dy = node.y + node.dy + nodePadding - y0; if (dy > 0) node.y -= dy; y0 = node.y; } } }); } function ascendingDepth(a, b) { return a.y - b.y; } } // Compute y-offset of the source endpoint (sy) and target endpoints (ty) of links, // relative to the source/target node's y-position. function computeLinkDepths() { nodes.forEach(function(node) { node.sourceLinks.sort(ascendingTargetDepth); node.targetLinks.sort(ascendingSourceDepth); }); nodes.forEach(function(node) { var sy = 0, ty = 0; node.sourceLinks.forEach(function(link) { link.sy = sy; sy += link.dy; }); node.targetLinks.forEach(function(link) { link.ty = ty; ty += link.dy; }); }); function ascendingSourceDepth(a, b) { return a.source.y - b.source.y; } function ascendingTargetDepth(a, b) { return a.target.y - b.target.y; } } // Value property accessor. function value(x) { return x.value; } sankey.options = nv.utils.optionsFunc.bind(sankey); sankey._options = Object.create({}, { nodeWidth: {get: function(){return nodeWidth;}, set: function(_){nodeWidth=+_;}}, nodePadding: {get: function(){return nodePadding;}, set: function(_){nodePadding=_;}}, nodes: {get: function(){return nodes;}, set: function(_){nodes=_;}}, links: {get: function(){return links ;}, set: function(_){links=_;}}, size: {get: function(){return size;}, set: function(_){size=_;}}, sinksRight: {get: function(){return sinksRight;}, set: function(_){sinksRight=_;}}, layout: {get: function(){layout(32);}, set: function(_){layout(_);}}, relayout: {get: function(){relayout();}, set: function(_){}}, center: {get: function(){return center();}, set: function(_){ if(typeof _ === 'function'){ center=_; } }}, link: {get: function(){return link();}, set: function(_){ if(typeof _ === 'function'){ link=_; } return link(); }} }); nv.utils.initOptions(sankey); return sankey; }; nv.models.sankeyChart = function() { "use strict"; // Sources: // - https://bost.ocks.org/mike/sankey/ // - https://github.com/soxofaan/d3-plugin-captain-sankey //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 5, right: 0, bottom: 5, left: 0} , sankey = nv.models.sankey() , width = 600 , height = 400 , nodeWidth = 36 , nodePadding = 40 , units = 'units' , center = undefined ; //============================================================ // Private Variables //------------------------------------------------------------ var formatNumber = d3.format(',.0f'); // zero decimal places var format = function(d) { return formatNumber(d) + ' ' + units; }; var color = d3.scale.category20(); var linkTitle = function(d){ return d.source.name + ' → ' + d.target.name + '\n' + format(d.value); }; var nodeFillColor = function(d){ return d.color = color(d.name.replace(/ .*/, '')); }; var nodeStrokeColor = function(d){ return d3.rgb(d.color).darker(2); }; var nodeTitle = function(d){ return d.name + '\n' + format(d.value); }; var showError = function(element, message) { element.append('text') .attr('x', 0) .attr('y', 0) .attr('class', 'nvd3-sankey-chart-error') .attr('text-anchor', 'middle') .text(message); }; function chart(selection) { selection.each(function(data) { var testData = { nodes: [ {'node': 1, 'name': 'Test 1'}, {'node': 2, 'name': 'Test 2'}, {'node': 3, 'name': 'Test 3'}, {'node': 4, 'name': 'Test 4'}, {'node': 5, 'name': 'Test 5'}, {'node': 6, 'name': 'Test 6'} ], links: [ {'source': 0, 'target': 1, 'value': 2295}, {'source': 0, 'target': 5, 'value': 1199}, {'source': 1, 'target': 2, 'value': 1119}, {'source': 1, 'target': 5, 'value': 1176}, {'source': 2, 'target': 3, 'value': 487}, {'source': 2, 'target': 5, 'value': 632}, {'source': 3, 'target': 4, 'value': 301}, {'source': 3, 'target': 5, 'value': 186} ] }; // Error handling var isDataValid = false; var dataAvailable = false; // check if data is valid if( (typeof data['nodes'] === 'object' && data['nodes'].length) >= 0 && (typeof data['links'] === 'object' && data['links'].length) >= 0 ){ isDataValid = true; } // check if data is available if( data['nodes'] && data['nodes'].length > 0 && data['links'] && data['links'].length > 0 ) { dataAvailable = true; } // show error if(!isDataValid) { console.error('NVD3 Sankey chart error:', 'invalid data format for', data); console.info('Valid data format is: ', testData, JSON.stringify(testData)); showError(selection, 'Error loading chart, data is invalid'); return false; } // TODO use nv.utils.noData if(!dataAvailable) { showError(selection, 'No data available'); return false; } // No errors, continue // append the svg canvas to the page var svg = selection.append('svg') .attr('width', width) .attr('height', height) .append('g') .attr('class', 'nvd3 nv-wrap nv-sankeyChart'); // Set the sankey diagram properties sankey .nodeWidth(nodeWidth) .nodePadding(nodePadding) .size([width, height]); var path = sankey.link(); sankey .nodes(data.nodes) .links(data.links) .layout(32) .center(center); // add in the links var link = svg.append('g').selectAll('.link') .data(data.links) .enter().append('path') .attr('class', 'link') .attr('d', path) .style('stroke-width', function(d) { return Math.max(1, d.dy); }) .sort(function(a,b) { return b.dy - a.dy; }); // add the link titles link.append('title') .text(linkTitle); // add in the nodes var node = svg.append('g').selectAll('.node') .data(data.nodes) .enter().append('g') .attr('class', 'node') .attr('transform', function(d) { return 'translate(' + d.x + ',' + d.y + ')'; }) .call( d3.behavior .drag() .origin(function(d) { return d; }) .on('dragstart', function() { this.parentNode.appendChild(this); }) .on('drag', dragmove) ); // add the rectangles for the nodes node.append('rect') .attr('height', function(d) { return d.dy; }) .attr('width', sankey.nodeWidth()) .style('fill', nodeFillColor) .style('stroke', nodeStrokeColor) .append('title') .text(nodeTitle); // add in the title for the nodes node.append('text') .attr('x', -6) .attr('y', function(d) { return d.dy / 2; }) .attr('dy', '.35em') .attr('text-anchor', 'end') .attr('transform', null) .text(function(d) { return d.name; }) .filter(function(d) { return d.x < width / 2; }) .attr('x', 6 + sankey.nodeWidth()) .attr('text-anchor', 'start'); // the function for moving the nodes function dragmove(d) { d3.select(this).attr('transform', 'translate(' + d.x + ',' + ( d.y = Math.max(0, Math.min(height - d.dy, d3.event.y)) ) + ')'); sankey.relayout(); link.attr('d', path); } }); return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values units: {get: function(){return units;}, set: function(_){units=_;}}, width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, format: {get: function(){return format;}, set: function(_){format=_;}}, linkTitle: {get: function(){return linkTitle;}, set: function(_){linkTitle=_;}}, nodeWidth: {get: function(){return nodeWidth;}, set: function(_){nodeWidth=_;}}, nodePadding: {get: function(){return nodePadding;}, set: function(_){nodePadding=_;}}, center: {get: function(){return center}, set: function(_){center=_}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, nodeStyle: {get: function(){return {};}, set: function(_){ nodeFillColor = _.fillColor !== undefined ? _.fillColor : nodeFillColor; nodeStrokeColor = _.strokeColor !== undefined ? _.strokeColor : nodeStrokeColor; nodeTitle = _.title !== undefined ? _.title : nodeTitle; }} }); nv.utils.initOptions(chart); return chart; }; nv.models.scatter = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 0, right: 0, bottom: 0, left: 0} , width = null , height = null , color = nv.utils.defaultColor() // chooses color , pointBorderColor = null , id = Math.floor(Math.random() * 100000) //Create semi-unique ID incase user doesn't select one , container = null , x = d3.scale.linear() , y = d3.scale.linear() , z = d3.scale.linear() //linear because d3.svg.shape.size is treated as area , getX = function(d) { return d.x } // accessor to get the x value , getY = function(d) { return d.y } // accessor to get the y value , getSize = function(d) { return d.size || 1} // accessor to get the point size , getShape = function(d) { return d.shape || 'circle' } // accessor to get point shape , forceX = [] // List of numbers to Force into the X scale (ie. 0, or a max / min, etc.) , forceY = [] // List of numbers to Force into the Y scale , forceSize = [] // List of numbers to Force into the Size scale , interactive = true // If true, plots a voronoi overlay for advanced point intersection , pointActive = function(d) { return !d.notActive } // any points that return false will be filtered out , padData = false // If true, adds half a data points width to front and back, for lining up a line chart with a bar chart , padDataOuter = .1 //outerPadding to imitate ordinal scale outer padding , clipEdge = false // if true, masks points within x and y scale , clipVoronoi = true // if true, masks each point with a circle... can turn off to slightly increase performance , showVoronoi = false // display the voronoi areas , clipRadius = function() { return 25 } // function to get the radius for voronoi point clips , xDomain = null // Override x domain (skips the calculation from data) , yDomain = null // Override y domain , xRange = null // Override x range , yRange = null // Override y range , sizeDomain = null // Override point size domain , sizeRange = null , singlePoint = false , dispatch = d3.dispatch('elementClick', 'elementDblClick', 'elementMouseover', 'elementMouseout', 'renderEnd') , useVoronoi = true , duration = 250 , interactiveUpdateDelay = 300 , showLabels = false ; //============================================================ // Private Variables //------------------------------------------------------------ var x0, y0, z0 // used to store previous scales , xDom, yDom // used to store previous domains , width0 , height0 , timeoutID , needsUpdate = false // Flag for when the points are visually updating, but the interactive layer is behind, to disable tooltips , renderWatch = nv.utils.renderWatch(dispatch, duration) , _sizeRange_def = [16, 256] , _cache = {} ; //============================================================ // Diff and Cache Utilities //------------------------------------------------------------ // getDiffs is used to filter unchanged points from the update // selection. It implicitly updates it's cache when called and // therefor the diff is based upon the previous invocation NOT // the previous update. // // getDiffs takes a point as its first argument followed by n // key getter pairs (d, [key, get... key, get]) this approach // was chosen for efficiency. (The filter will call it a LOT). // // It is important to call delCache on point exit to prevent a // memory leak. It is also needed to prevent invalid caches if // a new point uses the same series and point id key. // // Argument Performance Concerns: // - Object property lists for key getter pairs would be very // expensive (points * objects for the GC every update). // - ES6 function names for implicit keys would be nice but // they are not guaranteed to be unique. // - function.toString to obtain implicit keys is possible // but long object keys are not free (internal hash). // - Explicit key without objects are the most efficient. function getCache(d) { var key, val; key = d[0].series + ':' + d[1]; val = _cache[key] = _cache[key] || {}; return val; } function delCache(d) { var key, val; key = d[0].series + ':' + d[1]; delete _cache[key]; } function getDiffs(d) { var i, key, val, cache = getCache(d), diffs = false; for (i = 1; i < arguments.length; i += 2) { key = arguments[i]; val = arguments[i + 1](d[0], d[1]); if (cache[key] !== val || !cache.hasOwnProperty(key)) { cache[key] = val; diffs = true; } } return diffs; } function chart(selection) { renderWatch.reset(); selection.each(function(data) { container = d3.select(this); var availableWidth = nv.utils.availableWidth(width, container, margin), availableHeight = nv.utils.availableHeight(height, container, margin); nv.utils.initSVG(container); //add series index to each data point for reference data.forEach(function(series, i) { series.values.forEach(function(point) { point.series = i; }); }); // Setup Scales var logScale = (typeof(chart.yScale().base) === "function"); // Only log scale has a method "base()" // remap and flatten the data for use in calculating the scales' domains var seriesData = (xDomain && yDomain && sizeDomain) ? [] : // if we know xDomain and yDomain and sizeDomain, no need to calculate.... if Size is constant remember to set sizeDomain to speed up performance d3.merge( data.map(function(d) { return d.values.map(function(d,i) { return { x: getX(d,i), y: getY(d,i), size: getSize(d,i) } }) }) ); x .domain(xDomain || d3.extent(seriesData.map(function(d) { return d.x; }).concat(forceX))) if (padData && data[0]) x.range(xRange || [(availableWidth * padDataOuter + availableWidth) / (2 *data[0].values.length), availableWidth - availableWidth * (1 + padDataOuter) / (2 * data[0].values.length) ]); //x.range([availableWidth * .5 / data[0].values.length, availableWidth * (data[0].values.length - .5) / data[0].values.length ]); else x.range(xRange || [0, availableWidth]); if (logScale) { var min = d3.min(seriesData.map(function(d) { if (d.y !== 0) return d.y; })); y.clamp(true) .domain(yDomain || d3.extent(seriesData.map(function(d) { if (d.y !== 0) return d.y; else return min * 0.1; }).concat(forceY))) .range(yRange || [availableHeight, 0]); } else { y.domain(yDomain || d3.extent(seriesData.map(function (d) { return d.y;}).concat(forceY))) .range(yRange || [availableHeight, 0]); } z .domain(sizeDomain || d3.extent(seriesData.map(function(d) { return d.size }).concat(forceSize))) .range(sizeRange || _sizeRange_def); // If scale's domain don't have a range, slightly adjust to make one... so a chart can show a single data point singlePoint = x.domain()[0] === x.domain()[1] || y.domain()[0] === y.domain()[1]; if (x.domain()[0] === x.domain()[1]) x.domain()[0] ? x.domain([x.domain()[0] - x.domain()[0] * 0.01, x.domain()[1] + x.domain()[1] * 0.01]) : x.domain([-1,1]); if (y.domain()[0] === y.domain()[1]) y.domain()[0] ? y.domain([y.domain()[0] - y.domain()[0] * 0.01, y.domain()[1] + y.domain()[1] * 0.01]) : y.domain([-1,1]); if ( isNaN(x.domain()[0])) { x.domain([-1,1]); } if ( isNaN(y.domain()[0])) { y.domain([-1,1]); } x0 = x0 || x; y0 = y0 || y; z0 = z0 || z; var scaleDiff = x(1) !== x0(1) || y(1) !== y0(1) || z(1) !== z0(1); width0 = width0 || width; height0 = height0 || height; var sizeDiff = width0 !== width || height0 !== height; // Domain Diffs xDom = xDom || []; var domainDiff = xDom[0] !== x.domain()[0] || xDom[1] !== x.domain()[1]; xDom = x.domain(); yDom = yDom || []; domainDiff = domainDiff || yDom[0] !== y.domain()[0] || yDom[1] !== y.domain()[1]; yDom = y.domain(); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-scatter').data([data]); var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-scatter nv-chart-' + id); var defsEnter = wrapEnter.append('defs'); var gEnter = wrapEnter.append('g'); var g = wrap.select('g'); wrap.classed('nv-single-point', singlePoint); gEnter.append('g').attr('class', 'nv-groups'); gEnter.append('g').attr('class', 'nv-point-paths'); wrapEnter.append('g').attr('class', 'nv-point-clips'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); defsEnter.append('clipPath') .attr('id', 'nv-edge-clip-' + id) .append('rect') .attr('transform', 'translate( -10, -10)'); wrap.select('#nv-edge-clip-' + id + ' rect') .attr('width', availableWidth + 20) .attr('height', (availableHeight > 0) ? availableHeight + 20 : 0); g.attr('clip-path', clipEdge ? 'url(#nv-edge-clip-' + id + ')' : ''); function updateInteractiveLayer() { // Always clear needs-update flag regardless of whether or not // we will actually do anything (avoids needless invocations). needsUpdate = false; if (!interactive) return false; container.selectAll(".nv-point.hover").classed("hover", false); // nuke all voronoi paths wrap.select('.nv-point-paths').selectAll('path').remove(); // inject series and point index for reference into voronoi if (useVoronoi === true) { var vertices = d3.merge(data.map(function(group, groupIndex) { return group.values .map(function(point, pointIndex) { // *Adding noise to make duplicates very unlikely // *Injecting series and point index for reference // *Adding a 'jitter' to the points, because there's an issue in d3.geom.voronoi. var pX = getX(point,pointIndex); var pY = getY(point,pointIndex); return [nv.utils.NaNtoZero(x(pX)) + Math.random() * 1e-4, nv.utils.NaNtoZero(y(pY)) + Math.random() * 1e-4, groupIndex, pointIndex, point]; }) .filter(function(pointArray, pointIndex) { return pointActive(pointArray[4], pointIndex); // Issue #237.. move filter to after map, so pointIndex is correct! }) }) ); if (vertices.length == 0) return false; // No active points, we're done if (vertices.length < 3) { // Issue #283 - Adding 2 dummy points to the voronoi b/c voronoi requires min 3 points to work vertices.push([x.range()[0] - 20, y.range()[0] - 20, null, null]); vertices.push([x.range()[1] + 20, y.range()[1] + 20, null, null]); vertices.push([x.range()[0] - 20, y.range()[0] + 20, null, null]); vertices.push([x.range()[1] + 20, y.range()[1] - 20, null, null]); } // keep voronoi sections from going more than 10 outside of graph // to avoid overlap with other things like legend etc var bounds = d3.geom.polygon([ [-10,-10], [-10,height + 10], [width + 10,height + 10], [width + 10,-10] ]); // delete duplicates from vertices - essential assumption for d3.geom.voronoi var epsilon = 1e-4; // Uses 1e-4 to determine equivalence. vertices = vertices.sort(function(a,b){return ((a[0] - b[0]) || (a[1] - b[1]))}); for (var i = 0; i < vertices.length - 1; ) { if ((Math.abs(vertices[i][0] - vertices[i+1][0]) < epsilon) && (Math.abs(vertices[i][1] - vertices[i+1][1]) < epsilon)) { vertices.splice(i+1, 1); } else { i++; } } var voronoi = d3.geom.voronoi(vertices).map(function(d, i) { if (d.length === 0) { return null; } return { 'data': bounds.clip(d), 'series': vertices[i][2], 'point': vertices[i][3] } }); var pointPaths = wrap.select('.nv-point-paths').selectAll('path').data(voronoi); var vPointPaths = pointPaths .enter().append("svg:path") .attr("d", function(d) { if (!d || !d.data || d.data.length === 0) return 'M 0 0'; else return "M" + d.data.join(",") + "Z"; }) .attr("id", function(d,i) { return "nv-path-"+i; }) .attr("clip-path", function(d,i) { return "url(#nv-clip-"+id+"-"+i+")"; }) ; // good for debugging point hover issues if (showVoronoi) { vPointPaths.style("fill", d3.rgb(230, 230, 230)) .style('fill-opacity', 0.4) .style('stroke-opacity', 1) .style("stroke", d3.rgb(200,200,200)); } if (clipVoronoi) { // voronoi sections are already set to clip, // just create the circles with the IDs they expect wrap.select('.nv-point-clips').selectAll('*').remove(); // must do * since it has sub-dom var pointClips = wrap.select('.nv-point-clips').selectAll('clipPath').data(vertices); var vPointClips = pointClips .enter().append("svg:clipPath") .attr("id", function(d, i) { return "nv-clip-"+id+"-"+i;}) .append("svg:circle") .attr('cx', function(d) { return d[0]; }) .attr('cy', function(d) { return d[1]; }) .attr('r', clipRadius); } var mouseEventCallback = function(el, d, mDispatch) { if (needsUpdate) return 0; var series = data[d.series]; if (series === undefined) return; var point = series.values[d.point]; point['color'] = color(series, d.series); // standardize attributes for tooltip. point['x'] = getX(point); point['y'] = getY(point); // can't just get box of event node since it's actually a voronoi polygon var box = container.node().getBoundingClientRect(); var scrollTop = window.pageYOffset || document.documentElement.scrollTop; var scrollLeft = window.pageXOffset || document.documentElement.scrollLeft; var pos = { left: x(getX(point, d.point)) + box.left + scrollLeft + margin.left + 10, top: y(getY(point, d.point)) + box.top + scrollTop + margin.top + 10 }; mDispatch({ point: point, series: series, pos: pos, relativePos: [x(getX(point, d.point)) + margin.left, y(getY(point, d.point)) + margin.top], seriesIndex: d.series, pointIndex: d.point, event: d3.event, element: el }); }; pointPaths .on('click', function(d) { mouseEventCallback(this, d, dispatch.elementClick); }) .on('dblclick', function(d) { mouseEventCallback(this, d, dispatch.elementDblClick); }) .on('mouseover', function(d) { mouseEventCallback(this, d, dispatch.elementMouseover); }) .on('mouseout', function(d, i) { mouseEventCallback(this, d, dispatch.elementMouseout); }); } else { // add event handlers to points instead voronoi paths wrap.select('.nv-groups').selectAll('.nv-group') .selectAll('.nv-point') //.data(dataWithPoints) //.style('pointer-events', 'auto') // recativate events, disabled by css .on('click', function(d,i) { //nv.log('test', d, i); if (needsUpdate || !data[d[0].series]) return 0; //check if this is a dummy point var series = data[d[0].series], point = series.values[i]; var element = this; dispatch.elementClick({ point: point, series: series, pos: [x(getX(point, i)) + margin.left, y(getY(point, i)) + margin.top], //TODO: make this pos base on the page relativePos: [x(getX(point, i)) + margin.left, y(getY(point, i)) + margin.top], seriesIndex: d[0].series, pointIndex: i, event: d3.event, element: element }); }) .on('dblclick', function(d,i) { if (needsUpdate || !data[d[0].series]) return 0; //check if this is a dummy point var series = data[d[0].series], point = series.values[i]; dispatch.elementDblClick({ point: point, series: series, pos: [x(getX(point, i)) + margin.left, y(getY(point, i)) + margin.top],//TODO: make this pos base on the page relativePos: [x(getX(point, i)) + margin.left, y(getY(point, i)) + margin.top], seriesIndex: d[0].series, pointIndex: i }); }) .on('mouseover', function(d,i) { if (needsUpdate || !data[d[0].series]) return 0; //check if this is a dummy point var series = data[d[0].series], point = series.values[i]; dispatch.elementMouseover({ point: point, series: series, pos: [x(getX(point, i)) + margin.left, y(getY(point, i)) + margin.top],//TODO: make this pos base on the page relativePos: [x(getX(point, i)) + margin.left, y(getY(point, i)) + margin.top], seriesIndex: d[0].series, pointIndex: i, color: color(d[0], i) }); }) .on('mouseout', function(d,i) { if (needsUpdate || !data[d[0].series]) return 0; //check if this is a dummy point var series = data[d[0].series], point = series.values[i]; dispatch.elementMouseout({ point: point, series: series, pos: [x(getX(point, i)) + margin.left, y(getY(point, i)) + margin.top],//TODO: make this pos base on the page relativePos: [x(getX(point, i)) + margin.left, y(getY(point, i)) + margin.top], seriesIndex: d[0].series, pointIndex: i, color: color(d[0], i) }); }); } } needsUpdate = true; var groups = wrap.select('.nv-groups').selectAll('.nv-group') .data(function(d) { return d }, function(d) { return d.key }); groups.enter().append('g') .style('stroke-opacity', 1e-6) .style('fill-opacity', 1e-6); groups.exit() .remove(); groups .attr('class', function(d,i) { return (d.classed || '') + ' nv-group nv-series-' + i; }) .classed('nv-noninteractive', !interactive) .classed('hover', function(d) { return d.hover }); groups.watchTransition(renderWatch, 'scatter: groups') .style('fill', function(d,i) { return color(d, i) }) .style('stroke', function(d,i) { return d.pointBorderColor || pointBorderColor || color(d, i) }) .style('stroke-opacity', 1) .style('fill-opacity', .5); // create the points, maintaining their IDs from the original data set var points = groups.selectAll('path.nv-point') .data(function(d) { return d.values.map( function (point, pointIndex) { return [point, pointIndex] }).filter( function(pointArray, pointIndex) { return pointActive(pointArray[0], pointIndex) }) }); points.enter().append('path') .attr('class', function (d) { return 'nv-point nv-point-' + d[1]; }) .style('fill', function (d) { return d.color }) .style('stroke', function (d) { return d.color }) .attr('transform', function(d) { return 'translate(' + nv.utils.NaNtoZero(x0(getX(d[0],d[1]))) + ',' + nv.utils.NaNtoZero(y0(getY(d[0],d[1]))) + ')' }) .attr('d', nv.utils.symbol() .type(function(d) { return getShape(d[0]); }) .size(function(d) { return z(getSize(d[0],d[1])) }) ); points.exit().each(delCache).remove(); groups.exit().selectAll('path.nv-point') .watchTransition(renderWatch, 'scatter exit') .attr('transform', function(d) { return 'translate(' + nv.utils.NaNtoZero(x(getX(d[0],d[1]))) + ',' + nv.utils.NaNtoZero(y(getY(d[0],d[1]))) + ')' }) .remove(); //============================================================ // Point Update Optimisation Notes //------------------------------------------------------------ // The following update selections are filtered with getDiffs // (defined at the top of this file) this brings a performance // benefit for charts with large data sets that accumulate a // subset of changes or additions over time. // // Uneccesary and expensive DOM calls are avoided by culling // unchanged points from the selection in exchange for the // cheaper overhead of caching and diffing each point first. // // Due to the way D3 and NVD3 work, other global changes need // to be considered in addition to local point properties. // This is a potential source of bugs (if any of the global // changes that possibly affect points are missed). // Update Point Positions [x, y] points.filter(function (d) { // getDiffs must always be called to update cache return getDiffs(d, 'x', getX, 'y', getY) || scaleDiff || sizeDiff || domainDiff; }) .watchTransition(renderWatch, 'scatter points') .attr('transform', function (d) { return 'translate(' + nv.utils.NaNtoZero(x(getX(d[0], d[1]))) + ',' + nv.utils.NaNtoZero(y(getY(d[0], d[1]))) + ')' }); // Update Point Appearance [shape, size] points.filter(function (d) { // getDiffs must always be called to update cache return getDiffs(d, 'shape', getShape, 'size', getSize) || scaleDiff || sizeDiff || domainDiff; }) .watchTransition(renderWatch, 'scatter points') .attr('d', nv.utils.symbol() .type(function (d) { return getShape(d[0]) }) .size(function (d) { return z(getSize(d[0], d[1])) }) ); // add label a label to scatter chart if(showLabels) { var titles = groups.selectAll('.nv-label') .data(function(d) { return d.values.map( function (point, pointIndex) { return [point, pointIndex] }).filter( function(pointArray, pointIndex) { return pointActive(pointArray[0], pointIndex) }) }); titles.enter().append('text') .style('fill', function (d,i) { return d.color }) .style('stroke-opacity', 0) .style('fill-opacity', 1) .attr('transform', function(d) { var dx = nv.utils.NaNtoZero(x0(getX(d[0],d[1]))) + Math.sqrt(z(getSize(d[0],d[1]))/Math.PI) + 2; return 'translate(' + dx + ',' + nv.utils.NaNtoZero(y0(getY(d[0],d[1]))) + ')'; }) .text(function(d,i){ return d[0].label;}); titles.exit().remove(); groups.exit().selectAll('path.nv-label') .watchTransition(renderWatch, 'scatter exit') .attr('transform', function(d) { var dx = nv.utils.NaNtoZero(x(getX(d[0],d[1])))+ Math.sqrt(z(getSize(d[0],d[1]))/Math.PI)+2; return 'translate(' + dx + ',' + nv.utils.NaNtoZero(y(getY(d[0],d[1]))) + ')'; }) .remove(); titles.each(function(d) { d3.select(this) .classed('nv-label', true) .classed('nv-label-' + d[1], false) .classed('hover',false); }); titles.watchTransition(renderWatch, 'scatter labels') .text(function(d,i){ return d[0].label;}) .attr('transform', function(d) { var dx = nv.utils.NaNtoZero(x(getX(d[0],d[1])))+ Math.sqrt(z(getSize(d[0],d[1]))/Math.PI)+2; return 'translate(' + dx + ',' + nv.utils.NaNtoZero(y(getY(d[0],d[1]))) + ')' }); } // Delay updating the invisible interactive layer for smoother animation if( interactiveUpdateDelay ) { clearTimeout(timeoutID); // stop repeat calls to updateInteractiveLayer timeoutID = setTimeout(updateInteractiveLayer, interactiveUpdateDelay ); } else { updateInteractiveLayer(); } //store old scales for use in transitions on update x0 = x.copy(); y0 = y.copy(); z0 = z.copy(); width0 = width; height0 = height; }); renderWatch.renderEnd('scatter immediate'); return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.dispatch = dispatch; chart.options = nv.utils.optionsFunc.bind(chart); // utility function calls provided by this chart chart._calls = new function() { this.clearHighlights = function () { nv.dom.write(function() { container.selectAll(".nv-point.hover").classed("hover", false); }); return null; }; this.highlightPoint = function (seriesIndex, pointIndex, isHoverOver) { nv.dom.write(function() { container.select('.nv-groups') .selectAll(".nv-series-" + seriesIndex) .selectAll(".nv-point-" + pointIndex) .classed("hover", isHoverOver); }); }; }; // trigger calls from events too dispatch.on('elementMouseover.point', function(d) { if (interactive) chart._calls.highlightPoint(d.seriesIndex,d.pointIndex,true); }); dispatch.on('elementMouseout.point', function(d) { if (interactive) chart._calls.highlightPoint(d.seriesIndex,d.pointIndex,false); }); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, xScale: {get: function(){return x;}, set: function(_){x=_;}}, yScale: {get: function(){return y;}, set: function(_){y=_;}}, pointScale: {get: function(){return z;}, set: function(_){z=_;}}, xDomain: {get: function(){return xDomain;}, set: function(_){xDomain=_;}}, yDomain: {get: function(){return yDomain;}, set: function(_){yDomain=_;}}, pointDomain: {get: function(){return sizeDomain;}, set: function(_){sizeDomain=_;}}, xRange: {get: function(){return xRange;}, set: function(_){xRange=_;}}, yRange: {get: function(){return yRange;}, set: function(_){yRange=_;}}, pointRange: {get: function(){return sizeRange;}, set: function(_){sizeRange=_;}}, forceX: {get: function(){return forceX;}, set: function(_){forceX=_;}}, forceY: {get: function(){return forceY;}, set: function(_){forceY=_;}}, forcePoint: {get: function(){return forceSize;}, set: function(_){forceSize=_;}}, interactive: {get: function(){return interactive;}, set: function(_){interactive=_;}}, pointActive: {get: function(){return pointActive;}, set: function(_){pointActive=_;}}, padDataOuter: {get: function(){return padDataOuter;}, set: function(_){padDataOuter=_;}}, padData: {get: function(){return padData;}, set: function(_){padData=_;}}, clipEdge: {get: function(){return clipEdge;}, set: function(_){clipEdge=_;}}, clipVoronoi: {get: function(){return clipVoronoi;}, set: function(_){clipVoronoi=_;}}, clipRadius: {get: function(){return clipRadius;}, set: function(_){clipRadius=_;}}, showVoronoi: {get: function(){return showVoronoi;}, set: function(_){showVoronoi=_;}}, id: {get: function(){return id;}, set: function(_){id=_;}}, interactiveUpdateDelay: {get:function(){return interactiveUpdateDelay;}, set: function(_){interactiveUpdateDelay=_;}}, showLabels: {get: function(){return showLabels;}, set: function(_){ showLabels = _;}}, pointBorderColor: {get: function(){return pointBorderColor;}, set: function(_){pointBorderColor=_;}}, // simple functor options x: {get: function(){return getX;}, set: function(_){getX = d3.functor(_);}}, y: {get: function(){return getY;}, set: function(_){getY = d3.functor(_);}}, pointSize: {get: function(){return getSize;}, set: function(_){getSize = d3.functor(_);}}, pointShape: {get: function(){return getShape;}, set: function(_){getShape = d3.functor(_);}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; renderWatch.reset(duration); }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); }}, useVoronoi: {get: function(){return useVoronoi;}, set: function(_){ useVoronoi = _; if (useVoronoi === false) { clipVoronoi = false; } }} }); nv.utils.initOptions(chart); return chart; }; nv.models.scatterChart = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var scatter = nv.models.scatter() , xAxis = nv.models.axis() , yAxis = nv.models.axis() , legend = nv.models.legend() , distX = nv.models.distribution() , distY = nv.models.distribution() , tooltip = nv.models.tooltip() ; var margin = {top: 30, right: 20, bottom: 50, left: 75} , marginTop = null , width = null , height = null , container = null , color = nv.utils.defaultColor() , x = scatter.xScale() , y = scatter.yScale() , showDistX = false , showDistY = false , showLegend = true , showXAxis = true , showYAxis = true , rightAlignYAxis = false , state = nv.utils.state() , defaultState = null , dispatch = d3.dispatch('stateChange', 'changeState', 'renderEnd') , noData = null , duration = 250 , showLabels = false ; scatter.xScale(x).yScale(y); xAxis.orient('bottom').tickPadding(10); yAxis .orient((rightAlignYAxis) ? 'right' : 'left') .tickPadding(10) ; distX.axis('x'); distY.axis('y'); tooltip .headerFormatter(function(d, i) { return xAxis.tickFormat()(d, i); }) .valueFormatter(function(d, i) { return yAxis.tickFormat()(d, i); }); //============================================================ // Private Variables //------------------------------------------------------------ var x0, y0 , renderWatch = nv.utils.renderWatch(dispatch, duration); var stateGetter = function(data) { return function(){ return { active: data.map(function(d) { return !d.disabled }) }; } }; var stateSetter = function(data) { return function(state) { if (state.active !== undefined) data.forEach(function(series,i) { series.disabled = !state.active[i]; }); } }; function chart(selection) { renderWatch.reset(); renderWatch.models(scatter); if (showXAxis) renderWatch.models(xAxis); if (showYAxis) renderWatch.models(yAxis); if (showDistX) renderWatch.models(distX); if (showDistY) renderWatch.models(distY); selection.each(function(data) { var that = this; container = d3.select(this); nv.utils.initSVG(container); var availableWidth = nv.utils.availableWidth(width, container, margin), availableHeight = nv.utils.availableHeight(height, container, margin); chart.update = function() { if (duration === 0) container.call(chart); else container.transition().duration(duration).call(chart); }; chart.container = this; state .setter(stateSetter(data), chart.update) .getter(stateGetter(data)) .update(); // DEPRECATED set state.disableddisabled state.disabled = data.map(function(d) { return !!d.disabled }); if (!defaultState) { var key; defaultState = {}; for (key in state) { if (state[key] instanceof Array) defaultState[key] = state[key].slice(0); else defaultState[key] = state[key]; } } // Display noData message if there's nothing to show. if (!data || !data.length || !data.filter(function(d) { return d.values.length }).length) { nv.utils.noData(chart, container); renderWatch.renderEnd('scatter immediate'); return chart; } else { container.selectAll('.nv-noData').remove(); } // Setup Scales x = scatter.xScale(); y = scatter.yScale(); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-scatterChart').data([data]); var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-scatterChart nv-chart-' + scatter.id()); var gEnter = wrapEnter.append('g'); var g = wrap.select('g'); // background for pointer events gEnter.append('rect').attr('class', 'nvd3 nv-background').style("pointer-events","none"); gEnter.append('g').attr('class', 'nv-x nv-axis'); gEnter.append('g').attr('class', 'nv-y nv-axis'); gEnter.append('g').attr('class', 'nv-scatterWrap'); gEnter.append('g').attr('class', 'nv-regressionLinesWrap'); gEnter.append('g').attr('class', 'nv-distWrap'); gEnter.append('g').attr('class', 'nv-legendWrap'); if (rightAlignYAxis) { g.select(".nv-y.nv-axis") .attr("transform", "translate(" + availableWidth + ",0)"); } // Legend if (!showLegend) { g.select('.nv-legendWrap').selectAll('*').remove(); } else { var legendWidth = availableWidth; legend.width(legendWidth); wrap.select('.nv-legendWrap') .datum(data) .call(legend); if (!marginTop && legend.height() !== margin.top) { margin.top = legend.height(); availableHeight = nv.utils.availableHeight(height, container, margin); } wrap.select('.nv-legendWrap') .attr('transform', 'translate(0' + ',' + (-margin.top) +')'); } wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); // Main Chart Component(s) scatter .width(availableWidth) .height(availableHeight) .color(data.map(function(d,i) { d.color = d.color || color(d, i); return d.color; }).filter(function(d,i) { return !data[i].disabled })) .showLabels(showLabels); wrap.select('.nv-scatterWrap') .datum(data.filter(function(d) { return !d.disabled })) .call(scatter); wrap.select('.nv-regressionLinesWrap') .attr('clip-path', 'url(#nv-edge-clip-' + scatter.id() + ')'); var regWrap = wrap.select('.nv-regressionLinesWrap').selectAll('.nv-regLines') .data(function (d) { return d; }); regWrap.enter().append('g').attr('class', 'nv-regLines'); var regLine = regWrap.selectAll('.nv-regLine') .data(function (d) { return [d] }); regLine.enter() .append('line').attr('class', 'nv-regLine') .style('stroke-opacity', 0); // don't add lines unless we have slope and intercept to use regLine.filter(function(d) { return d.intercept && d.slope; }) .watchTransition(renderWatch, 'scatterPlusLineChart: regline') .attr('x1', x.range()[0]) .attr('x2', x.range()[1]) .attr('y1', function (d, i) { return y(x.domain()[0] * d.slope + d.intercept) }) .attr('y2', function (d, i) { return y(x.domain()[1] * d.slope + d.intercept) }) .style('stroke', function (d, i, j) { return color(d, j) }) .style('stroke-opacity', function (d, i) { return (d.disabled || typeof d.slope === 'undefined' || typeof d.intercept === 'undefined') ? 0 : 1 }); // Setup Axes if (showXAxis) { xAxis .scale(x) ._ticks( nv.utils.calcTicksX(availableWidth/100, data) ) .tickSize( -availableHeight , 0); g.select('.nv-x.nv-axis') .attr('transform', 'translate(0,' + y.range()[0] + ')') .call(xAxis); } if (showYAxis) { yAxis .scale(y) ._ticks( nv.utils.calcTicksY(availableHeight/36, data) ) .tickSize( -availableWidth, 0); g.select('.nv-y.nv-axis') .call(yAxis); } // Setup Distribution distX .getData(scatter.x()) .scale(x) .width(availableWidth) .color(data.map(function(d,i) { return d.color || color(d, i); }).filter(function(d,i) { return !data[i].disabled })); gEnter.select('.nv-distWrap').append('g') .attr('class', 'nv-distributionX'); g.select('.nv-distributionX') .attr('transform', 'translate(0,' + y.range()[0] + ')') .datum(data.filter(function(d) { return !d.disabled })) .call(distX) .style('opacity', function() { return showDistX ? '1' : '1e-6'; }) .watchTransition(renderWatch, 'scatterPlusLineChart') .style('opacity', function() { return showDistX ? '1' : '1e-6'; }) distY .getData(scatter.y()) .scale(y) .width(availableHeight) .color(data.map(function(d,i) { return d.color || color(d, i); }).filter(function(d,i) { return !data[i].disabled })); gEnter.select('.nv-distWrap').append('g') .attr('class', 'nv-distributionY'); g.select('.nv-distributionY') .attr('transform', 'translate(' + (rightAlignYAxis ? availableWidth : -distY.size() ) + ',0)') .datum(data.filter(function(d) { return !d.disabled })) .call(distY) .style('opacity', function() { return showDistY ? '1' : '1e-6'; }) .watchTransition(renderWatch, 'scatterPlusLineChart') .style('opacity', function() { return showDistY ? '1' : '1e-6'; }) //============================================================ // Event Handling/Dispatching (in chart's scope) //------------------------------------------------------------ legend.dispatch.on('stateChange', function(newState) { for (var key in newState) state[key] = newState[key]; dispatch.stateChange(state); chart.update(); }); // Update chart from a state object passed to event handler dispatch.on('changeState', function(e) { if (typeof e.disabled !== 'undefined') { data.forEach(function(series,i) { series.disabled = e.disabled[i]; }); state.disabled = e.disabled; } chart.update(); }); // mouseover needs availableHeight so we just keep scatter mouse events inside the chart block scatter.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true); container.select('.nv-chart-' + scatter.id() + ' .nv-series-' + evt.seriesIndex + ' .nv-distx-' + evt.pointIndex) .attr('y1', 0); container.select('.nv-chart-' + scatter.id() + ' .nv-series-' + evt.seriesIndex + ' .nv-disty-' + evt.pointIndex) .attr('x2', distY.size()); }); scatter.dispatch.on('elementMouseover.tooltip', function(evt) { container.select('.nv-series-' + evt.seriesIndex + ' .nv-distx-' + evt.pointIndex) .attr('y1', evt.relativePos[1] - availableHeight); container.select('.nv-series-' + evt.seriesIndex + ' .nv-disty-' + evt.pointIndex) .attr('x2', evt.relativePos[0] + distX.size()); tooltip.data(evt).hidden(false); }); //store old scales for use in transitions on update x0 = x.copy(); y0 = y.copy(); }); renderWatch.renderEnd('scatter with line immediate'); return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ // expose chart's sub-components chart.dispatch = dispatch; chart.scatter = scatter; chart.legend = legend; chart.xAxis = xAxis; chart.yAxis = yAxis; chart.distX = distX; chart.distY = distY; chart.tooltip = tooltip; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, container: {get: function(){return container;}, set: function(_){container=_;}}, showDistX: {get: function(){return showDistX;}, set: function(_){showDistX=_;}}, showDistY: {get: function(){return showDistY;}, set: function(_){showDistY=_;}}, showLegend: {get: function(){return showLegend;}, set: function(_){showLegend=_;}}, showXAxis: {get: function(){return showXAxis;}, set: function(_){showXAxis=_;}}, showYAxis: {get: function(){return showYAxis;}, set: function(_){showYAxis=_;}}, defaultState: {get: function(){return defaultState;}, set: function(_){defaultState=_;}}, noData: {get: function(){return noData;}, set: function(_){noData=_;}}, duration: {get: function(){return duration;}, set: function(_){duration=_;}}, showLabels: {get: function(){return showLabels;}, set: function(_){showLabels=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ if (_.top !== undefined) { margin.top = _.top; marginTop = _.top; } margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, rightAlignYAxis: {get: function(){return rightAlignYAxis;}, set: function(_){ rightAlignYAxis = _; yAxis.orient( (_) ? 'right' : 'left'); }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); legend.color(color); distX.color(color); distY.color(color); }} }); nv.utils.inheritOptions(chart, scatter); nv.utils.initOptions(chart); return chart; }; nv.models.sparkline = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 2, right: 0, bottom: 2, left: 0} , width = 400 , height = 32 , container = null , animate = true , x = d3.scale.linear() , y = d3.scale.linear() , getX = function(d) { return d.x } , getY = function(d) { return d.y } , color = nv.utils.getColor(['#000']) , xDomain , yDomain , xRange , yRange , showMinMaxPoints = true , showCurrentPoint = true , dispatch = d3.dispatch('renderEnd') ; //============================================================ // Private Variables //------------------------------------------------------------ var renderWatch = nv.utils.renderWatch(dispatch); function chart(selection) { renderWatch.reset(); selection.each(function(data) { var availableWidth = width - margin.left - margin.right, availableHeight = height - margin.top - margin.bottom; container = d3.select(this); nv.utils.initSVG(container); // Setup Scales x .domain(xDomain || d3.extent(data, getX )) .range(xRange || [0, availableWidth]); y .domain(yDomain || d3.extent(data, getY )) .range(yRange || [availableHeight, 0]); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-sparkline').data([data]); var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-sparkline'); var gEnter = wrapEnter.append('g'); var g = wrap.select('g'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')') var paths = wrap.selectAll('path') .data(function(d) { return [d] }); paths.enter().append('path'); paths.exit().remove(); paths .style('stroke', function(d,i) { return d.color || color(d, i) }) .attr('d', d3.svg.line() .x(function(d,i) { return x(getX(d,i)) }) .y(function(d,i) { return y(getY(d,i)) }) ); // TODO: Add CURRENT data point (Need Min, Mac, Current / Most recent) var points = wrap.selectAll('circle.nv-point') .data(function(data) { var yValues = data.map(function(d, i) { return getY(d,i); }); function pointIndex(index) { if (index != -1) { var result = data[index]; result.pointIndex = index; return result; } else { return null; } } var maxPoint = pointIndex(yValues.lastIndexOf(y.domain()[1])), minPoint = pointIndex(yValues.indexOf(y.domain()[0])), currentPoint = pointIndex(yValues.length - 1); return [(showMinMaxPoints ? minPoint : null), (showMinMaxPoints ? maxPoint : null), (showCurrentPoint ? currentPoint : null)].filter(function (d) {return d != null;}); }); points.enter().append('circle'); points.exit().remove(); points .attr('cx', function(d,i) { return x(getX(d,d.pointIndex)) }) .attr('cy', function(d,i) { return y(getY(d,d.pointIndex)) }) .attr('r', 2) .attr('class', function(d,i) { return getX(d, d.pointIndex) == x.domain()[1] ? 'nv-point nv-currentValue' : getY(d, d.pointIndex) == y.domain()[0] ? 'nv-point nv-minValue' : 'nv-point nv-maxValue' }); }); renderWatch.renderEnd('sparkline immediate'); return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, xDomain: {get: function(){return xDomain;}, set: function(_){xDomain=_;}}, yDomain: {get: function(){return yDomain;}, set: function(_){yDomain=_;}}, xRange: {get: function(){return xRange;}, set: function(_){xRange=_;}}, yRange: {get: function(){return yRange;}, set: function(_){yRange=_;}}, xScale: {get: function(){return x;}, set: function(_){x=_;}}, yScale: {get: function(){return y;}, set: function(_){y=_;}}, animate: {get: function(){return animate;}, set: function(_){animate=_;}}, showMinMaxPoints: {get: function(){return showMinMaxPoints;}, set: function(_){showMinMaxPoints=_;}}, showCurrentPoint: {get: function(){return showCurrentPoint;}, set: function(_){showCurrentPoint=_;}}, //functor options x: {get: function(){return getX;}, set: function(_){getX=d3.functor(_);}}, y: {get: function(){return getY;}, set: function(_){getY=d3.functor(_);}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); }} }); chart.dispatch = dispatch; nv.utils.initOptions(chart); return chart; }; nv.models.sparklinePlus = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var sparkline = nv.models.sparkline(); var margin = {top: 15, right: 100, bottom: 10, left: 50} , width = null , height = null , x , y , index = [] , paused = false , xTickFormat = d3.format(',r') , yTickFormat = d3.format(',.2f') , showLastValue = true , alignValue = true , rightAlignValue = false , noData = null , dispatch = d3.dispatch('renderEnd') ; //============================================================ // Private Variables //------------------------------------------------------------ var renderWatch = nv.utils.renderWatch(dispatch); function chart(selection) { renderWatch.reset(); renderWatch.models(sparkline); selection.each(function(data) { var container = d3.select(this); nv.utils.initSVG(container); var availableWidth = nv.utils.availableWidth(width, container, margin), availableHeight = nv.utils.availableHeight(height, container, margin); chart.update = function() { container.call(chart); }; chart.container = this; // Display No Data message if there's nothing to show. if (!data || !data.length) { nv.utils.noData(chart, container) return chart; } else { container.selectAll('.nv-noData').remove(); } var currentValue = sparkline.y()(data[data.length-1], data.length-1); // Setup Scales x = sparkline.xScale(); y = sparkline.yScale(); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-sparklineplus').data([data]); var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-sparklineplus'); var gEnter = wrapEnter.append('g'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-sparklineWrap'); gEnter.append('g').attr('class', 'nv-valueWrap'); gEnter.append('g').attr('class', 'nv-hoverArea'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); // Main Chart Component(s) var sparklineWrap = g.select('.nv-sparklineWrap'); sparkline.width(availableWidth).height(availableHeight); sparklineWrap.call(sparkline); if (showLastValue) { var valueWrap = g.select('.nv-valueWrap'); var value = valueWrap.selectAll('.nv-currentValue') .data([currentValue]); value.enter().append('text').attr('class', 'nv-currentValue') .attr('dx', rightAlignValue ? -8 : 8) .attr('dy', '.9em') .style('text-anchor', rightAlignValue ? 'end' : 'start'); value .attr('x', availableWidth + (rightAlignValue ? margin.right : 0)) .attr('y', alignValue ? function (d) { return y(d) } : 0) .style('fill', sparkline.color()(data[data.length - 1], data.length - 1)) .text(yTickFormat(currentValue)); } gEnter.select('.nv-hoverArea').append('rect') .on('mousemove', sparklineHover) .on('click', function() { paused = !paused }) .on('mouseout', function() { index = []; updateValueLine(); }); g.select('.nv-hoverArea rect') .attr('transform', function(d) { return 'translate(' + -margin.left + ',' + -margin.top + ')' }) .attr('width', availableWidth + margin.left + margin.right) .attr('height', availableHeight + margin.top); //index is currently global (within the chart), may or may not keep it that way function updateValueLine() { if (paused) return; var hoverValue = g.selectAll('.nv-hoverValue').data(index); var hoverEnter = hoverValue.enter() .append('g').attr('class', 'nv-hoverValue') .style('stroke-opacity', 0) .style('fill-opacity', 0); hoverValue.exit() .transition().duration(250) .style('stroke-opacity', 0) .style('fill-opacity', 0) .remove(); hoverValue .attr('transform', function(d) { return 'translate(' + x(sparkline.x()(data[d],d)) + ',0)' }) .transition().duration(250) .style('stroke-opacity', 1) .style('fill-opacity', 1); if (!index.length) return; hoverEnter.append('line') .attr('x1', 0) .attr('y1', -margin.top) .attr('x2', 0) .attr('y2', availableHeight); hoverEnter.append('text').attr('class', 'nv-xValue') .attr('x', -6) .attr('y', -margin.top) .attr('text-anchor', 'end') .attr('dy', '.9em'); g.select('.nv-hoverValue .nv-xValue') .text(xTickFormat(sparkline.x()(data[index[0]], index[0]))); hoverEnter.append('text').attr('class', 'nv-yValue') .attr('x', 6) .attr('y', -margin.top) .attr('text-anchor', 'start') .attr('dy', '.9em'); g.select('.nv-hoverValue .nv-yValue') .text(yTickFormat(sparkline.y()(data[index[0]], index[0]))); } function sparklineHover() { if (paused) return; var pos = d3.mouse(this)[0] - margin.left; function getClosestIndex(data, x) { var distance = Math.abs(sparkline.x()(data[0], 0) - x); var closestIndex = 0; for (var i = 0; i < data.length; i++){ if (Math.abs(sparkline.x()(data[i], i) - x) < distance) { distance = Math.abs(sparkline.x()(data[i], i) - x); closestIndex = i; } } return closestIndex; } index = [getClosestIndex(data, Math.round(x.invert(pos)))]; updateValueLine(); } }); renderWatch.renderEnd('sparklinePlus immediate'); return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ // expose chart's sub-components chart.dispatch = dispatch; chart.sparkline = sparkline; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, xTickFormat: {get: function(){return xTickFormat;}, set: function(_){xTickFormat=_;}}, yTickFormat: {get: function(){return yTickFormat;}, set: function(_){yTickFormat=_;}}, showLastValue: {get: function(){return showLastValue;}, set: function(_){showLastValue=_;}}, alignValue: {get: function(){return alignValue;}, set: function(_){alignValue=_;}}, rightAlignValue: {get: function(){return rightAlignValue;}, set: function(_){rightAlignValue=_;}}, noData: {get: function(){return noData;}, set: function(_){noData=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }} }); nv.utils.inheritOptions(chart, sparkline); nv.utils.initOptions(chart); return chart; }; nv.models.stackedArea = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 0, right: 0, bottom: 0, left: 0} , width = 960 , height = 500 , color = nv.utils.defaultColor() // a function that computes the color , id = Math.floor(Math.random() * 100000) //Create semi-unique ID incase user doesn't selet one , container = null , getX = function(d) { return d.x } // accessor to get the x value from a data point , getY = function(d) { return d.y } // accessor to get the y value from a data point , defined = function(d,i) { return !isNaN(getY(d,i)) && getY(d,i) !== null } // allows a line to be not continuous when it is not defined , style = 'stack' , offset = 'zero' , order = 'default' , interpolate = 'linear' // controls the line interpolation , clipEdge = false // if true, masks lines within x and y scale , x //can be accessed via chart.xScale() , y //can be accessed via chart.yScale() , scatter = nv.models.scatter() , duration = 250 , dispatch = d3.dispatch('areaClick', 'areaMouseover', 'areaMouseout','renderEnd', 'elementClick', 'elementMouseover', 'elementMouseout') ; scatter .pointSize(2.2) // default size .pointDomain([2.2, 2.2]) // all the same size by default ; /************************************ * offset: * 'wiggle' (stream) * 'zero' (stacked) * 'expand' (normalize to 100%) * 'silhouette' (simple centered) * * order: * 'inside-out' (stream) * 'default' (input order) ************************************/ var renderWatch = nv.utils.renderWatch(dispatch, duration); function chart(selection) { renderWatch.reset(); renderWatch.models(scatter); selection.each(function(data) { var availableWidth = width - margin.left - margin.right, availableHeight = height - margin.top - margin.bottom; container = d3.select(this); nv.utils.initSVG(container); // Setup Scales x = scatter.xScale(); y = scatter.yScale(); var dataRaw = data; // Injecting point index into each point because d3.layout.stack().out does not give index data.forEach(function(aseries, i) { aseries.seriesIndex = i; aseries.values = aseries.values.map(function(d, j) { d.index = j; d.seriesIndex = i; return d; }); }); var dataFiltered = data.filter(function(series) { return !series.disabled; }); data = d3.layout.stack() .order(order) .offset(offset) .values(function(d) { return d.values }) //TODO: make values customizeable in EVERY model in this fashion .x(getX) .y(getY) .out(function(d, y0, y) { d.display = { y: y, y0: y0 }; }) (dataFiltered); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-stackedarea').data([data]); var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-stackedarea'); var defsEnter = wrapEnter.append('defs'); var gEnter = wrapEnter.append('g'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-areaWrap'); gEnter.append('g').attr('class', 'nv-scatterWrap'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); // If the user has not specified forceY, make sure 0 is included in the domain // Otherwise, use user-specified values for forceY if (scatter.forceY().length == 0) { scatter.forceY().push(0); } scatter .width(availableWidth) .height(availableHeight) .x(getX) .y(function(d) { if (d.display !== undefined) { return d.display.y + d.display.y0; } }) .color(data.map(function(d,i) { d.color = d.color || color(d, d.seriesIndex); return d.color; })); var scatterWrap = g.select('.nv-scatterWrap') .datum(data); scatterWrap.call(scatter); defsEnter.append('clipPath') .attr('id', 'nv-edge-clip-' + id) .append('rect'); wrap.select('#nv-edge-clip-' + id + ' rect') .attr('width', availableWidth) .attr('height', availableHeight); g.attr('clip-path', clipEdge ? 'url(#nv-edge-clip-' + id + ')' : ''); var area = d3.svg.area() .defined(defined) .x(function(d,i) { return x(getX(d,i)) }) .y0(function(d) { return y(d.display.y0) }) .y1(function(d) { return y(d.display.y + d.display.y0) }) .interpolate(interpolate); var zeroArea = d3.svg.area() .defined(defined) .x(function(d,i) { return x(getX(d,i)) }) .y0(function(d) { return y(d.display.y0) }) .y1(function(d) { return y(d.display.y0) }); var path = g.select('.nv-areaWrap').selectAll('path.nv-area') .data(function(d) { return d }); path.enter().append('path').attr('class', function(d,i) { return 'nv-area nv-area-' + i }) .attr('d', function(d,i){ return zeroArea(d.values, d.seriesIndex); }) .on('mouseover', function(d,i) { d3.select(this).classed('hover', true); dispatch.areaMouseover({ point: d, series: d.key, pos: [d3.event.pageX, d3.event.pageY], seriesIndex: d.seriesIndex }); }) .on('mouseout', function(d,i) { d3.select(this).classed('hover', false); dispatch.areaMouseout({ point: d, series: d.key, pos: [d3.event.pageX, d3.event.pageY], seriesIndex: d.seriesIndex }); }) .on('click', function(d,i) { d3.select(this).classed('hover', false); dispatch.areaClick({ point: d, series: d.key, pos: [d3.event.pageX, d3.event.pageY], seriesIndex: d.seriesIndex }); }); path.exit().remove(); path.style('fill', function(d,i){ return d.color || color(d, d.seriesIndex) }) .style('stroke', function(d,i){ return d.color || color(d, d.seriesIndex) }); path.watchTransition(renderWatch,'stackedArea path') .attr('d', function(d,i) { return area(d.values,i) }); //============================================================ // Event Handling/Dispatching (in chart's scope) //------------------------------------------------------------ scatter.dispatch.on('elementMouseover.area', function(e) { g.select('.nv-chart-' + id + ' .nv-area-' + e.seriesIndex).classed('hover', true); }); scatter.dispatch.on('elementMouseout.area', function(e) { g.select('.nv-chart-' + id + ' .nv-area-' + e.seriesIndex).classed('hover', false); }); //Special offset functions chart.d3_stackedOffset_stackPercent = function(stackData) { var n = stackData.length, //How many series m = stackData[0].length, //how many points per series i, j, o, y0 = []; for (j = 0; j < m; ++j) { //Looping through all points for (i = 0, o = 0; i < dataRaw.length; i++) { //looping through all series o += getY(dataRaw[i].values[j]); //total y value of all series at a certian point in time. } if (o) for (i = 0; i < n; i++) { //(total y value of all series at point in time i) != 0 stackData[i][j][1] /= o; } else { //(total y value of all series at point in time i) == 0 for (i = 0; i < n; i++) { stackData[i][j][1] = 0; } } } for (j = 0; j < m; ++j) y0[j] = 0; return y0; }; }); renderWatch.renderEnd('stackedArea immediate'); return chart; } //============================================================ // Global getters and setters //------------------------------------------------------------ chart.dispatch = dispatch; chart.scatter = scatter; scatter.dispatch.on('elementClick', function(){ dispatch.elementClick.apply(this, arguments); }); scatter.dispatch.on('elementMouseover', function(){ dispatch.elementMouseover.apply(this, arguments); }); scatter.dispatch.on('elementMouseout', function(){ dispatch.elementMouseout.apply(this, arguments); }); chart.interpolate = function(_) { if (!arguments.length) return interpolate; interpolate = _; return chart; }; chart.duration = function(_) { if (!arguments.length) return duration; duration = _; renderWatch.reset(duration); scatter.duration(duration); return chart; }; chart.dispatch = dispatch; chart.scatter = scatter; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, defined: {get: function(){return defined;}, set: function(_){defined=_;}}, clipEdge: {get: function(){return clipEdge;}, set: function(_){clipEdge=_;}}, offset: {get: function(){return offset;}, set: function(_){offset=_;}}, order: {get: function(){return order;}, set: function(_){order=_;}}, interpolate: {get: function(){return interpolate;}, set: function(_){interpolate=_;}}, // simple functor options x: {get: function(){return getX;}, set: function(_){getX = d3.functor(_);}}, y: {get: function(){return getY;}, set: function(_){getY = d3.functor(_);}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); }}, style: {get: function(){return style;}, set: function(_){ style = _; switch (style) { case 'stack': chart.offset('zero'); chart.order('default'); break; case 'stream': chart.offset('wiggle'); chart.order('inside-out'); break; case 'stream-center': chart.offset('silhouette'); chart.order('inside-out'); break; case 'expand': chart.offset('expand'); chart.order('default'); break; case 'stack_percent': chart.offset(chart.d3_stackedOffset_stackPercent); chart.order('default'); break; } }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; renderWatch.reset(duration); scatter.duration(duration); }} }); nv.utils.inheritOptions(chart, scatter); nv.utils.initOptions(chart); return chart; }; nv.models.stackedAreaChart = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var stacked = nv.models.stackedArea() , xAxis = nv.models.axis() , yAxis = nv.models.axis() , legend = nv.models.legend() , controls = nv.models.legend() , interactiveLayer = nv.interactiveGuideline() , tooltip = nv.models.tooltip() , focus = nv.models.focus(nv.models.stackedArea()) ; var margin = {top: 10, right: 25, bottom: 50, left: 60} , marginTop = null , width = null , height = null , color = nv.utils.defaultColor() , showControls = true , showLegend = true , legendPosition = 'top' , showXAxis = true , showYAxis = true , rightAlignYAxis = false , focusEnable = false , useInteractiveGuideline = false , showTotalInTooltip = true , totalLabel = 'TOTAL' , x //can be accessed via chart.xScale() , y //can be accessed via chart.yScale() , state = nv.utils.state() , defaultState = null , noData = null , dispatch = d3.dispatch('stateChange', 'changeState','renderEnd') , controlWidth = 250 , controlOptions = ['Stacked','Stream','Expanded'] , controlLabels = {} , duration = 250 ; state.style = stacked.style(); xAxis.orient('bottom').tickPadding(7); yAxis.orient((rightAlignYAxis) ? 'right' : 'left'); tooltip .headerFormatter(function(d, i) { return xAxis.tickFormat()(d, i); }) .valueFormatter(function(d, i) { return yAxis.tickFormat()(d, i); }); interactiveLayer.tooltip .headerFormatter(function(d, i) { return xAxis.tickFormat()(d, i); }) .valueFormatter(function(d, i) { return d == null ? "N/A" : yAxis.tickFormat()(d, i); }); var oldYTickFormat = null, oldValueFormatter = null; controls.updateState(false); //============================================================ // Private Variables //------------------------------------------------------------ var renderWatch = nv.utils.renderWatch(dispatch); var style = stacked.style(); var stateGetter = function(data) { return function(){ return { active: data.map(function(d) { return !d.disabled }), style: stacked.style() }; } }; var stateSetter = function(data) { return function(state) { if (state.style !== undefined) style = state.style; if (state.active !== undefined) data.forEach(function(series,i) { series.disabled = !state.active[i]; }); } }; var percentFormatter = d3.format('%'); function chart(selection) { renderWatch.reset(); renderWatch.models(stacked); if (showXAxis) renderWatch.models(xAxis); if (showYAxis) renderWatch.models(yAxis); selection.each(function(data) { var container = d3.select(this), that = this; nv.utils.initSVG(container); var availableWidth = nv.utils.availableWidth(width, container, margin), availableHeight = nv.utils.availableHeight(height, container, margin) - (focusEnable ? focus.height() : 0); chart.update = function() { container.transition().duration(duration).call(chart); }; chart.container = this; state .setter(stateSetter(data), chart.update) .getter(stateGetter(data)) .update(); // DEPRECATED set state.disabled state.disabled = data.map(function(d) { return !!d.disabled }); if (!defaultState) { var key; defaultState = {}; for (key in state) { if (state[key] instanceof Array) defaultState[key] = state[key].slice(0); else defaultState[key] = state[key]; } } // Display No Data message if there's nothing to show. if (!data || !data.length || !data.filter(function(d) { return d.values.length }).length) { nv.utils.noData(chart, container) return chart; } else { container.selectAll('.nv-noData').remove(); } // Setup Scales x = stacked.xScale(); y = stacked.yScale(); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-stackedAreaChart').data([data]); var gEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-stackedAreaChart').append('g'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-legendWrap'); gEnter.append('g').attr('class', 'nv-controlsWrap'); var focusEnter = gEnter.append('g').attr('class', 'nv-focus'); focusEnter.append('g').attr('class', 'nv-background').append('rect'); focusEnter.append('g').attr('class', 'nv-x nv-axis'); focusEnter.append('g').attr('class', 'nv-y nv-axis'); focusEnter.append('g').attr('class', 'nv-stackedWrap'); focusEnter.append('g').attr('class', 'nv-interactive'); // g.select("rect").attr("width",availableWidth).attr("height",availableHeight); var contextEnter = gEnter.append('g').attr('class', 'nv-focusWrap'); // Legend if (!showLegend) { g.select('.nv-legendWrap').selectAll('*').remove(); } else { var legendWidth = (showControls && legendPosition === 'top') ? availableWidth - controlWidth : availableWidth; legend.width(legendWidth); g.select('.nv-legendWrap').datum(data).call(legend); if (legendPosition === 'bottom') { var xAxisHeight = xAxis.height(); margin.bottom = Math.max(legend.height() + xAxisHeight, margin.bottom); availableHeight = nv.utils.availableHeight(height, container, margin) - (focusEnable ? focus.height() : 0); var legendTop = availableHeight + xAxisHeight; g.select('.nv-legendWrap') .attr('transform', 'translate(0,' + legendTop +')'); } else if (legendPosition === 'top') { if (!marginTop && margin.top != legend.height()) { margin.top = legend.height(); availableHeight = nv.utils.availableHeight(height, container, margin) - (focusEnable ? focus.height() : 0); } g.select('.nv-legendWrap') .attr('transform', 'translate(' + (availableWidth-legendWidth) + ',' + (-margin.top) +')'); } } // Controls if (!showControls) { g.select('.nv-controlsWrap').selectAll('*').remove(); } else { var controlsData = [ { key: controlLabels.stacked || 'Stacked', metaKey: 'Stacked', disabled: stacked.style() != 'stack', style: 'stack' }, { key: controlLabels.stream || 'Stream', metaKey: 'Stream', disabled: stacked.style() != 'stream', style: 'stream' }, { key: controlLabels.stream_center || 'Stream Center', metaKey: 'Stream_Center', disabled: stacked.style() != 'stream_center', style: 'stream-center' }, { key: controlLabels.expanded || 'Expanded', metaKey: 'Expanded', disabled: stacked.style() != 'expand', style: 'expand' }, { key: controlLabels.stack_percent || 'Stack %', metaKey: 'Stack_Percent', disabled: stacked.style() != 'stack_percent', style: 'stack_percent' } ]; controlWidth = (controlOptions.length/3) * 260; controlsData = controlsData.filter(function(d) { return controlOptions.indexOf(d.metaKey) !== -1; }); controls .width( controlWidth ) .color(['#444', '#444', '#444']); g.select('.nv-controlsWrap') .datum(controlsData) .call(controls); var requiredTop = Math.max(controls.height(), showLegend && (legendPosition === 'top') ? legend.height() : 0); if ( margin.top != requiredTop ) { margin.top = requiredTop; availableHeight = nv.utils.availableHeight(height, container, margin) - (focusEnable ? focus.height() : 0); } g.select('.nv-controlsWrap') .attr('transform', 'translate(0,' + (-margin.top) +')'); } wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); if (rightAlignYAxis) { g.select(".nv-y.nv-axis") .attr("transform", "translate(" + availableWidth + ",0)"); } //Set up interactive layer if (useInteractiveGuideline) { interactiveLayer .width(availableWidth) .height(availableHeight) .margin({left: margin.left, top: margin.top}) .svgContainer(container) .xScale(x); wrap.select(".nv-interactive").call(interactiveLayer); } g.select('.nv-focus .nv-background rect') .attr('width', availableWidth) .attr('height', availableHeight); stacked .width(availableWidth) .height(availableHeight) .color(data.map(function(d,i) { return d.color || color(d, i); }).filter(function(d,i) { return !data[i].disabled; })); var stackedWrap = g.select('.nv-focus .nv-stackedWrap') .datum(data.filter(function(d) { return !d.disabled; })); // Setup Axes if (showXAxis) { xAxis.scale(x) ._ticks( nv.utils.calcTicksX(availableWidth/100, data) ) .tickSize( -availableHeight, 0); } if (showYAxis) { var ticks; if (stacked.offset() === 'wiggle') { ticks = 0; } else { ticks = nv.utils.calcTicksY(availableHeight/36, data); } yAxis.scale(y) ._ticks(ticks) .tickSize(-availableWidth, 0); } //============================================================ // Update Axes //============================================================ function updateXAxis() { if(showXAxis) { g.select('.nv-focus .nv-x.nv-axis') .attr('transform', 'translate(0,' + availableHeight + ')') .transition() .duration(duration) .call(xAxis) ; } } function updateYAxis() { if(showYAxis) { if (stacked.style() === 'expand' || stacked.style() === 'stack_percent') { var currentFormat = yAxis.tickFormat(); if ( !oldYTickFormat || currentFormat !== percentFormatter ) oldYTickFormat = currentFormat; //Forces the yAxis to use percentage in 'expand' mode. yAxis.tickFormat(percentFormatter); } else { if (oldYTickFormat) { yAxis.tickFormat(oldYTickFormat); oldYTickFormat = null; } } g.select('.nv-focus .nv-y.nv-axis') .transition().duration(0) .call(yAxis); } } //============================================================ // Update Focus //============================================================ if(!focusEnable) { stackedWrap.transition().call(stacked); updateXAxis(); updateYAxis(); } else { focus.width(availableWidth); g.select('.nv-focusWrap') .attr('transform', 'translate(0,' + ( availableHeight + margin.bottom + focus.margin().top) + ')') .datum(data.filter(function(d) { return !d.disabled; })) .call(focus); var extent = focus.brush.empty() ? focus.xDomain() : focus.brush.extent(); if(extent !== null){ onBrush(extent); } } //============================================================ // Event Handling/Dispatching (in chart's scope) //------------------------------------------------------------ stacked.dispatch.on('areaClick.toggle', function(e) { if (data.filter(function(d) { return !d.disabled }).length === 1) data.forEach(function(d) { d.disabled = false; }); else data.forEach(function(d,i) { d.disabled = (i != e.seriesIndex); }); state.disabled = data.map(function(d) { return !!d.disabled }); dispatch.stateChange(state); chart.update(); }); legend.dispatch.on('stateChange', function(newState) { for (var key in newState) state[key] = newState[key]; dispatch.stateChange(state); chart.update(); }); controls.dispatch.on('legendClick', function(d,i) { if (!d.disabled) return; controlsData = controlsData.map(function(s) { s.disabled = true; return s; }); d.disabled = false; stacked.style(d.style); state.style = stacked.style(); dispatch.stateChange(state); chart.update(); }); interactiveLayer.dispatch.on('elementMousemove', function(e) { stacked.clearHighlights(); var singlePoint, pointIndex, pointXLocation, allData = [], valueSum = 0, allNullValues = true, atleastOnePoint = false; data .filter(function(series, i) { series.seriesIndex = i; return !series.disabled; }) .forEach(function(series,i) { pointIndex = nv.interactiveBisect(series.values, e.pointXValue, chart.x()); var point = series.values[pointIndex]; var pointYValue = chart.y()(point, pointIndex); if (pointYValue != null && pointYValue > 0) { stacked.highlightPoint(i, pointIndex, true); atleastOnePoint = true; } // Draw at least one point if all values are zero. if (i === (data.length - 1) && !atleastOnePoint) { stacked.highlightPoint(i, pointIndex, true); } if (typeof point === 'undefined') return; if (typeof singlePoint === 'undefined') singlePoint = point; if (typeof pointXLocation === 'undefined') pointXLocation = chart.xScale()(chart.x()(point,pointIndex)); //If we are in 'expand' mode, use the stacked percent value instead of raw value. var tooltipValue = (stacked.style() == 'expand') ? point.display.y : chart.y()(point,pointIndex); allData.push({ key: series.key, value: tooltipValue, color: color(series,series.seriesIndex), point: point }); if (showTotalInTooltip && stacked.style() != 'expand' && tooltipValue != null) { valueSum += tooltipValue; allNullValues = false; }; }); allData.reverse(); //Highlight the tooltip entry based on which stack the mouse is closest to. if (allData.length > 2) { var yValue = chart.yScale().invert(e.mouseY); var yDistMax = Infinity, indexToHighlight = null; allData.forEach(function(series,i) { //To handle situation where the stacked area chart is negative, we need to use absolute values //when checking if the mouse Y value is within the stack area. yValue = Math.abs(yValue); var stackedY0 = Math.abs(series.point.display.y0); var stackedY = Math.abs(series.point.display.y); if ( yValue >= stackedY0 && yValue <= (stackedY + stackedY0)) { indexToHighlight = i; return; } }); if (indexToHighlight != null) allData[indexToHighlight].highlight = true; } //If we are not in 'expand' mode, add a 'Total' row to the tooltip. if (showTotalInTooltip && stacked.style() != 'expand' && allData.length >= 2 && !allNullValues) { allData.push({ key: totalLabel, value: valueSum, total: true }); } var xValue = chart.x()(singlePoint,pointIndex); var valueFormatter = interactiveLayer.tooltip.valueFormatter(); // Keeps track of the tooltip valueFormatter if the chart changes to expanded view if (stacked.style() === 'expand' || stacked.style() === 'stack_percent') { if ( !oldValueFormatter ) { oldValueFormatter = valueFormatter; } //Forces the tooltip to use percentage in 'expand' mode. valueFormatter = d3.format(".1%"); } else { if (oldValueFormatter) { valueFormatter = oldValueFormatter; oldValueFormatter = null; } } interactiveLayer.tooltip .valueFormatter(valueFormatter) .data( { value: xValue, series: allData } )(); interactiveLayer.renderGuideLine(pointXLocation); }); interactiveLayer.dispatch.on("elementMouseout",function(e) { stacked.clearHighlights(); }); /* Update `main' graph on brush update. */ focus.dispatch.on("onBrush", function(extent) { onBrush(extent); }); // Update chart from a state object passed to event handler dispatch.on('changeState', function(e) { if (typeof e.disabled !== 'undefined' && data.length === e.disabled.length) { data.forEach(function(series,i) { series.disabled = e.disabled[i]; }); state.disabled = e.disabled; } if (typeof e.style !== 'undefined') { stacked.style(e.style); style = e.style; } chart.update(); }); //============================================================ // Functions //------------------------------------------------------------ function onBrush(extent) { // Update Main (Focus) var stackedWrap = g.select('.nv-focus .nv-stackedWrap') .datum( data.filter(function(d) { return !d.disabled; }) .map(function(d,i) { return { key: d.key, area: d.area, classed: d.classed, values: d.values.filter(function(d,i) { return stacked.x()(d,i) >= extent[0] && stacked.x()(d,i) <= extent[1]; }), disableTooltip: d.disableTooltip }; }) ); stackedWrap.transition().duration(duration).call(stacked); // Update Main (Focus) Axes updateXAxis(); updateYAxis(); } }); renderWatch.renderEnd('stacked Area chart immediate'); return chart; } //============================================================ // Event Handling/Dispatching (out of chart's scope) //------------------------------------------------------------ stacked.dispatch.on('elementMouseover.tooltip', function(evt) { evt.point['x'] = stacked.x()(evt.point); evt.point['y'] = stacked.y()(evt.point); tooltip.data(evt).hidden(false); }); stacked.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true) }); //============================================================ // Expose Public Variables //------------------------------------------------------------ // expose chart's sub-components chart.dispatch = dispatch; chart.stacked = stacked; chart.legend = legend; chart.controls = controls; chart.xAxis = xAxis; chart.x2Axis = focus.xAxis; chart.yAxis = yAxis; chart.y2Axis = focus.yAxis; chart.interactiveLayer = interactiveLayer; chart.tooltip = tooltip; chart.focus = focus; chart.dispatch = dispatch; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, showLegend: {get: function(){return showLegend;}, set: function(_){showLegend=_;}}, legendPosition: {get: function(){return legendPosition;}, set: function(_){legendPosition=_;}}, showXAxis: {get: function(){return showXAxis;}, set: function(_){showXAxis=_;}}, showYAxis: {get: function(){return showYAxis;}, set: function(_){showYAxis=_;}}, defaultState: {get: function(){return defaultState;}, set: function(_){defaultState=_;}}, noData: {get: function(){return noData;}, set: function(_){noData=_;}}, showControls: {get: function(){return showControls;}, set: function(_){showControls=_;}}, controlLabels: {get: function(){return controlLabels;}, set: function(_){controlLabels=_;}}, controlOptions: {get: function(){return controlOptions;}, set: function(_){controlOptions=_;}}, showTotalInTooltip: {get: function(){return showTotalInTooltip;}, set: function(_){showTotalInTooltip=_;}}, totalLabel: {get: function(){return totalLabel;}, set: function(_){totalLabel=_;}}, focusEnable: {get: function(){return focusEnable;}, set: function(_){focusEnable=_;}}, focusHeight: {get: function(){return focus.height();}, set: function(_){focus.height(_);}}, brushExtent: {get: function(){return focus.brushExtent();}, set: function(_){focus.brushExtent(_);}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ if (_.top !== undefined) { margin.top = _.top; marginTop = _.top; } margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, focusMargin: {get: function(){return focus.margin}, set: function(_){ focus.margin.top = _.top !== undefined ? _.top : focus.margin.top; focus.margin.right = _.right !== undefined ? _.right : focus.margin.right; focus.margin.bottom = _.bottom !== undefined ? _.bottom : focus.margin.bottom; focus.margin.left = _.left !== undefined ? _.left : focus.margin.left; }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; renderWatch.reset(duration); stacked.duration(duration); xAxis.duration(duration); yAxis.duration(duration); }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); legend.color(color); stacked.color(color); focus.color(color); }}, x: {get: function(){return stacked.x();}, set: function(_){ stacked.x(_); focus.x(_); }}, y: {get: function(){return stacked.y();}, set: function(_){ stacked.y(_); focus.y(_); }}, rightAlignYAxis: {get: function(){return rightAlignYAxis;}, set: function(_){ rightAlignYAxis = _; yAxis.orient( rightAlignYAxis ? 'right' : 'left'); }}, useInteractiveGuideline: {get: function(){return useInteractiveGuideline;}, set: function(_){ useInteractiveGuideline = !!_; chart.interactive(!_); chart.useVoronoi(!_); stacked.scatter.interactive(!_); }} }); nv.utils.inheritOptions(chart, stacked); nv.utils.initOptions(chart); return chart; }; nv.models.stackedAreaWithFocusChart = function() { return nv.models.stackedAreaChart() .margin({ bottom: 30 }) .focusEnable( true ); }; // based on http://bl.ocks.org/kerryrodden/477c1bfb081b783f80ad nv.models.sunburst = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 0, right: 0, bottom: 0, left: 0} , width = 600 , height = 600 , mode = "count" , modes = {count: function(d) { return 1; }, value: function(d) { return d.value || d.size }, size: function(d) { return d.value || d.size }} , id = Math.floor(Math.random() * 10000) //Create semi-unique ID in case user doesn't select one , container = null , color = nv.utils.defaultColor() , showLabels = false , labelFormat = function(d){if(mode === 'count'){return d.name + ' #' + d.value}else{return d.name + ' ' + (d.value || d.size)}} , labelThreshold = 0.02 , sort = function(d1, d2){return d1.name > d2.name;} , key = function(d,i){ if (d.parent !== undefined) { return d.name + '-' + d.parent.name + '-' + i; } else { return d.name; } } , groupColorByParent = true , duration = 500 , dispatch = d3.dispatch('chartClick', 'elementClick', 'elementDblClick', 'elementMousemove', 'elementMouseover', 'elementMouseout', 'renderEnd'); //============================================================ // aux functions and setup //------------------------------------------------------------ var x = d3.scale.linear().range([0, 2 * Math.PI]); var y = d3.scale.sqrt(); var partition = d3.layout.partition().sort(sort); var node, availableWidth, availableHeight, radius; var prevPositions = {}; var arc = d3.svg.arc() .startAngle(function(d) {return Math.max(0, Math.min(2 * Math.PI, x(d.x))) }) .endAngle(function(d) {return Math.max(0, Math.min(2 * Math.PI, x(d.x + d.dx))) }) .innerRadius(function(d) {return Math.max(0, y(d.y)) }) .outerRadius(function(d) {return Math.max(0, y(d.y + d.dy)) }); function rotationToAvoidUpsideDown(d) { var centerAngle = computeCenterAngle(d); if(centerAngle > 90){ return 180; } else { return 0; } } function computeCenterAngle(d) { var startAngle = Math.max(0, Math.min(2 * Math.PI, x(d.x))); var endAngle = Math.max(0, Math.min(2 * Math.PI, x(d.x + d.dx))); var centerAngle = (((startAngle + endAngle) / 2) * (180 / Math.PI)) - 90; return centerAngle; } function computeNodePercentage(d) { var startAngle = Math.max(0, Math.min(2 * Math.PI, x(d.x))); var endAngle = Math.max(0, Math.min(2 * Math.PI, x(d.x + d.dx))); return (endAngle - startAngle) / (2 * Math.PI); } function labelThresholdMatched(d) { var startAngle = Math.max(0, Math.min(2 * Math.PI, x(d.x))); var endAngle = Math.max(0, Math.min(2 * Math.PI, x(d.x + d.dx))); var size = endAngle - startAngle; return size > labelThreshold; } // When zooming: interpolate the scales. function arcTweenZoom(e,i) { var xd = d3.interpolate(x.domain(), [node.x, node.x + node.dx]), yd = d3.interpolate(y.domain(), [node.y, 1]), yr = d3.interpolate(y.range(), [node.y ? 20 : 0, radius]); if (i === 0) { return function() {return arc(e);} } else { return function (t) { x.domain(xd(t)); y.domain(yd(t)).range(yr(t)); return arc(e); } }; } function arcTweenUpdate(d) { var ipo = d3.interpolate({x: d.x0, dx: d.dx0, y: d.y0, dy: d.dy0}, d); return function (t) { var b = ipo(t); d.x0 = b.x; d.dx0 = b.dx; d.y0 = b.y; d.dy0 = b.dy; return arc(b); }; } function updatePrevPosition(node) { var k = key(node); if(! prevPositions[k]) prevPositions[k] = {}; var pP = prevPositions[k]; pP.dx = node.dx; pP.x = node.x; pP.dy = node.dy; pP.y = node.y; } function storeRetrievePrevPositions(nodes) { nodes.forEach(function(n){ var k = key(n); var pP = prevPositions[k]; //console.log(k,n,pP); if( pP ){ n.dx0 = pP.dx; n.x0 = pP.x; n.dy0 = pP.dy; n.y0 = pP.y; } else { n.dx0 = n.dx; n.x0 = n.x; n.dy0 = n.dy; n.y0 = n.y; } updatePrevPosition(n); }); } function zoomClick(d) { var labels = container.selectAll('text') var path = container.selectAll('path') // fade out all text elements labels.transition().attr("opacity",0); // to allow reference to the new center node node = d; path.transition() .duration(duration) .attrTween("d", arcTweenZoom) .each('end', function(e) { // partially taken from here: http://bl.ocks.org/metmajer/5480307 // check if the animated element's data e lies within the visible angle span given in d if(e.x >= d.x && e.x < (d.x + d.dx) ){ if(e.depth >= d.depth){ // get a selection of the associated text element var parentNode = d3.select(this.parentNode); var arcText = parentNode.select('text'); // fade in the text element and recalculate positions arcText.transition().duration(duration) .text( function(e){return labelFormat(e) }) .attr("opacity", function(d){ if(labelThresholdMatched(d)) { return 1; } else { return 0; } }) .attr("transform", function() { var width = this.getBBox().width; if(e.depth === 0) return "translate(" + (width / 2 * - 1) + ",0)"; else if(e.depth === d.depth){ return "translate(" + (y(e.y) + 5) + ",0)"; } else { var centerAngle = computeCenterAngle(e); var rotation = rotationToAvoidUpsideDown(e); if (rotation === 0) { return 'rotate('+ centerAngle +')translate(' + (y(e.y) + 5) + ',0)'; } else { return 'rotate('+ centerAngle +')translate(' + (y(e.y) + width + 5) + ',0)rotate(' + rotation + ')'; } } }); } } }) } //============================================================ // chart function //------------------------------------------------------------ var renderWatch = nv.utils.renderWatch(dispatch); function chart(selection) { renderWatch.reset(); selection.each(function(data) { container = d3.select(this); availableWidth = nv.utils.availableWidth(width, container, margin); availableHeight = nv.utils.availableHeight(height, container, margin); radius = Math.min(availableWidth, availableHeight) / 2; y.range([0, radius]); // Setup containers and skeleton of chart var wrap = container.select('g.nvd3.nv-wrap.nv-sunburst'); if( !wrap[0][0] ) { wrap = container.append('g') .attr('class', 'nvd3 nv-wrap nv-sunburst nv-chart-' + id) .attr('transform', 'translate(' + ((availableWidth / 2) + margin.left + margin.right) + ',' + ((availableHeight / 2) + margin.top + margin.bottom) + ')'); } else { wrap.attr('transform', 'translate(' + ((availableWidth / 2) + margin.left + margin.right) + ',' + ((availableHeight / 2) + margin.top + margin.bottom) + ')'); } container.on('click', function (d, i) { dispatch.chartClick({ data: d, index: i, pos: d3.event, id: id }); }); partition.value(modes[mode] || modes["count"]); //reverse the drawing order so that the labels of inner //arcs are drawn on top of the outer arcs. var nodes = partition.nodes(data[0]).reverse() storeRetrievePrevPositions(nodes); var cG = wrap.selectAll('.arc-container').data(nodes, key) //handle new datapoints var cGE = cG.enter() .append("g") .attr("class",'arc-container') cGE.append("path") .attr("d", arc) .style("fill", function (d) { if (d.color) { return d.color; } else if (groupColorByParent) { return color((d.children ? d : d.parent).name); } else { return color(d.name); } }) .style("stroke", "#FFF") .on("click", function(d,i){ zoomClick(d); dispatch.elementClick({ data: d, index: i }) }) .on('mouseover', function(d,i){ d3.select(this).classed('hover', true).style('opacity', 0.8); dispatch.elementMouseover({ data: d, color: d3.select(this).style("fill"), percent: computeNodePercentage(d) }); }) .on('mouseout', function(d,i){ d3.select(this).classed('hover', false).style('opacity', 1); dispatch.elementMouseout({ data: d }); }) .on('mousemove', function(d,i){ dispatch.elementMousemove({ data: d }); }); ///Iterating via each and selecting based on the this ///makes it work ... a cG.selectAll('path') doesn't. ///Without iteration the data (in the element) didn't update. cG.each(function(d){ d3.select(this).select('path') .transition() .duration(duration) .attrTween('d', arcTweenUpdate); }); if(showLabels){ //remove labels first and add them back cG.selectAll('text').remove(); //this way labels are on top of newly added arcs cG.append('text') .text( function(e){ return labelFormat(e)}) .transition() .duration(duration) .attr("opacity", function(d){ if(labelThresholdMatched(d)) { return 1; } else { return 0; } }) .attr("transform", function(d) { var width = this.getBBox().width; if(d.depth === 0){ return "rotate(0)translate(" + (width / 2 * -1) + ",0)"; } else { var centerAngle = computeCenterAngle(d); var rotation = rotationToAvoidUpsideDown(d); if (rotation === 0) { return 'rotate('+ centerAngle +')translate(' + (y(d.y) + 5) + ',0)'; } else { return 'rotate('+ centerAngle +')translate(' + (y(d.y) + width + 5) + ',0)rotate(' + rotation + ')'; } } }); } //zoom out to the center when the data is updated. zoomClick(nodes[nodes.length - 1]) //remove unmatched elements ... cG.exit() .transition() .duration(duration) .attr('opacity',0) .each('end',function(d){ var k = key(d); prevPositions[k] = undefined; }) .remove(); }); renderWatch.renderEnd('sunburst immediate'); return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.dispatch = dispatch; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, mode: {get: function(){return mode;}, set: function(_){mode=_;}}, id: {get: function(){return id;}, set: function(_){id=_;}}, duration: {get: function(){return duration;}, set: function(_){duration=_;}}, groupColorByParent: {get: function(){return groupColorByParent;}, set: function(_){groupColorByParent=!!_;}}, showLabels: {get: function(){return showLabels;}, set: function(_){showLabels=!!_}}, labelFormat: {get: function(){return labelFormat;}, set: function(_){labelFormat=_}}, labelThreshold: {get: function(){return labelThreshold;}, set: function(_){labelThreshold=_}}, sort: {get: function(){return sort;}, set: function(_){sort=_}}, key: {get: function(){return key;}, set: function(_){key=_}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top != undefined ? _.top : margin.top; margin.right = _.right != undefined ? _.right : margin.right; margin.bottom = _.bottom != undefined ? _.bottom : margin.bottom; margin.left = _.left != undefined ? _.left : margin.left; }}, color: {get: function(){return color;}, set: function(_){ color=nv.utils.getColor(_); }} }); nv.utils.initOptions(chart); return chart; }; nv.models.sunburstChart = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var sunburst = nv.models.sunburst(); var tooltip = nv.models.tooltip(); var margin = {top: 30, right: 20, bottom: 20, left: 20} , width = null , height = null , color = nv.utils.defaultColor() , showTooltipPercent = false , id = Math.round(Math.random() * 100000) , defaultState = null , noData = null , duration = 250 , dispatch = d3.dispatch('stateChange', 'changeState','renderEnd'); //============================================================ // Private Variables //------------------------------------------------------------ var renderWatch = nv.utils.renderWatch(dispatch); tooltip .duration(0) .headerEnabled(false) .valueFormatter(function(d){return d;}); //============================================================ // Chart function //------------------------------------------------------------ function chart(selection) { renderWatch.reset(); renderWatch.models(sunburst); selection.each(function(data) { var container = d3.select(this); nv.utils.initSVG(container); var availableWidth = nv.utils.availableWidth(width, container, margin); var availableHeight = nv.utils.availableHeight(height, container, margin); chart.update = function() { if (duration === 0) { container.call(chart); } else { container.transition().duration(duration).call(chart); } }; chart.container = container; // Display No Data message if there's nothing to show. if (!data || !data.length) { nv.utils.noData(chart, container); return chart; } else { container.selectAll('.nv-noData').remove(); } sunburst.width(availableWidth).height(availableHeight).margin(margin); container.call(sunburst); }); renderWatch.renderEnd('sunburstChart immediate'); return chart; } //============================================================ // Event Handling/Dispatching (out of chart's scope) //------------------------------------------------------------ sunburst.dispatch.on('elementMouseover.tooltip', function(evt) { evt.series = { key: evt.data.name, value: (evt.data.value || evt.data.size), color: evt.color, percent: evt.percent }; if (!showTooltipPercent) { delete evt.percent; delete evt.series.percent; } tooltip.data(evt).hidden(false); }); sunburst.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true); }); sunburst.dispatch.on('elementMousemove.tooltip', function(evt) { tooltip(); }); //============================================================ // Expose Public Variables //------------------------------------------------------------ // expose chart's sub-components chart.dispatch = dispatch; chart.sunburst = sunburst; chart.tooltip = tooltip; chart.options = nv.utils.optionsFunc.bind(chart); // use Object get/set functionality to map between vars and chart functions chart._options = Object.create({}, { // simple options, just get/set the necessary values noData: {get: function(){return noData;}, set: function(_){noData=_;}}, defaultState: {get: function(){return defaultState;}, set: function(_){defaultState=_;}}, showTooltipPercent: {get: function(){return showTooltipPercent;}, set: function(_){showTooltipPercent=_;}}, // options that require extra logic in the setter color: {get: function(){return color;}, set: function(_){ color = _; sunburst.color(color); }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; renderWatch.reset(duration); sunburst.duration(duration); }}, margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; sunburst.margin(margin); }} }); nv.utils.inheritOptions(chart, sunburst); nv.utils.initOptions(chart); return chart; }; nv.version = "1.8.6-dev"; })(); //# sourceMappingURL=nv.d3.js.map ================================================ FILE: composer.json ================================================ { "name": "novus/nvd3", "description": "A reusable charting library written in d3.js", "keywords": [ "nvd3", "d3", "chart", "graph" ], "homepage": "https://github.com/novus/nvd3", "license": "Apache-2.0", "authors": [ { "name": "Bob Monteverde" }, { "name": "Tyler Wolf" }, { "name": "Robin Hu" }, { "name": "Frank Shao" }, { "name": "liquidpele" } ], "require": { "mbostock/d3": "@stable" } } ================================================ FILE: examples/TimeSeries.html ================================================
(affects the x axis ticks and the bar spacing)
================================================ FILE: examples/actual.json ================================================ [{"key":{"measurement_point":"elec_energy_consumed","units":"kWh","interval_length":30,"timezone":"Asia/Tokyo"},"values":[{"recorded_at":"2017-07-01T00:30:00+0900","value":42.0,"flags":"historical"},{"recorded_at":"2017-07-01T01:00:00+0900","value":41.0,"flags":"historical"},{"recorded_at":"2017-07-01T01:30:00+0900","value":41.0,"flags":"historical"},{"recorded_at":"2017-07-01T02:00:00+0900","value":40.0,"flags":"historical"},{"recorded_at":"2017-07-01T02:30:00+0900","value":41.0,"flags":"historical"},{"recorded_at":"2017-07-01T03:00:00+0900","value":43.0,"flags":"historical"},{"recorded_at":"2017-07-01T03:30:00+0900","value":43.0,"flags":"historical"},{"recorded_at":"2017-07-01T04:00:00+0900","value":43.0,"flags":"historical"},{"recorded_at":"2017-07-01T04:30:00+0900","value":42.0,"flags":"historical"},{"recorded_at":"2017-07-01T05:00:00+0900","value":41.0,"flags":"historical"},{"recorded_at":"2017-07-01T05:30:00+0900","value":42.0,"flags":"historical"},{"recorded_at":"2017-07-01T06:00:00+0900","value":47.0,"flags":"historical"},{"recorded_at":"2017-07-01T06:30:00+0900","value":50.0,"flags":"historical"},{"recorded_at":"2017-07-01T07:00:00+0900","value":53.0,"flags":"historical"},{"recorded_at":"2017-07-01T07:30:00+0900","value":50.0,"flags":"historical"},{"recorded_at":"2017-07-01T08:00:00+0900","value":51.0,"flags":"historical"},{"recorded_at":"2017-07-01T08:30:00+0900","value":54.0,"flags":"historical"},{"recorded_at":"2017-07-01T09:00:00+0900","value":72.0,"flags":"historical"},{"recorded_at":"2017-07-01T09:30:00+0900","value":81.0,"flags":"historical"},{"recorded_at":"2017-07-01T10:00:00+0900","value":88.0,"flags":"historical"},{"recorded_at":"2017-07-01T10:30:00+0900","value":89.0,"flags":"historical"},{"recorded_at":"2017-07-01T11:00:00+0900","value":88.0,"flags":"historical"},{"recorded_at":"2017-07-01T11:30:00+0900","value":90.0,"flags":"historical"},{"recorded_at":"2017-07-01T12:00:00+0900","value":88.0,"flags":"historical"},{"recorded_at":"2017-07-01T12:30:00+0900","value":88.0,"flags":"historical"},{"recorded_at":"2017-07-01T13:00:00+0900","value":89.0,"flags":"historical"},{"recorded_at":"2017-07-01T13:30:00+0900","value":89.0,"flags":"historical"},{"recorded_at":"2017-07-01T14:00:00+0900","value":90.0,"flags":"historical"},{"recorded_at":"2017-07-01T14:30:00+0900","value":90.0,"flags":"historical"},{"recorded_at":"2017-07-01T15:00:00+0900","value":92.0,"flags":"historical"},{"recorded_at":"2017-07-01T15:30:00+0900","value":92.0,"flags":"historical"},{"recorded_at":"2017-07-01T16:00:00+0900","value":92.0,"flags":"historical"},{"recorded_at":"2017-07-01T16:30:00+0900","value":92.0,"flags":"historical"},{"recorded_at":"2017-07-01T17:00:00+0900","value":93.0,"flags":"historical"},{"recorded_at":"2017-07-01T17:30:00+0900","value":93.0,"flags":"historical"},{"recorded_at":"2017-07-01T18:00:00+0900","value":81.0,"flags":"historical"},{"recorded_at":"2017-07-01T18:30:00+0900","value":66.0,"flags":"historical"},{"recorded_at":"2017-07-01T19:00:00+0900","value":59.0,"flags":"historical"},{"recorded_at":"2017-07-01T19:30:00+0900","value":57.0,"flags":"historical"},{"recorded_at":"2017-07-01T20:00:00+0900","value":56.0,"flags":"historical"},{"recorded_at":"2017-07-01T20:30:00+0900","value":58.0,"flags":"historical"},{"recorded_at":"2017-07-01T21:00:00+0900","value":57.0,"flags":"historical"},{"recorded_at":"2017-07-01T21:30:00+0900","value":52.0,"flags":"historical"},{"recorded_at":"2017-07-01T22:00:00+0900","value":49.0,"flags":"historical"},{"recorded_at":"2017-07-01T22:30:00+0900","value":48.0,"flags":"historical"},{"recorded_at":"2017-07-01T23:00:00+0900","value":46.0,"flags":"historical"},{"recorded_at":"2017-07-01T23:30:00+0900","value":47.0,"flags":"historical"},{"recorded_at":"2017-07-02T00:00:00+0900","value":46.0,"flags":"historical"},{"recorded_at":"2017-07-02T00:30:00+0900","value":47.0,"flags":"historical"},{"recorded_at":"2017-07-02T01:00:00+0900","value":47.0,"flags":"historical"},{"recorded_at":"2017-07-02T01:30:00+0900","value":48.0,"flags":"historical"},{"recorded_at":"2017-07-02T02:00:00+0900","value":47.0,"flags":"historical"},{"recorded_at":"2017-07-02T02:30:00+0900","value":51.0,"flags":"historical"},{"recorded_at":"2017-07-02T03:00:00+0900","value":49.0,"flags":"historical"},{"recorded_at":"2017-07-02T03:30:00+0900","value":49.0,"flags":"historical"},{"recorded_at":"2017-07-02T04:00:00+0900","value":50.0,"flags":"historical"},{"recorded_at":"2017-07-02T04:30:00+0900","value":49.0,"flags":"historical"},{"recorded_at":"2017-07-02T05:00:00+0900","value":49.0,"flags":"historical"},{"recorded_at":"2017-07-02T05:30:00+0900","value":50.0,"flags":"historical"},{"recorded_at":"2017-07-02T06:00:00+0900","value":50.0,"flags":"historical"},{"recorded_at":"2017-07-02T06:30:00+0900","value":50.0,"flags":"historical"},{"recorded_at":"2017-07-02T07:00:00+0900","value":53.0,"flags":"historical"},{"recorded_at":"2017-07-02T07:30:00+0900","value":51.0,"flags":"historical"},{"recorded_at":"2017-07-02T08:00:00+0900","value":49.0,"flags":"historical"},{"recorded_at":"2017-07-02T08:30:00+0900","value":52.0,"flags":"historical"},{"recorded_at":"2017-07-02T09:00:00+0900","value":57.0,"flags":"historical"},{"recorded_at":"2017-07-02T09:30:00+0900","value":64.0,"flags":"historical"},{"recorded_at":"2017-07-02T10:00:00+0900","value":66.0,"flags":"historical"},{"recorded_at":"2017-07-02T10:30:00+0900","value":67.0,"flags":"historical"},{"recorded_at":"2017-07-02T11:00:00+0900","value":64.0,"flags":"historical"},{"recorded_at":"2017-07-02T11:30:00+0900","value":65.0,"flags":"historical"},{"recorded_at":"2017-07-02T12:00:00+0900","value":66.0,"flags":"historical"},{"recorded_at":"2017-07-02T12:30:00+0900","value":65.0,"flags":"historical"},{"recorded_at":"2017-07-02T13:00:00+0900","value":66.0,"flags":"historical"},{"recorded_at":"2017-07-02T13:30:00+0900","value":70.0,"flags":"historical"},{"recorded_at":"2017-07-02T14:00:00+0900","value":72.0,"flags":"historical"},{"recorded_at":"2017-07-02T14:30:00+0900","value":73.0,"flags":"historical"},{"recorded_at":"2017-07-02T15:00:00+0900","value":72.0,"flags":"historical"},{"recorded_at":"2017-07-02T15:30:00+0900","value":78.0,"flags":"historical"},{"recorded_at":"2017-07-02T16:00:00+0900","value":80.0,"flags":"historical"},{"recorded_at":"2017-07-02T16:30:00+0900","value":77.0,"flags":"historical"},{"recorded_at":"2017-07-02T17:00:00+0900","value":73.0,"flags":"historical"},{"recorded_at":"2017-07-02T17:30:00+0900","value":72.0,"flags":"historical"},{"recorded_at":"2017-07-02T18:00:00+0900","value":70.0,"flags":"historical"},{"recorded_at":"2017-07-02T18:30:00+0900","value":64.0,"flags":"historical"},{"recorded_at":"2017-07-02T19:00:00+0900","value":65.0,"flags":"historical"},{"recorded_at":"2017-07-02T19:30:00+0900","value":61.0,"flags":"historical"},{"recorded_at":"2017-07-02T20:00:00+0900","value":60.0,"flags":"historical"},{"recorded_at":"2017-07-02T20:30:00+0900","value":59.0,"flags":"historical"},{"recorded_at":"2017-07-02T21:00:00+0900","value":57.0,"flags":"historical"},{"recorded_at":"2017-07-02T21:30:00+0900","value":51.0,"flags":"historical"},{"recorded_at":"2017-07-02T22:00:00+0900","value":43.0,"flags":"historical"},{"recorded_at":"2017-07-02T22:30:00+0900","value":43.0,"flags":"historical"},{"recorded_at":"2017-07-02T23:00:00+0900","value":43.0,"flags":"historical"},{"recorded_at":"2017-07-02T23:30:00+0900","value":42.0,"flags":"historical"},{"recorded_at":"2017-07-03T00:00:00+0900","value":46.0,"flags":"historical"},{"recorded_at":"2017-07-03T00:30:00+0900","value":43.0,"flags":"historical"},{"recorded_at":"2017-07-03T01:00:00+0900","value":43.0,"flags":"historical"},{"recorded_at":"2017-07-03T01:30:00+0900","value":44.0,"flags":"historical"},{"recorded_at":"2017-07-03T02:00:00+0900","value":43.0,"flags":"historical"},{"recorded_at":"2017-07-03T02:30:00+0900","value":44.0,"flags":"historical"},{"recorded_at":"2017-07-03T03:00:00+0900","value":44.0,"flags":"historical"},{"recorded_at":"2017-07-03T03:30:00+0900","value":44.0,"flags":"historical"},{"recorded_at":"2017-07-03T04:00:00+0900","value":44.0,"flags":"historical"},{"recorded_at":"2017-07-03T04:30:00+0900","value":44.0,"flags":"historical"},{"recorded_at":"2017-07-03T05:00:00+0900","value":45.0,"flags":"historical"},{"recorded_at":"2017-07-03T05:30:00+0900","value":46.0,"flags":"historical"},{"recorded_at":"2017-07-03T06:00:00+0900","value":50.0,"flags":"historical"},{"recorded_at":"2017-07-03T06:30:00+0900","value":70.0,"flags":"historical"},{"recorded_at":"2017-07-03T07:00:00+0900","value":124.0,"flags":"historical"},{"recorded_at":"2017-07-03T07:30:00+0900","value":121.0,"flags":"historical"},{"recorded_at":"2017-07-03T08:00:00+0900","value":136.0,"flags":"historical"},{"recorded_at":"2017-07-03T08:30:00+0900","value":166.0,"flags":"historical"},{"recorded_at":"2017-07-03T09:00:00+0900","value":196.0,"flags":"historical"},{"recorded_at":"2017-07-03T09:30:00+0900","value":211.0,"flags":"historical"},{"recorded_at":"2017-07-03T10:00:00+0900","value":223.0,"flags":"historical"},{"recorded_at":"2017-07-03T10:30:00+0900","value":230.0,"flags":"historical"},{"recorded_at":"2017-07-03T11:00:00+0900","value":235.0,"flags":"historical"},{"recorded_at":"2017-07-03T11:30:00+0900","value":226.0,"flags":"historical"},{"recorded_at":"2017-07-03T12:00:00+0900","value":223.0,"flags":"historical"},{"recorded_at":"2017-07-03T12:30:00+0900","value":227.0,"flags":"historical"},{"recorded_at":"2017-07-03T13:00:00+0900","value":223.0,"flags":"historical"},{"recorded_at":"2017-07-03T13:30:00+0900","value":218.0,"flags":"historical"},{"recorded_at":"2017-07-03T14:00:00+0900","value":223.0,"flags":"historical"},{"recorded_at":"2017-07-03T14:30:00+0900","value":215.0,"flags":"historical"},{"recorded_at":"2017-07-03T15:00:00+0900","value":224.0,"flags":"historical"},{"recorded_at":"2017-07-03T15:30:00+0900","value":223.0,"flags":"historical"},{"recorded_at":"2017-07-03T16:00:00+0900","value":227.0,"flags":"historical"},{"recorded_at":"2017-07-03T16:30:00+0900","value":228.0,"flags":"historical"},{"recorded_at":"2017-07-03T17:00:00+0900","value":222.0,"flags":"historical"},{"recorded_at":"2017-07-03T17:30:00+0900","value":220.0,"flags":"historical"},{"recorded_at":"2017-07-03T18:00:00+0900","value":198.0,"flags":"historical"},{"recorded_at":"2017-07-03T18:30:00+0900","value":169.0,"flags":"historical"},{"recorded_at":"2017-07-03T19:00:00+0900","value":155.0,"flags":"historical"},{"recorded_at":"2017-07-03T19:30:00+0900","value":138.0,"flags":"historical"},{"recorded_at":"2017-07-03T20:00:00+0900","value":141.0,"flags":"historical"},{"recorded_at":"2017-07-03T20:30:00+0900","value":131.0,"flags":"historical"},{"recorded_at":"2017-07-03T21:00:00+0900","value":119.0,"flags":"historical"},{"recorded_at":"2017-07-03T21:30:00+0900","value":105.0,"flags":"historical"},{"recorded_at":"2017-07-03T22:00:00+0900","value":95.0,"flags":"historical"},{"recorded_at":"2017-07-03T22:30:00+0900","value":87.0,"flags":"historical"},{"recorded_at":"2017-07-03T23:00:00+0900","value":82.0,"flags":"historical"},{"recorded_at":"2017-07-03T23:30:00+0900","value":72.0,"flags":"historical"},{"recorded_at":"2017-07-04T00:00:00+0900","value":54.0,"flags":"historical"},{"recorded_at":"2017-07-04T00:30:00+0900","value":52.0,"flags":"historical"},{"recorded_at":"2017-07-04T01:00:00+0900","value":44.0,"flags":"historical"},{"recorded_at":"2017-07-04T01:30:00+0900","value":42.0,"flags":"historical"},{"recorded_at":"2017-07-04T02:00:00+0900","value":43.0,"flags":"historical"},{"recorded_at":"2017-07-04T02:30:00+0900","value":42.0,"flags":"historical"},{"recorded_at":"2017-07-04T03:00:00+0900","value":42.0,"flags":"historical"},{"recorded_at":"2017-07-04T03:30:00+0900","value":43.0,"flags":"historical"},{"recorded_at":"2017-07-04T04:00:00+0900","value":42.0,"flags":"historical"},{"recorded_at":"2017-07-04T04:30:00+0900","value":45.0,"flags":"historical"},{"recorded_at":"2017-07-04T05:00:00+0900","value":42.0,"flags":"historical"},{"recorded_at":"2017-07-04T05:30:00+0900","value":45.0,"flags":"historical"},{"recorded_at":"2017-07-04T06:00:00+0900","value":49.0,"flags":"historical"},{"recorded_at":"2017-07-04T06:30:00+0900","value":68.0,"flags":"historical"},{"recorded_at":"2017-07-04T07:00:00+0900","value":100.0,"flags":"historical"},{"recorded_at":"2017-07-04T07:30:00+0900","value":96.0,"flags":"historical"},{"recorded_at":"2017-07-04T08:00:00+0900","value":119.0,"flags":"historical"},{"recorded_at":"2017-07-04T08:30:00+0900","value":162.0,"flags":"historical"},{"recorded_at":"2017-07-04T09:00:00+0900","value":199.0,"flags":"historical"},{"recorded_at":"2017-07-04T09:30:00+0900","value":218.0,"flags":"historical"},{"recorded_at":"2017-07-04T10:00:00+0900","value":217.0,"flags":"historical"},{"recorded_at":"2017-07-04T10:30:00+0900","value":215.0,"flags":"historical"},{"recorded_at":"2017-07-04T11:00:00+0900","value":217.0,"flags":"historical"},{"recorded_at":"2017-07-04T11:30:00+0900","value":217.0,"flags":"historical"},{"recorded_at":"2017-07-04T12:00:00+0900","value":210.0,"flags":"historical"},{"recorded_at":"2017-07-04T12:30:00+0900","value":197.0,"flags":"historical"},{"recorded_at":"2017-07-04T13:00:00+0900","value":188.0,"flags":"historical"},{"recorded_at":"2017-07-04T13:30:00+0900","value":200.0,"flags":"historical"},{"recorded_at":"2017-07-04T14:00:00+0900","value":193.0,"flags":"historical"},{"recorded_at":"2017-07-04T14:30:00+0900","value":191.0,"flags":"historical"},{"recorded_at":"2017-07-04T15:00:00+0900","value":199.0,"flags":"historical"},{"recorded_at":"2017-07-04T15:30:00+0900","value":202.0,"flags":"historical"},{"recorded_at":"2017-07-04T16:00:00+0900","value":193.0,"flags":"historical"},{"recorded_at":"2017-07-04T16:30:00+0900","value":187.0,"flags":"historical"},{"recorded_at":"2017-07-04T17:00:00+0900","value":187.0,"flags":"historical"},{"recorded_at":"2017-07-04T17:30:00+0900","value":183.0,"flags":"historical"},{"recorded_at":"2017-07-04T18:00:00+0900","value":180.0,"flags":"historical"},{"recorded_at":"2017-07-04T18:30:00+0900","value":155.0,"flags":"historical"},{"recorded_at":"2017-07-04T19:00:00+0900","value":134.0,"flags":"historical"},{"recorded_at":"2017-07-04T19:30:00+0900","value":117.0,"flags":"historical"},{"recorded_at":"2017-07-04T20:00:00+0900","value":115.0,"flags":"historical"},{"recorded_at":"2017-07-04T20:30:00+0900","value":114.0,"flags":"historical"},{"recorded_at":"2017-07-04T21:00:00+0900","value":108.0,"flags":"historical"},{"recorded_at":"2017-07-04T21:30:00+0900","value":100.0,"flags":"historical"},{"recorded_at":"2017-07-04T22:00:00+0900","value":83.0,"flags":"historical"},{"recorded_at":"2017-07-04T22:30:00+0900","value":69.0,"flags":"historical"},{"recorded_at":"2017-07-04T23:00:00+0900","value":66.0,"flags":"historical"},{"recorded_at":"2017-07-04T23:30:00+0900","value":65.0,"flags":"historical"},{"recorded_at":"2017-07-05T00:00:00+0900","value":53.0,"flags":"historical"},{"recorded_at":"2017-07-05T00:30:00+0900","value":50.0,"flags":"historical"},{"recorded_at":"2017-07-05T01:00:00+0900","value":44.0,"flags":"historical"},{"recorded_at":"2017-07-05T01:30:00+0900","value":41.0,"flags":"historical"},{"recorded_at":"2017-07-05T02:00:00+0900","value":40.0,"flags":"historical"},{"recorded_at":"2017-07-05T02:30:00+0900","value":42.0,"flags":"historical"},{"recorded_at":"2017-07-05T03:00:00+0900","value":42.0,"flags":"historical"},{"recorded_at":"2017-07-05T03:30:00+0900","value":41.0,"flags":"historical"},{"recorded_at":"2017-07-05T04:00:00+0900","value":42.0,"flags":"historical"},{"recorded_at":"2017-07-05T04:30:00+0900","value":42.0,"flags":"historical"},{"recorded_at":"2017-07-05T05:00:00+0900","value":42.0,"flags":"historical"},{"recorded_at":"2017-07-05T05:30:00+0900","value":44.0,"flags":"historical"},{"recorded_at":"2017-07-05T06:00:00+0900","value":48.0,"flags":"historical"},{"recorded_at":"2017-07-05T06:30:00+0900","value":69.0,"flags":"historical"},{"recorded_at":"2017-07-05T07:00:00+0900","value":94.0,"flags":"historical"},{"recorded_at":"2017-07-05T07:30:00+0900","value":84.0,"flags":"historical"},{"recorded_at":"2017-07-05T08:00:00+0900","value":104.0,"flags":"historical"},{"recorded_at":"2017-07-05T08:30:00+0900","value":138.0,"flags":"historical"},{"recorded_at":"2017-07-05T09:00:00+0900","value":173.0,"flags":"historical"},{"recorded_at":"2017-07-05T09:30:00+0900","value":195.0,"flags":"historical"},{"recorded_at":"2017-07-05T10:00:00+0900","value":192.0,"flags":"historical"},{"recorded_at":"2017-07-05T10:30:00+0900","value":202.0,"flags":"historical"},{"recorded_at":"2017-07-05T11:00:00+0900","value":193.0,"flags":"historical"},{"recorded_at":"2017-07-05T11:30:00+0900","value":196.0,"flags":"historical"},{"recorded_at":"2017-07-05T12:00:00+0900","value":194.0,"flags":"historical"},{"recorded_at":"2017-07-05T12:30:00+0900","value":188.0,"flags":"historical"},{"recorded_at":"2017-07-05T13:00:00+0900","value":177.0,"flags":"historical"},{"recorded_at":"2017-07-05T13:30:00+0900","value":191.0,"flags":"historical"},{"recorded_at":"2017-07-05T14:00:00+0900","value":199.0,"flags":"historical"},{"recorded_at":"2017-07-05T14:30:00+0900","value":189.0,"flags":"historical"},{"recorded_at":"2017-07-05T15:00:00+0900","value":191.0,"flags":"historical"},{"recorded_at":"2017-07-05T15:30:00+0900","value":194.0,"flags":"historical"},{"recorded_at":"2017-07-05T16:00:00+0900","value":193.0,"flags":"historical"},{"recorded_at":"2017-07-05T16:30:00+0900","value":192.0,"flags":"historical"},{"recorded_at":"2017-07-05T17:00:00+0900","value":186.0,"flags":"historical"},{"recorded_at":"2017-07-05T17:30:00+0900","value":185.0,"flags":"historical"},{"recorded_at":"2017-07-05T18:00:00+0900","value":183.0,"flags":"historical"},{"recorded_at":"2017-07-05T18:30:00+0900","value":155.0,"flags":"historical"},{"recorded_at":"2017-07-05T19:00:00+0900","value":140.0,"flags":"historical"},{"recorded_at":"2017-07-05T19:30:00+0900","value":119.0,"flags":"historical"},{"recorded_at":"2017-07-05T20:00:00+0900","value":112.0,"flags":"historical"},{"recorded_at":"2017-07-05T20:30:00+0900","value":106.0,"flags":"historical"},{"recorded_at":"2017-07-05T21:00:00+0900","value":101.0,"flags":"historical"},{"recorded_at":"2017-07-05T21:30:00+0900","value":96.0,"flags":"historical"},{"recorded_at":"2017-07-05T22:00:00+0900","value":89.0,"flags":"historical"},{"recorded_at":"2017-07-05T22:30:00+0900","value":73.0,"flags":"historical"},{"recorded_at":"2017-07-05T23:00:00+0900","value":71.0,"flags":"historical"},{"recorded_at":"2017-07-05T23:30:00+0900","value":61.0,"flags":"historical"},{"recorded_at":"2017-07-06T00:00:00+0900","value":53.0,"flags":"historical"},{"recorded_at":"2017-07-06T00:30:00+0900","value":47.0,"flags":"historical"},{"recorded_at":"2017-07-06T01:00:00+0900","value":46.0,"flags":"historical"},{"recorded_at":"2017-07-06T01:30:00+0900","value":46.0,"flags":"historical"},{"recorded_at":"2017-07-06T02:00:00+0900","value":46.0,"flags":"historical"},{"recorded_at":"2017-07-06T02:30:00+0900","value":46.0,"flags":"historical"},{"recorded_at":"2017-07-06T03:00:00+0900","value":46.0,"flags":"historical"},{"recorded_at":"2017-07-06T03:30:00+0900","value":43.0,"flags":"historical"},{"recorded_at":"2017-07-06T04:00:00+0900","value":41.0,"flags":"historical"},{"recorded_at":"2017-07-06T04:30:00+0900","value":43.0,"flags":"historical"},{"recorded_at":"2017-07-06T05:00:00+0900","value":42.0,"flags":"historical"},{"recorded_at":"2017-07-06T05:30:00+0900","value":43.0,"flags":"historical"},{"recorded_at":"2017-07-06T06:00:00+0900","value":49.0,"flags":"historical"},{"recorded_at":"2017-07-06T06:30:00+0900","value":69.0,"flags":"historical"},{"recorded_at":"2017-07-06T07:00:00+0900","value":92.0,"flags":"historical"},{"recorded_at":"2017-07-06T07:30:00+0900","value":89.0,"flags":"historical"},{"recorded_at":"2017-07-06T08:00:00+0900","value":111.0,"flags":"historical"},{"recorded_at":"2017-07-06T08:30:00+0900","value":145.0,"flags":"historical"},{"recorded_at":"2017-07-06T09:00:00+0900","value":173.0,"flags":"historical"},{"recorded_at":"2017-07-06T09:30:00+0900","value":185.0,"flags":"historical"},{"recorded_at":"2017-07-06T10:00:00+0900","value":187.0,"flags":"historical"},{"recorded_at":"2017-07-06T10:30:00+0900","value":196.0,"flags":"historical"},{"recorded_at":"2017-07-06T11:00:00+0900","value":200.0,"flags":"historical"},{"recorded_at":"2017-07-06T11:30:00+0900","value":199.0,"flags":"historical"},{"recorded_at":"2017-07-06T12:00:00+0900","value":199.0,"flags":"historical"},{"recorded_at":"2017-07-06T12:30:00+0900","value":198.0,"flags":"historical"},{"recorded_at":"2017-07-06T13:00:00+0900","value":191.0,"flags":"historical"},{"recorded_at":"2017-07-06T13:30:00+0900","value":197.0,"flags":"historical"},{"recorded_at":"2017-07-06T14:00:00+0900","value":195.0,"flags":"historical"},{"recorded_at":"2017-07-06T14:30:00+0900","value":200.0,"flags":"historical"},{"recorded_at":"2017-07-06T15:00:00+0900","value":204.0,"flags":"historical"},{"recorded_at":"2017-07-06T15:30:00+0900","value":216.0,"flags":"historical"},{"recorded_at":"2017-07-06T16:00:00+0900","value":216.0,"flags":"historical"},{"recorded_at":"2017-07-06T16:30:00+0900","value":206.0,"flags":"historical"},{"recorded_at":"2017-07-06T17:00:00+0900","value":204.0,"flags":"historical"},{"recorded_at":"2017-07-06T17:30:00+0900","value":213.0,"flags":"historical"},{"recorded_at":"2017-07-06T18:00:00+0900","value":197.0,"flags":"historical"},{"recorded_at":"2017-07-06T18:30:00+0900","value":163.0,"flags":"historical"},{"recorded_at":"2017-07-06T19:00:00+0900","value":149.0,"flags":"historical"},{"recorded_at":"2017-07-06T19:30:00+0900","value":125.0,"flags":"historical"},{"recorded_at":"2017-07-06T20:00:00+0900","value":121.0,"flags":"historical"},{"recorded_at":"2017-07-06T20:30:00+0900","value":119.0,"flags":"historical"},{"recorded_at":"2017-07-06T21:00:00+0900","value":113.0,"flags":"historical"},{"recorded_at":"2017-07-06T21:30:00+0900","value":100.0,"flags":"historical"},{"recorded_at":"2017-07-06T22:00:00+0900","value":93.0,"flags":"historical"},{"recorded_at":"2017-07-06T22:30:00+0900","value":80.0,"flags":"historical"},{"recorded_at":"2017-07-06T23:00:00+0900","value":64.0,"flags":"historical"},{"recorded_at":"2017-07-06T23:30:00+0900","value":52.0,"flags":"historical"},{"recorded_at":"2017-07-07T00:00:00+0900","value":43.0,"flags":"historical"},{"recorded_at":"2017-07-07T00:30:00+0900","value":41.0,"flags":"historical"},{"recorded_at":"2017-07-07T01:00:00+0900","value":42.0,"flags":"historical"},{"recorded_at":"2017-07-07T01:30:00+0900","value":43.0,"flags":"historical"},{"recorded_at":"2017-07-07T02:00:00+0900","value":42.0,"flags":"historical"},{"recorded_at":"2017-07-07T02:30:00+0900","value":49.0,"flags":"historical"},{"recorded_at":"2017-07-07T03:00:00+0900","value":43.0,"flags":"historical"},{"recorded_at":"2017-07-07T03:30:00+0900","value":44.0,"flags":"historical"},{"recorded_at":"2017-07-07T04:00:00+0900","value":41.0,"flags":"historical"},{"recorded_at":"2017-07-07T04:30:00+0900","value":43.0,"flags":"historical"},{"recorded_at":"2017-07-07T05:00:00+0900","value":42.0,"flags":"historical"},{"recorded_at":"2017-07-07T05:30:00+0900","value":43.0,"flags":"historical"},{"recorded_at":"2017-07-07T06:00:00+0900","value":49.0,"flags":"historical"},{"recorded_at":"2017-07-07T06:30:00+0900","value":68.0,"flags":"historical"},{"recorded_at":"2017-07-07T07:00:00+0900","value":92.0,"flags":"historical"},{"recorded_at":"2017-07-07T07:30:00+0900","value":95.0,"flags":"historical"},{"recorded_at":"2017-07-07T08:00:00+0900","value":106.0,"flags":"historical"},{"recorded_at":"2017-07-07T08:30:00+0900","value":140.0,"flags":"historical"},{"recorded_at":"2017-07-07T09:00:00+0900","value":176.0,"flags":"historical"},{"recorded_at":"2017-07-07T09:30:00+0900","value":185.0,"flags":"historical"},{"recorded_at":"2017-07-07T10:00:00+0900","value":192.0,"flags":"historical"},{"recorded_at":"2017-07-07T10:30:00+0900","value":201.0,"flags":"historical"},{"recorded_at":"2017-07-07T11:00:00+0900","value":202.0,"flags":"historical"},{"recorded_at":"2017-07-07T11:30:00+0900","value":194.0,"flags":"historical"},{"recorded_at":"2017-07-07T12:00:00+0900","value":196.0,"flags":"historical"},{"recorded_at":"2017-07-07T12:30:00+0900","value":195.0,"flags":"historical"},{"recorded_at":"2017-07-07T13:00:00+0900","value":183.0,"flags":"historical"},{"recorded_at":"2017-07-07T13:30:00+0900","value":203.0,"flags":"historical"},{"recorded_at":"2017-07-07T14:00:00+0900","value":202.0,"flags":"historical"},{"recorded_at":"2017-07-07T14:30:00+0900","value":194.0,"flags":"historical"},{"recorded_at":"2017-07-07T15:00:00+0900","value":206.0,"flags":"historical"},{"recorded_at":"2017-07-07T15:30:00+0900","value":206.0,"flags":"historical"},{"recorded_at":"2017-07-07T16:00:00+0900","value":199.0,"flags":"historical"},{"recorded_at":"2017-07-07T16:30:00+0900","value":194.0,"flags":"historical"},{"recorded_at":"2017-07-07T17:00:00+0900","value":198.0,"flags":"historical"},{"recorded_at":"2017-07-07T17:30:00+0900","value":208.0,"flags":"historical"},{"recorded_at":"2017-07-07T18:00:00+0900","value":195.0,"flags":"historical"},{"recorded_at":"2017-07-07T18:30:00+0900","value":162.0,"flags":"historical"},{"recorded_at":"2017-07-07T19:00:00+0900","value":139.0,"flags":"historical"},{"recorded_at":"2017-07-07T19:30:00+0900","value":124.0,"flags":"historical"},{"recorded_at":"2017-07-07T20:00:00+0900","value":117.0,"flags":"historical"},{"recorded_at":"2017-07-07T20:30:00+0900","value":107.0,"flags":"historical"},{"recorded_at":"2017-07-07T21:00:00+0900","value":103.0,"flags":"historical"},{"recorded_at":"2017-07-07T21:30:00+0900","value":100.0,"flags":"historical"},{"recorded_at":"2017-07-07T22:00:00+0900","value":84.0,"flags":"historical"},{"recorded_at":"2017-07-07T22:30:00+0900","value":80.0,"flags":"historical"},{"recorded_at":"2017-07-07T23:00:00+0900","value":75.0,"flags":"historical"},{"recorded_at":"2017-07-07T23:30:00+0900","value":72.0,"flags":"historical"},{"recorded_at":"2017-07-08T00:00:00+0900","value":57.0,"flags":"historical"},{"recorded_at":"2017-07-08T00:30:00+0900","value":50.0,"flags":"historical"},{"recorded_at":"2017-07-08T01:00:00+0900","value":44.0,"flags":"historical"},{"recorded_at":"2017-07-08T01:30:00+0900","value":41.0,"flags":"historical"},{"recorded_at":"2017-07-08T02:00:00+0900","value":41.0,"flags":"historical"},{"recorded_at":"2017-07-08T02:30:00+0900","value":41.0,"flags":"historical"},{"recorded_at":"2017-07-08T03:00:00+0900","value":46.0,"flags":"historical"},{"recorded_at":"2017-07-08T03:30:00+0900","value":49.0,"flags":"historical"},{"recorded_at":"2017-07-08T04:00:00+0900","value":49.0,"flags":"historical"},{"recorded_at":"2017-07-08T04:30:00+0900","value":50.0,"flags":"historical"},{"recorded_at":"2017-07-08T05:00:00+0900","value":49.0,"flags":"historical"},{"recorded_at":"2017-07-08T05:30:00+0900","value":50.0,"flags":"historical"},{"recorded_at":"2017-07-08T06:00:00+0900","value":50.0,"flags":"historical"},{"recorded_at":"2017-07-08T06:30:00+0900","value":61.0,"flags":"historical"},{"recorded_at":"2017-07-08T07:00:00+0900","value":66.0,"flags":"historical"},{"recorded_at":"2017-07-08T07:30:00+0900","value":68.0,"flags":"historical"},{"recorded_at":"2017-07-08T08:00:00+0900","value":64.0,"flags":"historical"},{"recorded_at":"2017-07-08T08:30:00+0900","value":66.0,"flags":"historical"},{"recorded_at":"2017-07-08T09:00:00+0900","value":68.0,"flags":"historical"},{"recorded_at":"2017-07-08T09:30:00+0900","value":76.0,"flags":"historical"},{"recorded_at":"2017-07-08T10:00:00+0900","value":87.0,"flags":"historical"},{"recorded_at":"2017-07-08T10:30:00+0900","value":89.0,"flags":"historical"},{"recorded_at":"2017-07-08T11:00:00+0900","value":83.0,"flags":"historical"},{"recorded_at":"2017-07-08T11:30:00+0900","value":83.0,"flags":"historical"},{"recorded_at":"2017-07-08T12:00:00+0900","value":85.0,"flags":"historical"},{"recorded_at":"2017-07-08T12:30:00+0900","value":89.0,"flags":"historical"},{"recorded_at":"2017-07-08T13:00:00+0900","value":84.0,"flags":"historical"},{"recorded_at":"2017-07-08T13:30:00+0900","value":88.0,"flags":"historical"},{"recorded_at":"2017-07-08T14:00:00+0900","value":94.0,"flags":"historical"},{"recorded_at":"2017-07-08T14:30:00+0900","value":95.0,"flags":"historical"},{"recorded_at":"2017-07-08T15:00:00+0900","value":93.0,"flags":"historical"},{"recorded_at":"2017-07-08T15:30:00+0900","value":92.0,"flags":"historical"},{"recorded_at":"2017-07-08T16:00:00+0900","value":88.0,"flags":"historical"},{"recorded_at":"2017-07-08T16:30:00+0900","value":87.0,"flags":"historical"},{"recorded_at":"2017-07-08T17:00:00+0900","value":85.0,"flags":"historical"},{"recorded_at":"2017-07-08T17:30:00+0900","value":83.0,"flags":"historical"},{"recorded_at":"2017-07-08T18:00:00+0900","value":73.0,"flags":"historical"},{"recorded_at":"2017-07-08T18:30:00+0900","value":65.0,"flags":"historical"},{"recorded_at":"2017-07-08T19:00:00+0900","value":65.0,"flags":"historical"},{"recorded_at":"2017-07-08T19:30:00+0900","value":64.0,"flags":"historical"},{"recorded_at":"2017-07-08T20:00:00+0900","value":59.0,"flags":"historical"},{"recorded_at":"2017-07-08T20:30:00+0900","value":57.0,"flags":"historical"},{"recorded_at":"2017-07-08T21:00:00+0900","value":53.0,"flags":"historical"},{"recorded_at":"2017-07-08T21:30:00+0900","value":49.0,"flags":"historical"},{"recorded_at":"2017-07-08T22:00:00+0900","value":51.0,"flags":"historical"},{"recorded_at":"2017-07-08T22:30:00+0900","value":50.0,"flags":"historical"},{"recorded_at":"2017-07-08T23:00:00+0900","value":47.0,"flags":"historical"},{"recorded_at":"2017-07-08T23:30:00+0900","value":43.0,"flags":"historical"},{"recorded_at":"2017-07-09T00:00:00+0900","value":41.0,"flags":"historical"},{"recorded_at":"2017-07-09T00:30:00+0900","value":42.0,"flags":"historical"},{"recorded_at":"2017-07-09T01:00:00+0900","value":42.0,"flags":"historical"},{"recorded_at":"2017-07-09T01:30:00+0900","value":42.0,"flags":"historical"},{"recorded_at":"2017-07-09T02:00:00+0900","value":43.0,"flags":"historical"},{"recorded_at":"2017-07-09T02:30:00+0900","value":43.0,"flags":"historical"},{"recorded_at":"2017-07-09T03:00:00+0900","value":42.0,"flags":"historical"},{"recorded_at":"2017-07-09T03:30:00+0900","value":42.0,"flags":"historical"},{"recorded_at":"2017-07-09T04:00:00+0900","value":42.0,"flags":"historical"},{"recorded_at":"2017-07-09T04:30:00+0900","value":43.0,"flags":"historical"},{"recorded_at":"2017-07-09T05:00:00+0900","value":45.0,"flags":"historical"},{"recorded_at":"2017-07-09T05:30:00+0900","value":43.0,"flags":"historical"},{"recorded_at":"2017-07-09T06:00:00+0900","value":42.0,"flags":"historical"},{"recorded_at":"2017-07-09T06:30:00+0900","value":45.0,"flags":"historical"},{"recorded_at":"2017-07-09T07:00:00+0900","value":46.0,"flags":"historical"},{"recorded_at":"2017-07-09T07:30:00+0900","value":46.0,"flags":"historical"},{"recorded_at":"2017-07-09T08:00:00+0900","value":47.0,"flags":"historical"},{"recorded_at":"2017-07-09T08:30:00+0900","value":53.0,"flags":"historical"},{"recorded_at":"2017-07-09T09:00:00+0900","value":56.0,"flags":"historical"},{"recorded_at":"2017-07-09T09:30:00+0900","value":66.0,"flags":"historical"},{"recorded_at":"2017-07-09T10:00:00+0900","value":71.0,"flags":"historical"},{"recorded_at":"2017-07-09T10:30:00+0900","value":72.0,"flags":"historical"},{"recorded_at":"2017-07-09T11:00:00+0900","value":75.0,"flags":"historical"},{"recorded_at":"2017-07-09T11:30:00+0900","value":80.0,"flags":"historical"},{"recorded_at":"2017-07-09T12:00:00+0900","value":76.0,"flags":"historical"},{"recorded_at":"2017-07-09T12:30:00+0900","value":81.0,"flags":"historical"},{"recorded_at":"2017-07-09T13:00:00+0900","value":89.0,"flags":"historical"},{"recorded_at":"2017-07-09T13:30:00+0900","value":89.0,"flags":"historical"},{"recorded_at":"2017-07-09T14:00:00+0900","value":88.0,"flags":"historical"},{"recorded_at":"2017-07-09T14:30:00+0900","value":87.0,"flags":"historical"},{"recorded_at":"2017-07-09T15:00:00+0900","value":88.0,"flags":"historical"},{"recorded_at":"2017-07-09T15:30:00+0900","value":85.0,"flags":"historical"},{"recorded_at":"2017-07-09T16:00:00+0900","value":88.0,"flags":"historical"},{"recorded_at":"2017-07-09T16:30:00+0900","value":76.0,"flags":"historical"},{"recorded_at":"2017-07-09T17:00:00+0900","value":75.0,"flags":"historical"},{"recorded_at":"2017-07-09T17:30:00+0900","value":77.0,"flags":"historical"},{"recorded_at":"2017-07-09T18:00:00+0900","value":74.0,"flags":"historical"},{"recorded_at":"2017-07-09T18:30:00+0900","value":66.0,"flags":"historical"},{"recorded_at":"2017-07-09T19:00:00+0900","value":65.0,"flags":"historical"},{"recorded_at":"2017-07-09T19:30:00+0900","value":60.0,"flags":"historical"},{"recorded_at":"2017-07-09T20:00:00+0900","value":58.0,"flags":"historical"},{"recorded_at":"2017-07-09T20:30:00+0900","value":56.0,"flags":"historical"},{"recorded_at":"2017-07-09T21:00:00+0900","value":57.0,"flags":"historical"},{"recorded_at":"2017-07-09T21:30:00+0900","value":55.0,"flags":"historical"},{"recorded_at":"2017-07-09T22:00:00+0900","value":52.0,"flags":"historical"},{"recorded_at":"2017-07-09T22:30:00+0900","value":51.0,"flags":"historical"},{"recorded_at":"2017-07-09T23:00:00+0900","value":49.0,"flags":"historical"},{"recorded_at":"2017-07-09T23:30:00+0900","value":50.0,"flags":"historical"},{"recorded_at":"2017-07-10T00:00:00+0900","value":49.0,"flags":"historical"},{"recorded_at":"2017-07-10T00:30:00+0900","value":50.0,"flags":"historical"},{"recorded_at":"2017-07-10T01:00:00+0900","value":49.0,"flags":"historical"},{"recorded_at":"2017-07-10T01:30:00+0900","value":49.0,"flags":"historical"},{"recorded_at":"2017-07-10T02:00:00+0900","value":49.0,"flags":"historical"},{"recorded_at":"2017-07-10T02:30:00+0900","value":43.0,"flags":"historical"},{"recorded_at":"2017-07-10T03:00:00+0900","value":44.0,"flags":"historical"},{"recorded_at":"2017-07-10T03:30:00+0900","value":44.0,"flags":"historical"},{"recorded_at":"2017-07-10T04:00:00+0900","value":45.0,"flags":"historical"},{"recorded_at":"2017-07-10T04:30:00+0900","value":45.0,"flags":"historical"},{"recorded_at":"2017-07-10T05:00:00+0900","value":44.0,"flags":"historical"},{"recorded_at":"2017-07-10T05:30:00+0900","value":46.0,"flags":"historical"},{"recorded_at":"2017-07-10T06:00:00+0900","value":51.0,"flags":"historical"},{"recorded_at":"2017-07-10T06:30:00+0900","value":69.0,"flags":"historical"},{"recorded_at":"2017-07-10T07:00:00+0900","value":121.0,"flags":"historical"},{"recorded_at":"2017-07-10T07:30:00+0900","value":90.0,"flags":"historical"},{"recorded_at":"2017-07-10T08:00:00+0900","value":116.0,"flags":"historical"},{"recorded_at":"2017-07-10T08:30:00+0900","value":150.0,"flags":"historical"},{"recorded_at":"2017-07-10T09:00:00+0900","value":201.0,"flags":"historical"},{"recorded_at":"2017-07-10T09:30:00+0900","value":213.0,"flags":"historical"},{"recorded_at":"2017-07-10T10:00:00+0900","value":223.0,"flags":"historical"},{"recorded_at":"2017-07-10T10:30:00+0900","value":226.0,"flags":"historical"},{"recorded_at":"2017-07-10T11:00:00+0900","value":224.0,"flags":"historical"},{"recorded_at":"2017-07-10T11:30:00+0900","value":222.0,"flags":"historical"},{"recorded_at":"2017-07-10T12:00:00+0900","value":225.0,"flags":"historical"},{"recorded_at":"2017-07-10T12:30:00+0900","value":216.0,"flags":"historical"},{"recorded_at":"2017-07-10T13:00:00+0900","value":207.0,"flags":"historical"},{"recorded_at":"2017-07-10T13:30:00+0900","value":224.0,"flags":"historical"},{"recorded_at":"2017-07-10T14:00:00+0900","value":221.0,"flags":"historical"},{"recorded_at":"2017-07-10T14:30:00+0900","value":217.0,"flags":"historical"},{"recorded_at":"2017-07-10T15:00:00+0900","value":215.0,"flags":"historical"},{"recorded_at":"2017-07-10T15:30:00+0900","value":234.0,"flags":"historical"},{"recorded_at":"2017-07-10T16:00:00+0900","value":240.0,"flags":"historical"},{"recorded_at":"2017-07-10T16:30:00+0900","value":243.0,"flags":"historical"},{"recorded_at":"2017-07-10T17:00:00+0900","value":233.0,"flags":"historical"},{"recorded_at":"2017-07-10T17:30:00+0900","value":232.0,"flags":"historical"},{"recorded_at":"2017-07-10T18:00:00+0900","value":214.0,"flags":"historical"},{"recorded_at":"2017-07-10T18:30:00+0900","value":176.0,"flags":"historical"},{"recorded_at":"2017-07-10T19:00:00+0900","value":163.0,"flags":"historical"},{"recorded_at":"2017-07-10T19:30:00+0900","value":141.0,"flags":"historical"},{"recorded_at":"2017-07-10T20:00:00+0900","value":137.0,"flags":"historical"},{"recorded_at":"2017-07-10T20:30:00+0900","value":134.0,"flags":"historical"},{"recorded_at":"2017-07-10T21:00:00+0900","value":130.0,"flags":"historical"},{"recorded_at":"2017-07-10T21:30:00+0900","value":116.0,"flags":"historical"},{"recorded_at":"2017-07-10T22:00:00+0900","value":109.0,"flags":"historical"},{"recorded_at":"2017-07-10T22:30:00+0900","value":92.0,"flags":"historical"},{"recorded_at":"2017-07-10T23:00:00+0900","value":74.0,"flags":"historical"},{"recorded_at":"2017-07-10T23:30:00+0900","value":63.0,"flags":"historical"},{"recorded_at":"2017-07-11T00:00:00+0900","value":58.0,"flags":"historical"},{"recorded_at":"2017-07-11T00:30:00+0900","value":54.0,"flags":"historical"},{"recorded_at":"2017-07-11T01:00:00+0900","value":42.0,"flags":"historical"},{"recorded_at":"2017-07-11T01:30:00+0900","value":41.0,"flags":"historical"},{"recorded_at":"2017-07-11T02:00:00+0900","value":43.0,"flags":"historical"},{"recorded_at":"2017-07-11T02:30:00+0900","value":41.0,"flags":"historical"},{"recorded_at":"2017-07-11T03:00:00+0900","value":43.0,"flags":"historical"},{"recorded_at":"2017-07-11T03:30:00+0900","value":43.0,"flags":"historical"},{"recorded_at":"2017-07-11T04:00:00+0900","value":42.0,"flags":"historical"},{"recorded_at":"2017-07-11T04:30:00+0900","value":42.0,"flags":"historical"},{"recorded_at":"2017-07-11T05:00:00+0900","value":42.0,"flags":"historical"},{"recorded_at":"2017-07-11T05:30:00+0900","value":43.0,"flags":"historical"},{"recorded_at":"2017-07-11T06:00:00+0900","value":48.0,"flags":"historical"},{"recorded_at":"2017-07-11T06:30:00+0900","value":66.0,"flags":"historical"},{"recorded_at":"2017-07-11T07:00:00+0900","value":102.0,"flags":"historical"},{"recorded_at":"2017-07-11T07:30:00+0900","value":96.0,"flags":"historical"},{"recorded_at":"2017-07-11T08:00:00+0900","value":125.0,"flags":"historical"},{"recorded_at":"2017-07-11T08:30:00+0900","value":159.0,"flags":"historical"},{"recorded_at":"2017-07-11T09:00:00+0900","value":201.0,"flags":"historical"},{"recorded_at":"2017-07-11T09:30:00+0900","value":212.0,"flags":"historical"},{"recorded_at":"2017-07-11T10:00:00+0900","value":217.0,"flags":"historical"},{"recorded_at":"2017-07-11T10:30:00+0900","value":216.0,"flags":"historical"},{"recorded_at":"2017-07-11T11:00:00+0900","value":227.0,"flags":"historical"},{"recorded_at":"2017-07-11T11:30:00+0900","value":233.0,"flags":"historical"},{"recorded_at":"2017-07-11T12:00:00+0900","value":224.0,"flags":"historical"},{"recorded_at":"2017-07-11T12:30:00+0900","value":211.0,"flags":"historical"},{"recorded_at":"2017-07-11T13:00:00+0900","value":207.0,"flags":"historical"},{"recorded_at":"2017-07-11T13:30:00+0900","value":220.0,"flags":"historical"},{"recorded_at":"2017-07-11T14:00:00+0900","value":218.0,"flags":"historical"},{"recorded_at":"2017-07-11T14:30:00+0900","value":224.0,"flags":"historical"},{"recorded_at":"2017-07-11T15:00:00+0900","value":230.0,"flags":"historical"},{"recorded_at":"2017-07-11T15:30:00+0900","value":222.0,"flags":"historical"},{"recorded_at":"2017-07-11T16:00:00+0900","value":230.0,"flags":"historical"},{"recorded_at":"2017-07-11T16:30:00+0900","value":224.0,"flags":"historical"},{"recorded_at":"2017-07-11T17:00:00+0900","value":238.0,"flags":"historical"},{"recorded_at":"2017-07-11T17:30:00+0900","value":243.0,"flags":"historical"},{"recorded_at":"2017-07-11T18:00:00+0900","value":227.0,"flags":"historical"},{"recorded_at":"2017-07-11T18:30:00+0900","value":191.0,"flags":"historical"},{"recorded_at":"2017-07-11T19:00:00+0900","value":175.0,"flags":"historical"},{"recorded_at":"2017-07-11T19:30:00+0900","value":145.0,"flags":"historical"},{"recorded_at":"2017-07-11T20:00:00+0900","value":141.0,"flags":"historical"},{"recorded_at":"2017-07-11T20:30:00+0900","value":132.0,"flags":"historical"},{"recorded_at":"2017-07-11T21:00:00+0900","value":121.0,"flags":"historical"},{"recorded_at":"2017-07-11T21:30:00+0900","value":108.0,"flags":"historical"},{"recorded_at":"2017-07-11T22:00:00+0900","value":94.0,"flags":"historical"},{"recorded_at":"2017-07-11T22:30:00+0900","value":84.0,"flags":"historical"},{"recorded_at":"2017-07-11T23:00:00+0900","value":80.0,"flags":"historical"},{"recorded_at":"2017-07-11T23:30:00+0900","value":65.0,"flags":"historical"},{"recorded_at":"2017-07-12T00:00:00+0900","value":54.0,"flags":"historical"},{"recorded_at":"2017-07-12T00:30:00+0900","value":54.0,"flags":"historical"},{"recorded_at":"2017-07-12T01:00:00+0900","value":51.0,"flags":"historical"},{"recorded_at":"2017-07-12T01:30:00+0900","value":51.0,"flags":"historical"},{"recorded_at":"2017-07-12T02:00:00+0900","value":52.0,"flags":"historical"},{"recorded_at":"2017-07-12T02:30:00+0900","value":52.0,"flags":"historical"},{"recorded_at":"2017-07-12T03:00:00+0900","value":52.0,"flags":"historical"},{"recorded_at":"2017-07-12T03:30:00+0900","value":48.0,"flags":"historical"},{"recorded_at":"2017-07-12T04:00:00+0900","value":41.0,"flags":"historical"},{"recorded_at":"2017-07-12T04:30:00+0900","value":51.0,"flags":"historical"},{"recorded_at":"2017-07-12T05:00:00+0900","value":51.0,"flags":"historical"},{"recorded_at":"2017-07-12T05:30:00+0900","value":53.0,"flags":"historical"},{"recorded_at":"2017-07-12T06:00:00+0900","value":54.0,"flags":"historical"},{"recorded_at":"2017-07-12T06:30:00+0900","value":79.0,"flags":"historical"},{"recorded_at":"2017-07-12T07:00:00+0900","value":116.0,"flags":"historical"},{"recorded_at":"2017-07-12T07:30:00+0900","value":106.0,"flags":"historical"},{"recorded_at":"2017-07-12T08:00:00+0900","value":121.0,"flags":"historical"},{"recorded_at":"2017-07-12T08:30:00+0900","value":163.0,"flags":"historical"},{"recorded_at":"2017-07-12T09:00:00+0900","value":204.0,"flags":"historical"},{"recorded_at":"2017-07-12T09:30:00+0900","value":221.0,"flags":"historical"},{"recorded_at":"2017-07-12T10:00:00+0900","value":224.0,"flags":"historical"},{"recorded_at":"2017-07-12T10:30:00+0900","value":224.0,"flags":"historical"},{"recorded_at":"2017-07-12T11:00:00+0900","value":231.0,"flags":"historical"},{"recorded_at":"2017-07-12T11:30:00+0900","value":229.0,"flags":"historical"},{"recorded_at":"2017-07-12T12:00:00+0900","value":211.0,"flags":"historical"},{"recorded_at":"2017-07-12T12:30:00+0900","value":204.0,"flags":"historical"},{"recorded_at":"2017-07-12T13:00:00+0900","value":208.0,"flags":"historical"},{"recorded_at":"2017-07-12T13:30:00+0900","value":226.0,"flags":"historical"},{"recorded_at":"2017-07-12T14:00:00+0900","value":226.0,"flags":"historical"},{"recorded_at":"2017-07-12T14:30:00+0900","value":228.0,"flags":"historical"},{"recorded_at":"2017-07-12T15:00:00+0900","value":220.0,"flags":"historical"},{"recorded_at":"2017-07-12T15:30:00+0900","value":219.0,"flags":"historical"},{"recorded_at":"2017-07-12T16:00:00+0900","value":217.0,"flags":"historical"},{"recorded_at":"2017-07-12T16:30:00+0900","value":217.0,"flags":"historical"},{"recorded_at":"2017-07-12T17:00:00+0900","value":216.0,"flags":"historical"},{"recorded_at":"2017-07-12T17:30:00+0900","value":223.0,"flags":"historical"},{"recorded_at":"2017-07-12T18:00:00+0900","value":206.0,"flags":"historical"},{"recorded_at":"2017-07-12T18:30:00+0900","value":176.0,"flags":"historical"},{"recorded_at":"2017-07-12T19:00:00+0900","value":158.0,"flags":"historical"},{"recorded_at":"2017-07-12T19:30:00+0900","value":133.0,"flags":"historical"},{"recorded_at":"2017-07-12T20:00:00+0900","value":128.0,"flags":"historical"},{"recorded_at":"2017-07-12T20:30:00+0900","value":120.0,"flags":"historical"},{"recorded_at":"2017-07-12T21:00:00+0900","value":110.0,"flags":"historical"},{"recorded_at":"2017-07-12T21:30:00+0900","value":95.0,"flags":"historical"},{"recorded_at":"2017-07-12T22:00:00+0900","value":83.0,"flags":"historical"},{"recorded_at":"2017-07-12T22:30:00+0900","value":77.0,"flags":"historical"},{"recorded_at":"2017-07-12T23:00:00+0900","value":66.0,"flags":"historical"},{"recorded_at":"2017-07-12T23:30:00+0900","value":60.0,"flags":"historical"},{"recorded_at":"2017-07-13T00:00:00+0900","value":57.0,"flags":"historical"},{"recorded_at":"2017-07-13T00:30:00+0900","value":52.0,"flags":"historical"},{"recorded_at":"2017-07-13T01:00:00+0900","value":51.0,"flags":"historical"},{"recorded_at":"2017-07-13T01:30:00+0900","value":42.0,"flags":"historical"},{"recorded_at":"2017-07-13T02:00:00+0900","value":42.0,"flags":"historical"},{"recorded_at":"2017-07-13T02:30:00+0900","value":43.0,"flags":"historical"},{"recorded_at":"2017-07-13T03:00:00+0900","value":43.0,"flags":"historical"},{"recorded_at":"2017-07-13T03:30:00+0900","value":42.0,"flags":"historical"},{"recorded_at":"2017-07-13T04:00:00+0900","value":44.0,"flags":"historical"},{"recorded_at":"2017-07-13T04:30:00+0900","value":42.0,"flags":"historical"},{"recorded_at":"2017-07-13T05:00:00+0900","value":43.0,"flags":"historical"},{"recorded_at":"2017-07-13T05:30:00+0900","value":44.0,"flags":"historical"},{"recorded_at":"2017-07-13T06:00:00+0900","value":48.0,"flags":"historical"},{"recorded_at":"2017-07-13T06:30:00+0900","value":73.0,"flags":"historical"},{"recorded_at":"2017-07-13T07:00:00+0900","value":108.0,"flags":"historical"},{"recorded_at":"2017-07-13T07:30:00+0900","value":108.0,"flags":"historical"},{"recorded_at":"2017-07-13T08:00:00+0900","value":119.0,"flags":"historical"},{"recorded_at":"2017-07-13T08:30:00+0900","value":155.0,"flags":"historical"},{"recorded_at":"2017-07-13T09:00:00+0900","value":200.0,"flags":"historical"},{"recorded_at":"2017-07-13T09:30:00+0900","value":217.0,"flags":"historical"},{"recorded_at":"2017-07-13T10:00:00+0900","value":220.0,"flags":"historical"},{"recorded_at":"2017-07-13T10:30:00+0900","value":229.0,"flags":"historical"},{"recorded_at":"2017-07-13T11:00:00+0900","value":231.0,"flags":"historical"},{"recorded_at":"2017-07-13T11:30:00+0900","value":231.0,"flags":"historical"},{"recorded_at":"2017-07-13T12:00:00+0900","value":221.0,"flags":"historical"},{"recorded_at":"2017-07-13T12:30:00+0900","value":222.0,"flags":"historical"},{"recorded_at":"2017-07-13T13:00:00+0900","value":216.0,"flags":"historical"},{"recorded_at":"2017-07-13T13:30:00+0900","value":218.0,"flags":"historical"},{"recorded_at":"2017-07-13T14:00:00+0900","value":218.0,"flags":"historical"},{"recorded_at":"2017-07-13T14:30:00+0900","value":215.0,"flags":"historical"},{"recorded_at":"2017-07-13T15:00:00+0900","value":216.0,"flags":"historical"},{"recorded_at":"2017-07-13T15:30:00+0900","value":230.0,"flags":"historical"},{"recorded_at":"2017-07-13T16:00:00+0900","value":227.0,"flags":"historical"},{"recorded_at":"2017-07-13T16:30:00+0900","value":240.0,"flags":"historical"},{"recorded_at":"2017-07-13T17:00:00+0900","value":228.0,"flags":"historical"},{"recorded_at":"2017-07-13T17:30:00+0900","value":229.0,"flags":"historical"},{"recorded_at":"2017-07-13T18:00:00+0900","value":218.0,"flags":"historical"},{"recorded_at":"2017-07-13T18:30:00+0900","value":206.0,"flags":"historical"},{"recorded_at":"2017-07-13T19:00:00+0900","value":183.0,"flags":"historical"},{"recorded_at":"2017-07-13T19:30:00+0900","value":152.0,"flags":"historical"},{"recorded_at":"2017-07-13T20:00:00+0900","value":156.0,"flags":"historical"},{"recorded_at":"2017-07-13T20:30:00+0900","value":150.0,"flags":"historical"},{"recorded_at":"2017-07-13T21:00:00+0900","value":132.0,"flags":"historical"},{"recorded_at":"2017-07-13T21:30:00+0900","value":109.0,"flags":"historical"},{"recorded_at":"2017-07-13T22:00:00+0900","value":95.0,"flags":"historical"},{"recorded_at":"2017-07-13T22:30:00+0900","value":89.0,"flags":"historical"},{"recorded_at":"2017-07-13T23:00:00+0900","value":83.0,"flags":"historical"},{"recorded_at":"2017-07-13T23:30:00+0900","value":78.0,"flags":"historical"},{"recorded_at":"2017-07-14T00:00:00+0900","value":65.0,"flags":"historical"},{"recorded_at":"2017-07-14T00:30:00+0900","value":61.0,"flags":"historical"},{"recorded_at":"2017-07-14T01:00:00+0900","value":57.0,"flags":"historical"},{"recorded_at":"2017-07-14T01:30:00+0900","value":57.0,"flags":"historical"},{"recorded_at":"2017-07-14T02:00:00+0900","value":56.0,"flags":"historical"},{"recorded_at":"2017-07-14T02:30:00+0900","value":57.0,"flags":"historical"},{"recorded_at":"2017-07-14T03:00:00+0900","value":57.0,"flags":"historical"},{"recorded_at":"2017-07-14T03:30:00+0900","value":52.0,"flags":"historical"},{"recorded_at":"2017-07-14T04:00:00+0900","value":49.0,"flags":"historical"},{"recorded_at":"2017-07-14T04:30:00+0900","value":50.0,"flags":"historical"},{"recorded_at":"2017-07-14T05:00:00+0900","value":49.0,"flags":"historical"},{"recorded_at":"2017-07-14T05:30:00+0900","value":53.0,"flags":"historical"},{"recorded_at":"2017-07-14T06:00:00+0900","value":58.0,"flags":"historical"},{"recorded_at":"2017-07-14T06:30:00+0900","value":74.0,"flags":"historical"},{"recorded_at":"2017-07-14T07:00:00+0900","value":117.0,"flags":"historical"},{"recorded_at":"2017-07-14T07:30:00+0900","value":121.0,"flags":"historical"},{"recorded_at":"2017-07-14T08:00:00+0900","value":135.0,"flags":"historical"},{"recorded_at":"2017-07-14T08:30:00+0900","value":159.0,"flags":"historical"},{"recorded_at":"2017-07-14T09:00:00+0900","value":211.0,"flags":"historical"},{"recorded_at":"2017-07-14T09:30:00+0900","value":230.0,"flags":"historical"},{"recorded_at":"2017-07-14T10:00:00+0900","value":225.0,"flags":"historical"},{"recorded_at":"2017-07-14T10:30:00+0900","value":230.0,"flags":"historical"},{"recorded_at":"2017-07-14T11:00:00+0900","value":231.0,"flags":"historical"},{"recorded_at":"2017-07-14T11:30:00+0900","value":222.0,"flags":"historical"},{"recorded_at":"2017-07-14T12:00:00+0900","value":221.0,"flags":"historical"},{"recorded_at":"2017-07-14T12:30:00+0900","value":220.0,"flags":"historical"},{"recorded_at":"2017-07-14T13:00:00+0900","value":209.0,"flags":"historical"},{"recorded_at":"2017-07-14T13:30:00+0900","value":225.0,"flags":"historical"},{"recorded_at":"2017-07-14T14:00:00+0900","value":222.0,"flags":"historical"},{"recorded_at":"2017-07-14T14:30:00+0900","value":214.0,"flags":"historical"},{"recorded_at":"2017-07-14T15:00:00+0900","value":218.0,"flags":"historical"},{"recorded_at":"2017-07-14T15:30:00+0900","value":225.0,"flags":"historical"},{"recorded_at":"2017-07-14T16:00:00+0900","value":225.0,"flags":"historical"},{"recorded_at":"2017-07-14T16:30:00+0900","value":222.0,"flags":"historical"},{"recorded_at":"2017-07-14T17:00:00+0900","value":221.0,"flags":"historical"},{"recorded_at":"2017-07-14T17:30:00+0900","value":218.0,"flags":"historical"},{"recorded_at":"2017-07-14T18:00:00+0900","value":211.0,"flags":"historical"},{"recorded_at":"2017-07-14T18:30:00+0900","value":179.0,"flags":"historical"},{"recorded_at":"2017-07-14T19:00:00+0900","value":149.0,"flags":"historical"},{"recorded_at":"2017-07-14T19:30:00+0900","value":127.0,"flags":"historical"},{"recorded_at":"2017-07-14T20:00:00+0900","value":119.0,"flags":"historical"},{"recorded_at":"2017-07-14T20:30:00+0900","value":105.0,"flags":"historical"},{"recorded_at":"2017-07-14T21:00:00+0900","value":97.0,"flags":"historical"},{"recorded_at":"2017-07-14T21:30:00+0900","value":85.0,"flags":"historical"},{"recorded_at":"2017-07-14T22:00:00+0900","value":70.0,"flags":"historical"},{"recorded_at":"2017-07-14T22:30:00+0900","value":62.0,"flags":"historical"},{"recorded_at":"2017-07-14T23:00:00+0900","value":58.0,"flags":"historical"},{"recorded_at":"2017-07-14T23:30:00+0900","value":56.0,"flags":"historical"},{"recorded_at":"2017-07-15T00:00:00+0900","value":57.0,"flags":"historical"},{"recorded_at":"2017-07-15T00:30:00+0900","value":51.0,"flags":"historical"},{"recorded_at":"2017-07-15T01:00:00+0900","value":46.0,"flags":"historical"},{"recorded_at":"2017-07-15T01:30:00+0900","value":47.0,"flags":"historical"},{"recorded_at":"2017-07-15T02:00:00+0900","value":46.0,"flags":"historical"},{"recorded_at":"2017-07-15T02:30:00+0900","value":47.0,"flags":"historical"},{"recorded_at":"2017-07-15T03:00:00+0900","value":46.0,"flags":"historical"},{"recorded_at":"2017-07-15T03:30:00+0900","value":47.0,"flags":"historical"},{"recorded_at":"2017-07-15T04:00:00+0900","value":71.0,"flags":"historical"},{"recorded_at":"2017-07-15T04:30:00+0900","value":77.0,"flags":"historical"},{"recorded_at":"2017-07-15T05:00:00+0900","value":73.0,"flags":"historical"},{"recorded_at":"2017-07-15T05:30:00+0900","value":54.0,"flags":"historical"},{"recorded_at":"2017-07-15T06:00:00+0900","value":53.0,"flags":"historical"},{"recorded_at":"2017-07-15T06:30:00+0900","value":52.0,"flags":"historical"},{"recorded_at":"2017-07-15T07:00:00+0900","value":55.0,"flags":"historical"},{"recorded_at":"2017-07-15T07:30:00+0900","value":54.0,"flags":"historical"},{"recorded_at":"2017-07-15T08:00:00+0900","value":56.0,"flags":"historical"},{"recorded_at":"2017-07-15T08:30:00+0900","value":60.0,"flags":"historical"},{"recorded_at":"2017-07-15T09:00:00+0900","value":68.0,"flags":"historical"},{"recorded_at":"2017-07-15T09:30:00+0900","value":76.0,"flags":"historical"},{"recorded_at":"2017-07-15T10:00:00+0900","value":79.0,"flags":"historical"},{"recorded_at":"2017-07-15T10:30:00+0900","value":82.0,"flags":"historical"},{"recorded_at":"2017-07-15T11:00:00+0900","value":80.0,"flags":"historical"},{"recorded_at":"2017-07-15T11:30:00+0900","value":82.0,"flags":"historical"},{"recorded_at":"2017-07-15T12:00:00+0900","value":81.0,"flags":"historical"},{"recorded_at":"2017-07-15T12:30:00+0900","value":79.0,"flags":"historical"},{"recorded_at":"2017-07-15T13:00:00+0900","value":79.0,"flags":"historical"},{"recorded_at":"2017-07-15T13:30:00+0900","value":88.0,"flags":"historical"},{"recorded_at":"2017-07-15T14:00:00+0900","value":90.0,"flags":"historical"},{"recorded_at":"2017-07-15T14:30:00+0900","value":91.0,"flags":"historical"},{"recorded_at":"2017-07-15T15:00:00+0900","value":89.0,"flags":"historical"},{"recorded_at":"2017-07-15T15:30:00+0900","value":90.0,"flags":"historical"},{"recorded_at":"2017-07-15T16:00:00+0900","value":89.0,"flags":"historical"},{"recorded_at":"2017-07-15T16:30:00+0900","value":87.0,"flags":"historical"},{"recorded_at":"2017-07-15T17:00:00+0900","value":78.0,"flags":"historical"},{"recorded_at":"2017-07-15T17:30:00+0900","value":77.0,"flags":"historical"},{"recorded_at":"2017-07-15T18:00:00+0900","value":74.0,"flags":"historical"},{"recorded_at":"2017-07-15T18:30:00+0900","value":69.0,"flags":"historical"},{"recorded_at":"2017-07-15T19:00:00+0900","value":70.0,"flags":"historical"},{"recorded_at":"2017-07-15T19:30:00+0900","value":68.0,"flags":"historical"},{"recorded_at":"2017-07-15T20:00:00+0900","value":67.0,"flags":"historical"},{"recorded_at":"2017-07-15T20:30:00+0900","value":68.0,"flags":"historical"},{"recorded_at":"2017-07-15T21:00:00+0900","value":68.0,"flags":"historical"},{"recorded_at":"2017-07-15T21:30:00+0900","value":60.0,"flags":"historical"},{"recorded_at":"2017-07-15T22:00:00+0900","value":54.0,"flags":"historical"},{"recorded_at":"2017-07-15T22:30:00+0900","value":56.0,"flags":"historical"},{"recorded_at":"2017-07-15T23:00:00+0900","value":54.0,"flags":"historical"},{"recorded_at":"2017-07-15T23:30:00+0900","value":54.0,"flags":"historical"},{"recorded_at":"2017-07-16T00:00:00+0900","value":53.0,"flags":"historical"},{"recorded_at":"2017-07-16T00:30:00+0900","value":50.0,"flags":"historical"},{"recorded_at":"2017-07-16T01:00:00+0900","value":47.0,"flags":"historical"},{"recorded_at":"2017-07-16T01:30:00+0900","value":47.0,"flags":"historical"},{"recorded_at":"2017-07-16T02:00:00+0900","value":47.0,"flags":"historical"},{"recorded_at":"2017-07-16T02:30:00+0900","value":48.0,"flags":"historical"},{"recorded_at":"2017-07-16T03:00:00+0900","value":47.0,"flags":"historical"},{"recorded_at":"2017-07-16T03:30:00+0900","value":47.0,"flags":"historical"},{"recorded_at":"2017-07-16T04:00:00+0900","value":47.0,"flags":"historical"},{"recorded_at":"2017-07-16T04:30:00+0900","value":48.0,"flags":"historical"},{"recorded_at":"2017-07-16T05:00:00+0900","value":48.0,"flags":"historical"},{"recorded_at":"2017-07-16T05:30:00+0900","value":48.0,"flags":"historical"},{"recorded_at":"2017-07-16T06:00:00+0900","value":49.0,"flags":"historical"},{"recorded_at":"2017-07-16T06:30:00+0900","value":48.0,"flags":"historical"},{"recorded_at":"2017-07-16T07:00:00+0900","value":53.0,"flags":"historical"},{"recorded_at":"2017-07-16T07:30:00+0900","value":53.0,"flags":"historical"},{"recorded_at":"2017-07-16T08:00:00+0900","value":52.0,"flags":"historical"},{"recorded_at":"2017-07-16T08:30:00+0900","value":56.0,"flags":"historical"},{"recorded_at":"2017-07-16T09:00:00+0900","value":66.0,"flags":"historical"},{"recorded_at":"2017-07-16T09:30:00+0900","value":71.0,"flags":"historical"},{"recorded_at":"2017-07-16T10:00:00+0900","value":69.0,"flags":"historical"},{"recorded_at":"2017-07-16T10:30:00+0900","value":74.0,"flags":"historical"},{"recorded_at":"2017-07-16T11:00:00+0900","value":78.0,"flags":"historical"},{"recorded_at":"2017-07-16T11:30:00+0900","value":77.0,"flags":"historical"},{"recorded_at":"2017-07-16T12:00:00+0900","value":78.0,"flags":"historical"},{"recorded_at":"2017-07-16T12:30:00+0900","value":81.0,"flags":"historical"},{"recorded_at":"2017-07-16T13:00:00+0900","value":75.0,"flags":"historical"},{"recorded_at":"2017-07-16T13:30:00+0900","value":77.0,"flags":"historical"},{"recorded_at":"2017-07-16T14:00:00+0900","value":72.0,"flags":"historical"},{"recorded_at":"2017-07-16T14:30:00+0900","value":72.0,"flags":"historical"},{"recorded_at":"2017-07-16T15:00:00+0900","value":72.0,"flags":"historical"},{"recorded_at":"2017-07-16T15:30:00+0900","value":73.0,"flags":"historical"},{"recorded_at":"2017-07-16T16:00:00+0900","value":75.0,"flags":"historical"},{"recorded_at":"2017-07-16T16:30:00+0900","value":79.0,"flags":"historical"},{"recorded_at":"2017-07-16T17:00:00+0900","value":77.0,"flags":"historical"},{"recorded_at":"2017-07-16T17:30:00+0900","value":71.0,"flags":"historical"},{"recorded_at":"2017-07-16T18:00:00+0900","value":66.0,"flags":"historical"},{"recorded_at":"2017-07-16T18:30:00+0900","value":59.0,"flags":"historical"},{"recorded_at":"2017-07-16T19:00:00+0900","value":59.0,"flags":"historical"},{"recorded_at":"2017-07-16T19:30:00+0900","value":52.0,"flags":"historical"},{"recorded_at":"2017-07-16T20:00:00+0900","value":52.0,"flags":"historical"},{"recorded_at":"2017-07-16T20:30:00+0900","value":54.0,"flags":"historical"},{"recorded_at":"2017-07-16T21:00:00+0900","value":53.0,"flags":"historical"},{"recorded_at":"2017-07-16T21:30:00+0900","value":53.0,"flags":"historical"},{"recorded_at":"2017-07-16T22:00:00+0900","value":53.0,"flags":"historical"},{"recorded_at":"2017-07-16T22:30:00+0900","value":51.0,"flags":"historical"},{"recorded_at":"2017-07-16T23:00:00+0900","value":50.0,"flags":"historical"},{"recorded_at":"2017-07-16T23:30:00+0900","value":50.0,"flags":"historical"},{"recorded_at":"2017-07-17T00:00:00+0900","value":46.0,"flags":"historical"},{"recorded_at":"2017-07-17T00:30:00+0900","value":47.0,"flags":"historical"},{"recorded_at":"2017-07-17T01:00:00+0900","value":47.0,"flags":"historical"},{"recorded_at":"2017-07-17T01:30:00+0900","value":47.0,"flags":"historical"},{"recorded_at":"2017-07-17T02:00:00+0900","value":47.0,"flags":"historical"},{"recorded_at":"2017-07-17T02:30:00+0900","value":48.0,"flags":"historical"},{"recorded_at":"2017-07-17T03:00:00+0900","value":49.0,"flags":"historical"},{"recorded_at":"2017-07-17T03:30:00+0900","value":48.0,"flags":"historical"},{"recorded_at":"2017-07-17T04:00:00+0900","value":49.0,"flags":"historical"},{"recorded_at":"2017-07-17T04:30:00+0900","value":48.0,"flags":"historical"},{"recorded_at":"2017-07-17T05:00:00+0900","value":48.0,"flags":"historical"},{"recorded_at":"2017-07-17T05:30:00+0900","value":49.0,"flags":"historical"},{"recorded_at":"2017-07-17T06:00:00+0900","value":51.0,"flags":"historical"},{"recorded_at":"2017-07-17T06:30:00+0900","value":61.0,"flags":"historical"},{"recorded_at":"2017-07-17T07:00:00+0900","value":99.0,"flags":"historical"},{"recorded_at":"2017-07-17T07:30:00+0900","value":62.0,"flags":"historical"},{"recorded_at":"2017-07-17T08:00:00+0900","value":58.0,"flags":"historical"},{"recorded_at":"2017-07-17T08:30:00+0900","value":58.0,"flags":"historical"},{"recorded_at":"2017-07-17T09:00:00+0900","value":64.0,"flags":"historical"},{"recorded_at":"2017-07-17T09:30:00+0900","value":72.0,"flags":"historical"},{"recorded_at":"2017-07-17T10:00:00+0900","value":75.0,"flags":"historical"},{"recorded_at":"2017-07-17T10:30:00+0900","value":80.0,"flags":"historical"},{"recorded_at":"2017-07-17T11:00:00+0900","value":83.0,"flags":"historical"},{"recorded_at":"2017-07-17T11:30:00+0900","value":80.0,"flags":"historical"},{"recorded_at":"2017-07-17T12:00:00+0900","value":77.0,"flags":"historical"},{"recorded_at":"2017-07-17T12:30:00+0900","value":74.0,"flags":"historical"},{"recorded_at":"2017-07-17T13:00:00+0900","value":76.0,"flags":"historical"},{"recorded_at":"2017-07-17T13:30:00+0900","value":73.0,"flags":"historical"},{"recorded_at":"2017-07-17T14:00:00+0900","value":74.0,"flags":"historical"},{"recorded_at":"2017-07-17T14:30:00+0900","value":73.0,"flags":"historical"},{"recorded_at":"2017-07-17T15:00:00+0900","value":73.0,"flags":"historical"},{"recorded_at":"2017-07-17T15:30:00+0900","value":72.0,"flags":"historical"},{"recorded_at":"2017-07-17T16:00:00+0900","value":76.0,"flags":"historical"},{"recorded_at":"2017-07-17T16:30:00+0900","value":76.0,"flags":"historical"},{"recorded_at":"2017-07-17T17:00:00+0900","value":72.0,"flags":"historical"},{"recorded_at":"2017-07-17T17:30:00+0900","value":75.0,"flags":"historical"},{"recorded_at":"2017-07-17T18:00:00+0900","value":72.0,"flags":"historical"},{"recorded_at":"2017-07-17T18:30:00+0900","value":67.0,"flags":"historical"},{"recorded_at":"2017-07-17T19:00:00+0900","value":69.0,"flags":"historical"},{"recorded_at":"2017-07-17T19:30:00+0900","value":68.0,"flags":"historical"},{"recorded_at":"2017-07-17T20:00:00+0900","value":67.0,"flags":"historical"},{"recorded_at":"2017-07-17T20:30:00+0900","value":66.0,"flags":"historical"},{"recorded_at":"2017-07-17T21:00:00+0900","value":64.0,"flags":"historical"},{"recorded_at":"2017-07-17T21:30:00+0900","value":58.0,"flags":"historical"},{"recorded_at":"2017-07-17T22:00:00+0900","value":57.0,"flags":"historical"},{"recorded_at":"2017-07-17T22:30:00+0900","value":55.0,"flags":"historical"},{"recorded_at":"2017-07-17T23:00:00+0900","value":52.0,"flags":"historical"},{"recorded_at":"2017-07-17T23:30:00+0900","value":51.0,"flags":"historical"},{"recorded_at":"2017-07-18T00:00:00+0900","value":51.0,"flags":"historical"},{"recorded_at":"2017-07-18T00:30:00+0900","value":51.0,"flags":"historical"},{"recorded_at":"2017-07-18T01:00:00+0900","value":51.0,"flags":"historical"},{"recorded_at":"2017-07-18T01:30:00+0900","value":52.0,"flags":"historical"},{"recorded_at":"2017-07-18T02:00:00+0900","value":51.0,"flags":"historical"},{"recorded_at":"2017-07-18T02:30:00+0900","value":51.0,"flags":"historical"},{"recorded_at":"2017-07-18T03:00:00+0900","value":48.0,"flags":"historical"},{"recorded_at":"2017-07-18T03:30:00+0900","value":46.0,"flags":"historical"},{"recorded_at":"2017-07-18T04:00:00+0900","value":45.0,"flags":"historical"},{"recorded_at":"2017-07-18T04:30:00+0900","value":46.0,"flags":"historical"},{"recorded_at":"2017-07-18T05:00:00+0900","value":46.0,"flags":"historical"},{"recorded_at":"2017-07-18T05:30:00+0900","value":47.0,"flags":"historical"},{"recorded_at":"2017-07-18T06:00:00+0900","value":52.0,"flags":"historical"},{"recorded_at":"2017-07-18T06:30:00+0900","value":68.0,"flags":"historical"},{"recorded_at":"2017-07-18T07:00:00+0900","value":121.0,"flags":"historical"},{"recorded_at":"2017-07-18T07:30:00+0900","value":130.0,"flags":"historical"},{"recorded_at":"2017-07-18T08:00:00+0900","value":156.0,"flags":"historical"},{"recorded_at":"2017-07-18T08:30:00+0900","value":195.0,"flags":"historical"},{"recorded_at":"2017-07-18T09:00:00+0900","value":238.0,"flags":"historical"},{"recorded_at":"2017-07-18T09:30:00+0900","value":262.0,"flags":"historical"},{"recorded_at":"2017-07-18T10:00:00+0900","value":262.0,"flags":"historical"},{"recorded_at":"2017-07-18T10:30:00+0900","value":246.0,"flags":"historical"},{"recorded_at":"2017-07-18T11:00:00+0900","value":236.0,"flags":"historical"},{"recorded_at":"2017-07-18T11:30:00+0900","value":229.0,"flags":"historical"},{"recorded_at":"2017-07-18T12:00:00+0900","value":221.0,"flags":"historical"},{"recorded_at":"2017-07-18T12:30:00+0900","value":209.0,"flags":"historical"},{"recorded_at":"2017-07-18T13:00:00+0900","value":205.0,"flags":"historical"},{"recorded_at":"2017-07-18T13:30:00+0900","value":216.0,"flags":"historical"},{"recorded_at":"2017-07-18T14:00:00+0900","value":218.0,"flags":"historical"},{"recorded_at":"2017-07-18T14:30:00+0900","value":213.0,"flags":"historical"},{"recorded_at":"2017-07-18T15:00:00+0900","value":212.0,"flags":"historical"},{"recorded_at":"2017-07-18T15:30:00+0900","value":208.0,"flags":"historical"},{"recorded_at":"2017-07-18T16:00:00+0900","value":223.0,"flags":"historical"},{"recorded_at":"2017-07-18T16:30:00+0900","value":219.0,"flags":"historical"},{"recorded_at":"2017-07-18T17:00:00+0900","value":218.0,"flags":"historical"},{"recorded_at":"2017-07-18T17:30:00+0900","value":217.0,"flags":"historical"},{"recorded_at":"2017-07-18T18:00:00+0900","value":207.0,"flags":"historical"},{"recorded_at":"2017-07-18T18:30:00+0900","value":183.0,"flags":"historical"},{"recorded_at":"2017-07-18T19:00:00+0900","value":160.0,"flags":"historical"},{"recorded_at":"2017-07-18T19:30:00+0900","value":145.0,"flags":"historical"},{"recorded_at":"2017-07-18T20:00:00+0900","value":140.0,"flags":"historical"},{"recorded_at":"2017-07-18T20:30:00+0900","value":135.0,"flags":"historical"},{"recorded_at":"2017-07-18T21:00:00+0900","value":131.0,"flags":"historical"},{"recorded_at":"2017-07-18T21:30:00+0900","value":122.0,"flags":"historical"},{"recorded_at":"2017-07-18T22:00:00+0900","value":115.0,"flags":"historical"},{"recorded_at":"2017-07-18T22:30:00+0900","value":101.0,"flags":"historical"},{"recorded_at":"2017-07-18T23:00:00+0900","value":82.0,"flags":"historical"},{"recorded_at":"2017-07-18T23:30:00+0900","value":72.0,"flags":"historical"},{"recorded_at":"2017-07-19T00:00:00+0900","value":70.0,"flags":"historical"},{"recorded_at":"2017-07-19T00:30:00+0900","value":70.0,"flags":"historical"},{"recorded_at":"2017-07-19T01:00:00+0900","value":69.0,"flags":"historical"},{"recorded_at":"2017-07-19T01:30:00+0900","value":65.0,"flags":"historical"},{"recorded_at":"2017-07-19T02:00:00+0900","value":60.0,"flags":"historical"},{"recorded_at":"2017-07-19T02:30:00+0900","value":59.0,"flags":"historical"},{"recorded_at":"2017-07-19T03:00:00+0900","value":53.0,"flags":"historical"},{"recorded_at":"2017-07-19T03:30:00+0900","value":47.0,"flags":"historical"},{"recorded_at":"2017-07-19T04:00:00+0900","value":47.0,"flags":"historical"},{"recorded_at":"2017-07-19T04:30:00+0900","value":48.0,"flags":"historical"},{"recorded_at":"2017-07-19T05:00:00+0900","value":47.0,"flags":"historical"},{"recorded_at":"2017-07-19T05:30:00+0900","value":46.0,"flags":"historical"},{"recorded_at":"2017-07-19T06:00:00+0900","value":53.0,"flags":"historical"},{"recorded_at":"2017-07-19T06:30:00+0900","value":72.0,"flags":"historical"},{"recorded_at":"2017-07-19T07:00:00+0900","value":112.0,"flags":"historical"},{"recorded_at":"2017-07-19T07:30:00+0900","value":109.0,"flags":"historical"},{"recorded_at":"2017-07-19T08:00:00+0900","value":123.0,"flags":"historical"},{"recorded_at":"2017-07-19T08:30:00+0900","value":161.0,"flags":"historical"},{"recorded_at":"2017-07-19T09:00:00+0900","value":215.0,"flags":"historical"},{"recorded_at":"2017-07-19T09:30:00+0900","value":234.0,"flags":"historical"},{"recorded_at":"2017-07-19T10:00:00+0900","value":232.0,"flags":"historical"},{"recorded_at":"2017-07-19T10:30:00+0900","value":232.0,"flags":"historical"},{"recorded_at":"2017-07-19T11:00:00+0900","value":233.0,"flags":"historical"},{"recorded_at":"2017-07-19T11:30:00+0900","value":235.0,"flags":"historical"},{"recorded_at":"2017-07-19T12:00:00+0900","value":222.0,"flags":"historical"},{"recorded_at":"2017-07-19T12:30:00+0900","value":216.0,"flags":"historical"},{"recorded_at":"2017-07-19T13:00:00+0900","value":209.0,"flags":"historical"},{"recorded_at":"2017-07-19T13:30:00+0900","value":222.0,"flags":"historical"},{"recorded_at":"2017-07-19T14:00:00+0900","value":230.0,"flags":"historical"},{"recorded_at":"2017-07-19T14:30:00+0900","value":221.0,"flags":"historical"},{"recorded_at":"2017-07-19T15:00:00+0900","value":227.0,"flags":"historical"},{"recorded_at":"2017-07-19T15:30:00+0900","value":232.0,"flags":"historical"},{"recorded_at":"2017-07-19T16:00:00+0900","value":238.0,"flags":"historical"},{"recorded_at":"2017-07-19T16:30:00+0900","value":229.0,"flags":"historical"},{"recorded_at":"2017-07-19T17:00:00+0900","value":231.0,"flags":"historical"},{"recorded_at":"2017-07-19T17:30:00+0900","value":229.0,"flags":"historical"},{"recorded_at":"2017-07-19T18:00:00+0900","value":213.0,"flags":"historical"},{"recorded_at":"2017-07-19T18:30:00+0900","value":181.0,"flags":"historical"},{"recorded_at":"2017-07-19T19:00:00+0900","value":162.0,"flags":"historical"},{"recorded_at":"2017-07-19T19:30:00+0900","value":137.0,"flags":"historical"},{"recorded_at":"2017-07-19T20:00:00+0900","value":126.0,"flags":"historical"},{"recorded_at":"2017-07-19T20:30:00+0900","value":119.0,"flags":"historical"},{"recorded_at":"2017-07-19T21:00:00+0900","value":107.0,"flags":"historical"},{"recorded_at":"2017-07-19T21:30:00+0900","value":97.0,"flags":"historical"},{"recorded_at":"2017-07-19T22:00:00+0900","value":94.0,"flags":"historical"},{"recorded_at":"2017-07-19T22:30:00+0900","value":84.0,"flags":"historical"},{"recorded_at":"2017-07-19T23:00:00+0900","value":68.0,"flags":"historical"},{"recorded_at":"2017-07-19T23:30:00+0900","value":57.0,"flags":"historical"},{"recorded_at":"2017-07-20T00:00:00+0900","value":54.0,"flags":"historical"},{"recorded_at":"2017-07-20T00:30:00+0900","value":45.0,"flags":"historical"},{"recorded_at":"2017-07-20T01:00:00+0900","value":47.0,"flags":"historical"},{"recorded_at":"2017-07-20T01:30:00+0900","value":51.0,"flags":"historical"},{"recorded_at":"2017-07-20T02:00:00+0900","value":51.0,"flags":"historical"},{"recorded_at":"2017-07-20T02:30:00+0900","value":52.0,"flags":"historical"},{"recorded_at":"2017-07-20T03:00:00+0900","value":51.0,"flags":"historical"},{"recorded_at":"2017-07-20T03:30:00+0900","value":51.0,"flags":"historical"},{"recorded_at":"2017-07-20T04:00:00+0900","value":51.0,"flags":"historical"},{"recorded_at":"2017-07-20T04:30:00+0900","value":52.0,"flags":"historical"},{"recorded_at":"2017-07-20T05:00:00+0900","value":52.0,"flags":"historical"},{"recorded_at":"2017-07-20T05:30:00+0900","value":52.0,"flags":"historical"},{"recorded_at":"2017-07-20T06:00:00+0900","value":56.0,"flags":"historical"},{"recorded_at":"2017-07-20T06:30:00+0900","value":71.0,"flags":"historical"},{"recorded_at":"2017-07-20T07:00:00+0900","value":110.0,"flags":"historical"},{"recorded_at":"2017-07-20T07:30:00+0900","value":103.0,"flags":"historical"},{"recorded_at":"2017-07-20T08:00:00+0900","value":132.0,"flags":"historical"},{"recorded_at":"2017-07-20T08:30:00+0900","value":167.0,"flags":"historical"},{"recorded_at":"2017-07-20T09:00:00+0900","value":212.0,"flags":"historical"},{"recorded_at":"2017-07-20T09:30:00+0900","value":230.0,"flags":"historical"},{"recorded_at":"2017-07-20T10:00:00+0900","value":239.0,"flags":"historical"},{"recorded_at":"2017-07-20T10:30:00+0900","value":251.0,"flags":"historical"},{"recorded_at":"2017-07-20T11:00:00+0900","value":251.0,"flags":"historical"},{"recorded_at":"2017-07-20T11:30:00+0900","value":242.0,"flags":"historical"},{"recorded_at":"2017-07-20T12:00:00+0900","value":238.0,"flags":"historical"},{"recorded_at":"2017-07-20T12:30:00+0900","value":224.0,"flags":"historical"},{"recorded_at":"2017-07-20T13:00:00+0900","value":211.0,"flags":"historical"},{"recorded_at":"2017-07-20T13:30:00+0900","value":231.0,"flags":"historical"},{"recorded_at":"2017-07-20T14:00:00+0900","value":244.0,"flags":"historical"},{"recorded_at":"2017-07-20T14:30:00+0900","value":237.0,"flags":"historical"},{"recorded_at":"2017-07-20T15:00:00+0900","value":248.0,"flags":"historical"},{"recorded_at":"2017-07-20T15:30:00+0900","value":248.0,"flags":"historical"},{"recorded_at":"2017-07-20T16:00:00+0900","value":262.0,"flags":"historical"},{"recorded_at":"2017-07-20T16:30:00+0900","value":241.0,"flags":"historical"},{"recorded_at":"2017-07-20T17:00:00+0900","value":243.0,"flags":"historical"},{"recorded_at":"2017-07-20T17:30:00+0900","value":239.0,"flags":"historical"},{"recorded_at":"2017-07-20T18:00:00+0900","value":237.0,"flags":"historical"},{"recorded_at":"2017-07-20T18:30:00+0900","value":200.0,"flags":"historical"},{"recorded_at":"2017-07-20T19:00:00+0900","value":179.0,"flags":"historical"},{"recorded_at":"2017-07-20T19:30:00+0900","value":153.0,"flags":"historical"},{"recorded_at":"2017-07-20T20:00:00+0900","value":149.0,"flags":"historical"},{"recorded_at":"2017-07-20T20:30:00+0900","value":140.0,"flags":"historical"},{"recorded_at":"2017-07-20T21:00:00+0900","value":136.0,"flags":"historical"},{"recorded_at":"2017-07-20T21:30:00+0900","value":118.0,"flags":"historical"},{"recorded_at":"2017-07-20T22:00:00+0900","value":108.0,"flags":"historical"},{"recorded_at":"2017-07-20T22:30:00+0900","value":99.0,"flags":"historical"},{"recorded_at":"2017-07-20T23:00:00+0900","value":88.0,"flags":"historical"},{"recorded_at":"2017-07-20T23:30:00+0900","value":77.0,"flags":"historical"},{"recorded_at":"2017-07-21T00:00:00+0900","value":69.0,"flags":"historical"},{"recorded_at":"2017-07-21T00:30:00+0900","value":58.0,"flags":"historical"},{"recorded_at":"2017-07-21T01:00:00+0900","value":51.0,"flags":"historical"},{"recorded_at":"2017-07-21T01:30:00+0900","value":44.0,"flags":"historical"},{"recorded_at":"2017-07-21T02:00:00+0900","value":47.0,"flags":"historical"},{"recorded_at":"2017-07-21T02:30:00+0900","value":45.0,"flags":"historical"},{"recorded_at":"2017-07-21T03:00:00+0900","value":45.0,"flags":"historical"},{"recorded_at":"2017-07-21T03:30:00+0900","value":44.0,"flags":"historical"},{"recorded_at":"2017-07-21T04:00:00+0900","value":45.0,"flags":"historical"},{"recorded_at":"2017-07-21T04:30:00+0900","value":46.0,"flags":"historical"},{"recorded_at":"2017-07-21T05:00:00+0900","value":46.0,"flags":"historical"},{"recorded_at":"2017-07-21T05:30:00+0900","value":46.0,"flags":"historical"},{"recorded_at":"2017-07-21T06:00:00+0900","value":51.0,"flags":"historical"},{"recorded_at":"2017-07-21T06:30:00+0900","value":69.0,"flags":"historical"},{"recorded_at":"2017-07-21T07:00:00+0900","value":113.0,"flags":"historical"},{"recorded_at":"2017-07-21T07:30:00+0900","value":128.0,"flags":"historical"},{"recorded_at":"2017-07-21T08:00:00+0900","value":140.0,"flags":"historical"},{"recorded_at":"2017-07-21T08:30:00+0900","value":162.0,"flags":"historical"},{"recorded_at":"2017-07-21T09:00:00+0900","value":220.0,"flags":"historical"},{"recorded_at":"2017-07-21T09:30:00+0900","value":236.0,"flags":"historical"},{"recorded_at":"2017-07-21T10:00:00+0900","value":241.0,"flags":"historical"},{"recorded_at":"2017-07-21T10:30:00+0900","value":257.0,"flags":"historical"},{"recorded_at":"2017-07-21T11:00:00+0900","value":254.0,"flags":"historical"},{"recorded_at":"2017-07-21T11:30:00+0900","value":245.0,"flags":"historical"},{"recorded_at":"2017-07-21T12:00:00+0900","value":244.0,"flags":"historical"},{"recorded_at":"2017-07-21T12:30:00+0900","value":233.0,"flags":"historical"},{"recorded_at":"2017-07-21T13:00:00+0900","value":229.0,"flags":"historical"},{"recorded_at":"2017-07-21T13:30:00+0900","value":242.0,"flags":"historical"},{"recorded_at":"2017-07-21T14:00:00+0900","value":240.0,"flags":"historical"},{"recorded_at":"2017-07-21T14:30:00+0900","value":239.0,"flags":"historical"},{"recorded_at":"2017-07-21T15:00:00+0900","value":236.0,"flags":"historical"},{"recorded_at":"2017-07-21T15:30:00+0900","value":248.0,"flags":"historical"},{"recorded_at":"2017-07-21T16:00:00+0900","value":243.0,"flags":"historical"},{"recorded_at":"2017-07-21T16:30:00+0900","value":238.0,"flags":"historical"},{"recorded_at":"2017-07-21T17:00:00+0900","value":238.0,"flags":"historical"},{"recorded_at":"2017-07-21T17:30:00+0900","value":230.0,"flags":"historical"},{"recorded_at":"2017-07-21T18:00:00+0900","value":205.0,"flags":"historical"},{"recorded_at":"2017-07-21T18:30:00+0900","value":178.0,"flags":"historical"},{"recorded_at":"2017-07-21T19:00:00+0900","value":160.0,"flags":"historical"},{"recorded_at":"2017-07-21T19:30:00+0900","value":130.0,"flags":"historical"},{"recorded_at":"2017-07-21T20:00:00+0900","value":128.0,"flags":"historical"},{"recorded_at":"2017-07-21T20:30:00+0900","value":126.0,"flags":"historical"},{"recorded_at":"2017-07-21T21:00:00+0900","value":118.0,"flags":"historical"},{"recorded_at":"2017-07-21T21:30:00+0900","value":120.0,"flags":"historical"},{"recorded_at":"2017-07-21T22:00:00+0900","value":105.0,"flags":"historical"},{"recorded_at":"2017-07-21T22:30:00+0900","value":95.0,"flags":"historical"},{"recorded_at":"2017-07-21T23:00:00+0900","value":79.0,"flags":"historical"},{"recorded_at":"2017-07-21T23:30:00+0900","value":67.0,"flags":"historical"},{"recorded_at":"2017-07-22T00:00:00+0900","value":61.0,"flags":"historical"},{"recorded_at":"2017-07-22T00:30:00+0900","value":56.0,"flags":"historical"},{"recorded_at":"2017-07-22T01:00:00+0900","value":57.0,"flags":"historical"},{"recorded_at":"2017-07-22T01:30:00+0900","value":53.0,"flags":"historical"},{"recorded_at":"2017-07-22T02:00:00+0900","value":53.0,"flags":"historical"},{"recorded_at":"2017-07-22T02:30:00+0900","value":51.0,"flags":"historical"},{"recorded_at":"2017-07-22T03:00:00+0900","value":44.0,"flags":"historical"},{"recorded_at":"2017-07-22T03:30:00+0900","value":45.0,"flags":"historical"},{"recorded_at":"2017-07-22T04:00:00+0900","value":46.0,"flags":"historical"},{"recorded_at":"2017-07-22T04:30:00+0900","value":47.0,"flags":"historical"},{"recorded_at":"2017-07-22T05:00:00+0900","value":46.0,"flags":"historical"},{"recorded_at":"2017-07-22T05:30:00+0900","value":46.0,"flags":"historical"},{"recorded_at":"2017-07-22T06:00:00+0900","value":51.0,"flags":"historical"},{"recorded_at":"2017-07-22T06:30:00+0900","value":67.0,"flags":"historical"},{"recorded_at":"2017-07-22T07:00:00+0900","value":75.0,"flags":"historical"},{"recorded_at":"2017-07-22T07:30:00+0900","value":69.0,"flags":"historical"},{"recorded_at":"2017-07-22T08:00:00+0900","value":70.0,"flags":"historical"},{"recorded_at":"2017-07-22T08:30:00+0900","value":75.0,"flags":"historical"},{"recorded_at":"2017-07-22T09:00:00+0900","value":74.0,"flags":"historical"},{"recorded_at":"2017-07-22T09:30:00+0900","value":80.0,"flags":"historical"},{"recorded_at":"2017-07-22T10:00:00+0900","value":86.0,"flags":"historical"},{"recorded_at":"2017-07-22T10:30:00+0900","value":81.0,"flags":"historical"},{"recorded_at":"2017-07-22T11:00:00+0900","value":89.0,"flags":"historical"},{"recorded_at":"2017-07-22T11:30:00+0900","value":91.0,"flags":"historical"},{"recorded_at":"2017-07-22T12:00:00+0900","value":89.0,"flags":"historical"},{"recorded_at":"2017-07-22T12:30:00+0900","value":85.0,"flags":"historical"},{"recorded_at":"2017-07-22T13:00:00+0900","value":88.0,"flags":"historical"},{"recorded_at":"2017-07-22T13:30:00+0900","value":89.0,"flags":"historical"},{"recorded_at":"2017-07-22T14:00:00+0900","value":92.0,"flags":"historical"},{"recorded_at":"2017-07-22T14:30:00+0900","value":88.0,"flags":"historical"},{"recorded_at":"2017-07-22T15:00:00+0900","value":90.0,"flags":"historical"},{"recorded_at":"2017-07-22T15:30:00+0900","value":92.0,"flags":"historical"},{"recorded_at":"2017-07-22T16:00:00+0900","value":90.0,"flags":"historical"},{"recorded_at":"2017-07-22T16:30:00+0900","value":91.0,"flags":"historical"},{"recorded_at":"2017-07-22T17:00:00+0900","value":88.0,"flags":"historical"},{"recorded_at":"2017-07-22T17:30:00+0900","value":84.0,"flags":"historical"},{"recorded_at":"2017-07-22T18:00:00+0900","value":82.0,"flags":"historical"},{"recorded_at":"2017-07-22T18:30:00+0900","value":73.0,"flags":"historical"},{"recorded_at":"2017-07-22T19:00:00+0900","value":70.0,"flags":"historical"},{"recorded_at":"2017-07-22T19:30:00+0900","value":66.0,"flags":"historical"},{"recorded_at":"2017-07-22T20:00:00+0900","value":64.0,"flags":"historical"},{"recorded_at":"2017-07-22T20:30:00+0900","value":65.0,"flags":"historical"},{"recorded_at":"2017-07-22T21:00:00+0900","value":65.0,"flags":"historical"},{"recorded_at":"2017-07-22T21:30:00+0900","value":56.0,"flags":"historical"},{"recorded_at":"2017-07-22T22:00:00+0900","value":54.0,"flags":"historical"},{"recorded_at":"2017-07-22T22:30:00+0900","value":53.0,"flags":"historical"},{"recorded_at":"2017-07-22T23:00:00+0900","value":53.0,"flags":"historical"},{"recorded_at":"2017-07-22T23:30:00+0900","value":53.0,"flags":"historical"},{"recorded_at":"2017-07-23T00:00:00+0900","value":52.0,"flags":"historical"},{"recorded_at":"2017-07-23T00:30:00+0900","value":53.0,"flags":"historical"},{"recorded_at":"2017-07-23T01:00:00+0900","value":48.0,"flags":"historical"},{"recorded_at":"2017-07-23T01:30:00+0900","value":48.0,"flags":"historical"},{"recorded_at":"2017-07-23T02:00:00+0900","value":46.0,"flags":"historical"},{"recorded_at":"2017-07-23T02:30:00+0900","value":47.0,"flags":"historical"},{"recorded_at":"2017-07-23T03:00:00+0900","value":48.0,"flags":"historical"},{"recorded_at":"2017-07-23T03:30:00+0900","value":48.0,"flags":"historical"},{"recorded_at":"2017-07-23T04:00:00+0900","value":47.0,"flags":"historical"},{"recorded_at":"2017-07-23T04:30:00+0900","value":46.0,"flags":"historical"},{"recorded_at":"2017-07-23T05:00:00+0900","value":48.0,"flags":"historical"},{"recorded_at":"2017-07-23T05:30:00+0900","value":47.0,"flags":"historical"},{"recorded_at":"2017-07-23T06:00:00+0900","value":48.0,"flags":"historical"},{"recorded_at":"2017-07-23T06:30:00+0900","value":49.0,"flags":"historical"},{"recorded_at":"2017-07-23T07:00:00+0900","value":47.0,"flags":"historical"},{"recorded_at":"2017-07-23T07:30:00+0900","value":53.0,"flags":"historical"},{"recorded_at":"2017-07-23T08:00:00+0900","value":53.0,"flags":"historical"},{"recorded_at":"2017-07-23T08:30:00+0900","value":56.0,"flags":"historical"},{"recorded_at":"2017-07-23T09:00:00+0900","value":60.0,"flags":"historical"},{"recorded_at":"2017-07-23T09:30:00+0900","value":64.0,"flags":"historical"},{"recorded_at":"2017-07-23T10:00:00+0900","value":68.0,"flags":"historical"},{"recorded_at":"2017-07-23T10:30:00+0900","value":69.0,"flags":"historical"},{"recorded_at":"2017-07-23T11:00:00+0900","value":70.0,"flags":"historical"},{"recorded_at":"2017-07-23T11:30:00+0900","value":71.0,"flags":"historical"},{"recorded_at":"2017-07-23T12:00:00+0900","value":69.0,"flags":"historical"},{"recorded_at":"2017-07-23T12:30:00+0900","value":70.0,"flags":"historical"},{"recorded_at":"2017-07-23T13:00:00+0900","value":71.0,"flags":"historical"},{"recorded_at":"2017-07-23T13:30:00+0900","value":80.0,"flags":"historical"},{"recorded_at":"2017-07-23T14:00:00+0900","value":78.0,"flags":"historical"},{"recorded_at":"2017-07-23T14:30:00+0900","value":81.0,"flags":"historical"},{"recorded_at":"2017-07-23T15:00:00+0900","value":82.0,"flags":"historical"},{"recorded_at":"2017-07-23T15:30:00+0900","value":86.0,"flags":"historical"},{"recorded_at":"2017-07-23T16:00:00+0900","value":84.0,"flags":"historical"},{"recorded_at":"2017-07-23T16:30:00+0900","value":82.0,"flags":"historical"},{"recorded_at":"2017-07-23T17:00:00+0900","value":81.0,"flags":"historical"},{"recorded_at":"2017-07-23T17:30:00+0900","value":78.0,"flags":"historical"},{"recorded_at":"2017-07-23T18:00:00+0900","value":75.0,"flags":"historical"},{"recorded_at":"2017-07-23T18:30:00+0900","value":67.0,"flags":"historical"},{"recorded_at":"2017-07-23T19:00:00+0900","value":67.0,"flags":"historical"},{"recorded_at":"2017-07-23T19:30:00+0900","value":64.0,"flags":"historical"},{"recorded_at":"2017-07-23T20:00:00+0900","value":63.0,"flags":"historical"},{"recorded_at":"2017-07-23T20:30:00+0900","value":63.0,"flags":"historical"},{"recorded_at":"2017-07-23T21:00:00+0900","value":62.0,"flags":"historical"},{"recorded_at":"2017-07-23T21:30:00+0900","value":61.0,"flags":"historical"},{"recorded_at":"2017-07-23T22:00:00+0900","value":61.0,"flags":"historical"},{"recorded_at":"2017-07-23T22:30:00+0900","value":62.0,"flags":"historical"},{"recorded_at":"2017-07-23T23:00:00+0900","value":61.0,"flags":"historical"},{"recorded_at":"2017-07-23T23:30:00+0900","value":61.0,"flags":"historical"},{"recorded_at":"2017-07-24T00:00:00+0900","value":59.0,"flags":"historical"},{"recorded_at":"2017-07-24T00:30:00+0900","value":55.0,"flags":"historical"},{"recorded_at":"2017-07-24T01:00:00+0900","value":51.0,"flags":"historical"},{"recorded_at":"2017-07-24T01:30:00+0900","value":53.0,"flags":"historical"},{"recorded_at":"2017-07-24T02:00:00+0900","value":48.0,"flags":"historical"},{"recorded_at":"2017-07-24T02:30:00+0900","value":47.0,"flags":"historical"},{"recorded_at":"2017-07-24T03:00:00+0900","value":49.0,"flags":"historical"},{"recorded_at":"2017-07-24T03:30:00+0900","value":48.0,"flags":"historical"},{"recorded_at":"2017-07-24T04:00:00+0900","value":47.0,"flags":"historical"},{"recorded_at":"2017-07-24T04:30:00+0900","value":47.0,"flags":"historical"},{"recorded_at":"2017-07-24T05:00:00+0900","value":48.0,"flags":"historical"},{"recorded_at":"2017-07-24T05:30:00+0900","value":48.0,"flags":"historical"},{"recorded_at":"2017-07-24T06:00:00+0900","value":54.0,"flags":"historical"},{"recorded_at":"2017-07-24T06:30:00+0900","value":74.0,"flags":"historical"},{"recorded_at":"2017-07-24T07:00:00+0900","value":143.0,"flags":"historical"},{"recorded_at":"2017-07-24T07:30:00+0900","value":113.0,"flags":"historical"},{"recorded_at":"2017-07-24T08:00:00+0900","value":132.0,"flags":"historical"},{"recorded_at":"2017-07-24T08:30:00+0900","value":179.0,"flags":"historical"},{"recorded_at":"2017-07-24T09:00:00+0900","value":222.0,"flags":"historical"},{"recorded_at":"2017-07-24T09:30:00+0900","value":232.0,"flags":"historical"},{"recorded_at":"2017-07-24T10:00:00+0900","value":241.0,"flags":"historical"},{"recorded_at":"2017-07-24T10:30:00+0900","value":238.0,"flags":"historical"},{"recorded_at":"2017-07-24T11:00:00+0900","value":229.0,"flags":"historical"},{"recorded_at":"2017-07-24T11:30:00+0900","value":222.0,"flags":"historical"},{"recorded_at":"2017-07-24T12:00:00+0900","value":225.0,"flags":"historical"},{"recorded_at":"2017-07-24T12:30:00+0900","value":215.0,"flags":"historical"},{"recorded_at":"2017-07-24T13:00:00+0900","value":209.0,"flags":"historical"},{"recorded_at":"2017-07-24T13:30:00+0900","value":214.0,"flags":"historical"},{"recorded_at":"2017-07-24T14:00:00+0900","value":224.0,"flags":"historical"},{"recorded_at":"2017-07-24T14:30:00+0900","value":222.0,"flags":"historical"},{"recorded_at":"2017-07-24T15:00:00+0900","value":230.0,"flags":"historical"},{"recorded_at":"2017-07-24T15:30:00+0900","value":224.0,"flags":"historical"},{"recorded_at":"2017-07-24T16:00:00+0900","value":233.0,"flags":"historical"},{"recorded_at":"2017-07-24T16:30:00+0900","value":232.0,"flags":"historical"},{"recorded_at":"2017-07-24T17:00:00+0900","value":237.0,"flags":"historical"},{"recorded_at":"2017-07-24T17:30:00+0900","value":235.0,"flags":"historical"},{"recorded_at":"2017-07-24T18:00:00+0900","value":218.0,"flags":"historical"},{"recorded_at":"2017-07-24T18:30:00+0900","value":184.0,"flags":"historical"},{"recorded_at":"2017-07-24T19:00:00+0900","value":174.0,"flags":"historical"},{"recorded_at":"2017-07-24T19:30:00+0900","value":152.0,"flags":"historical"},{"recorded_at":"2017-07-24T20:00:00+0900","value":145.0,"flags":"historical"},{"recorded_at":"2017-07-24T20:30:00+0900","value":134.0,"flags":"historical"},{"recorded_at":"2017-07-24T21:00:00+0900","value":136.0,"flags":"historical"},{"recorded_at":"2017-07-24T21:30:00+0900","value":126.0,"flags":"historical"},{"recorded_at":"2017-07-24T22:00:00+0900","value":119.0,"flags":"historical"},{"recorded_at":"2017-07-24T22:30:00+0900","value":107.0,"flags":"historical"},{"recorded_at":"2017-07-24T23:00:00+0900","value":99.0,"flags":"historical"},{"recorded_at":"2017-07-24T23:30:00+0900","value":83.0,"flags":"historical"},{"recorded_at":"2017-07-25T00:00:00+0900","value":65.0,"flags":"historical"},{"recorded_at":"2017-07-25T00:30:00+0900","value":53.0,"flags":"historical"},{"recorded_at":"2017-07-25T01:00:00+0900","value":53.0,"flags":"historical"},{"recorded_at":"2017-07-25T01:30:00+0900","value":52.0,"flags":"historical"},{"recorded_at":"2017-07-25T02:00:00+0900","value":51.0,"flags":"historical"},{"recorded_at":"2017-07-25T02:30:00+0900","value":50.0,"flags":"historical"},{"recorded_at":"2017-07-25T03:00:00+0900","value":50.0,"flags":"historical"},{"recorded_at":"2017-07-25T03:30:00+0900","value":50.0,"flags":"historical"},{"recorded_at":"2017-07-25T04:00:00+0900","value":48.0,"flags":"historical"},{"recorded_at":"2017-07-25T04:30:00+0900","value":44.0,"flags":"historical"},{"recorded_at":"2017-07-25T05:00:00+0900","value":45.0,"flags":"historical"},{"recorded_at":"2017-07-25T05:30:00+0900","value":46.0,"flags":"historical"},{"recorded_at":"2017-07-25T06:00:00+0900","value":51.0,"flags":"historical"},{"recorded_at":"2017-07-25T06:30:00+0900","value":68.0,"flags":"historical"},{"recorded_at":"2017-07-25T07:00:00+0900","value":115.0,"flags":"historical"},{"recorded_at":"2017-07-25T07:30:00+0900","value":111.0,"flags":"historical"},{"recorded_at":"2017-07-25T08:00:00+0900","value":129.0,"flags":"historical"},{"recorded_at":"2017-07-25T08:30:00+0900","value":170.0,"flags":"historical"},{"recorded_at":"2017-07-25T09:00:00+0900","value":203.0,"flags":"historical"},{"recorded_at":"2017-07-25T09:30:00+0900","value":214.0,"flags":"historical"},{"recorded_at":"2017-07-25T10:00:00+0900","value":219.0,"flags":"historical"},{"recorded_at":"2017-07-25T10:30:00+0900","value":218.0,"flags":"historical"},{"recorded_at":"2017-07-25T11:00:00+0900","value":219.0,"flags":"historical"},{"recorded_at":"2017-07-25T11:30:00+0900","value":226.0,"flags":"historical"},{"recorded_at":"2017-07-25T12:00:00+0900","value":225.0,"flags":"historical"},{"recorded_at":"2017-07-25T12:30:00+0900","value":217.0,"flags":"historical"},{"recorded_at":"2017-07-25T13:00:00+0900","value":207.0,"flags":"historical"},{"recorded_at":"2017-07-25T13:30:00+0900","value":219.0,"flags":"historical"},{"recorded_at":"2017-07-25T14:00:00+0900","value":223.0,"flags":"historical"},{"recorded_at":"2017-07-25T14:30:00+0900","value":226.0,"flags":"historical"},{"recorded_at":"2017-07-25T15:00:00+0900","value":225.0,"flags":"historical"},{"recorded_at":"2017-07-25T15:30:00+0900","value":217.0,"flags":"historical"},{"recorded_at":"2017-07-25T16:00:00+0900","value":219.0,"flags":"historical"},{"recorded_at":"2017-07-25T16:30:00+0900","value":221.0,"flags":"historical"},{"recorded_at":"2017-07-25T17:00:00+0900","value":212.0,"flags":"historical"},{"recorded_at":"2017-07-25T17:30:00+0900","value":213.0,"flags":"historical"},{"recorded_at":"2017-07-25T18:00:00+0900","value":201.0,"flags":"historical"},{"recorded_at":"2017-07-25T18:30:00+0900","value":172.0,"flags":"historical"},{"recorded_at":"2017-07-25T19:00:00+0900","value":164.0,"flags":"historical"},{"recorded_at":"2017-07-25T19:30:00+0900","value":144.0,"flags":"historical"},{"recorded_at":"2017-07-25T20:00:00+0900","value":146.0,"flags":"historical"},{"recorded_at":"2017-07-25T20:30:00+0900","value":138.0,"flags":"historical"},{"recorded_at":"2017-07-25T21:00:00+0900","value":128.0,"flags":"historical"},{"recorded_at":"2017-07-25T21:30:00+0900","value":119.0,"flags":"historical"},{"recorded_at":"2017-07-25T22:00:00+0900","value":111.0,"flags":"historical"},{"recorded_at":"2017-07-25T22:30:00+0900","value":95.0,"flags":"historical"},{"recorded_at":"2017-07-25T23:00:00+0900","value":79.0,"flags":"historical"},{"recorded_at":"2017-07-25T23:30:00+0900","value":78.0,"flags":"historical"},{"recorded_at":"2017-07-26T00:00:00+0900","value":70.0,"flags":"historical"},{"recorded_at":"2017-07-26T00:30:00+0900","value":55.0,"flags":"historical"},{"recorded_at":"2017-07-26T01:00:00+0900","value":52.0,"flags":"historical"},{"recorded_at":"2017-07-26T01:30:00+0900","value":53.0,"flags":"historical"},{"recorded_at":"2017-07-26T02:00:00+0900","value":43.0,"flags":"historical"},{"recorded_at":"2017-07-26T02:30:00+0900","value":45.0,"flags":"historical"},{"recorded_at":"2017-07-26T03:00:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-07-26T03:30:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-07-26T04:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-07-26T04:30:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-07-26T05:00:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-07-26T05:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-07-26T06:00:00+0900","value":50.0,"flags":""},{"recorded_at":"2017-07-26T06:30:00+0900","value":69.0,"flags":""},{"recorded_at":"2017-07-26T07:00:00+0900","value":104.0,"flags":""},{"recorded_at":"2017-07-26T07:30:00+0900","value":93.0,"flags":""},{"recorded_at":"2017-07-26T08:00:00+0900","value":120.0,"flags":""},{"recorded_at":"2017-07-26T08:30:00+0900","value":164.0,"flags":""},{"recorded_at":"2017-07-26T09:00:00+0900","value":204.0,"flags":""},{"recorded_at":"2017-07-26T09:30:00+0900","value":210.0,"flags":""},{"recorded_at":"2017-07-26T10:00:00+0900","value":207.0,"flags":""},{"recorded_at":"2017-07-26T10:30:00+0900","value":224.0,"flags":""},{"recorded_at":"2017-07-26T11:00:00+0900","value":221.0,"flags":""},{"recorded_at":"2017-07-26T11:30:00+0900","value":224.0,"flags":""},{"recorded_at":"2017-07-26T12:00:00+0900","value":217.0,"flags":""},{"recorded_at":"2017-07-26T12:30:00+0900","value":208.0,"flags":""},{"recorded_at":"2017-07-26T13:00:00+0900","value":210.0,"flags":""},{"recorded_at":"2017-07-26T13:30:00+0900","value":215.0,"flags":""},{"recorded_at":"2017-07-26T14:00:00+0900","value":214.0,"flags":""},{"recorded_at":"2017-07-26T14:30:00+0900","value":214.0,"flags":""},{"recorded_at":"2017-07-26T15:00:00+0900","value":211.0,"flags":""},{"recorded_at":"2017-07-26T15:30:00+0900","value":217.0,"flags":""},{"recorded_at":"2017-07-26T16:00:00+0900","value":225.0,"flags":""},{"recorded_at":"2017-07-26T16:30:00+0900","value":220.0,"flags":""},{"recorded_at":"2017-07-26T17:00:00+0900","value":217.0,"flags":""},{"recorded_at":"2017-07-26T17:30:00+0900","value":210.0,"flags":""},{"recorded_at":"2017-07-26T18:00:00+0900","value":207.0,"flags":""},{"recorded_at":"2017-07-26T18:30:00+0900","value":171.0,"flags":""},{"recorded_at":"2017-07-26T19:00:00+0900","value":154.0,"flags":""},{"recorded_at":"2017-07-26T19:30:00+0900","value":121.0,"flags":""},{"recorded_at":"2017-07-26T20:00:00+0900","value":114.0,"flags":""},{"recorded_at":"2017-07-26T20:30:00+0900","value":106.0,"flags":""},{"recorded_at":"2017-07-26T21:00:00+0900","value":103.0,"flags":""},{"recorded_at":"2017-07-26T21:30:00+0900","value":97.0,"flags":""},{"recorded_at":"2017-07-26T22:00:00+0900","value":90.0,"flags":""},{"recorded_at":"2017-07-26T22:30:00+0900","value":81.0,"flags":""},{"recorded_at":"2017-07-26T23:00:00+0900","value":74.0,"flags":""},{"recorded_at":"2017-07-26T23:30:00+0900","value":71.0,"flags":""},{"recorded_at":"2017-07-27T00:00:00+0900","value":62.0,"flags":""},{"recorded_at":"2017-07-27T00:30:00+0900","value":56.0,"flags":""},{"recorded_at":"2017-07-27T01:00:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-07-27T01:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-07-27T02:00:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-07-27T02:30:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-07-27T03:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-07-27T03:30:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-07-27T04:00:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-07-27T04:30:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-07-27T05:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-07-27T05:30:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-07-27T06:00:00+0900","value":50.0,"flags":""},{"recorded_at":"2017-07-27T06:30:00+0900","value":68.0,"flags":""},{"recorded_at":"2017-07-27T07:00:00+0900","value":95.0,"flags":""},{"recorded_at":"2017-07-27T07:30:00+0900","value":95.0,"flags":""},{"recorded_at":"2017-07-27T08:00:00+0900","value":112.0,"flags":""},{"recorded_at":"2017-07-27T08:30:00+0900","value":148.0,"flags":""},{"recorded_at":"2017-07-27T09:00:00+0900","value":202.0,"flags":""},{"recorded_at":"2017-07-27T09:30:00+0900","value":229.0,"flags":""},{"recorded_at":"2017-07-27T10:00:00+0900","value":234.0,"flags":""},{"recorded_at":"2017-07-27T10:30:00+0900","value":238.0,"flags":""},{"recorded_at":"2017-07-27T11:00:00+0900","value":244.0,"flags":""},{"recorded_at":"2017-07-27T11:30:00+0900","value":248.0,"flags":""},{"recorded_at":"2017-07-27T12:00:00+0900","value":235.0,"flags":""},{"recorded_at":"2017-07-27T12:30:00+0900","value":235.0,"flags":""},{"recorded_at":"2017-07-27T13:00:00+0900","value":222.0,"flags":""},{"recorded_at":"2017-07-27T13:30:00+0900","value":223.0,"flags":""},{"recorded_at":"2017-07-27T14:00:00+0900","value":221.0,"flags":""},{"recorded_at":"2017-07-27T14:30:00+0900","value":224.0,"flags":""},{"recorded_at":"2017-07-27T15:00:00+0900","value":225.0,"flags":""},{"recorded_at":"2017-07-27T15:30:00+0900","value":229.0,"flags":""},{"recorded_at":"2017-07-27T16:00:00+0900","value":225.0,"flags":""},{"recorded_at":"2017-07-27T16:30:00+0900","value":223.0,"flags":""},{"recorded_at":"2017-07-27T17:00:00+0900","value":221.0,"flags":""},{"recorded_at":"2017-07-27T17:30:00+0900","value":225.0,"flags":""},{"recorded_at":"2017-07-27T18:00:00+0900","value":201.0,"flags":""},{"recorded_at":"2017-07-27T18:30:00+0900","value":183.0,"flags":""},{"recorded_at":"2017-07-27T19:00:00+0900","value":164.0,"flags":""},{"recorded_at":"2017-07-27T19:30:00+0900","value":142.0,"flags":""},{"recorded_at":"2017-07-27T20:00:00+0900","value":141.0,"flags":""},{"recorded_at":"2017-07-27T20:30:00+0900","value":139.0,"flags":""},{"recorded_at":"2017-07-27T21:00:00+0900","value":130.0,"flags":""},{"recorded_at":"2017-07-27T21:30:00+0900","value":116.0,"flags":""},{"recorded_at":"2017-07-27T22:00:00+0900","value":106.0,"flags":""},{"recorded_at":"2017-07-27T22:30:00+0900","value":97.0,"flags":""},{"recorded_at":"2017-07-27T23:00:00+0900","value":85.0,"flags":""},{"recorded_at":"2017-07-27T23:30:00+0900","value":78.0,"flags":""},{"recorded_at":"2017-07-28T00:00:00+0900","value":73.0,"flags":""},{"recorded_at":"2017-07-28T00:30:00+0900","value":70.0,"flags":""},{"recorded_at":"2017-07-28T01:00:00+0900","value":65.0,"flags":""},{"recorded_at":"2017-07-28T01:30:00+0900","value":55.0,"flags":""},{"recorded_at":"2017-07-28T02:00:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-07-28T02:30:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-07-28T03:00:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-07-28T03:30:00+0900","value":58.0,"flags":""},{"recorded_at":"2017-07-28T04:00:00+0900","value":61.0,"flags":""},{"recorded_at":"2017-07-28T04:30:00+0900","value":59.0,"flags":""},{"recorded_at":"2017-07-28T05:00:00+0900","value":60.0,"flags":""},{"recorded_at":"2017-07-28T05:30:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-07-28T06:00:00+0900","value":60.0,"flags":""},{"recorded_at":"2017-07-28T06:30:00+0900","value":71.0,"flags":""},{"recorded_at":"2017-07-28T07:00:00+0900","value":109.0,"flags":""},{"recorded_at":"2017-07-28T07:30:00+0900","value":100.0,"flags":""},{"recorded_at":"2017-07-28T08:00:00+0900","value":109.0,"flags":""},{"recorded_at":"2017-07-28T08:30:00+0900","value":147.0,"flags":""},{"recorded_at":"2017-07-28T09:00:00+0900","value":201.0,"flags":""},{"recorded_at":"2017-07-28T09:30:00+0900","value":224.0,"flags":""},{"recorded_at":"2017-07-28T10:00:00+0900","value":221.0,"flags":""},{"recorded_at":"2017-07-28T10:30:00+0900","value":224.0,"flags":""},{"recorded_at":"2017-07-28T11:00:00+0900","value":221.0,"flags":""},{"recorded_at":"2017-07-28T11:30:00+0900","value":215.0,"flags":""},{"recorded_at":"2017-07-28T12:00:00+0900","value":212.0,"flags":""},{"recorded_at":"2017-07-28T12:30:00+0900","value":226.0,"flags":""},{"recorded_at":"2017-07-28T13:00:00+0900","value":210.0,"flags":""},{"recorded_at":"2017-07-28T13:30:00+0900","value":225.0,"flags":""},{"recorded_at":"2017-07-28T14:00:00+0900","value":230.0,"flags":""},{"recorded_at":"2017-07-28T14:30:00+0900","value":217.0,"flags":""},{"recorded_at":"2017-07-28T15:00:00+0900","value":219.0,"flags":""},{"recorded_at":"2017-07-28T15:30:00+0900","value":228.0,"flags":""},{"recorded_at":"2017-07-28T16:00:00+0900","value":221.0,"flags":""},{"recorded_at":"2017-07-28T16:30:00+0900","value":223.0,"flags":""},{"recorded_at":"2017-07-28T17:00:00+0900","value":216.0,"flags":""},{"recorded_at":"2017-07-28T17:30:00+0900","value":218.0,"flags":""},{"recorded_at":"2017-07-28T18:00:00+0900","value":208.0,"flags":""},{"recorded_at":"2017-07-28T18:30:00+0900","value":180.0,"flags":""},{"recorded_at":"2017-07-28T19:00:00+0900","value":158.0,"flags":""},{"recorded_at":"2017-07-28T19:30:00+0900","value":138.0,"flags":""},{"recorded_at":"2017-07-28T20:00:00+0900","value":136.0,"flags":""},{"recorded_at":"2017-07-28T20:30:00+0900","value":127.0,"flags":""},{"recorded_at":"2017-07-28T21:00:00+0900","value":111.0,"flags":""},{"recorded_at":"2017-07-28T21:30:00+0900","value":102.0,"flags":""},{"recorded_at":"2017-07-28T22:00:00+0900","value":81.0,"flags":""},{"recorded_at":"2017-07-28T22:30:00+0900","value":68.0,"flags":""},{"recorded_at":"2017-07-28T23:00:00+0900","value":69.0,"flags":""},{"recorded_at":"2017-07-28T23:30:00+0900","value":63.0,"flags":""},{"recorded_at":"2017-07-29T00:00:00+0900","value":58.0,"flags":""},{"recorded_at":"2017-07-29T00:30:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-07-29T01:00:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-07-29T01:30:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-07-29T02:00:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-07-29T02:30:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-07-29T03:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-07-29T03:30:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-07-29T04:00:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-07-29T04:30:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-07-29T05:00:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-07-29T05:30:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-07-29T06:00:00+0900","value":50.0,"flags":""},{"recorded_at":"2017-07-29T06:30:00+0900","value":59.0,"flags":""},{"recorded_at":"2017-07-29T07:00:00+0900","value":63.0,"flags":""},{"recorded_at":"2017-07-29T07:30:00+0900","value":66.0,"flags":""},{"recorded_at":"2017-07-29T08:00:00+0900","value":70.0,"flags":""},{"recorded_at":"2017-07-29T08:30:00+0900","value":74.0,"flags":""},{"recorded_at":"2017-07-29T09:00:00+0900","value":79.0,"flags":""},{"recorded_at":"2017-07-29T09:30:00+0900","value":82.0,"flags":""},{"recorded_at":"2017-07-29T10:00:00+0900","value":82.0,"flags":""},{"recorded_at":"2017-07-29T10:30:00+0900","value":79.0,"flags":""},{"recorded_at":"2017-07-29T11:00:00+0900","value":80.0,"flags":""},{"recorded_at":"2017-07-29T11:30:00+0900","value":80.0,"flags":""},{"recorded_at":"2017-07-29T12:00:00+0900","value":82.0,"flags":""},{"recorded_at":"2017-07-29T12:30:00+0900","value":87.0,"flags":""},{"recorded_at":"2017-07-29T13:00:00+0900","value":84.0,"flags":""},{"recorded_at":"2017-07-29T13:30:00+0900","value":87.0,"flags":""},{"recorded_at":"2017-07-29T14:00:00+0900","value":89.0,"flags":""},{"recorded_at":"2017-07-29T14:30:00+0900","value":91.0,"flags":""},{"recorded_at":"2017-07-29T15:00:00+0900","value":84.0,"flags":""},{"recorded_at":"2017-07-29T15:30:00+0900","value":79.0,"flags":""},{"recorded_at":"2017-07-29T16:00:00+0900","value":82.0,"flags":""},{"recorded_at":"2017-07-29T16:30:00+0900","value":81.0,"flags":""},{"recorded_at":"2017-07-29T17:00:00+0900","value":82.0,"flags":""},{"recorded_at":"2017-07-29T17:30:00+0900","value":77.0,"flags":""},{"recorded_at":"2017-07-29T18:00:00+0900","value":75.0,"flags":""},{"recorded_at":"2017-07-29T18:30:00+0900","value":68.0,"flags":""},{"recorded_at":"2017-07-29T19:00:00+0900","value":65.0,"flags":""},{"recorded_at":"2017-07-29T19:30:00+0900","value":65.0,"flags":""},{"recorded_at":"2017-07-29T20:00:00+0900","value":65.0,"flags":""},{"recorded_at":"2017-07-29T20:30:00+0900","value":65.0,"flags":""},{"recorded_at":"2017-07-29T21:00:00+0900","value":62.0,"flags":""},{"recorded_at":"2017-07-29T21:30:00+0900","value":58.0,"flags":""},{"recorded_at":"2017-07-29T22:00:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-07-29T22:30:00+0900","value":56.0,"flags":""},{"recorded_at":"2017-07-29T23:00:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-07-29T23:30:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-07-30T00:00:00+0900","value":55.0,"flags":""},{"recorded_at":"2017-07-30T00:30:00+0900","value":53.0,"flags":""},{"recorded_at":"2017-07-30T01:00:00+0900","value":52.0,"flags":""},{"recorded_at":"2017-07-30T01:30:00+0900","value":53.0,"flags":""},{"recorded_at":"2017-07-30T02:00:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-07-30T02:30:00+0900","value":53.0,"flags":""},{"recorded_at":"2017-07-30T03:00:00+0900","value":52.0,"flags":""},{"recorded_at":"2017-07-30T03:30:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-07-30T04:00:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-07-30T04:30:00+0900","value":53.0,"flags":""},{"recorded_at":"2017-07-30T05:00:00+0900","value":52.0,"flags":""},{"recorded_at":"2017-07-30T05:30:00+0900","value":53.0,"flags":""},{"recorded_at":"2017-07-30T06:00:00+0900","value":56.0,"flags":""},{"recorded_at":"2017-07-30T06:30:00+0900","value":58.0,"flags":""},{"recorded_at":"2017-07-30T07:00:00+0900","value":56.0,"flags":""},{"recorded_at":"2017-07-30T07:30:00+0900","value":55.0,"flags":""},{"recorded_at":"2017-07-30T08:00:00+0900","value":58.0,"flags":""},{"recorded_at":"2017-07-30T08:30:00+0900","value":62.0,"flags":""},{"recorded_at":"2017-07-30T09:00:00+0900","value":69.0,"flags":""},{"recorded_at":"2017-07-30T09:30:00+0900","value":66.0,"flags":""},{"recorded_at":"2017-07-30T10:00:00+0900","value":66.0,"flags":""},{"recorded_at":"2017-07-30T10:30:00+0900","value":67.0,"flags":""},{"recorded_at":"2017-07-30T11:00:00+0900","value":66.0,"flags":""},{"recorded_at":"2017-07-30T11:30:00+0900","value":67.0,"flags":""},{"recorded_at":"2017-07-30T12:00:00+0900","value":81.0,"flags":""},{"recorded_at":"2017-07-30T12:30:00+0900","value":86.0,"flags":""},{"recorded_at":"2017-07-30T13:00:00+0900","value":80.0,"flags":""},{"recorded_at":"2017-07-30T13:30:00+0900","value":84.0,"flags":""},{"recorded_at":"2017-07-30T14:00:00+0900","value":83.0,"flags":""},{"recorded_at":"2017-07-30T14:30:00+0900","value":78.0,"flags":""},{"recorded_at":"2017-07-30T15:00:00+0900","value":78.0,"flags":""},{"recorded_at":"2017-07-30T15:30:00+0900","value":78.0,"flags":""},{"recorded_at":"2017-07-30T16:00:00+0900","value":78.0,"flags":""},{"recorded_at":"2017-07-30T16:30:00+0900","value":78.0,"flags":""},{"recorded_at":"2017-07-30T17:00:00+0900","value":80.0,"flags":""},{"recorded_at":"2017-07-30T17:30:00+0900","value":78.0,"flags":""},{"recorded_at":"2017-07-30T18:00:00+0900","value":74.0,"flags":""},{"recorded_at":"2017-07-30T18:30:00+0900","value":73.0,"flags":""},{"recorded_at":"2017-07-30T19:00:00+0900","value":67.0,"flags":""},{"recorded_at":"2017-07-30T19:30:00+0900","value":63.0,"flags":""},{"recorded_at":"2017-07-30T20:00:00+0900","value":61.0,"flags":""},{"recorded_at":"2017-07-30T20:30:00+0900","value":61.0,"flags":""},{"recorded_at":"2017-07-30T21:00:00+0900","value":59.0,"flags":""},{"recorded_at":"2017-07-30T21:30:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-07-30T22:00:00+0900","value":55.0,"flags":""},{"recorded_at":"2017-07-30T22:30:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-07-30T23:00:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-07-30T23:30:00+0900","value":52.0,"flags":""},{"recorded_at":"2017-07-31T00:00:00+0900","value":53.0,"flags":""},{"recorded_at":"2017-07-31T00:30:00+0900","value":53.0,"flags":""},{"recorded_at":"2017-07-31T01:00:00+0900","value":52.0,"flags":""},{"recorded_at":"2017-07-31T01:30:00+0900","value":52.0,"flags":""},{"recorded_at":"2017-07-31T02:00:00+0900","value":48.0,"flags":""},{"recorded_at":"2017-07-31T02:30:00+0900","value":47.0,"flags":""},{"recorded_at":"2017-07-31T03:00:00+0900","value":47.0,"flags":""},{"recorded_at":"2017-07-31T03:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-07-31T04:00:00+0900","value":48.0,"flags":""},{"recorded_at":"2017-07-31T04:30:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-07-31T05:00:00+0900","value":48.0,"flags":""},{"recorded_at":"2017-07-31T05:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-07-31T06:00:00+0900","value":52.0,"flags":""},{"recorded_at":"2017-07-31T06:30:00+0900","value":72.0,"flags":""},{"recorded_at":"2017-07-31T07:00:00+0900","value":152.0,"flags":""},{"recorded_at":"2017-07-31T07:30:00+0900","value":133.0,"flags":""},{"recorded_at":"2017-07-31T08:00:00+0900","value":141.0,"flags":""},{"recorded_at":"2017-07-31T08:30:00+0900","value":185.0,"flags":""},{"recorded_at":"2017-07-31T09:00:00+0900","value":250.0,"flags":""},{"recorded_at":"2017-07-31T09:30:00+0900","value":264.0,"flags":""},{"recorded_at":"2017-07-31T10:00:00+0900","value":262.0,"flags":""},{"recorded_at":"2017-07-31T10:30:00+0900","value":267.0,"flags":""},{"recorded_at":"2017-07-31T11:00:00+0900","value":266.0,"flags":""},{"recorded_at":"2017-07-31T11:30:00+0900","value":270.0,"flags":""},{"recorded_at":"2017-07-31T12:00:00+0900","value":256.0,"flags":""},{"recorded_at":"2017-07-31T12:30:00+0900","value":249.0,"flags":""},{"recorded_at":"2017-07-31T13:00:00+0900","value":235.0,"flags":""},{"recorded_at":"2017-07-31T13:30:00+0900","value":255.0,"flags":""},{"recorded_at":"2017-07-31T14:00:00+0900","value":255.0,"flags":""},{"recorded_at":"2017-07-31T14:30:00+0900","value":251.0,"flags":""},{"recorded_at":"2017-07-31T15:00:00+0900","value":243.0,"flags":""},{"recorded_at":"2017-07-31T15:30:00+0900","value":260.0,"flags":""},{"recorded_at":"2017-07-31T16:00:00+0900","value":263.0,"flags":""},{"recorded_at":"2017-07-31T16:30:00+0900","value":245.0,"flags":""},{"recorded_at":"2017-07-31T17:00:00+0900","value":252.0,"flags":""},{"recorded_at":"2017-07-31T17:30:00+0900","value":260.0,"flags":""},{"recorded_at":"2017-07-31T18:00:00+0900","value":244.0,"flags":""},{"recorded_at":"2017-07-31T18:30:00+0900","value":202.0,"flags":""},{"recorded_at":"2017-07-31T19:00:00+0900","value":188.0,"flags":""},{"recorded_at":"2017-07-31T19:30:00+0900","value":162.0,"flags":""},{"recorded_at":"2017-07-31T20:00:00+0900","value":142.0,"flags":""},{"recorded_at":"2017-07-31T20:30:00+0900","value":134.0,"flags":""},{"recorded_at":"2017-07-31T21:00:00+0900","value":128.0,"flags":""},{"recorded_at":"2017-07-31T21:30:00+0900","value":116.0,"flags":""},{"recorded_at":"2017-07-31T22:00:00+0900","value":99.0,"flags":""},{"recorded_at":"2017-07-31T22:30:00+0900","value":92.0,"flags":""},{"recorded_at":"2017-07-31T23:00:00+0900","value":83.0,"flags":""},{"recorded_at":"2017-07-31T23:30:00+0900","value":72.0,"flags":""},{"recorded_at":"2017-08-01T00:00:00+0900","value":64.0,"flags":""},{"recorded_at":"2017-08-01T00:30:00+0900","value":58.0,"flags":""},{"recorded_at":"2017-08-01T01:00:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-08-01T01:30:00+0900","value":58.0,"flags":""},{"recorded_at":"2017-08-01T02:00:00+0900","value":55.0,"flags":""},{"recorded_at":"2017-08-01T02:30:00+0900","value":52.0,"flags":""},{"recorded_at":"2017-08-01T03:00:00+0900","value":53.0,"flags":""},{"recorded_at":"2017-08-01T03:30:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-08-01T04:00:00+0900","value":52.0,"flags":""},{"recorded_at":"2017-08-01T04:30:00+0900","value":51.0,"flags":""},{"recorded_at":"2017-08-01T05:00:00+0900","value":53.0,"flags":""},{"recorded_at":"2017-08-01T05:30:00+0900","value":48.0,"flags":""},{"recorded_at":"2017-08-01T06:00:00+0900","value":53.0,"flags":""},{"recorded_at":"2017-08-01T06:30:00+0900","value":70.0,"flags":""},{"recorded_at":"2017-08-01T07:00:00+0900","value":121.0,"flags":""},{"recorded_at":"2017-08-01T07:30:00+0900","value":123.0,"flags":""},{"recorded_at":"2017-08-01T08:00:00+0900","value":136.0,"flags":""},{"recorded_at":"2017-08-01T08:30:00+0900","value":181.0,"flags":""},{"recorded_at":"2017-08-01T09:00:00+0900","value":228.0,"flags":""},{"recorded_at":"2017-08-01T09:30:00+0900","value":249.0,"flags":""},{"recorded_at":"2017-08-01T10:00:00+0900","value":252.0,"flags":""},{"recorded_at":"2017-08-01T10:30:00+0900","value":249.0,"flags":""},{"recorded_at":"2017-08-01T11:00:00+0900","value":237.0,"flags":""},{"recorded_at":"2017-08-01T11:30:00+0900","value":235.0,"flags":""},{"recorded_at":"2017-08-01T12:00:00+0900","value":236.0,"flags":""},{"recorded_at":"2017-08-01T12:30:00+0900","value":230.0,"flags":""},{"recorded_at":"2017-08-01T13:00:00+0900","value":231.0,"flags":""},{"recorded_at":"2017-08-01T13:30:00+0900","value":252.0,"flags":""},{"recorded_at":"2017-08-01T14:00:00+0900","value":244.0,"flags":""},{"recorded_at":"2017-08-01T14:30:00+0900","value":222.0,"flags":""},{"recorded_at":"2017-08-01T15:00:00+0900","value":219.0,"flags":""},{"recorded_at":"2017-08-01T15:30:00+0900","value":218.0,"flags":""},{"recorded_at":"2017-08-01T16:00:00+0900","value":216.0,"flags":""},{"recorded_at":"2017-08-01T16:30:00+0900","value":216.0,"flags":""},{"recorded_at":"2017-08-01T17:00:00+0900","value":222.0,"flags":""},{"recorded_at":"2017-08-01T17:30:00+0900","value":228.0,"flags":""},{"recorded_at":"2017-08-01T18:00:00+0900","value":222.0,"flags":""},{"recorded_at":"2017-08-01T18:30:00+0900","value":193.0,"flags":""},{"recorded_at":"2017-08-01T19:00:00+0900","value":179.0,"flags":""},{"recorded_at":"2017-08-01T19:30:00+0900","value":154.0,"flags":""},{"recorded_at":"2017-08-01T20:00:00+0900","value":145.0,"flags":""},{"recorded_at":"2017-08-01T20:30:00+0900","value":139.0,"flags":""},{"recorded_at":"2017-08-01T21:00:00+0900","value":126.0,"flags":""},{"recorded_at":"2017-08-01T21:30:00+0900","value":117.0,"flags":""},{"recorded_at":"2017-08-01T22:00:00+0900","value":102.0,"flags":""},{"recorded_at":"2017-08-01T22:30:00+0900","value":98.0,"flags":""},{"recorded_at":"2017-08-01T23:00:00+0900","value":81.0,"flags":""},{"recorded_at":"2017-08-01T23:30:00+0900","value":74.0,"flags":""},{"recorded_at":"2017-08-02T00:00:00+0900","value":65.0,"flags":""},{"recorded_at":"2017-08-02T00:30:00+0900","value":56.0,"flags":""},{"recorded_at":"2017-08-02T01:00:00+0900","value":55.0,"flags":""},{"recorded_at":"2017-08-02T01:30:00+0900","value":56.0,"flags":""},{"recorded_at":"2017-08-02T02:00:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-08-02T02:30:00+0900","value":55.0,"flags":""},{"recorded_at":"2017-08-02T03:00:00+0900","value":53.0,"flags":""},{"recorded_at":"2017-08-02T03:30:00+0900","value":53.0,"flags":""},{"recorded_at":"2017-08-02T04:00:00+0900","value":55.0,"flags":""},{"recorded_at":"2017-08-02T04:30:00+0900","value":53.0,"flags":""},{"recorded_at":"2017-08-02T05:00:00+0900","value":53.0,"flags":""},{"recorded_at":"2017-08-02T05:30:00+0900","value":55.0,"flags":""},{"recorded_at":"2017-08-02T06:00:00+0900","value":56.0,"flags":""},{"recorded_at":"2017-08-02T06:30:00+0900","value":72.0,"flags":""},{"recorded_at":"2017-08-02T07:00:00+0900","value":105.0,"flags":""},{"recorded_at":"2017-08-02T07:30:00+0900","value":98.0,"flags":""},{"recorded_at":"2017-08-02T08:00:00+0900","value":117.0,"flags":""},{"recorded_at":"2017-08-02T08:30:00+0900","value":160.0,"flags":""},{"recorded_at":"2017-08-02T09:00:00+0900","value":209.0,"flags":""},{"recorded_at":"2017-08-02T09:30:00+0900","value":218.0,"flags":""},{"recorded_at":"2017-08-02T10:00:00+0900","value":233.0,"flags":""},{"recorded_at":"2017-08-02T10:30:00+0900","value":247.0,"flags":""},{"recorded_at":"2017-08-02T11:00:00+0900","value":237.0,"flags":""},{"recorded_at":"2017-08-02T11:30:00+0900","value":233.0,"flags":""},{"recorded_at":"2017-08-02T12:00:00+0900","value":241.0,"flags":""},{"recorded_at":"2017-08-02T12:30:00+0900","value":228.0,"flags":""},{"recorded_at":"2017-08-02T13:00:00+0900","value":223.0,"flags":""},{"recorded_at":"2017-08-02T13:30:00+0900","value":238.0,"flags":""},{"recorded_at":"2017-08-02T14:00:00+0900","value":239.0,"flags":""},{"recorded_at":"2017-08-02T14:30:00+0900","value":237.0,"flags":""},{"recorded_at":"2017-08-02T15:00:00+0900","value":233.0,"flags":""},{"recorded_at":"2017-08-02T15:30:00+0900","value":240.0,"flags":""},{"recorded_at":"2017-08-02T16:00:00+0900","value":237.0,"flags":""},{"recorded_at":"2017-08-02T16:30:00+0900","value":239.0,"flags":""},{"recorded_at":"2017-08-02T17:00:00+0900","value":232.0,"flags":""},{"recorded_at":"2017-08-02T17:30:00+0900","value":231.0,"flags":""},{"recorded_at":"2017-08-02T18:00:00+0900","value":214.0,"flags":""},{"recorded_at":"2017-08-02T18:30:00+0900","value":173.0,"flags":""},{"recorded_at":"2017-08-02T19:00:00+0900","value":148.0,"flags":""},{"recorded_at":"2017-08-02T19:30:00+0900","value":113.0,"flags":""},{"recorded_at":"2017-08-02T20:00:00+0900","value":108.0,"flags":""},{"recorded_at":"2017-08-02T20:30:00+0900","value":104.0,"flags":""},{"recorded_at":"2017-08-02T21:00:00+0900","value":100.0,"flags":""},{"recorded_at":"2017-08-02T21:30:00+0900","value":92.0,"flags":""},{"recorded_at":"2017-08-02T22:00:00+0900","value":83.0,"flags":""},{"recorded_at":"2017-08-02T22:30:00+0900","value":71.0,"flags":""},{"recorded_at":"2017-08-02T23:00:00+0900","value":66.0,"flags":""},{"recorded_at":"2017-08-02T23:30:00+0900","value":61.0,"flags":""},{"recorded_at":"2017-08-03T00:00:00+0900","value":60.0,"flags":""},{"recorded_at":"2017-08-03T00:30:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-08-03T01:00:00+0900","value":51.0,"flags":""},{"recorded_at":"2017-08-03T01:30:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-08-03T02:00:00+0900","value":53.0,"flags":""},{"recorded_at":"2017-08-03T02:30:00+0900","value":52.0,"flags":""},{"recorded_at":"2017-08-03T03:00:00+0900","value":53.0,"flags":""},{"recorded_at":"2017-08-03T03:30:00+0900","value":53.0,"flags":""},{"recorded_at":"2017-08-03T04:00:00+0900","value":55.0,"flags":""},{"recorded_at":"2017-08-03T04:30:00+0900","value":55.0,"flags":""},{"recorded_at":"2017-08-03T05:00:00+0900","value":55.0,"flags":""},{"recorded_at":"2017-08-03T05:30:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-08-03T06:00:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-08-03T06:30:00+0900","value":73.0,"flags":""},{"recorded_at":"2017-08-03T07:00:00+0900","value":102.0,"flags":""},{"recorded_at":"2017-08-03T07:30:00+0900","value":91.0,"flags":""},{"recorded_at":"2017-08-03T08:00:00+0900","value":120.0,"flags":""},{"recorded_at":"2017-08-03T08:30:00+0900","value":163.0,"flags":""},{"recorded_at":"2017-08-03T09:00:00+0900","value":199.0,"flags":""},{"recorded_at":"2017-08-03T09:30:00+0900","value":213.0,"flags":""},{"recorded_at":"2017-08-03T10:00:00+0900","value":214.0,"flags":""},{"recorded_at":"2017-08-03T10:30:00+0900","value":223.0,"flags":""},{"recorded_at":"2017-08-03T11:00:00+0900","value":225.0,"flags":""},{"recorded_at":"2017-08-03T11:30:00+0900","value":223.0,"flags":""},{"recorded_at":"2017-08-03T12:00:00+0900","value":216.0,"flags":""},{"recorded_at":"2017-08-03T12:30:00+0900","value":212.0,"flags":""},{"recorded_at":"2017-08-03T13:00:00+0900","value":215.0,"flags":""},{"recorded_at":"2017-08-03T13:30:00+0900","value":225.0,"flags":""},{"recorded_at":"2017-08-03T14:00:00+0900","value":232.0,"flags":""},{"recorded_at":"2017-08-03T14:30:00+0900","value":229.0,"flags":""},{"recorded_at":"2017-08-03T15:00:00+0900","value":234.0,"flags":""},{"recorded_at":"2017-08-03T15:30:00+0900","value":237.0,"flags":""},{"recorded_at":"2017-08-03T16:00:00+0900","value":230.0,"flags":""},{"recorded_at":"2017-08-03T16:30:00+0900","value":229.0,"flags":""},{"recorded_at":"2017-08-03T17:00:00+0900","value":223.0,"flags":""},{"recorded_at":"2017-08-03T17:30:00+0900","value":219.0,"flags":""},{"recorded_at":"2017-08-03T18:00:00+0900","value":215.0,"flags":""},{"recorded_at":"2017-08-03T18:30:00+0900","value":189.0,"flags":""},{"recorded_at":"2017-08-03T19:00:00+0900","value":175.0,"flags":""},{"recorded_at":"2017-08-03T19:30:00+0900","value":146.0,"flags":""},{"recorded_at":"2017-08-03T20:00:00+0900","value":133.0,"flags":""},{"recorded_at":"2017-08-03T20:30:00+0900","value":127.0,"flags":""},{"recorded_at":"2017-08-03T21:00:00+0900","value":121.0,"flags":""},{"recorded_at":"2017-08-03T21:30:00+0900","value":110.0,"flags":""},{"recorded_at":"2017-08-03T22:00:00+0900","value":103.0,"flags":""},{"recorded_at":"2017-08-03T22:30:00+0900","value":95.0,"flags":""},{"recorded_at":"2017-08-03T23:00:00+0900","value":95.0,"flags":""},{"recorded_at":"2017-08-03T23:30:00+0900","value":91.0,"flags":""},{"recorded_at":"2017-08-04T00:00:00+0900","value":67.0,"flags":""},{"recorded_at":"2017-08-04T00:30:00+0900","value":47.0,"flags":""},{"recorded_at":"2017-08-04T01:00:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-08-04T01:30:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-04T02:00:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-08-04T02:30:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-04T03:00:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-08-04T03:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-04T04:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-04T04:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-04T05:00:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-04T05:30:00+0900","value":47.0,"flags":""},{"recorded_at":"2017-08-04T06:00:00+0900","value":51.0,"flags":""},{"recorded_at":"2017-08-04T06:30:00+0900","value":67.0,"flags":""},{"recorded_at":"2017-08-04T07:00:00+0900","value":106.0,"flags":""},{"recorded_at":"2017-08-04T07:30:00+0900","value":102.0,"flags":""},{"recorded_at":"2017-08-04T08:00:00+0900","value":120.0,"flags":""},{"recorded_at":"2017-08-04T08:30:00+0900","value":164.0,"flags":""},{"recorded_at":"2017-08-04T09:00:00+0900","value":219.0,"flags":""},{"recorded_at":"2017-08-04T09:30:00+0900","value":226.0,"flags":""},{"recorded_at":"2017-08-04T10:00:00+0900","value":232.0,"flags":""},{"recorded_at":"2017-08-04T10:30:00+0900","value":238.0,"flags":""},{"recorded_at":"2017-08-04T11:00:00+0900","value":230.0,"flags":""},{"recorded_at":"2017-08-04T11:30:00+0900","value":228.0,"flags":""},{"recorded_at":"2017-08-04T12:00:00+0900","value":235.0,"flags":""},{"recorded_at":"2017-08-04T12:30:00+0900","value":233.0,"flags":""},{"recorded_at":"2017-08-04T13:00:00+0900","value":220.0,"flags":""},{"recorded_at":"2017-08-04T13:30:00+0900","value":229.0,"flags":""},{"recorded_at":"2017-08-04T14:00:00+0900","value":232.0,"flags":""},{"recorded_at":"2017-08-04T14:30:00+0900","value":226.0,"flags":""},{"recorded_at":"2017-08-04T15:00:00+0900","value":230.0,"flags":""},{"recorded_at":"2017-08-04T15:30:00+0900","value":233.0,"flags":""},{"recorded_at":"2017-08-04T16:00:00+0900","value":232.0,"flags":""},{"recorded_at":"2017-08-04T16:30:00+0900","value":227.0,"flags":""},{"recorded_at":"2017-08-04T17:00:00+0900","value":213.0,"flags":""},{"recorded_at":"2017-08-04T17:30:00+0900","value":210.0,"flags":""},{"recorded_at":"2017-08-04T18:00:00+0900","value":203.0,"flags":""},{"recorded_at":"2017-08-04T18:30:00+0900","value":180.0,"flags":""},{"recorded_at":"2017-08-04T19:00:00+0900","value":160.0,"flags":""},{"recorded_at":"2017-08-04T19:30:00+0900","value":137.0,"flags":""},{"recorded_at":"2017-08-04T20:00:00+0900","value":134.0,"flags":""},{"recorded_at":"2017-08-04T20:30:00+0900","value":129.0,"flags":""},{"recorded_at":"2017-08-04T21:00:00+0900","value":121.0,"flags":""},{"recorded_at":"2017-08-04T21:30:00+0900","value":113.0,"flags":""},{"recorded_at":"2017-08-04T22:00:00+0900","value":103.0,"flags":""},{"recorded_at":"2017-08-04T22:30:00+0900","value":92.0,"flags":""},{"recorded_at":"2017-08-04T23:00:00+0900","value":79.0,"flags":""},{"recorded_at":"2017-08-04T23:30:00+0900","value":62.0,"flags":""},{"recorded_at":"2017-08-05T00:00:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-08-05T00:30:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-08-05T01:00:00+0900","value":50.0,"flags":""},{"recorded_at":"2017-08-05T01:30:00+0900","value":50.0,"flags":""},{"recorded_at":"2017-08-05T02:00:00+0900","value":49.0,"flags":""},{"recorded_at":"2017-08-05T02:30:00+0900","value":50.0,"flags":""},{"recorded_at":"2017-08-05T03:00:00+0900","value":53.0,"flags":""},{"recorded_at":"2017-08-05T03:30:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-08-05T04:00:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-08-05T04:30:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-08-05T05:00:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-08-05T05:30:00+0900","value":53.0,"flags":""},{"recorded_at":"2017-08-05T06:00:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-08-05T06:30:00+0900","value":62.0,"flags":""},{"recorded_at":"2017-08-05T07:00:00+0900","value":66.0,"flags":""},{"recorded_at":"2017-08-05T07:30:00+0900","value":65.0,"flags":""},{"recorded_at":"2017-08-05T08:00:00+0900","value":65.0,"flags":""},{"recorded_at":"2017-08-05T08:30:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-08-05T09:00:00+0900","value":64.0,"flags":""},{"recorded_at":"2017-08-05T09:30:00+0900","value":69.0,"flags":""},{"recorded_at":"2017-08-05T10:00:00+0900","value":72.0,"flags":""},{"recorded_at":"2017-08-05T10:30:00+0900","value":71.0,"flags":""},{"recorded_at":"2017-08-05T11:00:00+0900","value":68.0,"flags":""},{"recorded_at":"2017-08-05T11:30:00+0900","value":72.0,"flags":""},{"recorded_at":"2017-08-05T12:00:00+0900","value":77.0,"flags":""},{"recorded_at":"2017-08-05T12:30:00+0900","value":75.0,"flags":""},{"recorded_at":"2017-08-05T13:00:00+0900","value":75.0,"flags":""},{"recorded_at":"2017-08-05T13:30:00+0900","value":83.0,"flags":""},{"recorded_at":"2017-08-05T14:00:00+0900","value":88.0,"flags":""},{"recorded_at":"2017-08-05T14:30:00+0900","value":85.0,"flags":""},{"recorded_at":"2017-08-05T15:00:00+0900","value":79.0,"flags":""},{"recorded_at":"2017-08-05T15:30:00+0900","value":80.0,"flags":""},{"recorded_at":"2017-08-05T16:00:00+0900","value":85.0,"flags":""},{"recorded_at":"2017-08-05T16:30:00+0900","value":93.0,"flags":""},{"recorded_at":"2017-08-05T17:00:00+0900","value":95.0,"flags":""},{"recorded_at":"2017-08-05T17:30:00+0900","value":88.0,"flags":""},{"recorded_at":"2017-08-05T18:00:00+0900","value":78.0,"flags":""},{"recorded_at":"2017-08-05T18:30:00+0900","value":70.0,"flags":""},{"recorded_at":"2017-08-05T19:00:00+0900","value":71.0,"flags":""},{"recorded_at":"2017-08-05T19:30:00+0900","value":66.0,"flags":""},{"recorded_at":"2017-08-05T20:00:00+0900","value":61.0,"flags":""},{"recorded_at":"2017-08-05T20:30:00+0900","value":62.0,"flags":""},{"recorded_at":"2017-08-05T21:00:00+0900","value":60.0,"flags":""},{"recorded_at":"2017-08-05T21:30:00+0900","value":59.0,"flags":""},{"recorded_at":"2017-08-05T22:00:00+0900","value":66.0,"flags":""},{"recorded_at":"2017-08-05T22:30:00+0900","value":60.0,"flags":""},{"recorded_at":"2017-08-05T23:00:00+0900","value":58.0,"flags":""},{"recorded_at":"2017-08-05T23:30:00+0900","value":49.0,"flags":""},{"recorded_at":"2017-08-06T00:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-06T00:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-06T01:00:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-08-06T01:30:00+0900","value":48.0,"flags":""},{"recorded_at":"2017-08-06T02:00:00+0900","value":55.0,"flags":""},{"recorded_at":"2017-08-06T02:30:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-08-06T03:00:00+0900","value":47.0,"flags":""},{"recorded_at":"2017-08-06T03:30:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-06T04:00:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-06T04:30:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-08-06T05:00:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-08-06T05:30:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-08-06T06:00:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-06T06:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-06T07:00:00+0900","value":47.0,"flags":""},{"recorded_at":"2017-08-06T07:30:00+0900","value":51.0,"flags":""},{"recorded_at":"2017-08-06T08:00:00+0900","value":52.0,"flags":""},{"recorded_at":"2017-08-06T08:30:00+0900","value":64.0,"flags":""},{"recorded_at":"2017-08-06T09:00:00+0900","value":64.0,"flags":""},{"recorded_at":"2017-08-06T09:30:00+0900","value":66.0,"flags":""},{"recorded_at":"2017-08-06T10:00:00+0900","value":65.0,"flags":""},{"recorded_at":"2017-08-06T10:30:00+0900","value":64.0,"flags":""},{"recorded_at":"2017-08-06T11:00:00+0900","value":63.0,"flags":""},{"recorded_at":"2017-08-06T11:30:00+0900","value":62.0,"flags":""},{"recorded_at":"2017-08-06T12:00:00+0900","value":63.0,"flags":""},{"recorded_at":"2017-08-06T12:30:00+0900","value":66.0,"flags":""},{"recorded_at":"2017-08-06T13:00:00+0900","value":67.0,"flags":""},{"recorded_at":"2017-08-06T13:30:00+0900","value":66.0,"flags":""},{"recorded_at":"2017-08-06T14:00:00+0900","value":66.0,"flags":""},{"recorded_at":"2017-08-06T14:30:00+0900","value":69.0,"flags":""},{"recorded_at":"2017-08-06T15:00:00+0900","value":67.0,"flags":""},{"recorded_at":"2017-08-06T15:30:00+0900","value":69.0,"flags":""},{"recorded_at":"2017-08-06T16:00:00+0900","value":75.0,"flags":""},{"recorded_at":"2017-08-06T16:30:00+0900","value":86.0,"flags":""},{"recorded_at":"2017-08-06T17:00:00+0900","value":87.0,"flags":""},{"recorded_at":"2017-08-06T17:30:00+0900","value":80.0,"flags":""},{"recorded_at":"2017-08-06T18:00:00+0900","value":76.0,"flags":""},{"recorded_at":"2017-08-06T18:30:00+0900","value":71.0,"flags":""},{"recorded_at":"2017-08-06T19:00:00+0900","value":68.0,"flags":""},{"recorded_at":"2017-08-06T19:30:00+0900","value":65.0,"flags":""},{"recorded_at":"2017-08-06T20:00:00+0900","value":62.0,"flags":""},{"recorded_at":"2017-08-06T20:30:00+0900","value":63.0,"flags":""},{"recorded_at":"2017-08-06T21:00:00+0900","value":63.0,"flags":""},{"recorded_at":"2017-08-06T21:30:00+0900","value":60.0,"flags":""},{"recorded_at":"2017-08-06T22:00:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-08-06T22:30:00+0900","value":53.0,"flags":""},{"recorded_at":"2017-08-06T23:00:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-06T23:30:00+0900","value":51.0,"flags":""},{"recorded_at":"2017-08-07T00:00:00+0900","value":52.0,"flags":""},{"recorded_at":"2017-08-07T00:30:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-08-07T01:00:00+0900","value":56.0,"flags":""},{"recorded_at":"2017-08-07T01:30:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-08-07T02:00:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-08-07T02:30:00+0900","value":59.0,"flags":""},{"recorded_at":"2017-08-07T03:00:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-08-07T03:30:00+0900","value":56.0,"flags":""},{"recorded_at":"2017-08-07T04:00:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-08-07T04:30:00+0900","value":56.0,"flags":""},{"recorded_at":"2017-08-07T05:00:00+0900","value":59.0,"flags":""},{"recorded_at":"2017-08-07T05:30:00+0900","value":59.0,"flags":""},{"recorded_at":"2017-08-07T06:00:00+0900","value":64.0,"flags":""},{"recorded_at":"2017-08-07T06:30:00+0900","value":77.0,"flags":""},{"recorded_at":"2017-08-07T07:00:00+0900","value":157.0,"flags":""},{"recorded_at":"2017-08-07T07:30:00+0900","value":135.0,"flags":""},{"recorded_at":"2017-08-07T08:00:00+0900","value":152.0,"flags":""},{"recorded_at":"2017-08-07T08:30:00+0900","value":191.0,"flags":""},{"recorded_at":"2017-08-07T09:00:00+0900","value":239.0,"flags":""},{"recorded_at":"2017-08-07T09:30:00+0900","value":254.0,"flags":""},{"recorded_at":"2017-08-07T10:00:00+0900","value":263.0,"flags":""},{"recorded_at":"2017-08-07T10:30:00+0900","value":250.0,"flags":""},{"recorded_at":"2017-08-07T11:00:00+0900","value":240.0,"flags":""},{"recorded_at":"2017-08-07T11:30:00+0900","value":231.0,"flags":""},{"recorded_at":"2017-08-07T12:00:00+0900","value":218.0,"flags":""},{"recorded_at":"2017-08-07T12:30:00+0900","value":212.0,"flags":""},{"recorded_at":"2017-08-07T13:00:00+0900","value":207.0,"flags":""},{"recorded_at":"2017-08-07T13:30:00+0900","value":224.0,"flags":""},{"recorded_at":"2017-08-07T14:00:00+0900","value":214.0,"flags":""},{"recorded_at":"2017-08-07T14:30:00+0900","value":213.0,"flags":""},{"recorded_at":"2017-08-07T15:00:00+0900","value":204.0,"flags":""},{"recorded_at":"2017-08-07T15:30:00+0900","value":203.0,"flags":""},{"recorded_at":"2017-08-07T16:00:00+0900","value":211.0,"flags":""},{"recorded_at":"2017-08-07T16:30:00+0900","value":207.0,"flags":""},{"recorded_at":"2017-08-07T17:00:00+0900","value":196.0,"flags":""},{"recorded_at":"2017-08-07T17:30:00+0900","value":196.0,"flags":""},{"recorded_at":"2017-08-07T18:00:00+0900","value":180.0,"flags":""},{"recorded_at":"2017-08-07T18:30:00+0900","value":150.0,"flags":""},{"recorded_at":"2017-08-07T19:00:00+0900","value":143.0,"flags":""},{"recorded_at":"2017-08-07T19:30:00+0900","value":129.0,"flags":""},{"recorded_at":"2017-08-07T20:00:00+0900","value":119.0,"flags":""},{"recorded_at":"2017-08-07T20:30:00+0900","value":117.0,"flags":""},{"recorded_at":"2017-08-07T21:00:00+0900","value":107.0,"flags":""},{"recorded_at":"2017-08-07T21:30:00+0900","value":90.0,"flags":""},{"recorded_at":"2017-08-07T22:00:00+0900","value":81.0,"flags":""},{"recorded_at":"2017-08-07T22:30:00+0900","value":80.0,"flags":""},{"recorded_at":"2017-08-07T23:00:00+0900","value":74.0,"flags":""},{"recorded_at":"2017-08-07T23:30:00+0900","value":64.0,"flags":""},{"recorded_at":"2017-08-08T00:00:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-08T00:30:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-08T01:00:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-08T01:30:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-08T02:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-08T02:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-08T03:00:00+0900","value":47.0,"flags":""},{"recorded_at":"2017-08-08T03:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-08T04:00:00+0900","value":47.0,"flags":""},{"recorded_at":"2017-08-08T04:30:00+0900","value":47.0,"flags":""},{"recorded_at":"2017-08-08T05:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-08T05:30:00+0900","value":48.0,"flags":""},{"recorded_at":"2017-08-08T06:00:00+0900","value":51.0,"flags":""},{"recorded_at":"2017-08-08T06:30:00+0900","value":68.0,"flags":""},{"recorded_at":"2017-08-08T07:00:00+0900","value":102.0,"flags":""},{"recorded_at":"2017-08-08T07:30:00+0900","value":92.0,"flags":""},{"recorded_at":"2017-08-08T08:00:00+0900","value":106.0,"flags":""},{"recorded_at":"2017-08-08T08:30:00+0900","value":146.0,"flags":""},{"recorded_at":"2017-08-08T09:00:00+0900","value":192.0,"flags":""},{"recorded_at":"2017-08-08T09:30:00+0900","value":201.0,"flags":""},{"recorded_at":"2017-08-08T10:00:00+0900","value":215.0,"flags":""},{"recorded_at":"2017-08-08T10:30:00+0900","value":217.0,"flags":""},{"recorded_at":"2017-08-08T11:00:00+0900","value":212.0,"flags":""},{"recorded_at":"2017-08-08T11:30:00+0900","value":220.0,"flags":""},{"recorded_at":"2017-08-08T12:00:00+0900","value":227.0,"flags":""},{"recorded_at":"2017-08-08T12:30:00+0900","value":210.0,"flags":""},{"recorded_at":"2017-08-08T13:00:00+0900","value":196.0,"flags":""},{"recorded_at":"2017-08-08T13:30:00+0900","value":218.0,"flags":""},{"recorded_at":"2017-08-08T14:00:00+0900","value":217.0,"flags":""},{"recorded_at":"2017-08-08T14:30:00+0900","value":224.0,"flags":""},{"recorded_at":"2017-08-08T15:00:00+0900","value":220.0,"flags":""},{"recorded_at":"2017-08-08T15:30:00+0900","value":212.0,"flags":""},{"recorded_at":"2017-08-08T16:00:00+0900","value":218.0,"flags":""},{"recorded_at":"2017-08-08T16:30:00+0900","value":235.0,"flags":""},{"recorded_at":"2017-08-08T17:00:00+0900","value":238.0,"flags":""},{"recorded_at":"2017-08-08T17:30:00+0900","value":226.0,"flags":""},{"recorded_at":"2017-08-08T18:00:00+0900","value":214.0,"flags":""},{"recorded_at":"2017-08-08T18:30:00+0900","value":182.0,"flags":""},{"recorded_at":"2017-08-08T19:00:00+0900","value":162.0,"flags":""},{"recorded_at":"2017-08-08T19:30:00+0900","value":144.0,"flags":""},{"recorded_at":"2017-08-08T20:00:00+0900","value":137.0,"flags":""},{"recorded_at":"2017-08-08T20:30:00+0900","value":134.0,"flags":""},{"recorded_at":"2017-08-08T21:00:00+0900","value":126.0,"flags":""},{"recorded_at":"2017-08-08T21:30:00+0900","value":108.0,"flags":""},{"recorded_at":"2017-08-08T22:00:00+0900","value":101.0,"flags":""},{"recorded_at":"2017-08-08T22:30:00+0900","value":94.0,"flags":""},{"recorded_at":"2017-08-08T23:00:00+0900","value":76.0,"flags":""},{"recorded_at":"2017-08-08T23:30:00+0900","value":61.0,"flags":""},{"recorded_at":"2017-08-09T00:00:00+0900","value":48.0,"flags":""},{"recorded_at":"2017-08-09T00:30:00+0900","value":43.0,"flags":""},{"recorded_at":"2017-08-09T01:00:00+0900","value":43.0,"flags":""},{"recorded_at":"2017-08-09T01:30:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-08-09T02:00:00+0900","value":43.0,"flags":""},{"recorded_at":"2017-08-09T02:30:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-08-09T03:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-09T03:30:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-09T04:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-09T04:30:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-09T05:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-09T05:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-09T06:00:00+0900","value":52.0,"flags":""},{"recorded_at":"2017-08-09T06:30:00+0900","value":69.0,"flags":""},{"recorded_at":"2017-08-09T07:00:00+0900","value":100.0,"flags":""},{"recorded_at":"2017-08-09T07:30:00+0900","value":98.0,"flags":""},{"recorded_at":"2017-08-09T08:00:00+0900","value":119.0,"flags":""},{"recorded_at":"2017-08-09T08:30:00+0900","value":158.0,"flags":""},{"recorded_at":"2017-08-09T09:00:00+0900","value":202.0,"flags":""},{"recorded_at":"2017-08-09T09:30:00+0900","value":215.0,"flags":""},{"recorded_at":"2017-08-09T10:00:00+0900","value":212.0,"flags":""},{"recorded_at":"2017-08-09T10:30:00+0900","value":229.0,"flags":""},{"recorded_at":"2017-08-09T11:00:00+0900","value":220.0,"flags":""},{"recorded_at":"2017-08-09T11:30:00+0900","value":222.0,"flags":""},{"recorded_at":"2017-08-09T12:00:00+0900","value":224.0,"flags":""},{"recorded_at":"2017-08-09T12:30:00+0900","value":213.0,"flags":""},{"recorded_at":"2017-08-09T13:00:00+0900","value":200.0,"flags":""},{"recorded_at":"2017-08-09T13:30:00+0900","value":213.0,"flags":""},{"recorded_at":"2017-08-09T14:00:00+0900","value":216.0,"flags":""},{"recorded_at":"2017-08-09T14:30:00+0900","value":213.0,"flags":""},{"recorded_at":"2017-08-09T15:00:00+0900","value":218.0,"flags":""},{"recorded_at":"2017-08-09T15:30:00+0900","value":214.0,"flags":""},{"recorded_at":"2017-08-09T16:00:00+0900","value":227.0,"flags":""},{"recorded_at":"2017-08-09T16:30:00+0900","value":234.0,"flags":""},{"recorded_at":"2017-08-09T17:00:00+0900","value":229.0,"flags":""},{"recorded_at":"2017-08-09T17:30:00+0900","value":220.0,"flags":""},{"recorded_at":"2017-08-09T18:00:00+0900","value":202.0,"flags":""},{"recorded_at":"2017-08-09T18:30:00+0900","value":172.0,"flags":""},{"recorded_at":"2017-08-09T19:00:00+0900","value":158.0,"flags":""},{"recorded_at":"2017-08-09T19:30:00+0900","value":128.0,"flags":""},{"recorded_at":"2017-08-09T20:00:00+0900","value":115.0,"flags":""},{"recorded_at":"2017-08-09T20:30:00+0900","value":108.0,"flags":""},{"recorded_at":"2017-08-09T21:00:00+0900","value":103.0,"flags":""},{"recorded_at":"2017-08-09T21:30:00+0900","value":102.0,"flags":""},{"recorded_at":"2017-08-09T22:00:00+0900","value":98.0,"flags":""},{"recorded_at":"2017-08-09T22:30:00+0900","value":80.0,"flags":""},{"recorded_at":"2017-08-09T23:00:00+0900","value":68.0,"flags":""},{"recorded_at":"2017-08-09T23:30:00+0900","value":63.0,"flags":""},{"recorded_at":"2017-08-10T00:00:00+0900","value":56.0,"flags":""},{"recorded_at":"2017-08-10T00:30:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-08-10T01:00:00+0900","value":55.0,"flags":""},{"recorded_at":"2017-08-10T01:30:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-08-10T02:00:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-08-10T02:30:00+0900","value":56.0,"flags":""},{"recorded_at":"2017-08-10T03:00:00+0900","value":56.0,"flags":""},{"recorded_at":"2017-08-10T03:30:00+0900","value":58.0,"flags":""},{"recorded_at":"2017-08-10T04:00:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-08-10T04:30:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-08-10T05:00:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-08-10T05:30:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-08-10T06:00:00+0900","value":58.0,"flags":""},{"recorded_at":"2017-08-10T06:30:00+0900","value":75.0,"flags":""},{"recorded_at":"2017-08-10T07:00:00+0900","value":123.0,"flags":""},{"recorded_at":"2017-08-10T07:30:00+0900","value":121.0,"flags":""},{"recorded_at":"2017-08-10T08:00:00+0900","value":141.0,"flags":""},{"recorded_at":"2017-08-10T08:30:00+0900","value":157.0,"flags":""},{"recorded_at":"2017-08-10T09:00:00+0900","value":211.0,"flags":""},{"recorded_at":"2017-08-10T09:30:00+0900","value":220.0,"flags":""},{"recorded_at":"2017-08-10T10:00:00+0900","value":210.0,"flags":""},{"recorded_at":"2017-08-10T10:30:00+0900","value":220.0,"flags":""},{"recorded_at":"2017-08-10T11:00:00+0900","value":223.0,"flags":""},{"recorded_at":"2017-08-10T11:30:00+0900","value":228.0,"flags":""},{"recorded_at":"2017-08-10T12:00:00+0900","value":218.0,"flags":""},{"recorded_at":"2017-08-10T12:30:00+0900","value":214.0,"flags":""},{"recorded_at":"2017-08-10T13:00:00+0900","value":208.0,"flags":""},{"recorded_at":"2017-08-10T13:30:00+0900","value":219.0,"flags":""},{"recorded_at":"2017-08-10T14:00:00+0900","value":216.0,"flags":""},{"recorded_at":"2017-08-10T14:30:00+0900","value":225.0,"flags":""},{"recorded_at":"2017-08-10T15:00:00+0900","value":216.0,"flags":""},{"recorded_at":"2017-08-10T15:30:00+0900","value":228.0,"flags":""},{"recorded_at":"2017-08-10T16:00:00+0900","value":237.0,"flags":""},{"recorded_at":"2017-08-10T16:30:00+0900","value":241.0,"flags":""},{"recorded_at":"2017-08-10T17:00:00+0900","value":235.0,"flags":""},{"recorded_at":"2017-08-10T17:30:00+0900","value":235.0,"flags":""},{"recorded_at":"2017-08-10T18:00:00+0900","value":216.0,"flags":""},{"recorded_at":"2017-08-10T18:30:00+0900","value":195.0,"flags":""},{"recorded_at":"2017-08-10T19:00:00+0900","value":171.0,"flags":""},{"recorded_at":"2017-08-10T19:30:00+0900","value":141.0,"flags":""},{"recorded_at":"2017-08-10T20:00:00+0900","value":138.0,"flags":""},{"recorded_at":"2017-08-10T20:30:00+0900","value":129.0,"flags":""},{"recorded_at":"2017-08-10T21:00:00+0900","value":111.0,"flags":""},{"recorded_at":"2017-08-10T21:30:00+0900","value":103.0,"flags":""},{"recorded_at":"2017-08-10T22:00:00+0900","value":90.0,"flags":""},{"recorded_at":"2017-08-10T22:30:00+0900","value":75.0,"flags":""},{"recorded_at":"2017-08-10T23:00:00+0900","value":69.0,"flags":""},{"recorded_at":"2017-08-10T23:30:00+0900","value":64.0,"flags":""},{"recorded_at":"2017-08-11T00:00:00+0900","value":63.0,"flags":""},{"recorded_at":"2017-08-11T00:30:00+0900","value":59.0,"flags":""},{"recorded_at":"2017-08-11T01:00:00+0900","value":58.0,"flags":""},{"recorded_at":"2017-08-11T01:30:00+0900","value":58.0,"flags":""},{"recorded_at":"2017-08-11T02:00:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-08-11T02:30:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-08-11T03:00:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-11T03:30:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-11T04:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-11T04:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-11T05:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-11T05:30:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-11T06:00:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-11T06:30:00+0900","value":55.0,"flags":""},{"recorded_at":"2017-08-11T07:00:00+0900","value":65.0,"flags":""},{"recorded_at":"2017-08-11T07:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-11T08:00:00+0900","value":49.0,"flags":""},{"recorded_at":"2017-08-11T08:30:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-08-11T09:00:00+0900","value":66.0,"flags":""},{"recorded_at":"2017-08-11T09:30:00+0900","value":71.0,"flags":""},{"recorded_at":"2017-08-11T10:00:00+0900","value":74.0,"flags":""},{"recorded_at":"2017-08-11T10:30:00+0900","value":68.0,"flags":""},{"recorded_at":"2017-08-11T11:00:00+0900","value":69.0,"flags":""},{"recorded_at":"2017-08-11T11:30:00+0900","value":78.0,"flags":""},{"recorded_at":"2017-08-11T12:00:00+0900","value":78.0,"flags":""},{"recorded_at":"2017-08-11T12:30:00+0900","value":74.0,"flags":""},{"recorded_at":"2017-08-11T13:00:00+0900","value":75.0,"flags":""},{"recorded_at":"2017-08-11T13:30:00+0900","value":76.0,"flags":""},{"recorded_at":"2017-08-11T14:00:00+0900","value":75.0,"flags":""},{"recorded_at":"2017-08-11T14:30:00+0900","value":75.0,"flags":""},{"recorded_at":"2017-08-11T15:00:00+0900","value":80.0,"flags":""},{"recorded_at":"2017-08-11T15:30:00+0900","value":82.0,"flags":""},{"recorded_at":"2017-08-11T16:00:00+0900","value":80.0,"flags":""},{"recorded_at":"2017-08-11T16:30:00+0900","value":80.0,"flags":""},{"recorded_at":"2017-08-11T17:00:00+0900","value":79.0,"flags":""},{"recorded_at":"2017-08-11T17:30:00+0900","value":74.0,"flags":""},{"recorded_at":"2017-08-11T18:00:00+0900","value":75.0,"flags":""},{"recorded_at":"2017-08-11T18:30:00+0900","value":67.0,"flags":""},{"recorded_at":"2017-08-11T19:00:00+0900","value":65.0,"flags":""},{"recorded_at":"2017-08-11T19:30:00+0900","value":59.0,"flags":""},{"recorded_at":"2017-08-11T20:00:00+0900","value":61.0,"flags":""},{"recorded_at":"2017-08-11T20:30:00+0900","value":60.0,"flags":""},{"recorded_at":"2017-08-11T21:00:00+0900","value":56.0,"flags":""},{"recorded_at":"2017-08-11T21:30:00+0900","value":53.0,"flags":""},{"recorded_at":"2017-08-11T22:00:00+0900","value":53.0,"flags":""},{"recorded_at":"2017-08-11T22:30:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-08-11T23:00:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-08-11T23:30:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-08-12T00:00:00+0900","value":56.0,"flags":""},{"recorded_at":"2017-08-12T00:30:00+0900","value":48.0,"flags":""},{"recorded_at":"2017-08-12T01:00:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-12T01:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-12T02:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-12T02:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-12T03:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-12T03:30:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-12T04:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-12T04:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-12T05:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-12T05:30:00+0900","value":48.0,"flags":""},{"recorded_at":"2017-08-12T06:00:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-12T06:30:00+0900","value":47.0,"flags":""},{"recorded_at":"2017-08-12T07:00:00+0900","value":47.0,"flags":""},{"recorded_at":"2017-08-12T07:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-12T08:00:00+0900","value":52.0,"flags":""},{"recorded_at":"2017-08-12T08:30:00+0900","value":55.0,"flags":""},{"recorded_at":"2017-08-12T09:00:00+0900","value":63.0,"flags":""},{"recorded_at":"2017-08-12T09:30:00+0900","value":68.0,"flags":""},{"recorded_at":"2017-08-12T10:00:00+0900","value":73.0,"flags":""},{"recorded_at":"2017-08-12T10:30:00+0900","value":71.0,"flags":""},{"recorded_at":"2017-08-12T11:00:00+0900","value":74.0,"flags":""},{"recorded_at":"2017-08-12T11:30:00+0900","value":71.0,"flags":""},{"recorded_at":"2017-08-12T12:00:00+0900","value":70.0,"flags":""},{"recorded_at":"2017-08-12T12:30:00+0900","value":72.0,"flags":""},{"recorded_at":"2017-08-12T13:00:00+0900","value":73.0,"flags":""},{"recorded_at":"2017-08-12T13:30:00+0900","value":83.0,"flags":""},{"recorded_at":"2017-08-12T14:00:00+0900","value":81.0,"flags":""},{"recorded_at":"2017-08-12T14:30:00+0900","value":80.0,"flags":""},{"recorded_at":"2017-08-12T15:00:00+0900","value":77.0,"flags":""},{"recorded_at":"2017-08-12T15:30:00+0900","value":81.0,"flags":""},{"recorded_at":"2017-08-12T16:00:00+0900","value":80.0,"flags":""},{"recorded_at":"2017-08-12T16:30:00+0900","value":81.0,"flags":""},{"recorded_at":"2017-08-12T17:00:00+0900","value":85.0,"flags":""},{"recorded_at":"2017-08-12T17:30:00+0900","value":83.0,"flags":""},{"recorded_at":"2017-08-12T18:00:00+0900","value":75.0,"flags":""},{"recorded_at":"2017-08-12T18:30:00+0900","value":63.0,"flags":""},{"recorded_at":"2017-08-12T19:00:00+0900","value":60.0,"flags":""},{"recorded_at":"2017-08-12T19:30:00+0900","value":55.0,"flags":""},{"recorded_at":"2017-08-12T20:00:00+0900","value":53.0,"flags":""},{"recorded_at":"2017-08-12T20:30:00+0900","value":52.0,"flags":""},{"recorded_at":"2017-08-12T21:00:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-08-12T21:30:00+0900","value":53.0,"flags":""},{"recorded_at":"2017-08-12T22:00:00+0900","value":53.0,"flags":""},{"recorded_at":"2017-08-12T22:30:00+0900","value":52.0,"flags":""},{"recorded_at":"2017-08-12T23:00:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-08-12T23:30:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-08-13T00:00:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-08-13T00:30:00+0900","value":56.0,"flags":""},{"recorded_at":"2017-08-13T01:00:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-08-13T01:30:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-08-13T02:00:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-08-13T02:30:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-08-13T03:00:00+0900","value":56.0,"flags":""},{"recorded_at":"2017-08-13T03:30:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-08-13T04:00:00+0900","value":58.0,"flags":""},{"recorded_at":"2017-08-13T04:30:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-08-13T05:00:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-08-13T05:30:00+0900","value":58.0,"flags":""},{"recorded_at":"2017-08-13T06:00:00+0900","value":58.0,"flags":""},{"recorded_at":"2017-08-13T06:30:00+0900","value":60.0,"flags":""},{"recorded_at":"2017-08-13T07:00:00+0900","value":58.0,"flags":""},{"recorded_at":"2017-08-13T07:30:00+0900","value":55.0,"flags":""},{"recorded_at":"2017-08-13T08:00:00+0900","value":53.0,"flags":""},{"recorded_at":"2017-08-13T08:30:00+0900","value":56.0,"flags":""},{"recorded_at":"2017-08-13T09:00:00+0900","value":60.0,"flags":""},{"recorded_at":"2017-08-13T09:30:00+0900","value":68.0,"flags":""},{"recorded_at":"2017-08-13T10:00:00+0900","value":69.0,"flags":""},{"recorded_at":"2017-08-13T10:30:00+0900","value":67.0,"flags":""},{"recorded_at":"2017-08-13T11:00:00+0900","value":70.0,"flags":""},{"recorded_at":"2017-08-13T11:30:00+0900","value":71.0,"flags":""},{"recorded_at":"2017-08-13T12:00:00+0900","value":70.0,"flags":""},{"recorded_at":"2017-08-13T12:30:00+0900","value":70.0,"flags":""},{"recorded_at":"2017-08-13T13:00:00+0900","value":69.0,"flags":""},{"recorded_at":"2017-08-13T13:30:00+0900","value":75.0,"flags":""},{"recorded_at":"2017-08-13T14:00:00+0900","value":75.0,"flags":""},{"recorded_at":"2017-08-13T14:30:00+0900","value":78.0,"flags":""},{"recorded_at":"2017-08-13T15:00:00+0900","value":77.0,"flags":""},{"recorded_at":"2017-08-13T15:30:00+0900","value":75.0,"flags":""},{"recorded_at":"2017-08-13T16:00:00+0900","value":71.0,"flags":""},{"recorded_at":"2017-08-13T16:30:00+0900","value":67.0,"flags":""},{"recorded_at":"2017-08-13T17:00:00+0900","value":68.0,"flags":""},{"recorded_at":"2017-08-13T17:30:00+0900","value":63.0,"flags":""},{"recorded_at":"2017-08-13T18:00:00+0900","value":62.0,"flags":""},{"recorded_at":"2017-08-13T18:30:00+0900","value":67.0,"flags":""},{"recorded_at":"2017-08-13T19:00:00+0900","value":60.0,"flags":""},{"recorded_at":"2017-08-13T19:30:00+0900","value":60.0,"flags":""},{"recorded_at":"2017-08-13T20:00:00+0900","value":59.0,"flags":""},{"recorded_at":"2017-08-13T20:30:00+0900","value":61.0,"flags":""},{"recorded_at":"2017-08-13T21:00:00+0900","value":61.0,"flags":""},{"recorded_at":"2017-08-13T21:30:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-08-13T22:00:00+0900","value":51.0,"flags":""},{"recorded_at":"2017-08-13T22:30:00+0900","value":52.0,"flags":""},{"recorded_at":"2017-08-13T23:00:00+0900","value":47.0,"flags":""},{"recorded_at":"2017-08-13T23:30:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-08-14T00:00:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-08-14T00:30:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-08-14T01:00:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-08-14T01:30:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-14T02:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-14T02:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-14T03:00:00+0900","value":47.0,"flags":""},{"recorded_at":"2017-08-14T03:30:00+0900","value":47.0,"flags":""},{"recorded_at":"2017-08-14T04:00:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-14T04:30:00+0900","value":48.0,"flags":""},{"recorded_at":"2017-08-14T05:00:00+0900","value":47.0,"flags":""},{"recorded_at":"2017-08-14T05:30:00+0900","value":49.0,"flags":""},{"recorded_at":"2017-08-14T06:00:00+0900","value":55.0,"flags":""},{"recorded_at":"2017-08-14T06:30:00+0900","value":70.0,"flags":""},{"recorded_at":"2017-08-14T07:00:00+0900","value":134.0,"flags":""},{"recorded_at":"2017-08-14T07:30:00+0900","value":109.0,"flags":""},{"recorded_at":"2017-08-14T08:00:00+0900","value":124.0,"flags":""},{"recorded_at":"2017-08-14T08:30:00+0900","value":154.0,"flags":""},{"recorded_at":"2017-08-14T09:00:00+0900","value":187.0,"flags":""},{"recorded_at":"2017-08-14T09:30:00+0900","value":201.0,"flags":""},{"recorded_at":"2017-08-14T10:00:00+0900","value":198.0,"flags":""},{"recorded_at":"2017-08-14T10:30:00+0900","value":213.0,"flags":""},{"recorded_at":"2017-08-14T11:00:00+0900","value":212.0,"flags":""},{"recorded_at":"2017-08-14T11:30:00+0900","value":200.0,"flags":""},{"recorded_at":"2017-08-14T12:00:00+0900","value":194.0,"flags":""},{"recorded_at":"2017-08-14T12:30:00+0900","value":188.0,"flags":""},{"recorded_at":"2017-08-14T13:00:00+0900","value":184.0,"flags":""},{"recorded_at":"2017-08-14T13:30:00+0900","value":188.0,"flags":""},{"recorded_at":"2017-08-14T14:00:00+0900","value":193.0,"flags":""},{"recorded_at":"2017-08-14T14:30:00+0900","value":182.0,"flags":""},{"recorded_at":"2017-08-14T15:00:00+0900","value":179.0,"flags":""},{"recorded_at":"2017-08-14T15:30:00+0900","value":192.0,"flags":""},{"recorded_at":"2017-08-14T16:00:00+0900","value":199.0,"flags":""},{"recorded_at":"2017-08-14T16:30:00+0900","value":196.0,"flags":""},{"recorded_at":"2017-08-14T17:00:00+0900","value":190.0,"flags":""},{"recorded_at":"2017-08-14T17:30:00+0900","value":193.0,"flags":""},{"recorded_at":"2017-08-14T18:00:00+0900","value":177.0,"flags":""},{"recorded_at":"2017-08-14T18:30:00+0900","value":155.0,"flags":""},{"recorded_at":"2017-08-14T19:00:00+0900","value":134.0,"flags":""},{"recorded_at":"2017-08-14T19:30:00+0900","value":104.0,"flags":""},{"recorded_at":"2017-08-14T20:00:00+0900","value":96.0,"flags":""},{"recorded_at":"2017-08-14T20:30:00+0900","value":90.0,"flags":""},{"recorded_at":"2017-08-14T21:00:00+0900","value":84.0,"flags":""},{"recorded_at":"2017-08-14T21:30:00+0900","value":77.0,"flags":""},{"recorded_at":"2017-08-14T22:00:00+0900","value":70.0,"flags":""},{"recorded_at":"2017-08-14T22:30:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-08-14T23:00:00+0900","value":52.0,"flags":""},{"recorded_at":"2017-08-14T23:30:00+0900","value":51.0,"flags":""},{"recorded_at":"2017-08-15T00:00:00+0900","value":43.0,"flags":""},{"recorded_at":"2017-08-15T00:30:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-08-15T01:00:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-08-15T01:30:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-08-15T02:00:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-08-15T02:30:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-08-15T03:00:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-08-15T03:30:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-15T04:00:00+0900","value":48.0,"flags":""},{"recorded_at":"2017-08-15T04:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-15T05:00:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-15T05:30:00+0900","value":50.0,"flags":""},{"recorded_at":"2017-08-15T06:00:00+0900","value":55.0,"flags":""},{"recorded_at":"2017-08-15T06:30:00+0900","value":71.0,"flags":""},{"recorded_at":"2017-08-15T07:00:00+0900","value":105.0,"flags":""},{"recorded_at":"2017-08-15T07:30:00+0900","value":92.0,"flags":""},{"recorded_at":"2017-08-15T08:00:00+0900","value":101.0,"flags":""},{"recorded_at":"2017-08-15T08:30:00+0900","value":129.0,"flags":""},{"recorded_at":"2017-08-15T09:00:00+0900","value":170.0,"flags":""},{"recorded_at":"2017-08-15T09:30:00+0900","value":176.0,"flags":""},{"recorded_at":"2017-08-15T10:00:00+0900","value":165.0,"flags":""},{"recorded_at":"2017-08-15T10:30:00+0900","value":172.0,"flags":""},{"recorded_at":"2017-08-15T11:00:00+0900","value":170.0,"flags":""},{"recorded_at":"2017-08-15T11:30:00+0900","value":178.0,"flags":""},{"recorded_at":"2017-08-15T12:00:00+0900","value":169.0,"flags":""},{"recorded_at":"2017-08-15T12:30:00+0900","value":163.0,"flags":""},{"recorded_at":"2017-08-15T13:00:00+0900","value":149.0,"flags":""},{"recorded_at":"2017-08-15T13:30:00+0900","value":171.0,"flags":""},{"recorded_at":"2017-08-15T14:00:00+0900","value":175.0,"flags":""},{"recorded_at":"2017-08-15T14:30:00+0900","value":159.0,"flags":""},{"recorded_at":"2017-08-15T15:00:00+0900","value":164.0,"flags":""},{"recorded_at":"2017-08-15T15:30:00+0900","value":169.0,"flags":""},{"recorded_at":"2017-08-15T16:00:00+0900","value":173.0,"flags":""},{"recorded_at":"2017-08-15T16:30:00+0900","value":168.0,"flags":""},{"recorded_at":"2017-08-15T17:00:00+0900","value":170.0,"flags":""},{"recorded_at":"2017-08-15T17:30:00+0900","value":164.0,"flags":""},{"recorded_at":"2017-08-15T18:00:00+0900","value":155.0,"flags":""},{"recorded_at":"2017-08-15T18:30:00+0900","value":133.0,"flags":""},{"recorded_at":"2017-08-15T19:00:00+0900","value":122.0,"flags":""},{"recorded_at":"2017-08-15T19:30:00+0900","value":100.0,"flags":""},{"recorded_at":"2017-08-15T20:00:00+0900","value":91.0,"flags":""},{"recorded_at":"2017-08-15T20:30:00+0900","value":92.0,"flags":""},{"recorded_at":"2017-08-15T21:00:00+0900","value":84.0,"flags":""},{"recorded_at":"2017-08-15T21:30:00+0900","value":72.0,"flags":""},{"recorded_at":"2017-08-15T22:00:00+0900","value":72.0,"flags":""},{"recorded_at":"2017-08-15T22:30:00+0900","value":71.0,"flags":""},{"recorded_at":"2017-08-15T23:00:00+0900","value":67.0,"flags":""},{"recorded_at":"2017-08-15T23:30:00+0900","value":69.0,"flags":""},{"recorded_at":"2017-08-16T00:00:00+0900","value":65.0,"flags":""},{"recorded_at":"2017-08-16T00:30:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-08-16T01:00:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-08-16T01:30:00+0900","value":53.0,"flags":""},{"recorded_at":"2017-08-16T02:00:00+0900","value":52.0,"flags":""},{"recorded_at":"2017-08-16T02:30:00+0900","value":53.0,"flags":""},{"recorded_at":"2017-08-16T03:00:00+0900","value":52.0,"flags":""},{"recorded_at":"2017-08-16T03:30:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-08-16T04:00:00+0900","value":52.0,"flags":""},{"recorded_at":"2017-08-16T04:30:00+0900","value":53.0,"flags":""},{"recorded_at":"2017-08-16T05:00:00+0900","value":52.0,"flags":""},{"recorded_at":"2017-08-16T05:30:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-08-16T06:00:00+0900","value":55.0,"flags":""},{"recorded_at":"2017-08-16T06:30:00+0900","value":71.0,"flags":""},{"recorded_at":"2017-08-16T07:00:00+0900","value":103.0,"flags":""},{"recorded_at":"2017-08-16T07:30:00+0900","value":95.0,"flags":""},{"recorded_at":"2017-08-16T08:00:00+0900","value":110.0,"flags":""},{"recorded_at":"2017-08-16T08:30:00+0900","value":139.0,"flags":""},{"recorded_at":"2017-08-16T09:00:00+0900","value":178.0,"flags":""},{"recorded_at":"2017-08-16T09:30:00+0900","value":194.0,"flags":""},{"recorded_at":"2017-08-16T10:00:00+0900","value":199.0,"flags":""},{"recorded_at":"2017-08-16T10:30:00+0900","value":210.0,"flags":""},{"recorded_at":"2017-08-16T11:00:00+0900","value":203.0,"flags":""},{"recorded_at":"2017-08-16T11:30:00+0900","value":194.0,"flags":""},{"recorded_at":"2017-08-16T12:00:00+0900","value":198.0,"flags":""},{"recorded_at":"2017-08-16T12:30:00+0900","value":200.0,"flags":""},{"recorded_at":"2017-08-16T13:00:00+0900","value":195.0,"flags":""},{"recorded_at":"2017-08-16T13:30:00+0900","value":201.0,"flags":""},{"recorded_at":"2017-08-16T14:00:00+0900","value":204.0,"flags":""},{"recorded_at":"2017-08-16T14:30:00+0900","value":199.0,"flags":""},{"recorded_at":"2017-08-16T15:00:00+0900","value":202.0,"flags":""},{"recorded_at":"2017-08-16T15:30:00+0900","value":210.0,"flags":""},{"recorded_at":"2017-08-16T16:00:00+0900","value":206.0,"flags":""},{"recorded_at":"2017-08-16T16:30:00+0900","value":202.0,"flags":""},{"recorded_at":"2017-08-16T17:00:00+0900","value":208.0,"flags":""},{"recorded_at":"2017-08-16T17:30:00+0900","value":211.0,"flags":""},{"recorded_at":"2017-08-16T18:00:00+0900","value":189.0,"flags":""},{"recorded_at":"2017-08-16T18:30:00+0900","value":161.0,"flags":""},{"recorded_at":"2017-08-16T19:00:00+0900","value":140.0,"flags":""},{"recorded_at":"2017-08-16T19:30:00+0900","value":116.0,"flags":""},{"recorded_at":"2017-08-16T20:00:00+0900","value":106.0,"flags":""},{"recorded_at":"2017-08-16T20:30:00+0900","value":96.0,"flags":""},{"recorded_at":"2017-08-16T21:00:00+0900","value":87.0,"flags":""},{"recorded_at":"2017-08-16T21:30:00+0900","value":74.0,"flags":""},{"recorded_at":"2017-08-16T22:00:00+0900","value":65.0,"flags":""},{"recorded_at":"2017-08-16T22:30:00+0900","value":58.0,"flags":""},{"recorded_at":"2017-08-16T23:00:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-08-16T23:30:00+0900","value":50.0,"flags":""},{"recorded_at":"2017-08-17T00:00:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-17T00:30:00+0900","value":52.0,"flags":""},{"recorded_at":"2017-08-17T01:00:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-17T01:30:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-08-17T02:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-17T02:30:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-17T03:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-17T03:30:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-08-17T04:00:00+0900","value":43.0,"flags":""},{"recorded_at":"2017-08-17T04:30:00+0900","value":43.0,"flags":""},{"recorded_at":"2017-08-17T05:00:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-08-17T05:30:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-17T06:00:00+0900","value":51.0,"flags":""},{"recorded_at":"2017-08-17T06:30:00+0900","value":69.0,"flags":""},{"recorded_at":"2017-08-17T07:00:00+0900","value":101.0,"flags":""},{"recorded_at":"2017-08-17T07:30:00+0900","value":98.0,"flags":""},{"recorded_at":"2017-08-17T08:00:00+0900","value":117.0,"flags":""},{"recorded_at":"2017-08-17T08:30:00+0900","value":160.0,"flags":""},{"recorded_at":"2017-08-17T09:00:00+0900","value":212.0,"flags":""},{"recorded_at":"2017-08-17T09:30:00+0900","value":216.0,"flags":""},{"recorded_at":"2017-08-17T10:00:00+0900","value":204.0,"flags":""},{"recorded_at":"2017-08-17T10:30:00+0900","value":204.0,"flags":""},{"recorded_at":"2017-08-17T11:00:00+0900","value":213.0,"flags":""},{"recorded_at":"2017-08-17T11:30:00+0900","value":213.0,"flags":""},{"recorded_at":"2017-08-17T12:00:00+0900","value":216.0,"flags":""},{"recorded_at":"2017-08-17T12:30:00+0900","value":206.0,"flags":""},{"recorded_at":"2017-08-17T13:00:00+0900","value":210.0,"flags":""},{"recorded_at":"2017-08-17T13:30:00+0900","value":217.0,"flags":""},{"recorded_at":"2017-08-17T14:00:00+0900","value":221.0,"flags":""},{"recorded_at":"2017-08-17T14:30:00+0900","value":213.0,"flags":""},{"recorded_at":"2017-08-17T15:00:00+0900","value":219.0,"flags":""},{"recorded_at":"2017-08-17T15:30:00+0900","value":225.0,"flags":""},{"recorded_at":"2017-08-17T16:00:00+0900","value":226.0,"flags":""},{"recorded_at":"2017-08-17T16:30:00+0900","value":223.0,"flags":""},{"recorded_at":"2017-08-17T17:00:00+0900","value":223.0,"flags":""},{"recorded_at":"2017-08-17T17:30:00+0900","value":215.0,"flags":""},{"recorded_at":"2017-08-17T18:00:00+0900","value":205.0,"flags":""},{"recorded_at":"2017-08-17T18:30:00+0900","value":189.0,"flags":""},{"recorded_at":"2017-08-17T19:00:00+0900","value":168.0,"flags":""},{"recorded_at":"2017-08-17T19:30:00+0900","value":141.0,"flags":""},{"recorded_at":"2017-08-17T20:00:00+0900","value":138.0,"flags":""},{"recorded_at":"2017-08-17T20:30:00+0900","value":133.0,"flags":""},{"recorded_at":"2017-08-17T21:00:00+0900","value":116.0,"flags":""},{"recorded_at":"2017-08-17T21:30:00+0900","value":108.0,"flags":""},{"recorded_at":"2017-08-17T22:00:00+0900","value":91.0,"flags":""},{"recorded_at":"2017-08-17T22:30:00+0900","value":82.0,"flags":""},{"recorded_at":"2017-08-17T23:00:00+0900","value":68.0,"flags":""},{"recorded_at":"2017-08-17T23:30:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-08-18T00:00:00+0900","value":55.0,"flags":""},{"recorded_at":"2017-08-18T00:30:00+0900","value":53.0,"flags":""},{"recorded_at":"2017-08-18T01:00:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-08-18T01:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-18T02:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-18T02:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-18T03:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-18T03:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-18T04:00:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-18T04:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-18T05:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-18T05:30:00+0900","value":49.0,"flags":""},{"recorded_at":"2017-08-18T06:00:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-08-18T06:30:00+0900","value":67.0,"flags":""},{"recorded_at":"2017-08-18T07:00:00+0900","value":103.0,"flags":""},{"recorded_at":"2017-08-18T07:30:00+0900","value":98.0,"flags":""},{"recorded_at":"2017-08-18T08:00:00+0900","value":127.0,"flags":""},{"recorded_at":"2017-08-18T08:30:00+0900","value":154.0,"flags":""},{"recorded_at":"2017-08-18T09:00:00+0900","value":208.0,"flags":""},{"recorded_at":"2017-08-18T09:30:00+0900","value":219.0,"flags":""},{"recorded_at":"2017-08-18T10:00:00+0900","value":224.0,"flags":""},{"recorded_at":"2017-08-18T10:30:00+0900","value":219.0,"flags":""},{"recorded_at":"2017-08-18T11:00:00+0900","value":217.0,"flags":""},{"recorded_at":"2017-08-18T11:30:00+0900","value":220.0,"flags":""},{"recorded_at":"2017-08-18T12:00:00+0900","value":232.0,"flags":""},{"recorded_at":"2017-08-18T12:30:00+0900","value":223.0,"flags":""},{"recorded_at":"2017-08-18T13:00:00+0900","value":212.0,"flags":""},{"recorded_at":"2017-08-18T13:30:00+0900","value":225.0,"flags":""},{"recorded_at":"2017-08-18T14:00:00+0900","value":218.0,"flags":""},{"recorded_at":"2017-08-18T14:30:00+0900","value":203.0,"flags":""},{"recorded_at":"2017-08-18T15:00:00+0900","value":209.0,"flags":""},{"recorded_at":"2017-08-18T15:30:00+0900","value":216.0,"flags":""},{"recorded_at":"2017-08-18T16:00:00+0900","value":228.0,"flags":""},{"recorded_at":"2017-08-18T16:30:00+0900","value":233.0,"flags":""},{"recorded_at":"2017-08-18T17:00:00+0900","value":225.0,"flags":""},{"recorded_at":"2017-08-18T17:30:00+0900","value":223.0,"flags":""},{"recorded_at":"2017-08-18T18:00:00+0900","value":212.0,"flags":""},{"recorded_at":"2017-08-18T18:30:00+0900","value":184.0,"flags":""},{"recorded_at":"2017-08-18T19:00:00+0900","value":165.0,"flags":""},{"recorded_at":"2017-08-18T19:30:00+0900","value":134.0,"flags":""},{"recorded_at":"2017-08-18T20:00:00+0900","value":127.0,"flags":""},{"recorded_at":"2017-08-18T20:30:00+0900","value":114.0,"flags":""},{"recorded_at":"2017-08-18T21:00:00+0900","value":98.0,"flags":""},{"recorded_at":"2017-08-18T21:30:00+0900","value":88.0,"flags":""},{"recorded_at":"2017-08-18T22:00:00+0900","value":82.0,"flags":""},{"recorded_at":"2017-08-18T22:30:00+0900","value":71.0,"flags":""},{"recorded_at":"2017-08-18T23:00:00+0900","value":59.0,"flags":""},{"recorded_at":"2017-08-18T23:30:00+0900","value":55.0,"flags":""},{"recorded_at":"2017-08-19T00:00:00+0900","value":43.0,"flags":""},{"recorded_at":"2017-08-19T00:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-19T01:00:00+0900","value":43.0,"flags":""},{"recorded_at":"2017-08-19T01:30:00+0900","value":42.0,"flags":""},{"recorded_at":"2017-08-19T02:00:00+0900","value":42.0,"flags":""},{"recorded_at":"2017-08-19T02:30:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-08-19T03:00:00+0900","value":43.0,"flags":""},{"recorded_at":"2017-08-19T03:30:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-19T04:00:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-08-19T04:30:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-19T05:00:00+0900","value":43.0,"flags":""},{"recorded_at":"2017-08-19T05:30:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-08-19T06:00:00+0900","value":50.0,"flags":""},{"recorded_at":"2017-08-19T06:30:00+0900","value":58.0,"flags":""},{"recorded_at":"2017-08-19T07:00:00+0900","value":60.0,"flags":""},{"recorded_at":"2017-08-19T07:30:00+0900","value":59.0,"flags":""},{"recorded_at":"2017-08-19T08:00:00+0900","value":63.0,"flags":""},{"recorded_at":"2017-08-19T08:30:00+0900","value":68.0,"flags":""},{"recorded_at":"2017-08-19T09:00:00+0900","value":72.0,"flags":""},{"recorded_at":"2017-08-19T09:30:00+0900","value":76.0,"flags":""},{"recorded_at":"2017-08-19T10:00:00+0900","value":81.0,"flags":""},{"recorded_at":"2017-08-19T10:30:00+0900","value":87.0,"flags":""},{"recorded_at":"2017-08-19T11:00:00+0900","value":87.0,"flags":""},{"recorded_at":"2017-08-19T11:30:00+0900","value":81.0,"flags":""},{"recorded_at":"2017-08-19T12:00:00+0900","value":87.0,"flags":""},{"recorded_at":"2017-08-19T12:30:00+0900","value":80.0,"flags":""},{"recorded_at":"2017-08-19T13:00:00+0900","value":84.0,"flags":""},{"recorded_at":"2017-08-19T13:30:00+0900","value":87.0,"flags":""},{"recorded_at":"2017-08-19T14:00:00+0900","value":85.0,"flags":""},{"recorded_at":"2017-08-19T14:30:00+0900","value":82.0,"flags":""},{"recorded_at":"2017-08-19T15:00:00+0900","value":80.0,"flags":""},{"recorded_at":"2017-08-19T15:30:00+0900","value":79.0,"flags":""},{"recorded_at":"2017-08-19T16:00:00+0900","value":82.0,"flags":""},{"recorded_at":"2017-08-19T16:30:00+0900","value":84.0,"flags":""},{"recorded_at":"2017-08-19T17:00:00+0900","value":76.0,"flags":""},{"recorded_at":"2017-08-19T17:30:00+0900","value":76.0,"flags":""},{"recorded_at":"2017-08-19T18:00:00+0900","value":70.0,"flags":""},{"recorded_at":"2017-08-19T18:30:00+0900","value":66.0,"flags":""},{"recorded_at":"2017-08-19T19:00:00+0900","value":63.0,"flags":""},{"recorded_at":"2017-08-19T19:30:00+0900","value":63.0,"flags":""},{"recorded_at":"2017-08-19T20:00:00+0900","value":64.0,"flags":""},{"recorded_at":"2017-08-19T20:30:00+0900","value":62.0,"flags":""},{"recorded_at":"2017-08-19T21:00:00+0900","value":60.0,"flags":""},{"recorded_at":"2017-08-19T21:30:00+0900","value":52.0,"flags":""},{"recorded_at":"2017-08-19T22:00:00+0900","value":52.0,"flags":""},{"recorded_at":"2017-08-19T22:30:00+0900","value":51.0,"flags":""},{"recorded_at":"2017-08-19T23:00:00+0900","value":49.0,"flags":""},{"recorded_at":"2017-08-19T23:30:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-20T00:00:00+0900","value":50.0,"flags":""},{"recorded_at":"2017-08-20T00:30:00+0900","value":53.0,"flags":""},{"recorded_at":"2017-08-20T01:00:00+0900","value":47.0,"flags":""},{"recorded_at":"2017-08-20T01:30:00+0900","value":43.0,"flags":""},{"recorded_at":"2017-08-20T02:00:00+0900","value":42.0,"flags":""},{"recorded_at":"2017-08-20T02:30:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-20T03:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-20T03:30:00+0900","value":50.0,"flags":""},{"recorded_at":"2017-08-20T04:00:00+0900","value":50.0,"flags":""},{"recorded_at":"2017-08-20T04:30:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-20T05:00:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-20T05:30:00+0900","value":43.0,"flags":""},{"recorded_at":"2017-08-20T06:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-20T06:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-20T07:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-20T07:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-20T08:00:00+0900","value":47.0,"flags":""},{"recorded_at":"2017-08-20T08:30:00+0900","value":52.0,"flags":""},{"recorded_at":"2017-08-20T09:00:00+0900","value":60.0,"flags":""},{"recorded_at":"2017-08-20T09:30:00+0900","value":63.0,"flags":""},{"recorded_at":"2017-08-20T10:00:00+0900","value":62.0,"flags":""},{"recorded_at":"2017-08-20T10:30:00+0900","value":61.0,"flags":""},{"recorded_at":"2017-08-20T11:00:00+0900","value":63.0,"flags":""},{"recorded_at":"2017-08-20T11:30:00+0900","value":63.0,"flags":""},{"recorded_at":"2017-08-20T12:00:00+0900","value":64.0,"flags":""},{"recorded_at":"2017-08-20T12:30:00+0900","value":64.0,"flags":""},{"recorded_at":"2017-08-20T13:00:00+0900","value":62.0,"flags":""},{"recorded_at":"2017-08-20T13:30:00+0900","value":65.0,"flags":""},{"recorded_at":"2017-08-20T14:00:00+0900","value":67.0,"flags":""},{"recorded_at":"2017-08-20T14:30:00+0900","value":74.0,"flags":""},{"recorded_at":"2017-08-20T15:00:00+0900","value":75.0,"flags":""},{"recorded_at":"2017-08-20T15:30:00+0900","value":75.0,"flags":""},{"recorded_at":"2017-08-20T16:00:00+0900","value":72.0,"flags":""},{"recorded_at":"2017-08-20T16:30:00+0900","value":72.0,"flags":""},{"recorded_at":"2017-08-20T17:00:00+0900","value":72.0,"flags":""},{"recorded_at":"2017-08-20T17:30:00+0900","value":67.0,"flags":""},{"recorded_at":"2017-08-20T18:00:00+0900","value":63.0,"flags":""},{"recorded_at":"2017-08-20T18:30:00+0900","value":63.0,"flags":""},{"recorded_at":"2017-08-20T19:00:00+0900","value":67.0,"flags":""},{"recorded_at":"2017-08-20T19:30:00+0900","value":69.0,"flags":""},{"recorded_at":"2017-08-20T20:00:00+0900","value":64.0,"flags":""},{"recorded_at":"2017-08-20T20:30:00+0900","value":62.0,"flags":""},{"recorded_at":"2017-08-20T21:00:00+0900","value":63.0,"flags":""},{"recorded_at":"2017-08-20T21:30:00+0900","value":64.0,"flags":""},{"recorded_at":"2017-08-20T22:00:00+0900","value":62.0,"flags":""},{"recorded_at":"2017-08-20T22:30:00+0900","value":62.0,"flags":""},{"recorded_at":"2017-08-20T23:00:00+0900","value":61.0,"flags":""},{"recorded_at":"2017-08-20T23:30:00+0900","value":63.0,"flags":""},{"recorded_at":"2017-08-21T00:00:00+0900","value":61.0,"flags":""},{"recorded_at":"2017-08-21T00:30:00+0900","value":62.0,"flags":""},{"recorded_at":"2017-08-21T01:00:00+0900","value":61.0,"flags":""},{"recorded_at":"2017-08-21T01:30:00+0900","value":60.0,"flags":""},{"recorded_at":"2017-08-21T02:00:00+0900","value":60.0,"flags":""},{"recorded_at":"2017-08-21T02:30:00+0900","value":62.0,"flags":""},{"recorded_at":"2017-08-21T03:00:00+0900","value":63.0,"flags":""},{"recorded_at":"2017-08-21T03:30:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-08-21T04:00:00+0900","value":55.0,"flags":""},{"recorded_at":"2017-08-21T04:30:00+0900","value":56.0,"flags":""},{"recorded_at":"2017-08-21T05:00:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-08-21T05:30:00+0900","value":55.0,"flags":""},{"recorded_at":"2017-08-21T06:00:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-08-21T06:30:00+0900","value":73.0,"flags":""},{"recorded_at":"2017-08-21T07:00:00+0900","value":141.0,"flags":""},{"recorded_at":"2017-08-21T07:30:00+0900","value":132.0,"flags":""},{"recorded_at":"2017-08-21T08:00:00+0900","value":158.0,"flags":""},{"recorded_at":"2017-08-21T08:30:00+0900","value":193.0,"flags":""},{"recorded_at":"2017-08-21T09:00:00+0900","value":250.0,"flags":""},{"recorded_at":"2017-08-21T09:30:00+0900","value":263.0,"flags":""},{"recorded_at":"2017-08-21T10:00:00+0900","value":276.0,"flags":""},{"recorded_at":"2017-08-21T10:30:00+0900","value":276.0,"flags":""},{"recorded_at":"2017-08-21T11:00:00+0900","value":261.0,"flags":""},{"recorded_at":"2017-08-21T11:30:00+0900","value":252.0,"flags":""},{"recorded_at":"2017-08-21T12:00:00+0900","value":251.0,"flags":""},{"recorded_at":"2017-08-21T12:30:00+0900","value":248.0,"flags":""},{"recorded_at":"2017-08-21T13:00:00+0900","value":232.0,"flags":""},{"recorded_at":"2017-08-21T13:30:00+0900","value":241.0,"flags":""},{"recorded_at":"2017-08-21T14:00:00+0900","value":240.0,"flags":""},{"recorded_at":"2017-08-21T14:30:00+0900","value":239.0,"flags":""},{"recorded_at":"2017-08-21T15:00:00+0900","value":235.0,"flags":""},{"recorded_at":"2017-08-21T15:30:00+0900","value":248.0,"flags":""},{"recorded_at":"2017-08-21T16:00:00+0900","value":247.0,"flags":""},{"recorded_at":"2017-08-21T16:30:00+0900","value":241.0,"flags":""},{"recorded_at":"2017-08-21T17:00:00+0900","value":236.0,"flags":""},{"recorded_at":"2017-08-21T17:30:00+0900","value":239.0,"flags":""},{"recorded_at":"2017-08-21T18:00:00+0900","value":231.0,"flags":""},{"recorded_at":"2017-08-21T18:30:00+0900","value":203.0,"flags":""},{"recorded_at":"2017-08-21T19:00:00+0900","value":193.0,"flags":""},{"recorded_at":"2017-08-21T19:30:00+0900","value":159.0,"flags":""},{"recorded_at":"2017-08-21T20:00:00+0900","value":145.0,"flags":""},{"recorded_at":"2017-08-21T20:30:00+0900","value":132.0,"flags":""},{"recorded_at":"2017-08-21T21:00:00+0900","value":111.0,"flags":""},{"recorded_at":"2017-08-21T21:30:00+0900","value":106.0,"flags":""},{"recorded_at":"2017-08-21T22:00:00+0900","value":91.0,"flags":""},{"recorded_at":"2017-08-21T22:30:00+0900","value":86.0,"flags":""},{"recorded_at":"2017-08-21T23:00:00+0900","value":72.0,"flags":""},{"recorded_at":"2017-08-21T23:30:00+0900","value":64.0,"flags":""},{"recorded_at":"2017-08-22T00:00:00+0900","value":61.0,"flags":""},{"recorded_at":"2017-08-22T00:30:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-08-22T01:00:00+0900","value":52.0,"flags":""},{"recorded_at":"2017-08-22T01:30:00+0900","value":48.0,"flags":""},{"recorded_at":"2017-08-22T02:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-22T02:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-22T03:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-22T03:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-22T04:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-22T04:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-22T05:00:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-22T05:30:00+0900","value":49.0,"flags":""},{"recorded_at":"2017-08-22T06:00:00+0900","value":55.0,"flags":""},{"recorded_at":"2017-08-22T06:30:00+0900","value":77.0,"flags":""},{"recorded_at":"2017-08-22T07:00:00+0900","value":121.0,"flags":""},{"recorded_at":"2017-08-22T07:30:00+0900","value":136.0,"flags":""},{"recorded_at":"2017-08-22T08:00:00+0900","value":156.0,"flags":""},{"recorded_at":"2017-08-22T08:30:00+0900","value":187.0,"flags":""},{"recorded_at":"2017-08-22T09:00:00+0900","value":236.0,"flags":""},{"recorded_at":"2017-08-22T09:30:00+0900","value":241.0,"flags":""},{"recorded_at":"2017-08-22T10:00:00+0900","value":249.0,"flags":""},{"recorded_at":"2017-08-22T10:30:00+0900","value":253.0,"flags":""},{"recorded_at":"2017-08-22T11:00:00+0900","value":252.0,"flags":""},{"recorded_at":"2017-08-22T11:30:00+0900","value":250.0,"flags":""},{"recorded_at":"2017-08-22T12:00:00+0900","value":245.0,"flags":""},{"recorded_at":"2017-08-22T12:30:00+0900","value":237.0,"flags":""},{"recorded_at":"2017-08-22T13:00:00+0900","value":231.0,"flags":""},{"recorded_at":"2017-08-22T13:30:00+0900","value":252.0,"flags":""},{"recorded_at":"2017-08-22T14:00:00+0900","value":250.0,"flags":""},{"recorded_at":"2017-08-22T14:30:00+0900","value":230.0,"flags":""},{"recorded_at":"2017-08-22T15:00:00+0900","value":251.0,"flags":""},{"recorded_at":"2017-08-22T15:30:00+0900","value":246.0,"flags":""},{"recorded_at":"2017-08-22T16:00:00+0900","value":253.0,"flags":""},{"recorded_at":"2017-08-22T16:30:00+0900","value":244.0,"flags":""},{"recorded_at":"2017-08-22T17:00:00+0900","value":224.0,"flags":""},{"recorded_at":"2017-08-22T17:30:00+0900","value":229.0,"flags":""},{"recorded_at":"2017-08-22T18:00:00+0900","value":226.0,"flags":""},{"recorded_at":"2017-08-22T18:30:00+0900","value":211.0,"flags":""},{"recorded_at":"2017-08-22T19:00:00+0900","value":188.0,"flags":""},{"recorded_at":"2017-08-22T19:30:00+0900","value":161.0,"flags":""},{"recorded_at":"2017-08-22T20:00:00+0900","value":157.0,"flags":""},{"recorded_at":"2017-08-22T20:30:00+0900","value":139.0,"flags":""},{"recorded_at":"2017-08-22T21:00:00+0900","value":128.0,"flags":""},{"recorded_at":"2017-08-22T21:30:00+0900","value":116.0,"flags":""},{"recorded_at":"2017-08-22T22:00:00+0900","value":102.0,"flags":""},{"recorded_at":"2017-08-22T22:30:00+0900","value":81.0,"flags":""},{"recorded_at":"2017-08-22T23:00:00+0900","value":68.0,"flags":""},{"recorded_at":"2017-08-22T23:30:00+0900","value":55.0,"flags":""},{"recorded_at":"2017-08-23T00:00:00+0900","value":56.0,"flags":""},{"recorded_at":"2017-08-23T00:30:00+0900","value":51.0,"flags":""},{"recorded_at":"2017-08-23T01:00:00+0900","value":48.0,"flags":""},{"recorded_at":"2017-08-23T01:30:00+0900","value":47.0,"flags":""},{"recorded_at":"2017-08-23T02:00:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-23T02:30:00+0900","value":51.0,"flags":""},{"recorded_at":"2017-08-23T03:00:00+0900","value":50.0,"flags":""},{"recorded_at":"2017-08-23T03:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-23T04:00:00+0900","value":47.0,"flags":""},{"recorded_at":"2017-08-23T04:30:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-23T05:00:00+0900","value":47.0,"flags":""},{"recorded_at":"2017-08-23T05:30:00+0900","value":47.0,"flags":""},{"recorded_at":"2017-08-23T06:00:00+0900","value":51.0,"flags":""},{"recorded_at":"2017-08-23T06:30:00+0900","value":67.0,"flags":""},{"recorded_at":"2017-08-23T07:00:00+0900","value":114.0,"flags":""},{"recorded_at":"2017-08-23T07:30:00+0900","value":118.0,"flags":""},{"recorded_at":"2017-08-23T08:00:00+0900","value":152.0,"flags":""},{"recorded_at":"2017-08-23T08:30:00+0900","value":193.0,"flags":""},{"recorded_at":"2017-08-23T09:00:00+0900","value":240.0,"flags":""},{"recorded_at":"2017-08-23T09:30:00+0900","value":256.0,"flags":""},{"recorded_at":"2017-08-23T10:00:00+0900","value":256.0,"flags":""},{"recorded_at":"2017-08-23T10:30:00+0900","value":263.0,"flags":""},{"recorded_at":"2017-08-23T11:00:00+0900","value":259.0,"flags":""},{"recorded_at":"2017-08-23T11:30:00+0900","value":258.0,"flags":""},{"recorded_at":"2017-08-23T12:00:00+0900","value":252.0,"flags":""},{"recorded_at":"2017-08-23T12:30:00+0900","value":249.0,"flags":""},{"recorded_at":"2017-08-23T13:00:00+0900","value":236.0,"flags":""},{"recorded_at":"2017-08-23T13:30:00+0900","value":254.0,"flags":""},{"recorded_at":"2017-08-23T14:00:00+0900","value":255.0,"flags":""},{"recorded_at":"2017-08-23T14:30:00+0900","value":245.0,"flags":""},{"recorded_at":"2017-08-23T15:00:00+0900","value":257.0,"flags":""},{"recorded_at":"2017-08-23T15:30:00+0900","value":258.0,"flags":""},{"recorded_at":"2017-08-23T16:00:00+0900","value":253.0,"flags":""},{"recorded_at":"2017-08-23T16:30:00+0900","value":258.0,"flags":""},{"recorded_at":"2017-08-23T17:00:00+0900","value":255.0,"flags":""},{"recorded_at":"2017-08-23T17:30:00+0900","value":247.0,"flags":""},{"recorded_at":"2017-08-23T18:00:00+0900","value":233.0,"flags":""},{"recorded_at":"2017-08-23T18:30:00+0900","value":188.0,"flags":""},{"recorded_at":"2017-08-23T19:00:00+0900","value":171.0,"flags":""},{"recorded_at":"2017-08-23T19:30:00+0900","value":133.0,"flags":""},{"recorded_at":"2017-08-23T20:00:00+0900","value":124.0,"flags":""},{"recorded_at":"2017-08-23T20:30:00+0900","value":116.0,"flags":""},{"recorded_at":"2017-08-23T21:00:00+0900","value":110.0,"flags":""},{"recorded_at":"2017-08-23T21:30:00+0900","value":105.0,"flags":""},{"recorded_at":"2017-08-23T22:00:00+0900","value":91.0,"flags":""},{"recorded_at":"2017-08-23T22:30:00+0900","value":78.0,"flags":""},{"recorded_at":"2017-08-23T23:00:00+0900","value":65.0,"flags":""},{"recorded_at":"2017-08-23T23:30:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-08-24T00:00:00+0900","value":48.0,"flags":""},{"recorded_at":"2017-08-24T00:30:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-24T01:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-24T01:30:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-24T02:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-24T02:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-24T03:00:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-24T03:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-24T04:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-24T04:30:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-24T05:00:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-24T05:30:00+0900","value":47.0,"flags":""},{"recorded_at":"2017-08-24T06:00:00+0900","value":53.0,"flags":""},{"recorded_at":"2017-08-24T06:30:00+0900","value":68.0,"flags":""},{"recorded_at":"2017-08-24T07:00:00+0900","value":119.0,"flags":""},{"recorded_at":"2017-08-24T07:30:00+0900","value":132.0,"flags":""},{"recorded_at":"2017-08-24T08:00:00+0900","value":143.0,"flags":""},{"recorded_at":"2017-08-24T08:30:00+0900","value":188.0,"flags":""},{"recorded_at":"2017-08-24T09:00:00+0900","value":228.0,"flags":""},{"recorded_at":"2017-08-24T09:30:00+0900","value":250.0,"flags":""},{"recorded_at":"2017-08-24T10:00:00+0900","value":258.0,"flags":""},{"recorded_at":"2017-08-24T10:30:00+0900","value":268.0,"flags":""},{"recorded_at":"2017-08-24T11:00:00+0900","value":255.0,"flags":""},{"recorded_at":"2017-08-24T11:30:00+0900","value":250.0,"flags":""},{"recorded_at":"2017-08-24T12:00:00+0900","value":246.0,"flags":""},{"recorded_at":"2017-08-24T12:30:00+0900","value":247.0,"flags":""},{"recorded_at":"2017-08-24T13:00:00+0900","value":226.0,"flags":""},{"recorded_at":"2017-08-24T13:30:00+0900","value":241.0,"flags":""},{"recorded_at":"2017-08-24T14:00:00+0900","value":246.0,"flags":""},{"recorded_at":"2017-08-24T14:30:00+0900","value":240.0,"flags":""},{"recorded_at":"2017-08-24T15:00:00+0900","value":250.0,"flags":""},{"recorded_at":"2017-08-24T15:30:00+0900","value":264.0,"flags":""},{"recorded_at":"2017-08-24T16:00:00+0900","value":262.0,"flags":""},{"recorded_at":"2017-08-24T16:30:00+0900","value":254.0,"flags":""},{"recorded_at":"2017-08-24T17:00:00+0900","value":251.0,"flags":""},{"recorded_at":"2017-08-24T17:30:00+0900","value":267.0,"flags":""},{"recorded_at":"2017-08-24T18:00:00+0900","value":243.0,"flags":""},{"recorded_at":"2017-08-24T18:30:00+0900","value":221.0,"flags":""},{"recorded_at":"2017-08-24T19:00:00+0900","value":197.0,"flags":""},{"recorded_at":"2017-08-24T19:30:00+0900","value":163.0,"flags":""},{"recorded_at":"2017-08-24T20:00:00+0900","value":155.0,"flags":""},{"recorded_at":"2017-08-24T20:30:00+0900","value":137.0,"flags":""},{"recorded_at":"2017-08-24T21:00:00+0900","value":123.0,"flags":""},{"recorded_at":"2017-08-24T21:30:00+0900","value":113.0,"flags":""},{"recorded_at":"2017-08-24T22:00:00+0900","value":102.0,"flags":""},{"recorded_at":"2017-08-24T22:30:00+0900","value":79.0,"flags":""},{"recorded_at":"2017-08-24T23:00:00+0900","value":68.0,"flags":""},{"recorded_at":"2017-08-24T23:30:00+0900","value":68.0,"flags":""},{"recorded_at":"2017-08-25T00:00:00+0900","value":58.0,"flags":""},{"recorded_at":"2017-08-25T00:30:00+0900","value":43.0,"flags":""},{"recorded_at":"2017-08-25T01:00:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-08-25T01:30:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-25T02:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-25T02:30:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-08-25T03:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-25T03:30:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-25T04:00:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-25T04:30:00+0900","value":48.0,"flags":""},{"recorded_at":"2017-08-25T05:00:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-08-25T05:30:00+0900","value":47.0,"flags":""},{"recorded_at":"2017-08-25T06:00:00+0900","value":52.0,"flags":""},{"recorded_at":"2017-08-25T06:30:00+0900","value":65.0,"flags":""},{"recorded_at":"2017-08-25T07:00:00+0900","value":118.0,"flags":""},{"recorded_at":"2017-08-25T07:30:00+0900","value":119.0,"flags":""},{"recorded_at":"2017-08-25T08:00:00+0900","value":127.0,"flags":""},{"recorded_at":"2017-08-25T08:30:00+0900","value":158.0,"flags":""},{"recorded_at":"2017-08-25T09:00:00+0900","value":226.0,"flags":""},{"recorded_at":"2017-08-25T09:30:00+0900","value":241.0,"flags":""},{"recorded_at":"2017-08-25T10:00:00+0900","value":239.0,"flags":""},{"recorded_at":"2017-08-25T10:30:00+0900","value":255.0,"flags":""},{"recorded_at":"2017-08-25T11:00:00+0900","value":253.0,"flags":""},{"recorded_at":"2017-08-25T11:30:00+0900","value":243.0,"flags":""},{"recorded_at":"2017-08-25T12:00:00+0900","value":232.0,"flags":""},{"recorded_at":"2017-08-25T12:30:00+0900","value":232.0,"flags":""},{"recorded_at":"2017-08-25T13:00:00+0900","value":223.0,"flags":""},{"recorded_at":"2017-08-25T13:30:00+0900","value":230.0,"flags":""},{"recorded_at":"2017-08-25T14:00:00+0900","value":237.0,"flags":""},{"recorded_at":"2017-08-25T14:30:00+0900","value":237.0,"flags":""},{"recorded_at":"2017-08-25T15:00:00+0900","value":235.0,"flags":""},{"recorded_at":"2017-08-25T15:30:00+0900","value":239.0,"flags":""},{"recorded_at":"2017-08-25T16:00:00+0900","value":240.0,"flags":""},{"recorded_at":"2017-08-25T16:30:00+0900","value":237.0,"flags":""},{"recorded_at":"2017-08-25T17:00:00+0900","value":240.0,"flags":""},{"recorded_at":"2017-08-25T17:30:00+0900","value":238.0,"flags":""},{"recorded_at":"2017-08-25T18:00:00+0900","value":220.0,"flags":""},{"recorded_at":"2017-08-25T18:30:00+0900","value":189.0,"flags":""},{"recorded_at":"2017-08-25T19:00:00+0900","value":170.0,"flags":""},{"recorded_at":"2017-08-25T19:30:00+0900","value":130.0,"flags":""},{"recorded_at":"2017-08-25T20:00:00+0900","value":117.0,"flags":""},{"recorded_at":"2017-08-25T20:30:00+0900","value":104.0,"flags":""},{"recorded_at":"2017-08-25T21:00:00+0900","value":93.0,"flags":""},{"recorded_at":"2017-08-25T21:30:00+0900","value":91.0,"flags":""},{"recorded_at":"2017-08-25T22:00:00+0900","value":85.0,"flags":""},{"recorded_at":"2017-08-25T22:30:00+0900","value":81.0,"flags":""},{"recorded_at":"2017-08-25T23:00:00+0900","value":78.0,"flags":""},{"recorded_at":"2017-08-25T23:30:00+0900","value":61.0,"flags":""},{"recorded_at":"2017-08-26T00:00:00+0900","value":51.0,"flags":""},{"recorded_at":"2017-08-26T00:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-26T01:00:00+0900","value":48.0,"flags":""},{"recorded_at":"2017-08-26T01:30:00+0900","value":53.0,"flags":""},{"recorded_at":"2017-08-26T02:00:00+0900","value":53.0,"flags":""},{"recorded_at":"2017-08-26T02:30:00+0900","value":53.0,"flags":""},{"recorded_at":"2017-08-26T03:00:00+0900","value":61.0,"flags":""},{"recorded_at":"2017-08-26T03:30:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-08-26T04:00:00+0900","value":56.0,"flags":""},{"recorded_at":"2017-08-26T04:30:00+0900","value":55.0,"flags":""},{"recorded_at":"2017-08-26T05:00:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-08-26T05:30:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-08-26T06:00:00+0900","value":55.0,"flags":""},{"recorded_at":"2017-08-26T06:30:00+0900","value":64.0,"flags":""},{"recorded_at":"2017-08-26T07:00:00+0900","value":68.0,"flags":""},{"recorded_at":"2017-08-26T07:30:00+0900","value":67.0,"flags":""},{"recorded_at":"2017-08-26T08:00:00+0900","value":65.0,"flags":""},{"recorded_at":"2017-08-26T08:30:00+0900","value":62.0,"flags":""},{"recorded_at":"2017-08-26T09:00:00+0900","value":61.0,"flags":""},{"recorded_at":"2017-08-26T09:30:00+0900","value":72.0,"flags":""},{"recorded_at":"2017-08-26T10:00:00+0900","value":72.0,"flags":""},{"recorded_at":"2017-08-26T10:30:00+0900","value":71.0,"flags":""},{"recorded_at":"2017-08-26T11:00:00+0900","value":70.0,"flags":""},{"recorded_at":"2017-08-26T11:30:00+0900","value":71.0,"flags":""},{"recorded_at":"2017-08-26T12:00:00+0900","value":73.0,"flags":""},{"recorded_at":"2017-08-26T12:30:00+0900","value":76.0,"flags":""},{"recorded_at":"2017-08-26T13:00:00+0900","value":79.0,"flags":""},{"recorded_at":"2017-08-26T13:30:00+0900","value":85.0,"flags":""},{"recorded_at":"2017-08-26T14:00:00+0900","value":76.0,"flags":""},{"recorded_at":"2017-08-26T14:30:00+0900","value":75.0,"flags":""},{"recorded_at":"2017-08-26T15:00:00+0900","value":73.0,"flags":""},{"recorded_at":"2017-08-26T15:30:00+0900","value":76.0,"flags":""},{"recorded_at":"2017-08-26T16:00:00+0900","value":73.0,"flags":""},{"recorded_at":"2017-08-26T16:30:00+0900","value":79.0,"flags":""},{"recorded_at":"2017-08-26T17:00:00+0900","value":76.0,"flags":""},{"recorded_at":"2017-08-26T17:30:00+0900","value":74.0,"flags":""},{"recorded_at":"2017-08-26T18:00:00+0900","value":73.0,"flags":""},{"recorded_at":"2017-08-26T18:30:00+0900","value":72.0,"flags":""},{"recorded_at":"2017-08-26T19:00:00+0900","value":72.0,"flags":""},{"recorded_at":"2017-08-26T19:30:00+0900","value":69.0,"flags":""},{"recorded_at":"2017-08-26T20:00:00+0900","value":66.0,"flags":""},{"recorded_at":"2017-08-26T20:30:00+0900","value":64.0,"flags":""},{"recorded_at":"2017-08-26T21:00:00+0900","value":58.0,"flags":""},{"recorded_at":"2017-08-26T21:30:00+0900","value":47.0,"flags":""},{"recorded_at":"2017-08-26T22:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-26T22:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-26T23:00:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-08-26T23:30:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-27T00:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-27T00:30:00+0900","value":48.0,"flags":""},{"recorded_at":"2017-08-27T01:00:00+0900","value":50.0,"flags":""},{"recorded_at":"2017-08-27T01:30:00+0900","value":47.0,"flags":""},{"recorded_at":"2017-08-27T02:00:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-27T02:30:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-27T03:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-27T03:30:00+0900","value":47.0,"flags":""},{"recorded_at":"2017-08-27T04:00:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-27T04:30:00+0900","value":47.0,"flags":""},{"recorded_at":"2017-08-27T05:00:00+0900","value":47.0,"flags":""},{"recorded_at":"2017-08-27T05:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-27T06:00:00+0900","value":48.0,"flags":""},{"recorded_at":"2017-08-27T06:30:00+0900","value":47.0,"flags":""},{"recorded_at":"2017-08-27T07:00:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-08-27T07:30:00+0900","value":53.0,"flags":""},{"recorded_at":"2017-08-27T08:00:00+0900","value":53.0,"flags":""},{"recorded_at":"2017-08-27T08:30:00+0900","value":55.0,"flags":""},{"recorded_at":"2017-08-27T09:00:00+0900","value":58.0,"flags":""},{"recorded_at":"2017-08-27T09:30:00+0900","value":62.0,"flags":""},{"recorded_at":"2017-08-27T10:00:00+0900","value":67.0,"flags":""},{"recorded_at":"2017-08-27T10:30:00+0900","value":68.0,"flags":""},{"recorded_at":"2017-08-27T11:00:00+0900","value":68.0,"flags":""},{"recorded_at":"2017-08-27T11:30:00+0900","value":67.0,"flags":""},{"recorded_at":"2017-08-27T12:00:00+0900","value":66.0,"flags":""},{"recorded_at":"2017-08-27T12:30:00+0900","value":67.0,"flags":""},{"recorded_at":"2017-08-27T13:00:00+0900","value":66.0,"flags":""},{"recorded_at":"2017-08-27T13:30:00+0900","value":70.0,"flags":""},{"recorded_at":"2017-08-27T14:00:00+0900","value":67.0,"flags":""},{"recorded_at":"2017-08-27T14:30:00+0900","value":69.0,"flags":""},{"recorded_at":"2017-08-27T15:00:00+0900","value":71.0,"flags":""},{"recorded_at":"2017-08-27T15:30:00+0900","value":75.0,"flags":""},{"recorded_at":"2017-08-27T16:00:00+0900","value":74.0,"flags":""},{"recorded_at":"2017-08-27T16:30:00+0900","value":77.0,"flags":""},{"recorded_at":"2017-08-27T17:00:00+0900","value":76.0,"flags":""},{"recorded_at":"2017-08-27T17:30:00+0900","value":76.0,"flags":""},{"recorded_at":"2017-08-27T18:00:00+0900","value":78.0,"flags":""},{"recorded_at":"2017-08-27T18:30:00+0900","value":72.0,"flags":""},{"recorded_at":"2017-08-27T19:00:00+0900","value":65.0,"flags":""},{"recorded_at":"2017-08-27T19:30:00+0900","value":62.0,"flags":""},{"recorded_at":"2017-08-27T20:00:00+0900","value":61.0,"flags":""},{"recorded_at":"2017-08-27T20:30:00+0900","value":59.0,"flags":""},{"recorded_at":"2017-08-27T21:00:00+0900","value":59.0,"flags":""},{"recorded_at":"2017-08-27T21:30:00+0900","value":53.0,"flags":""},{"recorded_at":"2017-08-27T22:00:00+0900","value":50.0,"flags":""},{"recorded_at":"2017-08-27T22:30:00+0900","value":50.0,"flags":""},{"recorded_at":"2017-08-27T23:00:00+0900","value":50.0,"flags":""},{"recorded_at":"2017-08-27T23:30:00+0900","value":52.0,"flags":""},{"recorded_at":"2017-08-28T00:00:00+0900","value":50.0,"flags":""},{"recorded_at":"2017-08-28T00:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-28T01:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-28T01:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-28T02:00:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-28T02:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-28T03:00:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-28T03:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-28T04:00:00+0900","value":48.0,"flags":""},{"recorded_at":"2017-08-28T04:30:00+0900","value":48.0,"flags":""},{"recorded_at":"2017-08-28T05:00:00+0900","value":49.0,"flags":""},{"recorded_at":"2017-08-28T05:30:00+0900","value":51.0,"flags":""},{"recorded_at":"2017-08-28T06:00:00+0900","value":58.0,"flags":""},{"recorded_at":"2017-08-28T06:30:00+0900","value":70.0,"flags":""},{"recorded_at":"2017-08-28T07:00:00+0900","value":133.0,"flags":""},{"recorded_at":"2017-08-28T07:30:00+0900","value":122.0,"flags":""},{"recorded_at":"2017-08-28T08:00:00+0900","value":143.0,"flags":""},{"recorded_at":"2017-08-28T08:30:00+0900","value":171.0,"flags":""},{"recorded_at":"2017-08-28T09:00:00+0900","value":222.0,"flags":""},{"recorded_at":"2017-08-28T09:30:00+0900","value":238.0,"flags":""},{"recorded_at":"2017-08-28T10:00:00+0900","value":233.0,"flags":""},{"recorded_at":"2017-08-28T10:30:00+0900","value":236.0,"flags":""},{"recorded_at":"2017-08-28T11:00:00+0900","value":235.0,"flags":""},{"recorded_at":"2017-08-28T11:30:00+0900","value":237.0,"flags":""},{"recorded_at":"2017-08-28T12:00:00+0900","value":224.0,"flags":""},{"recorded_at":"2017-08-28T12:30:00+0900","value":221.0,"flags":""},{"recorded_at":"2017-08-28T13:00:00+0900","value":216.0,"flags":""},{"recorded_at":"2017-08-28T13:30:00+0900","value":228.0,"flags":""},{"recorded_at":"2017-08-28T14:00:00+0900","value":220.0,"flags":""},{"recorded_at":"2017-08-28T14:30:00+0900","value":206.0,"flags":""},{"recorded_at":"2017-08-28T15:00:00+0900","value":213.0,"flags":""},{"recorded_at":"2017-08-28T15:30:00+0900","value":215.0,"flags":""},{"recorded_at":"2017-08-28T16:00:00+0900","value":223.0,"flags":""},{"recorded_at":"2017-08-28T16:30:00+0900","value":218.0,"flags":""},{"recorded_at":"2017-08-28T17:00:00+0900","value":220.0,"flags":""},{"recorded_at":"2017-08-28T17:30:00+0900","value":217.0,"flags":""},{"recorded_at":"2017-08-28T18:00:00+0900","value":209.0,"flags":""},{"recorded_at":"2017-08-28T18:30:00+0900","value":179.0,"flags":""},{"recorded_at":"2017-08-28T19:00:00+0900","value":168.0,"flags":""},{"recorded_at":"2017-08-28T19:30:00+0900","value":132.0,"flags":""},{"recorded_at":"2017-08-28T20:00:00+0900","value":127.0,"flags":""},{"recorded_at":"2017-08-28T20:30:00+0900","value":119.0,"flags":""},{"recorded_at":"2017-08-28T21:00:00+0900","value":106.0,"flags":""},{"recorded_at":"2017-08-28T21:30:00+0900","value":97.0,"flags":""},{"recorded_at":"2017-08-28T22:00:00+0900","value":96.0,"flags":""},{"recorded_at":"2017-08-28T22:30:00+0900","value":88.0,"flags":""},{"recorded_at":"2017-08-28T23:00:00+0900","value":75.0,"flags":""},{"recorded_at":"2017-08-28T23:30:00+0900","value":67.0,"flags":""},{"recorded_at":"2017-08-29T00:00:00+0900","value":61.0,"flags":""},{"recorded_at":"2017-08-29T00:30:00+0900","value":55.0,"flags":""},{"recorded_at":"2017-08-29T01:00:00+0900","value":54.0,"flags":""},{"recorded_at":"2017-08-29T01:30:00+0900","value":55.0,"flags":""},{"recorded_at":"2017-08-29T02:00:00+0900","value":55.0,"flags":""},{"recorded_at":"2017-08-29T02:30:00+0900","value":55.0,"flags":""},{"recorded_at":"2017-08-29T03:00:00+0900","value":56.0,"flags":""},{"recorded_at":"2017-08-29T03:30:00+0900","value":55.0,"flags":""},{"recorded_at":"2017-08-29T04:00:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-29T04:30:00+0900","value":47.0,"flags":""},{"recorded_at":"2017-08-29T05:00:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-29T05:30:00+0900","value":49.0,"flags":""},{"recorded_at":"2017-08-29T06:00:00+0900","value":55.0,"flags":""},{"recorded_at":"2017-08-29T06:30:00+0900","value":67.0,"flags":""},{"recorded_at":"2017-08-29T07:00:00+0900","value":114.0,"flags":""},{"recorded_at":"2017-08-29T07:30:00+0900","value":114.0,"flags":""},{"recorded_at":"2017-08-29T08:00:00+0900","value":142.0,"flags":""},{"recorded_at":"2017-08-29T08:30:00+0900","value":173.0,"flags":""},{"recorded_at":"2017-08-29T09:00:00+0900","value":218.0,"flags":""},{"recorded_at":"2017-08-29T09:30:00+0900","value":235.0,"flags":""},{"recorded_at":"2017-08-29T10:00:00+0900","value":231.0,"flags":""},{"recorded_at":"2017-08-29T10:30:00+0900","value":229.0,"flags":""},{"recorded_at":"2017-08-29T11:00:00+0900","value":239.0,"flags":""},{"recorded_at":"2017-08-29T11:30:00+0900","value":231.0,"flags":""},{"recorded_at":"2017-08-29T12:00:00+0900","value":226.0,"flags":""},{"recorded_at":"2017-08-29T12:30:00+0900","value":224.0,"flags":""},{"recorded_at":"2017-08-29T13:00:00+0900","value":227.0,"flags":""},{"recorded_at":"2017-08-29T13:30:00+0900","value":230.0,"flags":""},{"recorded_at":"2017-08-29T14:00:00+0900","value":227.0,"flags":""},{"recorded_at":"2017-08-29T14:30:00+0900","value":228.0,"flags":""},{"recorded_at":"2017-08-29T15:00:00+0900","value":239.0,"flags":""},{"recorded_at":"2017-08-29T15:30:00+0900","value":233.0,"flags":""},{"recorded_at":"2017-08-29T16:00:00+0900","value":230.0,"flags":""},{"recorded_at":"2017-08-29T16:30:00+0900","value":226.0,"flags":""},{"recorded_at":"2017-08-29T17:00:00+0900","value":221.0,"flags":""},{"recorded_at":"2017-08-29T17:30:00+0900","value":225.0,"flags":""},{"recorded_at":"2017-08-29T18:00:00+0900","value":219.0,"flags":""},{"recorded_at":"2017-08-29T18:30:00+0900","value":194.0,"flags":""},{"recorded_at":"2017-08-29T19:00:00+0900","value":174.0,"flags":""},{"recorded_at":"2017-08-29T19:30:00+0900","value":150.0,"flags":""},{"recorded_at":"2017-08-29T20:00:00+0900","value":149.0,"flags":""},{"recorded_at":"2017-08-29T20:30:00+0900","value":147.0,"flags":""},{"recorded_at":"2017-08-29T21:00:00+0900","value":137.0,"flags":""},{"recorded_at":"2017-08-29T21:30:00+0900","value":127.0,"flags":""},{"recorded_at":"2017-08-29T22:00:00+0900","value":116.0,"flags":""},{"recorded_at":"2017-08-29T22:30:00+0900","value":101.0,"flags":""},{"recorded_at":"2017-08-29T23:00:00+0900","value":82.0,"flags":""},{"recorded_at":"2017-08-29T23:30:00+0900","value":65.0,"flags":""},{"recorded_at":"2017-08-30T00:00:00+0900","value":59.0,"flags":""},{"recorded_at":"2017-08-30T00:30:00+0900","value":58.0,"flags":""},{"recorded_at":"2017-08-30T01:00:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-08-30T01:30:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-08-30T02:00:00+0900","value":56.0,"flags":""},{"recorded_at":"2017-08-30T02:30:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-30T03:00:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-30T03:30:00+0900","value":47.0,"flags":""},{"recorded_at":"2017-08-30T04:00:00+0900","value":48.0,"flags":""},{"recorded_at":"2017-08-30T04:30:00+0900","value":47.0,"flags":""},{"recorded_at":"2017-08-30T05:00:00+0900","value":47.0,"flags":""},{"recorded_at":"2017-08-30T05:30:00+0900","value":51.0,"flags":""},{"recorded_at":"2017-08-30T06:00:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-08-30T06:30:00+0900","value":69.0,"flags":""},{"recorded_at":"2017-08-30T07:00:00+0900","value":113.0,"flags":""},{"recorded_at":"2017-08-30T07:30:00+0900","value":107.0,"flags":""},{"recorded_at":"2017-08-30T08:00:00+0900","value":121.0,"flags":""},{"recorded_at":"2017-08-30T08:30:00+0900","value":160.0,"flags":""},{"recorded_at":"2017-08-30T09:00:00+0900","value":210.0,"flags":""},{"recorded_at":"2017-08-30T09:30:00+0900","value":217.0,"flags":""},{"recorded_at":"2017-08-30T10:00:00+0900","value":219.0,"flags":""},{"recorded_at":"2017-08-30T10:30:00+0900","value":223.0,"flags":""},{"recorded_at":"2017-08-30T11:00:00+0900","value":214.0,"flags":""},{"recorded_at":"2017-08-30T11:30:00+0900","value":219.0,"flags":""},{"recorded_at":"2017-08-30T12:00:00+0900","value":220.0,"flags":""},{"recorded_at":"2017-08-30T12:30:00+0900","value":210.0,"flags":""},{"recorded_at":"2017-08-30T13:00:00+0900","value":202.0,"flags":""},{"recorded_at":"2017-08-30T13:30:00+0900","value":216.0,"flags":""},{"recorded_at":"2017-08-30T14:00:00+0900","value":212.0,"flags":""},{"recorded_at":"2017-08-30T14:30:00+0900","value":215.0,"flags":""},{"recorded_at":"2017-08-30T15:00:00+0900","value":217.0,"flags":""},{"recorded_at":"2017-08-30T15:30:00+0900","value":220.0,"flags":""},{"recorded_at":"2017-08-30T16:00:00+0900","value":218.0,"flags":""},{"recorded_at":"2017-08-30T16:30:00+0900","value":208.0,"flags":""},{"recorded_at":"2017-08-30T17:00:00+0900","value":198.0,"flags":""},{"recorded_at":"2017-08-30T17:30:00+0900","value":209.0,"flags":""},{"recorded_at":"2017-08-30T18:00:00+0900","value":199.0,"flags":""},{"recorded_at":"2017-08-30T18:30:00+0900","value":165.0,"flags":""},{"recorded_at":"2017-08-30T19:00:00+0900","value":142.0,"flags":""},{"recorded_at":"2017-08-30T19:30:00+0900","value":119.0,"flags":""},{"recorded_at":"2017-08-30T20:00:00+0900","value":113.0,"flags":""},{"recorded_at":"2017-08-30T20:30:00+0900","value":104.0,"flags":""},{"recorded_at":"2017-08-30T21:00:00+0900","value":100.0,"flags":""},{"recorded_at":"2017-08-30T21:30:00+0900","value":91.0,"flags":""},{"recorded_at":"2017-08-30T22:00:00+0900","value":85.0,"flags":""},{"recorded_at":"2017-08-30T22:30:00+0900","value":74.0,"flags":""},{"recorded_at":"2017-08-30T23:00:00+0900","value":65.0,"flags":""},{"recorded_at":"2017-08-30T23:30:00+0900","value":57.0,"flags":""},{"recorded_at":"2017-08-31T00:00:00+0900","value":49.0,"flags":""},{"recorded_at":"2017-08-31T00:30:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-08-31T01:00:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-08-31T01:30:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-08-31T02:00:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-08-31T02:30:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-08-31T03:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-31T03:30:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-31T04:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-31T04:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-31T05:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-08-31T05:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-08-31T06:00:00+0900","value":51.0,"flags":""},{"recorded_at":"2017-08-31T06:30:00+0900","value":66.0,"flags":""},{"recorded_at":"2017-08-31T07:00:00+0900","value":96.0,"flags":""},{"recorded_at":"2017-08-31T07:30:00+0900","value":93.0,"flags":""},{"recorded_at":"2017-08-31T08:00:00+0900","value":115.0,"flags":""},{"recorded_at":"2017-08-31T08:30:00+0900","value":148.0,"flags":""},{"recorded_at":"2017-08-31T09:00:00+0900","value":187.0,"flags":""},{"recorded_at":"2017-08-31T09:30:00+0900","value":191.0,"flags":""},{"recorded_at":"2017-08-31T10:00:00+0900","value":190.0,"flags":""},{"recorded_at":"2017-08-31T10:30:00+0900","value":205.0,"flags":""},{"recorded_at":"2017-08-31T11:00:00+0900","value":210.0,"flags":""},{"recorded_at":"2017-08-31T11:30:00+0900","value":201.0,"flags":""},{"recorded_at":"2017-08-31T12:00:00+0900","value":200.0,"flags":""},{"recorded_at":"2017-08-31T12:30:00+0900","value":200.0,"flags":""},{"recorded_at":"2017-08-31T13:00:00+0900","value":185.0,"flags":""},{"recorded_at":"2017-08-31T13:30:00+0900","value":199.0,"flags":""},{"recorded_at":"2017-08-31T14:00:00+0900","value":202.0,"flags":""},{"recorded_at":"2017-08-31T14:30:00+0900","value":199.0,"flags":""},{"recorded_at":"2017-08-31T15:00:00+0900","value":196.0,"flags":""},{"recorded_at":"2017-08-31T15:30:00+0900","value":202.0,"flags":""},{"recorded_at":"2017-08-31T16:00:00+0900","value":203.0,"flags":""},{"recorded_at":"2017-08-31T16:30:00+0900","value":196.0,"flags":""},{"recorded_at":"2017-08-31T17:00:00+0900","value":199.0,"flags":""},{"recorded_at":"2017-08-31T17:30:00+0900","value":199.0,"flags":""},{"recorded_at":"2017-08-31T18:00:00+0900","value":191.0,"flags":""},{"recorded_at":"2017-08-31T18:30:00+0900","value":162.0,"flags":""},{"recorded_at":"2017-08-31T19:00:00+0900","value":146.0,"flags":""},{"recorded_at":"2017-08-31T19:30:00+0900","value":129.0,"flags":""},{"recorded_at":"2017-08-31T20:00:00+0900","value":123.0,"flags":""},{"recorded_at":"2017-08-31T20:30:00+0900","value":121.0,"flags":""},{"recorded_at":"2017-08-31T21:00:00+0900","value":110.0,"flags":""},{"recorded_at":"2017-08-31T21:30:00+0900","value":103.0,"flags":""},{"recorded_at":"2017-08-31T22:00:00+0900","value":89.0,"flags":""},{"recorded_at":"2017-08-31T22:30:00+0900","value":76.0,"flags":""},{"recorded_at":"2017-08-31T23:00:00+0900","value":68.0,"flags":""},{"recorded_at":"2017-08-31T23:30:00+0900","value":62.0,"flags":""},{"recorded_at":"2017-09-01T00:00:00+0900","value":49.0,"flags":""},{"recorded_at":"2017-09-01T00:30:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-09-01T01:00:00+0900","value":44.0,"flags":""},{"recorded_at":"2017-09-01T01:30:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-09-01T02:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-09-01T02:30:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-09-01T03:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-09-01T03:30:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-09-01T04:00:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-09-01T04:30:00+0900","value":45.0,"flags":""},{"recorded_at":"2017-09-01T05:00:00+0900","value":46.0,"flags":""},{"recorded_at":"2017-09-01T05:30:00+0900","value":48.0,"flags":""},{"recorded_at":"2017-09-01T06:00:00+0900","value":56.0,"flags":""},{"recorded_at":"2017-09-01T06:30:00+0900","value":67.0,"flags":""},{"recorded_at":"2017-09-01T07:00:00+0900","value":93.0,"flags":""},{"recorded_at":"2017-09-01T07:30:00+0900","value":86.0,"flags":""},{"recorded_at":"2017-09-01T08:00:00+0900","value":106.0,"flags":""},{"recorded_at":"2017-09-01T08:30:00+0900","value":138.0,"flags":""},{"recorded_at":"2017-09-01T09:00:00+0900","value":179.0,"flags":""},{"recorded_at":"2017-09-01T09:30:00+0900","value":186.0,"flags":""},{"recorded_at":"2017-09-01T10:00:00+0900","value":190.0,"flags":""},{"recorded_at":"2017-09-01T10:30:00+0900","value":196.0,"flags":""},{"recorded_at":"2017-09-01T11:00:00+0900","value":199.0,"flags":""},{"recorded_at":"2017-09-01T11:30:00+0900","value":197.0,"flags":""},{"recorded_at":"2017-09-01T12:00:00+0900","value":191.0,"flags":""},{"recorded_at":"2017-09-01T12:30:00+0900","value":195.0,"flags":""},{"recorded_at":"2017-09-01T13:00:00+0900","value":182.0,"flags":""},{"recorded_at":"2017-09-01T13:30:00+0900","value":200.0,"flags":""},{"recorded_at":"2017-09-01T14:00:00+0900","value":196.0,"flags":""},{"recorded_at":"2017-09-01T14:30:00+0900","value":192.0,"flags":""},{"recorded_at":"2017-09-01T15:00:00+0900","value":192.0,"flags":""},{"recorded_at":"2017-09-01T15:30:00+0900","value":198.0,"flags":""},{"recorded_at":"2017-09-01T16:00:00+0900","value":195.0,"flags":""},{"recorded_at":"2017-09-01T16:30:00+0900","value":193.0,"flags":""},{"recorded_at":"2017-09-01T17:00:00+0900","value":189.0,"flags":""},{"recorded_at":"2017-09-01T17:30:00+0900","value":191.0,"flags":""},{"recorded_at":"2017-09-01T18:00:00+0900","value":176.0,"flags":""},{"recorded_at":"2017-09-01T18:30:00+0900","value":150.0,"flags":""},{"recorded_at":"2017-09-01T19:00:00+0900","value":141.0,"flags":""},{"recorded_at":"2017-09-01T19:30:00+0900","value":121.0,"flags":""},{"recorded_at":"2017-09-01T20:00:00+0900","value":112.0,"flags":""},{"recorded_at":"2017-09-01T20:30:00+0900","value":104.0,"flags":""},{"recorded_at":"2017-09-01T21:00:00+0900","value":93.0,"flags":""},{"recorded_at":"2017-09-01T21:30:00+0900","value":85.0,"flags":""},{"recorded_at":"2017-09-01T22:00:00+0900","value":78.0,"flags":""},{"recorded_at":"2017-09-01T22:30:00+0900","value":77.0,"flags":""},{"recorded_at":"2017-09-01T23:00:00+0900","value":72.0,"flags":""},{"recorded_at":"2017-09-01T23:30:00+0900","value":63.0,"flags":""},{"recorded_at":"2017-09-02T00:00:00+0900","value":61.0,"flags":""}]}] ================================================ FILE: examples/boxPlot.html ================================================ ================================================ FILE: examples/boxPlotCustomModel.html ================================================ ================================================ FILE: examples/bullet.html ================================================ ================================================ FILE: examples/bulletChart.html ================================================ Normal Bullet Chart Bullet Chart with Custom Labels ================================================ FILE: examples/candlestick.html ================================================
================================================ FILE: examples/candlestickChart.html ================================================
================================================ FILE: examples/cumulativeLineChart.html ================================================
================================================ FILE: examples/differenceChart.html ================================================
================================================ FILE: examples/discreteBarChart.html ================================================
================================================ FILE: examples/distroPlotChart.html ================================================
Plot types | X-axis
Decorations
Observation positions
Whisker definitions | Grouping
================================================ FILE: examples/documentation.html ================================================ Nvd3 - reusable charts for D3.js

Nvd3

A reusable chart library for d3.js

NVD3 Documentation

This page lists out all options available to the charts and is generated programatically using the new options object model. All options can be called as functions on the chart object to get the option vaue (if no argument given) or to set the value. Alternatively, you can use the options() method on the chart object and pass in a dictionary of the option names and values to set them all at once.

Example:
            var chart = nv.models.pieChart();
            chart.width(500);
            chart.title('stuff').titleOffset(-10);
            chart.options({height: 500, donut: true});
        

Shortcuts to Charts and Chart Parts

[ toggle all ]

================================================ FILE: examples/donutChart.html ================================================ ================================================ FILE: examples/forceDirected.html ================================================ ================================================ FILE: examples/furiousLegend.html ================================================

Legend 1

Legend 2

Setting align(false)

Legend 3

Setting legend padding distance

================================================ FILE: examples/heatMap.html ================================================

Normalize
Axes | Metadata | Cell Color
================================================ FILE: examples/historicalBar.html ================================================ ================================================ FILE: examples/historicalBarChart.html ================================================ ================================================ FILE: examples/index.html ================================================ NVD3 Examples List

NVD3 Examples List

================================================ FILE: examples/legend.html ================================================

Legend 1

Legend 2

Setting align(false)

Legend 3

Setting legend padding distance

================================================ FILE: examples/lib/colorbrewer.js ================================================ // This product includes color specifications and designs developed by Cynthia Brewer (http://colorbrewer.org/). var colorbrewer = {YlGn: { 3: ["#f7fcb9","#addd8e","#31a354"], 4: ["#ffffcc","#c2e699","#78c679","#238443"], 5: ["#ffffcc","#c2e699","#78c679","#31a354","#006837"], 6: ["#ffffcc","#d9f0a3","#addd8e","#78c679","#31a354","#006837"], 7: ["#ffffcc","#d9f0a3","#addd8e","#78c679","#41ab5d","#238443","#005a32"], 8: ["#ffffe5","#f7fcb9","#d9f0a3","#addd8e","#78c679","#41ab5d","#238443","#005a32"], 9: ["#ffffe5","#f7fcb9","#d9f0a3","#addd8e","#78c679","#41ab5d","#238443","#006837","#004529"] },YlGnBu: { 3: ["#edf8b1","#7fcdbb","#2c7fb8"], 4: ["#ffffcc","#a1dab4","#41b6c4","#225ea8"], 5: ["#ffffcc","#a1dab4","#41b6c4","#2c7fb8","#253494"], 6: ["#ffffcc","#c7e9b4","#7fcdbb","#41b6c4","#2c7fb8","#253494"], 7: ["#ffffcc","#c7e9b4","#7fcdbb","#41b6c4","#1d91c0","#225ea8","#0c2c84"], 8: ["#ffffd9","#edf8b1","#c7e9b4","#7fcdbb","#41b6c4","#1d91c0","#225ea8","#0c2c84"], 9: ["#ffffd9","#edf8b1","#c7e9b4","#7fcdbb","#41b6c4","#1d91c0","#225ea8","#253494","#081d58"] },GnBu: { 3: ["#e0f3db","#a8ddb5","#43a2ca"], 4: ["#f0f9e8","#bae4bc","#7bccc4","#2b8cbe"], 5: ["#f0f9e8","#bae4bc","#7bccc4","#43a2ca","#0868ac"], 6: ["#f0f9e8","#ccebc5","#a8ddb5","#7bccc4","#43a2ca","#0868ac"], 7: ["#f0f9e8","#ccebc5","#a8ddb5","#7bccc4","#4eb3d3","#2b8cbe","#08589e"], 8: ["#f7fcf0","#e0f3db","#ccebc5","#a8ddb5","#7bccc4","#4eb3d3","#2b8cbe","#08589e"], 9: ["#f7fcf0","#e0f3db","#ccebc5","#a8ddb5","#7bccc4","#4eb3d3","#2b8cbe","#0868ac","#084081"] },BuGn: { 3: ["#e5f5f9","#99d8c9","#2ca25f"], 4: ["#edf8fb","#b2e2e2","#66c2a4","#238b45"], 5: ["#edf8fb","#b2e2e2","#66c2a4","#2ca25f","#006d2c"], 6: ["#edf8fb","#ccece6","#99d8c9","#66c2a4","#2ca25f","#006d2c"], 7: ["#edf8fb","#ccece6","#99d8c9","#66c2a4","#41ae76","#238b45","#005824"], 8: ["#f7fcfd","#e5f5f9","#ccece6","#99d8c9","#66c2a4","#41ae76","#238b45","#005824"], 9: ["#f7fcfd","#e5f5f9","#ccece6","#99d8c9","#66c2a4","#41ae76","#238b45","#006d2c","#00441b"] },PuBuGn: { 3: ["#ece2f0","#a6bddb","#1c9099"], 4: ["#f6eff7","#bdc9e1","#67a9cf","#02818a"], 5: ["#f6eff7","#bdc9e1","#67a9cf","#1c9099","#016c59"], 6: ["#f6eff7","#d0d1e6","#a6bddb","#67a9cf","#1c9099","#016c59"], 7: ["#f6eff7","#d0d1e6","#a6bddb","#67a9cf","#3690c0","#02818a","#016450"], 8: ["#fff7fb","#ece2f0","#d0d1e6","#a6bddb","#67a9cf","#3690c0","#02818a","#016450"], 9: ["#fff7fb","#ece2f0","#d0d1e6","#a6bddb","#67a9cf","#3690c0","#02818a","#016c59","#014636"] },PuBu: { 3: ["#ece7f2","#a6bddb","#2b8cbe"], 4: ["#f1eef6","#bdc9e1","#74a9cf","#0570b0"], 5: ["#f1eef6","#bdc9e1","#74a9cf","#2b8cbe","#045a8d"], 6: ["#f1eef6","#d0d1e6","#a6bddb","#74a9cf","#2b8cbe","#045a8d"], 7: ["#f1eef6","#d0d1e6","#a6bddb","#74a9cf","#3690c0","#0570b0","#034e7b"], 8: ["#fff7fb","#ece7f2","#d0d1e6","#a6bddb","#74a9cf","#3690c0","#0570b0","#034e7b"], 9: ["#fff7fb","#ece7f2","#d0d1e6","#a6bddb","#74a9cf","#3690c0","#0570b0","#045a8d","#023858"] },BuPu: { 3: ["#e0ecf4","#9ebcda","#8856a7"], 4: ["#edf8fb","#b3cde3","#8c96c6","#88419d"], 5: ["#edf8fb","#b3cde3","#8c96c6","#8856a7","#810f7c"], 6: ["#edf8fb","#bfd3e6","#9ebcda","#8c96c6","#8856a7","#810f7c"], 7: ["#edf8fb","#bfd3e6","#9ebcda","#8c96c6","#8c6bb1","#88419d","#6e016b"], 8: ["#f7fcfd","#e0ecf4","#bfd3e6","#9ebcda","#8c96c6","#8c6bb1","#88419d","#6e016b"], 9: ["#f7fcfd","#e0ecf4","#bfd3e6","#9ebcda","#8c96c6","#8c6bb1","#88419d","#810f7c","#4d004b"] },RdPu: { 3: ["#fde0dd","#fa9fb5","#c51b8a"], 4: ["#feebe2","#fbb4b9","#f768a1","#ae017e"], 5: ["#feebe2","#fbb4b9","#f768a1","#c51b8a","#7a0177"], 6: ["#feebe2","#fcc5c0","#fa9fb5","#f768a1","#c51b8a","#7a0177"], 7: ["#feebe2","#fcc5c0","#fa9fb5","#f768a1","#dd3497","#ae017e","#7a0177"], 8: ["#fff7f3","#fde0dd","#fcc5c0","#fa9fb5","#f768a1","#dd3497","#ae017e","#7a0177"], 9: ["#fff7f3","#fde0dd","#fcc5c0","#fa9fb5","#f768a1","#dd3497","#ae017e","#7a0177","#49006a"] },PuRd: { 3: ["#e7e1ef","#c994c7","#dd1c77"], 4: ["#f1eef6","#d7b5d8","#df65b0","#ce1256"], 5: ["#f1eef6","#d7b5d8","#df65b0","#dd1c77","#980043"], 6: ["#f1eef6","#d4b9da","#c994c7","#df65b0","#dd1c77","#980043"], 7: ["#f1eef6","#d4b9da","#c994c7","#df65b0","#e7298a","#ce1256","#91003f"], 8: ["#f7f4f9","#e7e1ef","#d4b9da","#c994c7","#df65b0","#e7298a","#ce1256","#91003f"], 9: ["#f7f4f9","#e7e1ef","#d4b9da","#c994c7","#df65b0","#e7298a","#ce1256","#980043","#67001f"] },OrRd: { 3: ["#fee8c8","#fdbb84","#e34a33"], 4: ["#fef0d9","#fdcc8a","#fc8d59","#d7301f"], 5: ["#fef0d9","#fdcc8a","#fc8d59","#e34a33","#b30000"], 6: ["#fef0d9","#fdd49e","#fdbb84","#fc8d59","#e34a33","#b30000"], 7: ["#fef0d9","#fdd49e","#fdbb84","#fc8d59","#ef6548","#d7301f","#990000"], 8: ["#fff7ec","#fee8c8","#fdd49e","#fdbb84","#fc8d59","#ef6548","#d7301f","#990000"], 9: ["#fff7ec","#fee8c8","#fdd49e","#fdbb84","#fc8d59","#ef6548","#d7301f","#b30000","#7f0000"] },YlOrRd: { 3: ["#ffeda0","#feb24c","#f03b20"], 4: ["#ffffb2","#fecc5c","#fd8d3c","#e31a1c"], 5: ["#ffffb2","#fecc5c","#fd8d3c","#f03b20","#bd0026"], 6: ["#ffffb2","#fed976","#feb24c","#fd8d3c","#f03b20","#bd0026"], 7: ["#ffffb2","#fed976","#feb24c","#fd8d3c","#fc4e2a","#e31a1c","#b10026"], 8: ["#ffffcc","#ffeda0","#fed976","#feb24c","#fd8d3c","#fc4e2a","#e31a1c","#b10026"], 9: ["#ffffcc","#ffeda0","#fed976","#feb24c","#fd8d3c","#fc4e2a","#e31a1c","#bd0026","#800026"] },YlOrBr: { 3: ["#fff7bc","#fec44f","#d95f0e"], 4: ["#ffffd4","#fed98e","#fe9929","#cc4c02"], 5: ["#ffffd4","#fed98e","#fe9929","#d95f0e","#993404"], 6: ["#ffffd4","#fee391","#fec44f","#fe9929","#d95f0e","#993404"], 7: ["#ffffd4","#fee391","#fec44f","#fe9929","#ec7014","#cc4c02","#8c2d04"], 8: ["#ffffe5","#fff7bc","#fee391","#fec44f","#fe9929","#ec7014","#cc4c02","#8c2d04"], 9: ["#ffffe5","#fff7bc","#fee391","#fec44f","#fe9929","#ec7014","#cc4c02","#993404","#662506"] },Purples: { 3: ["#efedf5","#bcbddc","#756bb1"], 4: ["#f2f0f7","#cbc9e2","#9e9ac8","#6a51a3"], 5: ["#f2f0f7","#cbc9e2","#9e9ac8","#756bb1","#54278f"], 6: ["#f2f0f7","#dadaeb","#bcbddc","#9e9ac8","#756bb1","#54278f"], 7: ["#f2f0f7","#dadaeb","#bcbddc","#9e9ac8","#807dba","#6a51a3","#4a1486"], 8: ["#fcfbfd","#efedf5","#dadaeb","#bcbddc","#9e9ac8","#807dba","#6a51a3","#4a1486"], 9: ["#fcfbfd","#efedf5","#dadaeb","#bcbddc","#9e9ac8","#807dba","#6a51a3","#54278f","#3f007d"] },Blues: { 3: ["#deebf7","#9ecae1","#3182bd"], 4: ["#eff3ff","#bdd7e7","#6baed6","#2171b5"], 5: ["#eff3ff","#bdd7e7","#6baed6","#3182bd","#08519c"], 6: ["#eff3ff","#c6dbef","#9ecae1","#6baed6","#3182bd","#08519c"], 7: ["#eff3ff","#c6dbef","#9ecae1","#6baed6","#4292c6","#2171b5","#084594"], 8: ["#f7fbff","#deebf7","#c6dbef","#9ecae1","#6baed6","#4292c6","#2171b5","#084594"], 9: ["#f7fbff","#deebf7","#c6dbef","#9ecae1","#6baed6","#4292c6","#2171b5","#08519c","#08306b"] },Greens: { 3: ["#e5f5e0","#a1d99b","#31a354"], 4: ["#edf8e9","#bae4b3","#74c476","#238b45"], 5: ["#edf8e9","#bae4b3","#74c476","#31a354","#006d2c"], 6: ["#edf8e9","#c7e9c0","#a1d99b","#74c476","#31a354","#006d2c"], 7: ["#edf8e9","#c7e9c0","#a1d99b","#74c476","#41ab5d","#238b45","#005a32"], 8: ["#f7fcf5","#e5f5e0","#c7e9c0","#a1d99b","#74c476","#41ab5d","#238b45","#005a32"], 9: ["#f7fcf5","#e5f5e0","#c7e9c0","#a1d99b","#74c476","#41ab5d","#238b45","#006d2c","#00441b"] },Oranges: { 3: ["#fee6ce","#fdae6b","#e6550d"], 4: ["#feedde","#fdbe85","#fd8d3c","#d94701"], 5: ["#feedde","#fdbe85","#fd8d3c","#e6550d","#a63603"], 6: ["#feedde","#fdd0a2","#fdae6b","#fd8d3c","#e6550d","#a63603"], 7: ["#feedde","#fdd0a2","#fdae6b","#fd8d3c","#f16913","#d94801","#8c2d04"], 8: ["#fff5eb","#fee6ce","#fdd0a2","#fdae6b","#fd8d3c","#f16913","#d94801","#8c2d04"], 9: ["#fff5eb","#fee6ce","#fdd0a2","#fdae6b","#fd8d3c","#f16913","#d94801","#a63603","#7f2704"] },Reds: { 3: ["#fee0d2","#fc9272","#de2d26"], 4: ["#fee5d9","#fcae91","#fb6a4a","#cb181d"], 5: ["#fee5d9","#fcae91","#fb6a4a","#de2d26","#a50f15"], 6: ["#fee5d9","#fcbba1","#fc9272","#fb6a4a","#de2d26","#a50f15"], 7: ["#fee5d9","#fcbba1","#fc9272","#fb6a4a","#ef3b2c","#cb181d","#99000d"], 8: ["#fff5f0","#fee0d2","#fcbba1","#fc9272","#fb6a4a","#ef3b2c","#cb181d","#99000d"], 9: ["#fff5f0","#fee0d2","#fcbba1","#fc9272","#fb6a4a","#ef3b2c","#cb181d","#a50f15","#67000d"] },Greys: { 3: ["#f0f0f0","#bdbdbd","#636363"], 4: ["#f7f7f7","#cccccc","#969696","#525252"], 5: ["#f7f7f7","#cccccc","#969696","#636363","#252525"], 6: ["#f7f7f7","#d9d9d9","#bdbdbd","#969696","#636363","#252525"], 7: ["#f7f7f7","#d9d9d9","#bdbdbd","#969696","#737373","#525252","#252525"], 8: ["#ffffff","#f0f0f0","#d9d9d9","#bdbdbd","#969696","#737373","#525252","#252525"], 9: ["#ffffff","#f0f0f0","#d9d9d9","#bdbdbd","#969696","#737373","#525252","#252525","#000000"] },PuOr: { 3: ["#f1a340","#f7f7f7","#998ec3"], 4: ["#e66101","#fdb863","#b2abd2","#5e3c99"], 5: ["#e66101","#fdb863","#f7f7f7","#b2abd2","#5e3c99"], 6: ["#b35806","#f1a340","#fee0b6","#d8daeb","#998ec3","#542788"], 7: ["#b35806","#f1a340","#fee0b6","#f7f7f7","#d8daeb","#998ec3","#542788"], 8: ["#b35806","#e08214","#fdb863","#fee0b6","#d8daeb","#b2abd2","#8073ac","#542788"], 9: ["#b35806","#e08214","#fdb863","#fee0b6","#f7f7f7","#d8daeb","#b2abd2","#8073ac","#542788"], 10: ["#7f3b08","#b35806","#e08214","#fdb863","#fee0b6","#d8daeb","#b2abd2","#8073ac","#542788","#2d004b"], 11: ["#7f3b08","#b35806","#e08214","#fdb863","#fee0b6","#f7f7f7","#d8daeb","#b2abd2","#8073ac","#542788","#2d004b"] },BrBG: { 3: ["#d8b365","#f5f5f5","#5ab4ac"], 4: ["#a6611a","#dfc27d","#80cdc1","#018571"], 5: ["#a6611a","#dfc27d","#f5f5f5","#80cdc1","#018571"], 6: ["#8c510a","#d8b365","#f6e8c3","#c7eae5","#5ab4ac","#01665e"], 7: ["#8c510a","#d8b365","#f6e8c3","#f5f5f5","#c7eae5","#5ab4ac","#01665e"], 8: ["#8c510a","#bf812d","#dfc27d","#f6e8c3","#c7eae5","#80cdc1","#35978f","#01665e"], 9: ["#8c510a","#bf812d","#dfc27d","#f6e8c3","#f5f5f5","#c7eae5","#80cdc1","#35978f","#01665e"], 10: ["#543005","#8c510a","#bf812d","#dfc27d","#f6e8c3","#c7eae5","#80cdc1","#35978f","#01665e","#003c30"], 11: ["#543005","#8c510a","#bf812d","#dfc27d","#f6e8c3","#f5f5f5","#c7eae5","#80cdc1","#35978f","#01665e","#003c30"] },PRGn: { 3: ["#af8dc3","#f7f7f7","#7fbf7b"], 4: ["#7b3294","#c2a5cf","#a6dba0","#008837"], 5: ["#7b3294","#c2a5cf","#f7f7f7","#a6dba0","#008837"], 6: ["#762a83","#af8dc3","#e7d4e8","#d9f0d3","#7fbf7b","#1b7837"], 7: ["#762a83","#af8dc3","#e7d4e8","#f7f7f7","#d9f0d3","#7fbf7b","#1b7837"], 8: ["#762a83","#9970ab","#c2a5cf","#e7d4e8","#d9f0d3","#a6dba0","#5aae61","#1b7837"], 9: ["#762a83","#9970ab","#c2a5cf","#e7d4e8","#f7f7f7","#d9f0d3","#a6dba0","#5aae61","#1b7837"], 10: ["#40004b","#762a83","#9970ab","#c2a5cf","#e7d4e8","#d9f0d3","#a6dba0","#5aae61","#1b7837","#00441b"], 11: ["#40004b","#762a83","#9970ab","#c2a5cf","#e7d4e8","#f7f7f7","#d9f0d3","#a6dba0","#5aae61","#1b7837","#00441b"] },PiYG: { 3: ["#e9a3c9","#f7f7f7","#a1d76a"], 4: ["#d01c8b","#f1b6da","#b8e186","#4dac26"], 5: ["#d01c8b","#f1b6da","#f7f7f7","#b8e186","#4dac26"], 6: ["#c51b7d","#e9a3c9","#fde0ef","#e6f5d0","#a1d76a","#4d9221"], 7: ["#c51b7d","#e9a3c9","#fde0ef","#f7f7f7","#e6f5d0","#a1d76a","#4d9221"], 8: ["#c51b7d","#de77ae","#f1b6da","#fde0ef","#e6f5d0","#b8e186","#7fbc41","#4d9221"], 9: ["#c51b7d","#de77ae","#f1b6da","#fde0ef","#f7f7f7","#e6f5d0","#b8e186","#7fbc41","#4d9221"], 10: ["#8e0152","#c51b7d","#de77ae","#f1b6da","#fde0ef","#e6f5d0","#b8e186","#7fbc41","#4d9221","#276419"], 11: ["#8e0152","#c51b7d","#de77ae","#f1b6da","#fde0ef","#f7f7f7","#e6f5d0","#b8e186","#7fbc41","#4d9221","#276419"] },RdBu: { 3: ["#ef8a62","#f7f7f7","#67a9cf"], 4: ["#ca0020","#f4a582","#92c5de","#0571b0"], 5: ["#ca0020","#f4a582","#f7f7f7","#92c5de","#0571b0"], 6: ["#b2182b","#ef8a62","#fddbc7","#d1e5f0","#67a9cf","#2166ac"], 7: ["#b2182b","#ef8a62","#fddbc7","#f7f7f7","#d1e5f0","#67a9cf","#2166ac"], 8: ["#b2182b","#d6604d","#f4a582","#fddbc7","#d1e5f0","#92c5de","#4393c3","#2166ac"], 9: ["#b2182b","#d6604d","#f4a582","#fddbc7","#f7f7f7","#d1e5f0","#92c5de","#4393c3","#2166ac"], 10: ["#67001f","#b2182b","#d6604d","#f4a582","#fddbc7","#d1e5f0","#92c5de","#4393c3","#2166ac","#053061"], 11: ["#67001f","#b2182b","#d6604d","#f4a582","#fddbc7","#f7f7f7","#d1e5f0","#92c5de","#4393c3","#2166ac","#053061"] },RdGy: { 3: ["#ef8a62","#ffffff","#999999"], 4: ["#ca0020","#f4a582","#bababa","#404040"], 5: ["#ca0020","#f4a582","#ffffff","#bababa","#404040"], 6: ["#b2182b","#ef8a62","#fddbc7","#e0e0e0","#999999","#4d4d4d"], 7: ["#b2182b","#ef8a62","#fddbc7","#ffffff","#e0e0e0","#999999","#4d4d4d"], 8: ["#b2182b","#d6604d","#f4a582","#fddbc7","#e0e0e0","#bababa","#878787","#4d4d4d"], 9: ["#b2182b","#d6604d","#f4a582","#fddbc7","#ffffff","#e0e0e0","#bababa","#878787","#4d4d4d"], 10: ["#67001f","#b2182b","#d6604d","#f4a582","#fddbc7","#e0e0e0","#bababa","#878787","#4d4d4d","#1a1a1a"], 11: ["#67001f","#b2182b","#d6604d","#f4a582","#fddbc7","#ffffff","#e0e0e0","#bababa","#878787","#4d4d4d","#1a1a1a"] },RdYlBu: { 3: ["#fc8d59","#ffffbf","#91bfdb"], 4: ["#d7191c","#fdae61","#abd9e9","#2c7bb6"], 5: ["#d7191c","#fdae61","#ffffbf","#abd9e9","#2c7bb6"], 6: ["#d73027","#fc8d59","#fee090","#e0f3f8","#91bfdb","#4575b4"], 7: ["#d73027","#fc8d59","#fee090","#ffffbf","#e0f3f8","#91bfdb","#4575b4"], 8: ["#d73027","#f46d43","#fdae61","#fee090","#e0f3f8","#abd9e9","#74add1","#4575b4"], 9: ["#d73027","#f46d43","#fdae61","#fee090","#ffffbf","#e0f3f8","#abd9e9","#74add1","#4575b4"], 10: ["#a50026","#d73027","#f46d43","#fdae61","#fee090","#e0f3f8","#abd9e9","#74add1","#4575b4","#313695"], 11: ["#a50026","#d73027","#f46d43","#fdae61","#fee090","#ffffbf","#e0f3f8","#abd9e9","#74add1","#4575b4","#313695"] },Spectral: { 3: ["#fc8d59","#ffffbf","#99d594"], 4: ["#d7191c","#fdae61","#abdda4","#2b83ba"], 5: ["#d7191c","#fdae61","#ffffbf","#abdda4","#2b83ba"], 6: ["#d53e4f","#fc8d59","#fee08b","#e6f598","#99d594","#3288bd"], 7: ["#d53e4f","#fc8d59","#fee08b","#ffffbf","#e6f598","#99d594","#3288bd"], 8: ["#d53e4f","#f46d43","#fdae61","#fee08b","#e6f598","#abdda4","#66c2a5","#3288bd"], 9: ["#d53e4f","#f46d43","#fdae61","#fee08b","#ffffbf","#e6f598","#abdda4","#66c2a5","#3288bd"], 10: ["#9e0142","#d53e4f","#f46d43","#fdae61","#fee08b","#e6f598","#abdda4","#66c2a5","#3288bd","#5e4fa2"], 11: ["#9e0142","#d53e4f","#f46d43","#fdae61","#fee08b","#ffffbf","#e6f598","#abdda4","#66c2a5","#3288bd","#5e4fa2"] },RdYlGn: { 3: ["#fc8d59","#ffffbf","#91cf60"], 4: ["#d7191c","#fdae61","#a6d96a","#1a9641"], 5: ["#d7191c","#fdae61","#ffffbf","#a6d96a","#1a9641"], 6: ["#d73027","#fc8d59","#fee08b","#d9ef8b","#91cf60","#1a9850"], 7: ["#d73027","#fc8d59","#fee08b","#ffffbf","#d9ef8b","#91cf60","#1a9850"], 8: ["#d73027","#f46d43","#fdae61","#fee08b","#d9ef8b","#a6d96a","#66bd63","#1a9850"], 9: ["#d73027","#f46d43","#fdae61","#fee08b","#ffffbf","#d9ef8b","#a6d96a","#66bd63","#1a9850"], 10: ["#a50026","#d73027","#f46d43","#fdae61","#fee08b","#d9ef8b","#a6d96a","#66bd63","#1a9850","#006837"], 11: ["#a50026","#d73027","#f46d43","#fdae61","#fee08b","#ffffbf","#d9ef8b","#a6d96a","#66bd63","#1a9850","#006837"] },Accent: { 3: ["#7fc97f","#beaed4","#fdc086"], 4: ["#7fc97f","#beaed4","#fdc086","#ffff99"], 5: ["#7fc97f","#beaed4","#fdc086","#ffff99","#386cb0"], 6: ["#7fc97f","#beaed4","#fdc086","#ffff99","#386cb0","#f0027f"], 7: ["#7fc97f","#beaed4","#fdc086","#ffff99","#386cb0","#f0027f","#bf5b17"], 8: ["#7fc97f","#beaed4","#fdc086","#ffff99","#386cb0","#f0027f","#bf5b17","#666666"] },Dark2: { 3: ["#1b9e77","#d95f02","#7570b3"], 4: ["#1b9e77","#d95f02","#7570b3","#e7298a"], 5: ["#1b9e77","#d95f02","#7570b3","#e7298a","#66a61e"], 6: ["#1b9e77","#d95f02","#7570b3","#e7298a","#66a61e","#e6ab02"], 7: ["#1b9e77","#d95f02","#7570b3","#e7298a","#66a61e","#e6ab02","#a6761d"], 8: ["#1b9e77","#d95f02","#7570b3","#e7298a","#66a61e","#e6ab02","#a6761d","#666666"] },Paired: { 3: ["#a6cee3","#1f78b4","#b2df8a"], 4: ["#a6cee3","#1f78b4","#b2df8a","#33a02c"], 5: ["#a6cee3","#1f78b4","#b2df8a","#33a02c","#fb9a99"], 6: ["#a6cee3","#1f78b4","#b2df8a","#33a02c","#fb9a99","#e31a1c"], 7: ["#a6cee3","#1f78b4","#b2df8a","#33a02c","#fb9a99","#e31a1c","#fdbf6f"], 8: ["#a6cee3","#1f78b4","#b2df8a","#33a02c","#fb9a99","#e31a1c","#fdbf6f","#ff7f00"], 9: ["#a6cee3","#1f78b4","#b2df8a","#33a02c","#fb9a99","#e31a1c","#fdbf6f","#ff7f00","#cab2d6"], 10: ["#a6cee3","#1f78b4","#b2df8a","#33a02c","#fb9a99","#e31a1c","#fdbf6f","#ff7f00","#cab2d6","#6a3d9a"], 11: ["#a6cee3","#1f78b4","#b2df8a","#33a02c","#fb9a99","#e31a1c","#fdbf6f","#ff7f00","#cab2d6","#6a3d9a","#ffff99"], 12: ["#a6cee3","#1f78b4","#b2df8a","#33a02c","#fb9a99","#e31a1c","#fdbf6f","#ff7f00","#cab2d6","#6a3d9a","#ffff99","#b15928"] },Pastel1: { 3: ["#fbb4ae","#b3cde3","#ccebc5"], 4: ["#fbb4ae","#b3cde3","#ccebc5","#decbe4"], 5: ["#fbb4ae","#b3cde3","#ccebc5","#decbe4","#fed9a6"], 6: ["#fbb4ae","#b3cde3","#ccebc5","#decbe4","#fed9a6","#ffffcc"], 7: ["#fbb4ae","#b3cde3","#ccebc5","#decbe4","#fed9a6","#ffffcc","#e5d8bd"], 8: ["#fbb4ae","#b3cde3","#ccebc5","#decbe4","#fed9a6","#ffffcc","#e5d8bd","#fddaec"], 9: ["#fbb4ae","#b3cde3","#ccebc5","#decbe4","#fed9a6","#ffffcc","#e5d8bd","#fddaec","#f2f2f2"] },Pastel2: { 3: ["#b3e2cd","#fdcdac","#cbd5e8"], 4: ["#b3e2cd","#fdcdac","#cbd5e8","#f4cae4"], 5: ["#b3e2cd","#fdcdac","#cbd5e8","#f4cae4","#e6f5c9"], 6: ["#b3e2cd","#fdcdac","#cbd5e8","#f4cae4","#e6f5c9","#fff2ae"], 7: ["#b3e2cd","#fdcdac","#cbd5e8","#f4cae4","#e6f5c9","#fff2ae","#f1e2cc"], 8: ["#b3e2cd","#fdcdac","#cbd5e8","#f4cae4","#e6f5c9","#fff2ae","#f1e2cc","#cccccc"] },Set1: { 3: ["#e41a1c","#377eb8","#4daf4a"], 4: ["#e41a1c","#377eb8","#4daf4a","#984ea3"], 5: ["#e41a1c","#377eb8","#4daf4a","#984ea3","#ff7f00"], 6: ["#e41a1c","#377eb8","#4daf4a","#984ea3","#ff7f00","#ffff33"], 7: ["#e41a1c","#377eb8","#4daf4a","#984ea3","#ff7f00","#ffff33","#a65628"], 8: ["#e41a1c","#377eb8","#4daf4a","#984ea3","#ff7f00","#ffff33","#a65628","#f781bf"], 9: ["#e41a1c","#377eb8","#4daf4a","#984ea3","#ff7f00","#ffff33","#a65628","#f781bf","#999999"] },Set2: { 3: ["#66c2a5","#fc8d62","#8da0cb"], 4: ["#66c2a5","#fc8d62","#8da0cb","#e78ac3"], 5: ["#66c2a5","#fc8d62","#8da0cb","#e78ac3","#a6d854"], 6: ["#66c2a5","#fc8d62","#8da0cb","#e78ac3","#a6d854","#ffd92f"], 7: ["#66c2a5","#fc8d62","#8da0cb","#e78ac3","#a6d854","#ffd92f","#e5c494"], 8: ["#66c2a5","#fc8d62","#8da0cb","#e78ac3","#a6d854","#ffd92f","#e5c494","#b3b3b3"] },Set3: { 3: ["#8dd3c7","#ffffb3","#bebada"], 4: ["#8dd3c7","#ffffb3","#bebada","#fb8072"], 5: ["#8dd3c7","#ffffb3","#bebada","#fb8072","#80b1d3"], 6: ["#8dd3c7","#ffffb3","#bebada","#fb8072","#80b1d3","#fdb462"], 7: ["#8dd3c7","#ffffb3","#bebada","#fb8072","#80b1d3","#fdb462","#b3de69"], 8: ["#8dd3c7","#ffffb3","#bebada","#fb8072","#80b1d3","#fdb462","#b3de69","#fccde5"], 9: ["#8dd3c7","#ffffb3","#bebada","#fb8072","#80b1d3","#fdb462","#b3de69","#fccde5","#d9d9d9"], 10: ["#8dd3c7","#ffffb3","#bebada","#fb8072","#80b1d3","#fdb462","#b3de69","#fccde5","#d9d9d9","#bc80bd"], 11: ["#8dd3c7","#ffffb3","#bebada","#fb8072","#80b1d3","#fdb462","#b3de69","#fccde5","#d9d9d9","#bc80bd","#ccebc5"], 12: ["#8dd3c7","#ffffb3","#bebada","#fb8072","#80b1d3","#fdb462","#b3de69","#fccde5","#d9d9d9","#bc80bd","#ccebc5","#ffed6f"] }}; ================================================ FILE: examples/lib/stream_layers.js ================================================ /* Inspired by Lee Byron's test data generator. */ function stream_layers(n, m, o) { if (arguments.length < 3) o = 0; function bump(a) { var x = 1 / (.1 + Math.random()), y = 2 * Math.random() - .5, z = 10 / (.1 + Math.random()); for (var i = 0; i < m; i++) { var w = (i / m - y) * z; a[i] += x * Math.exp(-w * w); } } return d3.range(n).map(function() { var a = [], i; for (i = 0; i < m; i++) a[i] = o + o * Math.random(); for (i = 0; i < 5; i++) bump(a); return a.map(stream_index); }); } /* Another layer generator using gamma distributions. */ function stream_waves(n, m) { return d3.range(n).map(function(i) { return d3.range(m).map(function(j) { var x = 20 * j / m - i / 3; return 2 * x * Math.exp(-.5 * x); }).map(stream_index); }); } function stream_index(d, i) { return {x: i, y: Math.max(0, d)}; } ================================================ FILE: examples/line.html ================================================ ================================================ FILE: examples/lineChart.html ================================================
================================================ FILE: examples/lineChartLogScale.html ================================================
================================================ FILE: examples/lineChartSVGResize.html ================================================
================================================ FILE: examples/linePlusBarChart.html ================================================
<-- turn focus on or off!
================================================ FILE: examples/lineWithFocusChart.html ================================================
================================================ FILE: examples/lineWithFocusChart_x2AxisLabel.html ================================================
================================================ FILE: examples/monitoringChart.html ================================================  ================================================ FILE: examples/multiBarChart.html ================================================
================================================ FILE: examples/multiBarChart2.html ================================================
================================================ FILE: examples/multiBarHorizontalChart.html ================================================
================================================ FILE: examples/multiChart.html ================================================
================================================ FILE: examples/ohlc.html ================================================
================================================ FILE: examples/ohlcChart.html ================================================
================================================ FILE: examples/parallelCoordinates.html ================================================
================================================ FILE: examples/parallelCoordinatesChart.html ================================================
================================================ FILE: examples/pie.html ================================================
================================================ FILE: examples/pieChart.html ================================================ ================================================ FILE: examples/predicted.json ================================================ [{"actual":54.36052778662519,"falling_edge":"2017-06-30 15:00:00+00:00","predicted":54.36052778662519,"rising_edge":"2017-06-30 14:30:00+00:00"},{"actual":49.25752740561633,"falling_edge":"2017-06-30 15:30:00+00:00","predicted":49.25752740561633,"rising_edge":"2017-06-30 15:00:00+00:00"},{"actual":45.97036299597331,"falling_edge":"2017-06-30 16:00:00+00:00","predicted":45.97036299597331,"rising_edge":"2017-06-30 15:30:00+00:00"},{"actual":45.69754186891356,"falling_edge":"2017-06-30 16:30:00+00:00","predicted":45.69754186891356,"rising_edge":"2017-06-30 16:00:00+00:00"},{"actual":44.96142228319308,"falling_edge":"2017-06-30 17:00:00+00:00","predicted":44.96142228319308,"rising_edge":"2017-06-30 16:30:00+00:00"},{"actual":45.51063026323638,"falling_edge":"2017-06-30 17:30:00+00:00","predicted":45.51063026323638,"rising_edge":"2017-06-30 17:00:00+00:00"},{"actual":44.81584620790972,"falling_edge":"2017-06-30 18:00:00+00:00","predicted":44.81584620790972,"rising_edge":"2017-06-30 17:30:00+00:00"},{"actual":45.80573558803053,"falling_edge":"2017-06-30 18:30:00+00:00","predicted":45.80573558803053,"rising_edge":"2017-06-30 18:00:00+00:00"},{"actual":46.11541500651583,"falling_edge":"2017-06-30 19:00:00+00:00","predicted":46.11541500651583,"rising_edge":"2017-06-30 18:30:00+00:00"},{"actual":46.70585318978923,"falling_edge":"2017-06-30 19:30:00+00:00","predicted":46.70585318978923,"rising_edge":"2017-06-30 19:00:00+00:00"},{"actual":45.91226687808685,"falling_edge":"2017-06-30 20:00:00+00:00","predicted":45.91226687808685,"rising_edge":"2017-06-30 19:30:00+00:00"},{"actual":46.94304983477127,"falling_edge":"2017-06-30 20:30:00+00:00","predicted":46.94304983477127,"rising_edge":"2017-06-30 20:00:00+00:00"},{"actual":49.46970975296014,"falling_edge":"2017-06-30 21:00:00+00:00","predicted":49.46970975296014,"rising_edge":"2017-06-30 20:30:00+00:00"},{"actual":57.20880426191144,"falling_edge":"2017-06-30 21:30:00+00:00","predicted":57.20880426191144,"rising_edge":"2017-06-30 21:00:00+00:00"},{"actual":60.50737451332328,"falling_edge":"2017-06-30 22:00:00+00:00","predicted":60.50737451332328,"rising_edge":"2017-06-30 21:30:00+00:00"},{"actual":59.89928779176659,"falling_edge":"2017-06-30 22:30:00+00:00","predicted":59.89928779176659,"rising_edge":"2017-06-30 22:00:00+00:00"},{"actual":59.77592192471999,"falling_edge":"2017-06-30 23:00:00+00:00","predicted":59.77592192471999,"rising_edge":"2017-06-30 22:30:00+00:00"},{"actual":61.81796629595747,"falling_edge":"2017-06-30 23:30:00+00:00","predicted":61.81796629595747,"rising_edge":"2017-06-30 23:00:00+00:00"},{"actual":66.3791475823068,"falling_edge":"2017-07-01 00:00:00+00:00","predicted":66.3791475823068,"rising_edge":"2017-06-30 23:30:00+00:00"},{"actual":74.63577600007757,"falling_edge":"2017-07-01 00:30:00+00:00","predicted":74.63577600007757,"rising_edge":"2017-07-01 00:00:00+00:00"},{"actual":79.09750954598738,"falling_edge":"2017-07-01 01:00:00+00:00","predicted":79.09750954598738,"rising_edge":"2017-07-01 00:30:00+00:00"},{"actual":81.08383752035148,"falling_edge":"2017-07-01 01:30:00+00:00","predicted":81.08383752035148,"rising_edge":"2017-07-01 01:00:00+00:00"},{"actual":79.32401408084314,"falling_edge":"2017-07-01 02:00:00+00:00","predicted":79.32401408084314,"rising_edge":"2017-07-01 01:30:00+00:00"},{"actual":78.75743002793175,"falling_edge":"2017-07-01 02:30:00+00:00","predicted":78.75743002793175,"rising_edge":"2017-07-01 02:00:00+00:00"},{"actual":80.48505178613166,"falling_edge":"2017-07-01 03:00:00+00:00","predicted":80.48505178613166,"rising_edge":"2017-07-01 02:30:00+00:00"},{"actual":80.43730739589051,"falling_edge":"2017-07-01 03:30:00+00:00","predicted":80.43730739589051,"rising_edge":"2017-07-01 03:00:00+00:00"},{"actual":80.20103103338306,"falling_edge":"2017-07-01 04:00:00+00:00","predicted":80.20103103338306,"rising_edge":"2017-07-01 03:30:00+00:00"},{"actual":82.38922943862532,"falling_edge":"2017-07-01 04:30:00+00:00","predicted":82.38922943862532,"rising_edge":"2017-07-01 04:00:00+00:00"},{"actual":82.2086707828573,"falling_edge":"2017-07-01 05:00:00+00:00","predicted":82.2086707828573,"rising_edge":"2017-07-01 04:30:00+00:00"},{"actual":81.21719807041764,"falling_edge":"2017-07-01 05:30:00+00:00","predicted":81.21719807041764,"rising_edge":"2017-07-01 05:00:00+00:00"},{"actual":81.29197059018803,"falling_edge":"2017-07-01 06:00:00+00:00","predicted":81.29197059018803,"rising_edge":"2017-07-01 05:30:00+00:00"},{"actual":80.24596040908925,"falling_edge":"2017-07-01 06:30:00+00:00","predicted":80.24596040908925,"rising_edge":"2017-07-01 06:00:00+00:00"},{"actual":81.16692642003652,"falling_edge":"2017-07-01 07:00:00+00:00","predicted":81.16692642003652,"rising_edge":"2017-07-01 06:30:00+00:00"},{"actual":80.94238324713203,"falling_edge":"2017-07-01 07:30:00+00:00","predicted":80.94238324713203,"rising_edge":"2017-07-01 07:00:00+00:00"},{"actual":79.91177000871063,"falling_edge":"2017-07-01 08:00:00+00:00","predicted":79.91177000871063,"rising_edge":"2017-07-01 07:30:00+00:00"},{"actual":79.67410395097966,"falling_edge":"2017-07-01 08:30:00+00:00","predicted":79.67410395097966,"rising_edge":"2017-07-01 08:00:00+00:00"},{"actual":74.09976944544647,"falling_edge":"2017-07-01 09:00:00+00:00","predicted":74.09976944544647,"rising_edge":"2017-07-01 08:30:00+00:00"},{"actual":66.02058605093278,"falling_edge":"2017-07-01 09:30:00+00:00","predicted":66.02058605093278,"rising_edge":"2017-07-01 09:00:00+00:00"},{"actual":64.24119487731926,"falling_edge":"2017-07-01 10:00:00+00:00","predicted":64.24119487731926,"rising_edge":"2017-07-01 09:30:00+00:00"},{"actual":61.36683608678591,"falling_edge":"2017-07-01 10:30:00+00:00","predicted":61.36683608678591,"rising_edge":"2017-07-01 10:00:00+00:00"},{"actual":59.82711968413477,"falling_edge":"2017-07-01 11:00:00+00:00","predicted":59.82711968413477,"rising_edge":"2017-07-01 10:30:00+00:00"},{"actual":59.22764761026551,"falling_edge":"2017-07-01 11:30:00+00:00","predicted":59.22764761026551,"rising_edge":"2017-07-01 11:00:00+00:00"},{"actual":57.20063146986028,"falling_edge":"2017-07-01 12:00:00+00:00","predicted":57.20063146986028,"rising_edge":"2017-07-01 11:30:00+00:00"},{"actual":53.34881763229704,"falling_edge":"2017-07-01 12:30:00+00:00","predicted":53.34881763229704,"rising_edge":"2017-07-01 12:00:00+00:00"},{"actual":51.87665409591391,"falling_edge":"2017-07-01 13:00:00+00:00","predicted":51.87665409591391,"rising_edge":"2017-07-01 12:30:00+00:00"},{"actual":51.21397006112933,"falling_edge":"2017-07-01 13:30:00+00:00","predicted":51.21397006112933,"rising_edge":"2017-07-01 13:00:00+00:00"},{"actual":50.43194125544224,"falling_edge":"2017-07-01 14:00:00+00:00","predicted":50.43194125544224,"rising_edge":"2017-07-01 13:30:00+00:00"},{"actual":48.46624792680034,"falling_edge":"2017-07-01 14:30:00+00:00","predicted":48.46624792680034,"rising_edge":"2017-07-01 14:00:00+00:00"},{"actual":47.55846048009032,"falling_edge":"2017-07-01 15:00:00+00:00","predicted":47.55846048009032,"rising_edge":"2017-07-01 14:30:00+00:00"},{"actual":47.42054001869748,"falling_edge":"2017-07-01 15:30:00+00:00","predicted":47.42054001869748,"rising_edge":"2017-07-01 15:00:00+00:00"},{"actual":45.91448887024012,"falling_edge":"2017-07-01 16:00:00+00:00","predicted":45.91448887024012,"rising_edge":"2017-07-01 15:30:00+00:00"},{"actual":46.14057830037459,"falling_edge":"2017-07-01 16:30:00+00:00","predicted":46.14057830037459,"rising_edge":"2017-07-01 16:00:00+00:00"},{"actual":45.237418259578455,"falling_edge":"2017-07-01 17:00:00+00:00","predicted":45.237418259578455,"rising_edge":"2017-07-01 16:30:00+00:00"},{"actual":45.48823819473981,"falling_edge":"2017-07-01 17:30:00+00:00","predicted":45.48823819473981,"rising_edge":"2017-07-01 17:00:00+00:00"},{"actual":44.9591970510554,"falling_edge":"2017-07-01 18:00:00+00:00","predicted":44.9591970510554,"rising_edge":"2017-07-01 17:30:00+00:00"},{"actual":45.22021512909244,"falling_edge":"2017-07-01 18:30:00+00:00","predicted":45.22021512909244,"rising_edge":"2017-07-01 18:00:00+00:00"},{"actual":45.16931711454131,"falling_edge":"2017-07-01 19:00:00+00:00","predicted":45.16931711454131,"rising_edge":"2017-07-01 18:30:00+00:00"},{"actual":45.14677973852566,"falling_edge":"2017-07-01 19:30:00+00:00","predicted":45.14677973852566,"rising_edge":"2017-07-01 19:00:00+00:00"},{"actual":45.541281323330544,"falling_edge":"2017-07-01 20:00:00+00:00","predicted":45.541281323330544,"rising_edge":"2017-07-01 19:30:00+00:00"},{"actual":45.36200363180318,"falling_edge":"2017-07-01 20:30:00+00:00","predicted":45.36200363180318,"rising_edge":"2017-07-01 20:00:00+00:00"},{"actual":46.42421948837546,"falling_edge":"2017-07-01 21:00:00+00:00","predicted":46.42421948837546,"rising_edge":"2017-07-01 20:30:00+00:00"},{"actual":47.075449847550836,"falling_edge":"2017-07-01 21:30:00+00:00","predicted":47.075449847550836,"rising_edge":"2017-07-01 21:00:00+00:00"},{"actual":49.44981600501445,"falling_edge":"2017-07-01 22:00:00+00:00","predicted":49.44981600501445,"rising_edge":"2017-07-01 21:30:00+00:00"},{"actual":50.84130454890258,"falling_edge":"2017-07-01 22:30:00+00:00","predicted":50.84130454890258,"rising_edge":"2017-07-01 22:00:00+00:00"},{"actual":51.09754406356962,"falling_edge":"2017-07-01 23:00:00+00:00","predicted":51.09754406356962,"rising_edge":"2017-07-01 22:30:00+00:00"},{"actual":55.34219798418586,"falling_edge":"2017-07-01 23:30:00+00:00","predicted":55.34219798418586,"rising_edge":"2017-07-01 23:00:00+00:00"},{"actual":58.53543962885969,"falling_edge":"2017-07-02 00:00:00+00:00","predicted":58.53543962885969,"rising_edge":"2017-07-01 23:30:00+00:00"},{"actual":64.17186348629046,"falling_edge":"2017-07-02 00:30:00+00:00","predicted":64.17186348629046,"rising_edge":"2017-07-02 00:00:00+00:00"},{"actual":67.1449824819642,"falling_edge":"2017-07-02 01:00:00+00:00","predicted":67.1449824819642,"rising_edge":"2017-07-02 00:30:00+00:00"},{"actual":68.14869969521473,"falling_edge":"2017-07-02 01:30:00+00:00","predicted":68.14869969521473,"rising_edge":"2017-07-02 01:00:00+00:00"},{"actual":68.43420736889522,"falling_edge":"2017-07-02 02:00:00+00:00","predicted":68.43420736889522,"rising_edge":"2017-07-02 01:30:00+00:00"},{"actual":68.99108231782868,"falling_edge":"2017-07-02 02:30:00+00:00","predicted":68.99108231782868,"rising_edge":"2017-07-02 02:00:00+00:00"},{"actual":69.50994005537758,"falling_edge":"2017-07-02 03:00:00+00:00","predicted":69.50994005537758,"rising_edge":"2017-07-02 02:30:00+00:00"},{"actual":70.13241800877181,"falling_edge":"2017-07-02 03:30:00+00:00","predicted":70.13241800877181,"rising_edge":"2017-07-02 03:00:00+00:00"},{"actual":69.80983414428287,"falling_edge":"2017-07-02 04:00:00+00:00","predicted":69.80983414428287,"rising_edge":"2017-07-02 03:30:00+00:00"},{"actual":74.62118046165294,"falling_edge":"2017-07-02 04:30:00+00:00","predicted":74.62118046165294,"rising_edge":"2017-07-02 04:00:00+00:00"},{"actual":74.73757039210626,"falling_edge":"2017-07-02 05:00:00+00:00","predicted":74.73757039210626,"rising_edge":"2017-07-02 04:30:00+00:00"},{"actual":76.67503653867307,"falling_edge":"2017-07-02 05:30:00+00:00","predicted":76.67503653867307,"rising_edge":"2017-07-02 05:00:00+00:00"},{"actual":73.85896058857453,"falling_edge":"2017-07-02 06:00:00+00:00","predicted":73.85896058857453,"rising_edge":"2017-07-02 05:30:00+00:00"},{"actual":75.55083230541204,"falling_edge":"2017-07-02 06:30:00+00:00","predicted":75.55083230541204,"rising_edge":"2017-07-02 06:00:00+00:00"},{"actual":77.62091779033874,"falling_edge":"2017-07-02 07:00:00+00:00","predicted":77.62091779033874,"rising_edge":"2017-07-02 06:30:00+00:00"},{"actual":77.84908794003042,"falling_edge":"2017-07-02 07:30:00+00:00","predicted":77.84908794003042,"rising_edge":"2017-07-02 07:00:00+00:00"},{"actual":74.16839605769886,"falling_edge":"2017-07-02 08:00:00+00:00","predicted":74.16839605769886,"rising_edge":"2017-07-02 07:30:00+00:00"},{"actual":72.37737212495318,"falling_edge":"2017-07-02 08:30:00+00:00","predicted":72.37737212495318,"rising_edge":"2017-07-02 08:00:00+00:00"},{"actual":70.06326663892881,"falling_edge":"2017-07-02 09:00:00+00:00","predicted":70.06326663892881,"rising_edge":"2017-07-02 08:30:00+00:00"},{"actual":65.99219528269568,"falling_edge":"2017-07-02 09:30:00+00:00","predicted":65.99219528269568,"rising_edge":"2017-07-02 09:00:00+00:00"},{"actual":64.52418315857481,"falling_edge":"2017-07-02 10:00:00+00:00","predicted":64.52418315857481,"rising_edge":"2017-07-02 09:30:00+00:00"},{"actual":60.834100547053126,"falling_edge":"2017-07-02 10:30:00+00:00","predicted":60.834100547053126,"rising_edge":"2017-07-02 10:00:00+00:00"},{"actual":59.081976319821486,"falling_edge":"2017-07-02 11:00:00+00:00","predicted":59.081976319821486,"rising_edge":"2017-07-02 10:30:00+00:00"},{"actual":57.53121767348194,"falling_edge":"2017-07-02 11:30:00+00:00","predicted":57.53121767348194,"rising_edge":"2017-07-02 11:00:00+00:00"},{"actual":57.65267955101386,"falling_edge":"2017-07-02 12:00:00+00:00","predicted":57.65267955101386,"rising_edge":"2017-07-02 11:30:00+00:00"},{"actual":54.284438270111345,"falling_edge":"2017-07-02 12:30:00+00:00","predicted":54.284438270111345,"rising_edge":"2017-07-02 12:00:00+00:00"},{"actual":52.77685437669969,"falling_edge":"2017-07-02 13:00:00+00:00","predicted":52.77685437669969,"rising_edge":"2017-07-02 12:30:00+00:00"},{"actual":51.85972974521758,"falling_edge":"2017-07-02 13:30:00+00:00","predicted":51.85972974521758,"rising_edge":"2017-07-02 13:00:00+00:00"},{"actual":49.97948400406949,"falling_edge":"2017-07-02 14:00:00+00:00","predicted":49.97948400406949,"rising_edge":"2017-07-02 13:30:00+00:00"},{"actual":50.887978015841604,"falling_edge":"2017-07-02 14:30:00+00:00","predicted":50.887978015841604,"rising_edge":"2017-07-02 14:00:00+00:00"},{"actual":48.954231611651814,"falling_edge":"2017-07-02 15:00:00+00:00","predicted":48.954231611651814,"rising_edge":"2017-07-02 14:30:00+00:00"},{"actual":48.52063029612959,"falling_edge":"2017-07-02 15:30:00+00:00","predicted":48.52063029612959,"rising_edge":"2017-07-02 15:00:00+00:00"},{"actual":47.983999006898934,"falling_edge":"2017-07-02 16:00:00+00:00","predicted":47.983999006898934,"rising_edge":"2017-07-02 15:30:00+00:00"},{"actual":48.689075217937074,"falling_edge":"2017-07-02 16:30:00+00:00","predicted":48.689075217937074,"rising_edge":"2017-07-02 16:00:00+00:00"},{"actual":47.3038195607827,"falling_edge":"2017-07-02 17:00:00+00:00","predicted":47.3038195607827,"rising_edge":"2017-07-02 16:30:00+00:00"},{"actual":46.39695851232495,"falling_edge":"2017-07-02 17:30:00+00:00","predicted":46.39695851232495,"rising_edge":"2017-07-02 17:00:00+00:00"},{"actual":47.076498405897496,"falling_edge":"2017-07-02 18:00:00+00:00","predicted":47.076498405897496,"rising_edge":"2017-07-02 17:30:00+00:00"},{"actual":46.4681151249321,"falling_edge":"2017-07-02 18:30:00+00:00","predicted":46.4681151249321,"rising_edge":"2017-07-02 18:00:00+00:00"},{"actual":46.637521782491824,"falling_edge":"2017-07-02 19:00:00+00:00","predicted":46.637521782491824,"rising_edge":"2017-07-02 18:30:00+00:00"},{"actual":45.91397317194595,"falling_edge":"2017-07-02 19:30:00+00:00","predicted":45.91397317194595,"rising_edge":"2017-07-02 19:00:00+00:00"},{"actual":46.559729245939856,"falling_edge":"2017-07-02 20:00:00+00:00","predicted":46.559729245939856,"rising_edge":"2017-07-02 19:30:00+00:00"},{"actual":47.26266271816268,"falling_edge":"2017-07-02 20:30:00+00:00","predicted":47.26266271816268,"rising_edge":"2017-07-02 20:00:00+00:00"},{"actual":52.3805261519144,"falling_edge":"2017-07-02 21:00:00+00:00","predicted":52.3805261519144,"rising_edge":"2017-07-02 20:30:00+00:00"},{"actual":70.18451402372149,"falling_edge":"2017-07-02 21:30:00+00:00","predicted":70.18451402372149,"rising_edge":"2017-07-02 21:00:00+00:00"},{"actual":126.43190466333122,"falling_edge":"2017-07-02 22:00:00+00:00","predicted":126.43190466333122,"rising_edge":"2017-07-02 21:30:00+00:00"},{"actual":110.43336098547563,"falling_edge":"2017-07-02 22:30:00+00:00","predicted":110.43336098547563,"rising_edge":"2017-07-02 22:00:00+00:00"},{"actual":130.28709204015158,"falling_edge":"2017-07-02 23:00:00+00:00","predicted":130.28709204015158,"rising_edge":"2017-07-02 22:30:00+00:00"},{"actual":158.78563708276837,"falling_edge":"2017-07-02 23:30:00+00:00","predicted":158.78563708276837,"rising_edge":"2017-07-02 23:00:00+00:00"},{"actual":200.9486331291908,"falling_edge":"2017-07-03 00:00:00+00:00","predicted":200.9486331291908,"rising_edge":"2017-07-02 23:30:00+00:00"},{"actual":214.46453849301008,"falling_edge":"2017-07-03 00:30:00+00:00","predicted":214.46453849301008,"rising_edge":"2017-07-03 00:00:00+00:00"},{"actual":217.0850665211394,"falling_edge":"2017-07-03 01:00:00+00:00","predicted":217.0850665211394,"rising_edge":"2017-07-03 00:30:00+00:00"},{"actual":224.22945030325843,"falling_edge":"2017-07-03 01:30:00+00:00","predicted":224.22945030325843,"rising_edge":"2017-07-03 01:00:00+00:00"},{"actual":222.84273348587007,"falling_edge":"2017-07-03 02:00:00+00:00","predicted":222.84273348587007,"rising_edge":"2017-07-03 01:30:00+00:00"},{"actual":220.09697035299473,"falling_edge":"2017-07-03 02:30:00+00:00","predicted":220.09697035299473,"rising_edge":"2017-07-03 02:00:00+00:00"},{"actual":218.25679923261276,"falling_edge":"2017-07-03 03:00:00+00:00","predicted":218.25679923261276,"rising_edge":"2017-07-03 02:30:00+00:00"},{"actual":214.14184659781358,"falling_edge":"2017-07-03 03:30:00+00:00","predicted":214.14184659781358,"rising_edge":"2017-07-03 03:00:00+00:00"},{"actual":196.8695402471554,"falling_edge":"2017-07-03 04:00:00+00:00","predicted":196.8695402471554,"rising_edge":"2017-07-03 03:30:00+00:00"},{"actual":211.12859338435453,"falling_edge":"2017-07-03 04:30:00+00:00","predicted":211.12859338435453,"rising_edge":"2017-07-03 04:00:00+00:00"},{"actual":208.50923966422005,"falling_edge":"2017-07-03 05:00:00+00:00","predicted":208.50923966422005,"rising_edge":"2017-07-03 04:30:00+00:00"},{"actual":206.35827313633422,"falling_edge":"2017-07-03 05:30:00+00:00","predicted":206.35827313633422,"rising_edge":"2017-07-03 05:00:00+00:00"},{"actual":207.52451288695616,"falling_edge":"2017-07-03 06:00:00+00:00","predicted":207.52451288695616,"rising_edge":"2017-07-03 05:30:00+00:00"},{"actual":213.04807708221347,"falling_edge":"2017-07-03 06:30:00+00:00","predicted":213.04807708221347,"rising_edge":"2017-07-03 06:00:00+00:00"},{"actual":215.24766745916344,"falling_edge":"2017-07-03 07:00:00+00:00","predicted":215.24766745916344,"rising_edge":"2017-07-03 06:30:00+00:00"},{"actual":211.52467410138468,"falling_edge":"2017-07-03 07:30:00+00:00","predicted":211.52467410138468,"rising_edge":"2017-07-03 07:00:00+00:00"},{"actual":208.49670519376502,"falling_edge":"2017-07-03 08:00:00+00:00","predicted":208.49670519376502,"rising_edge":"2017-07-03 07:30:00+00:00"},{"actual":211.66347951676593,"falling_edge":"2017-07-03 08:30:00+00:00","predicted":211.66347951676593,"rising_edge":"2017-07-03 08:00:00+00:00"},{"actual":198.8631678923863,"falling_edge":"2017-07-03 09:00:00+00:00","predicted":198.8631678923863,"rising_edge":"2017-07-03 08:30:00+00:00"},{"actual":170.70797622671887,"falling_edge":"2017-07-03 09:30:00+00:00","predicted":170.70797622671887,"rising_edge":"2017-07-03 09:00:00+00:00"},{"actual":158.07526827270505,"falling_edge":"2017-07-03 10:00:00+00:00","predicted":158.07526827270505,"rising_edge":"2017-07-03 09:30:00+00:00"},{"actual":135.4388861733956,"falling_edge":"2017-07-03 10:30:00+00:00","predicted":135.4388861733956,"rising_edge":"2017-07-03 10:00:00+00:00"},{"actual":131.74151918488468,"falling_edge":"2017-07-03 11:00:00+00:00","predicted":131.74151918488468,"rising_edge":"2017-07-03 10:30:00+00:00"},{"actual":124.163227699957,"falling_edge":"2017-07-03 11:30:00+00:00","predicted":124.163227699957,"rising_edge":"2017-07-03 11:00:00+00:00"},{"actual":112.2088041121433,"falling_edge":"2017-07-03 12:00:00+00:00","predicted":112.2088041121433,"rising_edge":"2017-07-03 11:30:00+00:00"},{"actual":101.04678931510966,"falling_edge":"2017-07-03 12:30:00+00:00","predicted":101.04678931510966,"rising_edge":"2017-07-03 12:00:00+00:00"},{"actual":93.36111416486159,"falling_edge":"2017-07-03 13:00:00+00:00","predicted":93.36111416486159,"rising_edge":"2017-07-03 12:30:00+00:00"},{"actual":85.58114685081433,"falling_edge":"2017-07-03 13:30:00+00:00","predicted":85.58114685081433,"rising_edge":"2017-07-03 13:00:00+00:00"},{"actual":74.20860960413054,"falling_edge":"2017-07-03 14:00:00+00:00","predicted":74.20860960413054,"rising_edge":"2017-07-03 13:30:00+00:00"},{"actual":64.1624151850402,"falling_edge":"2017-07-03 14:30:00+00:00","predicted":64.1624151850402,"rising_edge":"2017-07-03 14:00:00+00:00"},{"actual":56.91119643748203,"falling_edge":"2017-07-03 15:00:00+00:00","predicted":56.91119643748203,"rising_edge":"2017-07-03 14:30:00+00:00"},{"actual":52.06326229726732,"falling_edge":"2017-07-03 15:30:00+00:00","predicted":52.06326229726732,"rising_edge":"2017-07-03 15:00:00+00:00"},{"actual":47.86406831736378,"falling_edge":"2017-07-03 16:00:00+00:00","predicted":47.86406831736378,"rising_edge":"2017-07-03 15:30:00+00:00"},{"actual":46.70266335100992,"falling_edge":"2017-07-03 16:30:00+00:00","predicted":46.70266335100992,"rising_edge":"2017-07-03 16:00:00+00:00"},{"actual":46.13170476216933,"falling_edge":"2017-07-03 17:00:00+00:00","predicted":46.13170476216933,"rising_edge":"2017-07-03 16:30:00+00:00"},{"actual":46.050663802369044,"falling_edge":"2017-07-03 17:30:00+00:00","predicted":46.050663802369044,"rising_edge":"2017-07-03 17:00:00+00:00"},{"actual":45.35372089340315,"falling_edge":"2017-07-03 18:00:00+00:00","predicted":45.35372089340315,"rising_edge":"2017-07-03 17:30:00+00:00"},{"actual":45.21408423915497,"falling_edge":"2017-07-03 18:30:00+00:00","predicted":45.21408423915497,"rising_edge":"2017-07-03 18:00:00+00:00"},{"actual":44.6246001926098,"falling_edge":"2017-07-03 19:00:00+00:00","predicted":44.6246001926098,"rising_edge":"2017-07-03 18:30:00+00:00"},{"actual":45.02464315609231,"falling_edge":"2017-07-03 19:30:00+00:00","predicted":45.02464315609231,"rising_edge":"2017-07-03 19:00:00+00:00"},{"actual":44.28952208801992,"falling_edge":"2017-07-03 20:00:00+00:00","predicted":44.28952208801992,"rising_edge":"2017-07-03 19:30:00+00:00"},{"actual":46.28182759177426,"falling_edge":"2017-07-03 20:30:00+00:00","predicted":46.28182759177426,"rising_edge":"2017-07-03 20:00:00+00:00"},{"actual":51.13249694957967,"falling_edge":"2017-07-03 21:00:00+00:00","predicted":51.13249694957967,"rising_edge":"2017-07-03 20:30:00+00:00"},{"actual":67.86006060681797,"falling_edge":"2017-07-03 21:30:00+00:00","predicted":67.86006060681797,"rising_edge":"2017-07-03 21:00:00+00:00"},{"actual":106.71198206573257,"falling_edge":"2017-07-03 22:00:00+00:00","predicted":106.71198206573257,"rising_edge":"2017-07-03 21:30:00+00:00"},{"actual":104.84381714930883,"falling_edge":"2017-07-03 22:30:00+00:00","predicted":104.84381714930883,"rising_edge":"2017-07-03 22:00:00+00:00"},{"actual":130.71156885234706,"falling_edge":"2017-07-03 23:00:00+00:00","predicted":130.71156885234706,"rising_edge":"2017-07-03 22:30:00+00:00"},{"actual":166.7766199871199,"falling_edge":"2017-07-03 23:30:00+00:00","predicted":166.7766199871199,"rising_edge":"2017-07-03 23:00:00+00:00"},{"actual":205.32041834128827,"falling_edge":"2017-07-04 00:00:00+00:00","predicted":205.32041834128827,"rising_edge":"2017-07-03 23:30:00+00:00"},{"actual":213.01962931317627,"falling_edge":"2017-07-04 00:30:00+00:00","predicted":213.01962931317627,"rising_edge":"2017-07-04 00:00:00+00:00"},{"actual":217.56849658186587,"falling_edge":"2017-07-04 01:00:00+00:00","predicted":217.56849658186587,"rising_edge":"2017-07-04 00:30:00+00:00"},{"actual":217.2340318973378,"falling_edge":"2017-07-04 01:30:00+00:00","predicted":217.2340318973378,"rising_edge":"2017-07-04 01:00:00+00:00"},{"actual":216.82869065718876,"falling_edge":"2017-07-04 02:00:00+00:00","predicted":216.82869065718876,"rising_edge":"2017-07-04 01:30:00+00:00"},{"actual":209.45032311899917,"falling_edge":"2017-07-04 02:30:00+00:00","predicted":209.45032311899917,"rising_edge":"2017-07-04 02:00:00+00:00"},{"actual":200.49969089924105,"falling_edge":"2017-07-04 03:00:00+00:00","predicted":200.49969089924105,"rising_edge":"2017-07-04 02:30:00+00:00"},{"actual":193.37270748786574,"falling_edge":"2017-07-04 03:30:00+00:00","predicted":193.37270748786574,"rising_edge":"2017-07-04 03:00:00+00:00"},{"actual":187.39077012007468,"falling_edge":"2017-07-04 04:00:00+00:00","predicted":187.39077012007468,"rising_edge":"2017-07-04 03:30:00+00:00"},{"actual":196.5540199820921,"falling_edge":"2017-07-04 04:30:00+00:00","predicted":196.5540199820921,"rising_edge":"2017-07-04 04:00:00+00:00"},{"actual":194.96322204578237,"falling_edge":"2017-07-04 05:00:00+00:00","predicted":194.96322204578237,"rising_edge":"2017-07-04 04:30:00+00:00"},{"actual":192.1558888059677,"falling_edge":"2017-07-04 05:30:00+00:00","predicted":192.1558888059677,"rising_edge":"2017-07-04 05:00:00+00:00"},{"actual":199.30324053199317,"falling_edge":"2017-07-04 06:00:00+00:00","predicted":199.30324053199317,"rising_edge":"2017-07-04 05:30:00+00:00"},{"actual":197.0280186007689,"falling_edge":"2017-07-04 06:30:00+00:00","predicted":197.0280186007689,"rising_edge":"2017-07-04 06:00:00+00:00"},{"actual":198.84627915778643,"falling_edge":"2017-07-04 07:00:00+00:00","predicted":198.84627915778643,"rising_edge":"2017-07-04 06:30:00+00:00"},{"actual":196.57177910486186,"falling_edge":"2017-07-04 07:30:00+00:00","predicted":196.57177910486186,"rising_edge":"2017-07-04 07:00:00+00:00"},{"actual":196.30647705982346,"falling_edge":"2017-07-04 08:00:00+00:00","predicted":196.30647705982346,"rising_edge":"2017-07-04 07:30:00+00:00"},{"actual":201.45496467317975,"falling_edge":"2017-07-04 08:30:00+00:00","predicted":201.45496467317975,"rising_edge":"2017-07-04 08:00:00+00:00"},{"actual":196.1229852292311,"falling_edge":"2017-07-04 09:00:00+00:00","predicted":196.1229852292311,"rising_edge":"2017-07-04 08:30:00+00:00"},{"actual":168.38448300193082,"falling_edge":"2017-07-04 09:30:00+00:00","predicted":168.38448300193082,"rising_edge":"2017-07-04 09:00:00+00:00"},{"actual":157.6615934247332,"falling_edge":"2017-07-04 10:00:00+00:00","predicted":157.6615934247332,"rising_edge":"2017-07-04 09:30:00+00:00"},{"actual":138.6120149991092,"falling_edge":"2017-07-04 10:30:00+00:00","predicted":138.6120149991092,"rising_edge":"2017-07-04 10:00:00+00:00"},{"actual":136.17920760335997,"falling_edge":"2017-07-04 11:00:00+00:00","predicted":136.17920760335997,"rising_edge":"2017-07-04 10:30:00+00:00"},{"actual":129.16347866979476,"falling_edge":"2017-07-04 11:30:00+00:00","predicted":129.16347866979476,"rising_edge":"2017-07-04 11:00:00+00:00"},{"actual":119.58863195965827,"falling_edge":"2017-07-04 12:00:00+00:00","predicted":119.58863195965827,"rising_edge":"2017-07-04 11:30:00+00:00"},{"actual":108.83173594473458,"falling_edge":"2017-07-04 12:30:00+00:00","predicted":108.83173594473458,"rising_edge":"2017-07-04 12:00:00+00:00"},{"actual":97.35865966527088,"falling_edge":"2017-07-04 13:00:00+00:00","predicted":97.35865966527088,"rising_edge":"2017-07-04 12:30:00+00:00"},{"actual":88.79889895978643,"falling_edge":"2017-07-04 13:30:00+00:00","predicted":88.79889895978643,"rising_edge":"2017-07-04 13:00:00+00:00"},{"actual":75.62947229792867,"falling_edge":"2017-07-04 14:00:00+00:00","predicted":75.62947229792867,"rising_edge":"2017-07-04 13:30:00+00:00"},{"actual":65.39702207103429,"falling_edge":"2017-07-04 14:30:00+00:00","predicted":65.39702207103429,"rising_edge":"2017-07-04 14:00:00+00:00"},{"actual":58.09814842581181,"falling_edge":"2017-07-04 15:00:00+00:00","predicted":58.09814842581181,"rising_edge":"2017-07-04 14:30:00+00:00"},{"actual":54.419085926775985,"falling_edge":"2017-08-08 15:30:00+00:00","predicted":54.419085926775985,"rising_edge":"2017-08-08 15:00:00+00:00"},{"actual":51.23820847348304,"falling_edge":"2017-08-08 16:00:00+00:00","predicted":51.23820847348304,"rising_edge":"2017-08-08 15:30:00+00:00"},{"actual":52.336659700061105,"falling_edge":"2017-08-08 16:30:00+00:00","predicted":52.336659700061105,"rising_edge":"2017-08-08 16:00:00+00:00"},{"actual":49.459448624949,"falling_edge":"2017-08-08 17:00:00+00:00","predicted":49.459448624949,"rising_edge":"2017-08-08 16:30:00+00:00"},{"actual":48.258249389230784,"falling_edge":"2017-08-08 17:30:00+00:00","predicted":48.258249389230784,"rising_edge":"2017-08-08 17:00:00+00:00"},{"actual":47.86282913085337,"falling_edge":"2017-08-08 18:00:00+00:00","predicted":47.86282913085337,"rising_edge":"2017-08-08 17:30:00+00:00"},{"actual":45.879065348711435,"falling_edge":"2017-08-08 18:30:00+00:00","predicted":45.879065348711435,"rising_edge":"2017-08-08 18:00:00+00:00"},{"actual":44.76760502584984,"falling_edge":"2017-08-08 19:00:00+00:00","predicted":44.76760502584984,"rising_edge":"2017-08-08 18:30:00+00:00"},{"actual":45.99671317866938,"falling_edge":"2017-08-08 19:30:00+00:00","predicted":45.99671317866938,"rising_edge":"2017-08-08 19:00:00+00:00"},{"actual":46.059930781987724,"falling_edge":"2017-08-08 20:00:00+00:00","predicted":46.059930781987724,"rising_edge":"2017-08-08 19:30:00+00:00"},{"actual":47.49826695511959,"falling_edge":"2017-08-08 20:30:00+00:00","predicted":47.49826695511959,"rising_edge":"2017-08-08 20:00:00+00:00"},{"actual":52.479354790599636,"falling_edge":"2017-08-08 21:00:00+00:00","predicted":52.479354790599636,"rising_edge":"2017-08-08 20:30:00+00:00"},{"actual":70.19004598012893,"falling_edge":"2017-08-08 21:30:00+00:00","predicted":70.19004598012893,"rising_edge":"2017-08-08 21:00:00+00:00"},{"actual":102.89920780007665,"falling_edge":"2017-08-08 22:00:00+00:00","predicted":102.89920780007665,"rising_edge":"2017-08-08 21:30:00+00:00"},{"actual":99.58516453179436,"falling_edge":"2017-08-08 22:30:00+00:00","predicted":99.58516453179436,"rising_edge":"2017-08-08 22:00:00+00:00"},{"actual":122.53490272879391,"falling_edge":"2017-08-08 23:00:00+00:00","predicted":122.53490272879391,"rising_edge":"2017-08-08 22:30:00+00:00"},{"actual":168.05066249271073,"falling_edge":"2017-08-08 23:30:00+00:00","predicted":168.05066249271073,"rising_edge":"2017-08-08 23:00:00+00:00"},{"actual":209.6246274131777,"falling_edge":"2017-08-09 00:00:00+00:00","predicted":209.6246274131777,"rising_edge":"2017-08-08 23:30:00+00:00"},{"actual":224.62580579894112,"falling_edge":"2017-08-09 00:30:00+00:00","predicted":224.62580579894112,"rising_edge":"2017-08-09 00:00:00+00:00"},{"actual":220.43228942114544,"falling_edge":"2017-08-09 01:00:00+00:00","predicted":220.43228942114544,"rising_edge":"2017-08-09 00:30:00+00:00"},{"actual":231.00886216218663,"falling_edge":"2017-08-09 01:30:00+00:00","predicted":231.00886216218663,"rising_edge":"2017-08-09 01:00:00+00:00"},{"actual":223.25447131798364,"falling_edge":"2017-08-09 02:00:00+00:00","predicted":223.25447131798364,"rising_edge":"2017-08-09 01:30:00+00:00"},{"actual":233.89392089989704,"falling_edge":"2017-08-09 02:30:00+00:00","predicted":233.89392089989704,"rising_edge":"2017-08-09 02:00:00+00:00"},{"actual":229.11826102692214,"falling_edge":"2017-08-09 03:00:00+00:00","predicted":229.11826102692214,"rising_edge":"2017-08-09 02:30:00+00:00"},{"actual":220.3374067628817,"falling_edge":"2017-08-09 03:30:00+00:00","predicted":220.3374067628817,"rising_edge":"2017-08-09 03:00:00+00:00"},{"actual":214.14851330576653,"falling_edge":"2017-08-09 04:00:00+00:00","predicted":214.14851330576653,"rising_edge":"2017-08-09 03:30:00+00:00"},{"actual":226.33421570365627,"falling_edge":"2017-08-09 04:30:00+00:00","predicted":226.33421570365627,"rising_edge":"2017-08-09 04:00:00+00:00"},{"actual":224.4259874116268,"falling_edge":"2017-08-09 05:00:00+00:00","predicted":224.4259874116268,"rising_edge":"2017-08-09 04:30:00+00:00"},{"actual":216.84949617588822,"falling_edge":"2017-08-09 05:30:00+00:00","predicted":216.84949617588822,"rising_edge":"2017-08-09 05:00:00+00:00"},{"actual":220.92558068561664,"falling_edge":"2017-08-09 06:00:00+00:00","predicted":220.92558068561664,"rising_edge":"2017-08-09 05:30:00+00:00"},{"actual":232.586734025574,"falling_edge":"2017-08-09 06:30:00+00:00","predicted":232.586734025574,"rising_edge":"2017-08-09 06:00:00+00:00"},{"actual":234.24712918877538,"falling_edge":"2017-08-09 07:00:00+00:00","predicted":234.24712918877538,"rising_edge":"2017-08-09 06:30:00+00:00"},{"actual":229.12594073987609,"falling_edge":"2017-08-09 07:30:00+00:00","predicted":229.12594073987609,"rising_edge":"2017-08-09 07:00:00+00:00"},{"actual":225.98455318833285,"falling_edge":"2017-08-09 08:00:00+00:00","predicted":225.98455318833285,"rising_edge":"2017-08-09 07:30:00+00:00"},{"actual":223.4330976938116,"falling_edge":"2017-08-09 08:30:00+00:00","predicted":223.4330976938116,"rising_edge":"2017-08-09 08:00:00+00:00"},{"actual":211.35302465766625,"falling_edge":"2017-08-09 09:00:00+00:00","predicted":211.35302465766625,"rising_edge":"2017-08-09 08:30:00+00:00"},{"actual":177.33742857027198,"falling_edge":"2017-08-09 09:30:00+00:00","predicted":177.33742857027198,"rising_edge":"2017-08-09 09:00:00+00:00"},{"actual":158.58345782937704,"falling_edge":"2017-08-09 10:00:00+00:00","predicted":158.58345782937704,"rising_edge":"2017-08-09 09:30:00+00:00"},{"actual":127.99358293740666,"falling_edge":"2017-08-09 10:30:00+00:00","predicted":127.99358293740666,"rising_edge":"2017-08-09 10:00:00+00:00"},{"actual":122.43274726541982,"falling_edge":"2017-08-09 11:00:00+00:00","predicted":122.43274726541982,"rising_edge":"2017-08-09 10:30:00+00:00"},{"actual":114.05361356932781,"falling_edge":"2017-08-09 11:30:00+00:00","predicted":114.05361356932781,"rising_edge":"2017-08-09 11:00:00+00:00"},{"actual":109.18505163290635,"falling_edge":"2017-08-09 12:00:00+00:00","predicted":109.18505163290635,"rising_edge":"2017-08-09 11:30:00+00:00"},{"actual":101.70700052171712,"falling_edge":"2017-08-09 12:30:00+00:00","predicted":101.70700052171712,"rising_edge":"2017-08-09 12:00:00+00:00"},{"actual":93.51210641970644,"falling_edge":"2017-08-09 13:00:00+00:00","predicted":93.51210641970644,"rising_edge":"2017-08-09 12:30:00+00:00"},{"actual":80.7938739808895,"falling_edge":"2017-08-09 13:30:00+00:00","predicted":80.7938739808895,"rising_edge":"2017-08-09 13:00:00+00:00"},{"actual":70.89748761721911,"falling_edge":"2017-08-09 14:00:00+00:00","predicted":70.89748761721911,"rising_edge":"2017-08-09 13:30:00+00:00"},{"actual":63.03782769630544,"falling_edge":"2017-08-09 14:30:00+00:00","predicted":63.03782769630544,"rising_edge":"2017-08-09 14:00:00+00:00"},{"actual":56.86744763935753,"falling_edge":"2017-08-09 15:00:00+00:00","predicted":56.86744763935753,"rising_edge":"2017-08-09 14:30:00+00:00"},{"actual":52.396334031772405,"falling_edge":"2017-08-09 15:30:00+00:00","predicted":52.396334031772405,"rising_edge":"2017-08-09 15:00:00+00:00"},{"actual":49.6939243811914,"falling_edge":"2017-08-09 16:00:00+00:00","predicted":49.6939243811914,"rising_edge":"2017-08-09 15:30:00+00:00"},{"actual":47.26113346313511,"falling_edge":"2017-08-09 16:30:00+00:00","predicted":47.26113346313511,"rising_edge":"2017-08-09 16:00:00+00:00"},{"actual":47.19974380544476,"falling_edge":"2017-08-09 17:00:00+00:00","predicted":47.19974380544476,"rising_edge":"2017-08-09 16:30:00+00:00"},{"actual":48.16055340502203,"falling_edge":"2017-08-09 17:30:00+00:00","predicted":48.16055340502203,"rising_edge":"2017-08-09 17:00:00+00:00"},{"actual":47.640333276435506,"falling_edge":"2017-08-09 18:00:00+00:00","predicted":47.640333276435506,"rising_edge":"2017-08-09 17:30:00+00:00"},{"actual":46.89446660678482,"falling_edge":"2017-08-09 18:30:00+00:00","predicted":46.89446660678482,"rising_edge":"2017-08-09 18:00:00+00:00"},{"actual":46.482052037348545,"falling_edge":"2017-08-09 19:00:00+00:00","predicted":46.482052037348545,"rising_edge":"2017-08-09 18:30:00+00:00"},{"actual":46.179518257957156,"falling_edge":"2017-08-09 19:30:00+00:00","predicted":46.179518257957156,"rising_edge":"2017-08-09 19:00:00+00:00"},{"actual":46.32751814873525,"falling_edge":"2017-08-09 20:00:00+00:00","predicted":46.32751814873525,"rising_edge":"2017-08-09 19:30:00+00:00"},{"actual":47.532361005058654,"falling_edge":"2017-08-09 20:30:00+00:00","predicted":47.532361005058654,"rising_edge":"2017-08-09 20:00:00+00:00"},{"actual":52.660325708178604,"falling_edge":"2017-08-09 21:00:00+00:00","predicted":52.660325708178604,"rising_edge":"2017-08-09 20:30:00+00:00"},{"actual":71.33435419543473,"falling_edge":"2017-08-09 21:30:00+00:00","predicted":71.33435419543473,"rising_edge":"2017-08-09 21:00:00+00:00"},{"actual":107.49251270949783,"falling_edge":"2017-08-09 22:00:00+00:00","predicted":107.49251270949783,"rising_edge":"2017-08-09 21:30:00+00:00"},{"actual":105.46834218078376,"falling_edge":"2017-08-09 22:30:00+00:00","predicted":105.46834218078376,"rising_edge":"2017-08-09 22:00:00+00:00"},{"actual":127.67159072498572,"falling_edge":"2017-08-09 23:00:00+00:00","predicted":127.67159072498572,"rising_edge":"2017-08-09 22:30:00+00:00"},{"actual":164.83243025527074,"falling_edge":"2017-08-09 23:30:00+00:00","predicted":164.83243025527074,"rising_edge":"2017-08-09 23:00:00+00:00"},{"actual":205.11066164996942,"falling_edge":"2017-08-10 00:00:00+00:00","predicted":205.11066164996942,"rising_edge":"2017-08-09 23:30:00+00:00"},{"actual":218.03073622597242,"falling_edge":"2017-08-10 00:30:00+00:00","predicted":218.03073622597242,"rising_edge":"2017-08-10 00:00:00+00:00"},{"actual":218.89801257923946,"falling_edge":"2017-08-10 01:00:00+00:00","predicted":218.89801257923946,"rising_edge":"2017-08-10 00:30:00+00:00"},{"actual":227.27282878092146,"falling_edge":"2017-08-10 01:30:00+00:00","predicted":227.27282878092146,"rising_edge":"2017-08-10 01:00:00+00:00"},{"actual":229.84070011774256,"falling_edge":"2017-08-10 02:00:00+00:00","predicted":229.84070011774256,"rising_edge":"2017-08-10 01:30:00+00:00"},{"actual":230.33550470918743,"falling_edge":"2017-08-10 02:30:00+00:00","predicted":230.33550470918743,"rising_edge":"2017-08-10 02:00:00+00:00"},{"actual":222.46444513065555,"falling_edge":"2017-08-10 03:00:00+00:00","predicted":222.46444513065555,"rising_edge":"2017-08-10 02:30:00+00:00"},{"actual":215.52780973782404,"falling_edge":"2017-08-10 03:30:00+00:00","predicted":215.52780973782404,"rising_edge":"2017-08-10 03:00:00+00:00"},{"actual":210.26690190040955,"falling_edge":"2017-08-10 04:00:00+00:00","predicted":210.26690190040955,"rising_edge":"2017-08-10 03:30:00+00:00"},{"actual":222.9003768524504,"falling_edge":"2017-08-10 04:30:00+00:00","predicted":222.9003768524504,"rising_edge":"2017-08-10 04:00:00+00:00"},{"actual":223.9042211153032,"falling_edge":"2017-08-10 05:00:00+00:00","predicted":223.9042211153032,"rising_edge":"2017-08-10 04:30:00+00:00"},{"actual":231.1482458694368,"falling_edge":"2017-08-10 05:30:00+00:00","predicted":231.1482458694368,"rising_edge":"2017-08-10 05:00:00+00:00"},{"actual":239.32240626637224,"falling_edge":"2017-08-10 06:00:00+00:00","predicted":239.32240626637224,"rising_edge":"2017-08-10 05:30:00+00:00"},{"actual":245.48757544050062,"falling_edge":"2017-08-10 06:30:00+00:00","predicted":245.48757544050062,"rising_edge":"2017-08-10 06:00:00+00:00"},{"actual":240.114477900543,"falling_edge":"2017-08-10 07:00:00+00:00","predicted":240.114477900543,"rising_edge":"2017-08-10 06:30:00+00:00"},{"actual":246.48640488604013,"falling_edge":"2017-08-10 07:30:00+00:00","predicted":246.48640488604013,"rising_edge":"2017-08-10 07:00:00+00:00"},{"actual":254.13610481918548,"falling_edge":"2017-08-10 08:00:00+00:00","predicted":254.13610481918548,"rising_edge":"2017-08-10 07:30:00+00:00"},{"actual":252.85083952213319,"falling_edge":"2017-08-10 08:30:00+00:00","predicted":252.85083952213319,"rising_edge":"2017-08-10 08:00:00+00:00"},{"actual":233.98971481414517,"falling_edge":"2017-08-10 09:00:00+00:00","predicted":233.98971481414517,"rising_edge":"2017-08-10 08:30:00+00:00"},{"actual":201.18736614307358,"falling_edge":"2017-08-10 09:30:00+00:00","predicted":201.18736614307358,"rising_edge":"2017-08-10 09:00:00+00:00"},{"actual":177.68129164179012,"falling_edge":"2017-08-10 10:00:00+00:00","predicted":177.68129164179012,"rising_edge":"2017-08-10 09:30:00+00:00"},{"actual":152.0605413482581,"falling_edge":"2017-08-10 10:30:00+00:00","predicted":152.0605413482581,"rising_edge":"2017-08-10 10:00:00+00:00"},{"actual":147.89491759106636,"falling_edge":"2017-08-10 11:00:00+00:00","predicted":147.89491759106636,"rising_edge":"2017-08-10 10:30:00+00:00"},{"actual":136.9424113919971,"falling_edge":"2017-08-10 11:30:00+00:00","predicted":136.9424113919971,"rising_edge":"2017-08-10 11:00:00+00:00"},{"actual":123.98025540885497,"falling_edge":"2017-08-10 12:00:00+00:00","predicted":123.98025540885497,"rising_edge":"2017-08-10 11:30:00+00:00"},{"actual":113.6502494957401,"falling_edge":"2017-08-10 12:30:00+00:00","predicted":113.6502494957401,"rising_edge":"2017-08-10 12:00:00+00:00"},{"actual":100.5656239253851,"falling_edge":"2017-08-10 13:00:00+00:00","predicted":100.5656239253851,"rising_edge":"2017-08-10 12:30:00+00:00"},{"actual":86.79452900580628,"falling_edge":"2017-08-10 13:30:00+00:00","predicted":86.79452900580628,"rising_edge":"2017-08-10 13:00:00+00:00"},{"actual":76.81510438983739,"falling_edge":"2017-08-10 14:00:00+00:00","predicted":76.81510438983739,"rising_edge":"2017-08-10 13:30:00+00:00"},{"actual":70.03246291131575,"falling_edge":"2017-08-10 14:30:00+00:00","predicted":70.03246291131575,"rising_edge":"2017-08-10 14:00:00+00:00"},{"actual":62.25419580093924,"falling_edge":"2017-08-10 15:00:00+00:00","predicted":62.25419580093924,"rising_edge":"2017-08-10 14:30:00+00:00"},{"actual":54.518796300605146,"falling_edge":"2017-08-10 15:30:00+00:00","predicted":54.518796300605146,"rising_edge":"2017-08-10 15:00:00+00:00"},{"actual":49.31647355762566,"falling_edge":"2017-08-10 16:00:00+00:00","predicted":49.31647355762566,"rising_edge":"2017-08-10 15:30:00+00:00"},{"actual":47.73225667089444,"falling_edge":"2017-08-10 16:30:00+00:00","predicted":47.73225667089444,"rising_edge":"2017-08-10 16:00:00+00:00"},{"actual":48.528962412375336,"falling_edge":"2017-08-10 17:00:00+00:00","predicted":48.528962412375336,"rising_edge":"2017-08-10 16:30:00+00:00"},{"actual":48.3078040876235,"falling_edge":"2017-08-10 17:30:00+00:00","predicted":48.3078040876235,"rising_edge":"2017-08-10 17:00:00+00:00"},{"actual":46.48243815388582,"falling_edge":"2017-08-10 18:00:00+00:00","predicted":46.48243815388582,"rising_edge":"2017-08-10 17:30:00+00:00"},{"actual":47.19285883498315,"falling_edge":"2017-08-10 18:30:00+00:00","predicted":47.19285883498315,"rising_edge":"2017-08-10 18:00:00+00:00"},{"actual":47.05125592870837,"falling_edge":"2017-08-10 19:00:00+00:00","predicted":47.05125592870837,"rising_edge":"2017-08-10 18:30:00+00:00"},{"actual":47.93107576374616,"falling_edge":"2017-08-10 19:30:00+00:00","predicted":47.93107576374616,"rising_edge":"2017-08-10 19:00:00+00:00"},{"actual":46.52930735227755,"falling_edge":"2017-08-10 20:00:00+00:00","predicted":46.52930735227755,"rising_edge":"2017-08-10 19:30:00+00:00"},{"actual":48.53137183475149,"falling_edge":"2017-08-10 20:30:00+00:00","predicted":48.53137183475149,"rising_edge":"2017-08-10 20:00:00+00:00"},{"actual":53.1514030160058,"falling_edge":"2017-08-10 21:00:00+00:00","predicted":53.1514030160058,"rising_edge":"2017-08-10 20:30:00+00:00"},{"actual":69.55634074260946,"falling_edge":"2017-08-10 21:30:00+00:00","predicted":69.55634074260946,"rising_edge":"2017-08-10 21:00:00+00:00"},{"actual":111.06862878290262,"falling_edge":"2017-08-10 22:00:00+00:00","predicted":111.06862878290262,"rising_edge":"2017-08-10 21:30:00+00:00"},{"actual":109.1375341790687,"falling_edge":"2017-08-10 22:30:00+00:00","predicted":109.1375341790687,"rising_edge":"2017-08-10 22:00:00+00:00"},{"actual":125.467239150148,"falling_edge":"2017-08-10 23:00:00+00:00","predicted":125.467239150148,"rising_edge":"2017-08-10 22:30:00+00:00"},{"actual":158.85248435243778,"falling_edge":"2017-08-10 23:30:00+00:00","predicted":158.85248435243778,"rising_edge":"2017-08-10 23:00:00+00:00"},{"actual":207.63953428637095,"falling_edge":"2017-08-11 00:00:00+00:00","predicted":207.63953428637095,"rising_edge":"2017-08-10 23:30:00+00:00"},{"actual":227.43749202500834,"falling_edge":"2017-08-11 00:30:00+00:00","predicted":227.43749202500834,"rising_edge":"2017-08-11 00:00:00+00:00"},{"actual":218.85112513156767,"falling_edge":"2017-08-11 01:00:00+00:00","predicted":218.85112513156767,"rising_edge":"2017-08-11 00:30:00+00:00"},{"actual":229.46973823615272,"falling_edge":"2017-08-11 01:30:00+00:00","predicted":229.46973823615272,"rising_edge":"2017-08-11 01:00:00+00:00"},{"actual":229.61930662892865,"falling_edge":"2017-08-11 02:00:00+00:00","predicted":229.61930662892865,"rising_edge":"2017-08-11 01:30:00+00:00"},{"actual":223.63400991433818,"falling_edge":"2017-08-11 02:30:00+00:00","predicted":223.63400991433818,"rising_edge":"2017-08-11 02:00:00+00:00"},{"actual":219.52888456962089,"falling_edge":"2017-08-11 03:00:00+00:00","predicted":219.52888456962089,"rising_edge":"2017-08-11 02:30:00+00:00"},{"actual":225.75168293366195,"falling_edge":"2017-08-11 03:30:00+00:00","predicted":225.75168293366195,"rising_edge":"2017-08-11 03:00:00+00:00"},{"actual":213.7612536262905,"falling_edge":"2017-08-11 04:00:00+00:00","predicted":213.7612536262905,"rising_edge":"2017-08-11 03:30:00+00:00"},{"actual":232.01489612711583,"falling_edge":"2017-08-11 04:30:00+00:00","predicted":232.01489612711583,"rising_edge":"2017-08-11 04:00:00+00:00"},{"actual":239.90707432822646,"falling_edge":"2017-08-11 05:00:00+00:00","predicted":239.90707432822646,"rising_edge":"2017-08-11 04:30:00+00:00"},{"actual":232.05125626523227,"falling_edge":"2017-08-11 05:30:00+00:00","predicted":232.05125626523227,"rising_edge":"2017-08-11 05:00:00+00:00"},{"actual":233.78132768030775,"falling_edge":"2017-08-11 06:00:00+00:00","predicted":233.78132768030775,"rising_edge":"2017-08-11 05:30:00+00:00"},{"actual":232.5087118157547,"falling_edge":"2017-08-11 06:30:00+00:00","predicted":232.5087118157547,"rising_edge":"2017-08-11 06:00:00+00:00"},{"actual":241.02575069013713,"falling_edge":"2017-08-11 07:00:00+00:00","predicted":241.02575069013713,"rising_edge":"2017-08-11 06:30:00+00:00"},{"actual":233.85584720604894,"falling_edge":"2017-08-11 07:30:00+00:00","predicted":233.85584720604894,"rising_edge":"2017-08-11 07:00:00+00:00"},{"actual":239.29722802935933,"falling_edge":"2017-08-11 08:00:00+00:00","predicted":239.29722802935933,"rising_edge":"2017-08-11 07:30:00+00:00"},{"actual":237.9870642011752,"falling_edge":"2017-08-11 08:30:00+00:00","predicted":237.9870642011752,"rising_edge":"2017-08-11 08:00:00+00:00"},{"actual":213.95817753774946,"falling_edge":"2017-08-11 09:00:00+00:00","predicted":213.95817753774946,"rising_edge":"2017-08-11 08:30:00+00:00"},{"actual":188.4414238565777,"falling_edge":"2017-08-11 09:30:00+00:00","predicted":188.4414238565777,"rising_edge":"2017-08-11 09:00:00+00:00"},{"actual":167.73106139800905,"falling_edge":"2017-08-11 10:00:00+00:00","predicted":167.73106139800905,"rising_edge":"2017-08-11 09:30:00+00:00"},{"actual":137.15851716378927,"falling_edge":"2017-08-11 10:30:00+00:00","predicted":137.15851716378927,"rising_edge":"2017-08-11 10:00:00+00:00"},{"actual":128.60248441902345,"falling_edge":"2017-08-11 11:00:00+00:00","predicted":128.60248441902345,"rising_edge":"2017-08-11 10:30:00+00:00"},{"actual":114.72371607166724,"falling_edge":"2017-08-11 11:30:00+00:00","predicted":114.72371607166724,"rising_edge":"2017-08-11 11:00:00+00:00"},{"actual":104.14129418876418,"falling_edge":"2017-08-11 12:00:00+00:00","predicted":104.14129418876418,"rising_edge":"2017-08-11 11:30:00+00:00"},{"actual":93.13421223042627,"falling_edge":"2017-08-11 12:30:00+00:00","predicted":93.13421223042627,"rising_edge":"2017-08-11 12:00:00+00:00"},{"actual":83.16040874480137,"falling_edge":"2017-08-11 13:00:00+00:00","predicted":83.16040874480137,"rising_edge":"2017-08-11 12:30:00+00:00"},{"actual":75.5929145242805,"falling_edge":"2017-08-11 13:30:00+00:00","predicted":75.5929145242805,"rising_edge":"2017-08-11 13:00:00+00:00"},{"actual":70.92882252331124,"falling_edge":"2017-08-11 14:00:00+00:00","predicted":70.92882252331124,"rising_edge":"2017-08-11 13:30:00+00:00"},{"actual":61.15213287983627,"falling_edge":"2017-08-11 14:30:00+00:00","predicted":61.15213287983627,"rising_edge":"2017-08-11 14:00:00+00:00"},{"actual":57.012246909185656,"falling_edge":"2017-08-11 15:00:00+00:00","predicted":57.012246909185656,"rising_edge":"2017-08-11 14:30:00+00:00"},{"actual":50.791750297058535,"falling_edge":"2017-08-11 15:30:00+00:00","predicted":50.791750297058535,"rising_edge":"2017-08-11 15:00:00+00:00"},{"actual":47.578063890584275,"falling_edge":"2017-08-11 16:00:00+00:00","predicted":47.578063890584275,"rising_edge":"2017-08-11 15:30:00+00:00"},{"actual":48.29035063765445,"falling_edge":"2017-08-11 16:30:00+00:00","predicted":48.29035063765445,"rising_edge":"2017-08-11 16:00:00+00:00"},{"actual":47.62216682182844,"falling_edge":"2017-08-11 17:00:00+00:00","predicted":47.62216682182844,"rising_edge":"2017-08-11 16:30:00+00:00"},{"actual":47.76746534368265,"falling_edge":"2017-08-11 17:30:00+00:00","predicted":47.76746534368265,"rising_edge":"2017-08-11 17:00:00+00:00"},{"actual":46.20651616344821,"falling_edge":"2017-08-11 18:00:00+00:00","predicted":46.20651616344821,"rising_edge":"2017-08-11 17:30:00+00:00"},{"actual":47.85745994538916,"falling_edge":"2017-08-11 18:30:00+00:00","predicted":47.85745994538916,"rising_edge":"2017-08-11 18:00:00+00:00"},{"actual":49.07291578013346,"falling_edge":"2017-08-11 19:00:00+00:00","predicted":49.07291578013346,"rising_edge":"2017-08-11 18:30:00+00:00"},{"actual":49.92375561400337,"falling_edge":"2017-08-11 19:30:00+00:00","predicted":49.92375561400337,"rising_edge":"2017-08-11 19:00:00+00:00"},{"actual":49.30311141342266,"falling_edge":"2017-08-11 20:00:00+00:00","predicted":49.30311141342266,"rising_edge":"2017-08-11 19:30:00+00:00"},{"actual":49.969680199397935,"falling_edge":"2017-08-11 20:30:00+00:00","predicted":49.969680199397935,"rising_edge":"2017-08-11 20:00:00+00:00"},{"actual":52.06484669117899,"falling_edge":"2017-08-11 21:00:00+00:00","predicted":52.06484669117899,"rising_edge":"2017-08-11 20:30:00+00:00"},{"actual":61.22727159651524,"falling_edge":"2017-08-11 21:30:00+00:00","predicted":61.22727159651524,"rising_edge":"2017-08-11 21:00:00+00:00"},{"actual":64.18972440597582,"falling_edge":"2017-08-11 22:00:00+00:00","predicted":64.18972440597582,"rising_edge":"2017-08-11 21:30:00+00:00"},{"actual":63.56193840870798,"falling_edge":"2017-08-11 22:30:00+00:00","predicted":63.56193840870798,"rising_edge":"2017-08-11 22:00:00+00:00"},{"actual":64.99328880472255,"falling_edge":"2017-08-11 23:00:00+00:00","predicted":64.99328880472255,"rising_edge":"2017-08-11 22:30:00+00:00"},{"actual":67.8933687477279,"falling_edge":"2017-08-11 23:30:00+00:00","predicted":67.8933687477279,"rising_edge":"2017-08-11 23:00:00+00:00"},{"actual":72.57292325555792,"falling_edge":"2017-08-12 00:00:00+00:00","predicted":72.57292325555792,"rising_edge":"2017-08-11 23:30:00+00:00"},{"actual":81.59780632925288,"falling_edge":"2017-08-12 00:30:00+00:00","predicted":81.59780632925288,"rising_edge":"2017-08-12 00:00:00+00:00"},{"actual":91.24807235591092,"falling_edge":"2017-08-12 01:00:00+00:00","predicted":91.24807235591092,"rising_edge":"2017-08-12 00:30:00+00:00"},{"actual":88.68081269203363,"falling_edge":"2017-08-12 01:30:00+00:00","predicted":88.68081269203363,"rising_edge":"2017-08-12 01:00:00+00:00"},{"actual":88.78028306588983,"falling_edge":"2017-08-12 02:00:00+00:00","predicted":88.78028306588983,"rising_edge":"2017-08-12 01:30:00+00:00"},{"actual":89.00444470341057,"falling_edge":"2017-08-12 02:30:00+00:00","predicted":89.00444470341057,"rising_edge":"2017-08-12 02:00:00+00:00"},{"actual":91.08453460942708,"falling_edge":"2017-08-12 03:00:00+00:00","predicted":91.08453460942708,"rising_edge":"2017-08-12 02:30:00+00:00"},{"actual":88.98829922707073,"falling_edge":"2017-08-12 03:30:00+00:00","predicted":88.98829922707073,"rising_edge":"2017-08-12 03:00:00+00:00"},{"actual":90.86753205230957,"falling_edge":"2017-08-12 04:00:00+00:00","predicted":90.86753205230957,"rising_edge":"2017-08-12 03:30:00+00:00"},{"actual":95.51545465595251,"falling_edge":"2017-08-12 04:30:00+00:00","predicted":95.51545465595251,"rising_edge":"2017-08-12 04:00:00+00:00"},{"actual":92.22783581339255,"falling_edge":"2017-08-12 05:00:00+00:00","predicted":92.22783581339255,"rising_edge":"2017-08-12 04:30:00+00:00"},{"actual":89.40682499516747,"falling_edge":"2017-08-12 05:30:00+00:00","predicted":89.40682499516747,"rising_edge":"2017-08-12 05:00:00+00:00"},{"actual":89.57286982715249,"falling_edge":"2017-08-12 06:00:00+00:00","predicted":89.57286982715249,"rising_edge":"2017-08-12 05:30:00+00:00"},{"actual":88.29825746328618,"falling_edge":"2017-08-12 06:30:00+00:00","predicted":88.29825746328618,"rising_edge":"2017-08-12 06:00:00+00:00"},{"actual":89.96446773139449,"falling_edge":"2017-08-12 07:00:00+00:00","predicted":89.96446773139449,"rising_edge":"2017-08-12 06:30:00+00:00"},{"actual":89.35600459790982,"falling_edge":"2017-08-12 07:30:00+00:00","predicted":89.35600459790982,"rising_edge":"2017-08-12 07:00:00+00:00"},{"actual":87.58358619883438,"falling_edge":"2017-08-12 08:00:00+00:00","predicted":87.58358619883438,"rising_edge":"2017-08-12 07:30:00+00:00"},{"actual":85.02028441935184,"falling_edge":"2017-08-12 08:30:00+00:00","predicted":85.02028441935184,"rising_edge":"2017-08-12 08:00:00+00:00"},{"actual":78.8568906259304,"falling_edge":"2017-08-12 09:00:00+00:00","predicted":78.8568906259304,"rising_edge":"2017-08-12 08:30:00+00:00"},{"actual":69.2752905427013,"falling_edge":"2017-08-12 09:30:00+00:00","predicted":69.2752905427013,"rising_edge":"2017-08-12 09:00:00+00:00"},{"actual":67.12493819257041,"falling_edge":"2017-08-12 10:00:00+00:00","predicted":67.12493819257041,"rising_edge":"2017-08-12 09:30:00+00:00"},{"actual":64.39566926022522,"falling_edge":"2017-08-12 10:30:00+00:00","predicted":64.39566926022522,"rising_edge":"2017-08-12 10:00:00+00:00"},{"actual":61.98349787121546,"falling_edge":"2017-08-12 11:00:00+00:00","predicted":61.98349787121546,"rising_edge":"2017-08-12 10:30:00+00:00"},{"actual":61.12379675658134,"falling_edge":"2017-08-12 11:30:00+00:00","predicted":61.12379675658134,"rising_edge":"2017-08-12 11:00:00+00:00"},{"actual":59.14541380487749,"falling_edge":"2017-08-12 12:00:00+00:00","predicted":59.14541380487749,"rising_edge":"2017-08-12 11:30:00+00:00"},{"actual":54.83354935651643,"falling_edge":"2017-08-12 12:30:00+00:00","predicted":54.83354935651643,"rising_edge":"2017-08-12 12:00:00+00:00"},{"actual":53.94538582472015,"falling_edge":"2017-08-12 13:00:00+00:00","predicted":53.94538582472015,"rising_edge":"2017-08-12 12:30:00+00:00"},{"actual":53.29378665336265,"falling_edge":"2017-08-12 13:30:00+00:00","predicted":53.29378665336265,"rising_edge":"2017-08-12 13:00:00+00:00"},{"actual":52.55742314615942,"falling_edge":"2017-08-12 14:00:00+00:00","predicted":52.55742314615942,"rising_edge":"2017-08-12 13:30:00+00:00"},{"actual":49.89287364579101,"falling_edge":"2017-08-12 14:30:00+00:00","predicted":49.89287364579101,"rising_edge":"2017-08-12 14:00:00+00:00"},{"actual":48.936029487790485,"falling_edge":"2017-08-12 15:00:00+00:00","predicted":48.936029487790485,"rising_edge":"2017-08-12 14:30:00+00:00"},{"actual":49.19825779205303,"falling_edge":"2017-08-12 15:30:00+00:00","predicted":49.19825779205303,"rising_edge":"2017-08-12 15:00:00+00:00"},{"actual":47.24853404314293,"falling_edge":"2017-08-12 16:00:00+00:00","predicted":47.24853404314293,"rising_edge":"2017-08-12 15:30:00+00:00"},{"actual":47.179605378138014,"falling_edge":"2017-08-12 16:30:00+00:00","predicted":47.179605378138014,"rising_edge":"2017-08-12 16:00:00+00:00"},{"actual":46.63305457754063,"falling_edge":"2017-08-12 17:00:00+00:00","predicted":46.63305457754063,"rising_edge":"2017-08-12 16:30:00+00:00"},{"actual":47.124033128401464,"falling_edge":"2017-08-12 17:30:00+00:00","predicted":47.124033128401464,"rising_edge":"2017-08-12 17:00:00+00:00"},{"actual":46.569318641406774,"falling_edge":"2017-08-12 18:00:00+00:00","predicted":46.569318641406774,"rising_edge":"2017-08-12 17:30:00+00:00"},{"actual":46.92660740428029,"falling_edge":"2017-08-12 18:30:00+00:00","predicted":46.92660740428029,"rising_edge":"2017-08-12 18:00:00+00:00"},{"actual":46.373643931367624,"falling_edge":"2017-08-12 19:00:00+00:00","predicted":46.373643931367624,"rising_edge":"2017-08-12 18:30:00+00:00"},{"actual":46.14349709480515,"falling_edge":"2017-08-12 19:30:00+00:00","predicted":46.14349709480515,"rising_edge":"2017-08-12 19:00:00+00:00"},{"actual":46.56792611388364,"falling_edge":"2017-08-12 20:00:00+00:00","predicted":46.56792611388364,"rising_edge":"2017-08-12 19:30:00+00:00"},{"actual":45.92190495957928,"falling_edge":"2017-08-12 20:30:00+00:00","predicted":45.92190495957928,"rising_edge":"2017-08-12 20:00:00+00:00"},{"actual":47.33893588061124,"falling_edge":"2017-08-12 21:00:00+00:00","predicted":47.33893588061124,"rising_edge":"2017-08-12 20:30:00+00:00"},{"actual":47.78235877262256,"falling_edge":"2017-08-12 21:30:00+00:00","predicted":47.78235877262256,"rising_edge":"2017-08-12 21:00:00+00:00"},{"actual":50.32774948032127,"falling_edge":"2017-08-12 22:00:00+00:00","predicted":50.32774948032127,"rising_edge":"2017-08-12 21:30:00+00:00"},{"actual":52.31891878161063,"falling_edge":"2017-08-12 22:30:00+00:00","predicted":52.31891878161063,"rising_edge":"2017-08-12 22:00:00+00:00"},{"actual":52.174066996340734,"falling_edge":"2017-08-12 23:00:00+00:00","predicted":52.174066996340734,"rising_edge":"2017-08-12 22:30:00+00:00"},{"actual":56.78021186711044,"falling_edge":"2017-08-12 23:30:00+00:00","predicted":56.78021186711044,"rising_edge":"2017-08-12 23:00:00+00:00"},{"actual":59.82149496258744,"falling_edge":"2017-08-13 00:00:00+00:00","predicted":59.82149496258744,"rising_edge":"2017-08-12 23:30:00+00:00"},{"actual":65.66647918686927,"falling_edge":"2017-08-13 00:30:00+00:00","predicted":65.66647918686927,"rising_edge":"2017-08-13 00:00:00+00:00"},{"actual":68.0562586854074,"falling_edge":"2017-08-13 01:00:00+00:00","predicted":68.0562586854074,"rising_edge":"2017-08-13 00:30:00+00:00"},{"actual":67.64863774350567,"falling_edge":"2017-08-13 01:30:00+00:00","predicted":67.64863774350567,"rising_edge":"2017-08-13 01:00:00+00:00"},{"actual":67.08709914767934,"falling_edge":"2017-08-13 02:00:00+00:00","predicted":67.08709914767934,"rising_edge":"2017-08-13 01:30:00+00:00"},{"actual":68.51830296786522,"falling_edge":"2017-08-13 02:30:00+00:00","predicted":68.51830296786522,"rising_edge":"2017-08-13 02:00:00+00:00"},{"actual":68.90370440218273,"falling_edge":"2017-08-13 03:00:00+00:00","predicted":68.90370440218273,"rising_edge":"2017-08-13 02:30:00+00:00"},{"actual":69.2668450696971,"falling_edge":"2017-08-13 03:30:00+00:00","predicted":69.2668450696971,"rising_edge":"2017-08-13 03:00:00+00:00"},{"actual":68.8266101558864,"falling_edge":"2017-08-13 04:00:00+00:00","predicted":68.8266101558864,"rising_edge":"2017-08-13 03:30:00+00:00"},{"actual":73.09365789865417,"falling_edge":"2017-08-13 04:30:00+00:00","predicted":73.09365789865417,"rising_edge":"2017-08-13 04:00:00+00:00"},{"actual":73.7832647451016,"falling_edge":"2017-08-13 05:00:00+00:00","predicted":73.7832647451016,"rising_edge":"2017-08-13 04:30:00+00:00"},{"actual":73.66124920218472,"falling_edge":"2017-08-13 05:30:00+00:00","predicted":73.66124920218472,"rising_edge":"2017-08-13 05:00:00+00:00"},{"actual":76.6649896637411,"falling_edge":"2017-08-13 06:00:00+00:00","predicted":76.6649896637411,"rising_edge":"2017-08-13 05:30:00+00:00"},{"actual":76.84979988441403,"falling_edge":"2017-08-13 06:30:00+00:00","predicted":76.84979988441403,"rising_edge":"2017-08-13 06:00:00+00:00"},{"actual":80.22841490512693,"falling_edge":"2017-08-13 07:00:00+00:00","predicted":80.22841490512693,"rising_edge":"2017-08-13 06:30:00+00:00"},{"actual":81.42168450796629,"falling_edge":"2017-08-13 07:30:00+00:00","predicted":81.42168450796629,"rising_edge":"2017-08-13 07:00:00+00:00"},{"actual":79.55365935246755,"falling_edge":"2017-08-13 08:00:00+00:00","predicted":79.55365935246755,"rising_edge":"2017-08-13 07:30:00+00:00"},{"actual":77.55908518798702,"falling_edge":"2017-08-13 08:30:00+00:00","predicted":77.55908518798702,"rising_edge":"2017-08-13 08:00:00+00:00"},{"actual":74.18400595368273,"falling_edge":"2017-08-13 09:00:00+00:00","predicted":74.18400595368273,"rising_edge":"2017-08-13 08:30:00+00:00"},{"actual":66.63105031595316,"falling_edge":"2017-08-13 09:30:00+00:00","predicted":66.63105031595316,"rising_edge":"2017-08-13 09:00:00+00:00"},{"actual":64.36497673580303,"falling_edge":"2017-08-13 10:00:00+00:00","predicted":64.36497673580303,"rising_edge":"2017-08-13 09:30:00+00:00"},{"actual":60.696431399418046,"falling_edge":"2017-08-13 10:30:00+00:00","predicted":60.696431399418046,"rising_edge":"2017-08-13 10:00:00+00:00"},{"actual":60.16570292769407,"falling_edge":"2017-08-13 11:00:00+00:00","predicted":60.16570292769407,"rising_edge":"2017-08-13 10:30:00+00:00"},{"actual":59.38106821392948,"falling_edge":"2017-08-13 11:30:00+00:00","predicted":59.38106821392948,"rising_edge":"2017-08-13 11:00:00+00:00"},{"actual":59.31967598874854,"falling_edge":"2017-08-13 12:00:00+00:00","predicted":59.31967598874854,"rising_edge":"2017-08-13 11:30:00+00:00"},{"actual":55.83837171320501,"falling_edge":"2017-08-13 12:30:00+00:00","predicted":55.83837171320501,"rising_edge":"2017-08-13 12:00:00+00:00"},{"actual":53.6237963092964,"falling_edge":"2017-08-13 13:00:00+00:00","predicted":53.6237963092964,"rising_edge":"2017-08-13 12:30:00+00:00"},{"actual":52.47491551853473,"falling_edge":"2017-08-13 13:30:00+00:00","predicted":52.47491551853473,"rising_edge":"2017-08-13 13:00:00+00:00"},{"actual":50.20128992087897,"falling_edge":"2017-08-13 14:00:00+00:00","predicted":50.20128992087897,"rising_edge":"2017-08-13 13:30:00+00:00"},{"actual":51.03985917952794,"falling_edge":"2017-08-13 14:30:00+00:00","predicted":51.03985917952794,"rising_edge":"2017-08-13 14:00:00+00:00"},{"actual":49.24530452671577,"falling_edge":"2017-08-13 15:00:00+00:00","predicted":49.24530452671577,"rising_edge":"2017-08-13 14:30:00+00:00"},{"actual":48.946270287249504,"falling_edge":"2017-08-13 15:30:00+00:00","predicted":48.946270287249504,"rising_edge":"2017-08-13 15:00:00+00:00"},{"actual":48.05525342678571,"falling_edge":"2017-08-13 16:00:00+00:00","predicted":48.05525342678571,"rising_edge":"2017-08-13 15:30:00+00:00"},{"actual":48.397744520045876,"falling_edge":"2017-08-13 16:30:00+00:00","predicted":48.397744520045876,"rising_edge":"2017-08-13 16:00:00+00:00"},{"actual":47.00906497031298,"falling_edge":"2017-08-13 17:00:00+00:00","predicted":47.00906497031298,"rising_edge":"2017-08-13 16:30:00+00:00"},{"actual":45.939444687981066,"falling_edge":"2017-08-13 17:30:00+00:00","predicted":45.939444687981066,"rising_edge":"2017-08-13 17:00:00+00:00"},{"actual":46.621507186337766,"falling_edge":"2017-08-13 18:00:00+00:00","predicted":46.621507186337766,"rising_edge":"2017-08-13 17:30:00+00:00"},{"actual":45.950839077990615,"falling_edge":"2017-08-13 18:30:00+00:00","predicted":45.950839077990615,"rising_edge":"2017-08-13 18:00:00+00:00"},{"actual":46.32858686736054,"falling_edge":"2017-08-13 19:00:00+00:00","predicted":46.32858686736054,"rising_edge":"2017-08-13 18:30:00+00:00"},{"actual":45.83973956296681,"falling_edge":"2017-08-13 19:30:00+00:00","predicted":45.83973956296681,"rising_edge":"2017-08-13 19:00:00+00:00"},{"actual":46.11572474919584,"falling_edge":"2017-08-13 20:00:00+00:00","predicted":46.11572474919584,"rising_edge":"2017-08-13 19:30:00+00:00"},{"actual":47.182386949345094,"falling_edge":"2017-08-13 20:30:00+00:00","predicted":47.182386949345094,"rising_edge":"2017-08-13 20:00:00+00:00"},{"actual":52.005451873846404,"falling_edge":"2017-08-13 21:00:00+00:00","predicted":52.005451873846404,"rising_edge":"2017-08-13 20:30:00+00:00"},{"actual":69.93372594507244,"falling_edge":"2017-08-13 21:30:00+00:00","predicted":69.93372594507244,"rising_edge":"2017-08-13 21:00:00+00:00"},{"actual":125.37676394086421,"falling_edge":"2017-08-13 22:00:00+00:00","predicted":125.37676394086421,"rising_edge":"2017-08-13 21:30:00+00:00"},{"actual":108.26803806872985,"falling_edge":"2017-08-13 22:30:00+00:00","predicted":108.26803806872985,"rising_edge":"2017-08-13 22:00:00+00:00"},{"actual":126.75915124626042,"falling_edge":"2017-08-13 23:00:00+00:00","predicted":126.75915124626042,"rising_edge":"2017-08-13 22:30:00+00:00"},{"actual":159.65033268058892,"falling_edge":"2017-08-13 23:30:00+00:00","predicted":159.65033268058892,"rising_edge":"2017-08-13 23:00:00+00:00"},{"actual":199.06480476801036,"falling_edge":"2017-08-14 00:00:00+00:00","predicted":199.06480476801036,"rising_edge":"2017-08-13 23:30:00+00:00"},{"actual":214.46453849301102,"falling_edge":"2017-08-14 00:30:00+00:00","predicted":214.46453849301102,"rising_edge":"2017-08-14 00:00:00+00:00"},{"actual":222.64508623232967,"falling_edge":"2017-08-14 01:00:00+00:00","predicted":222.64508623232967,"rising_edge":"2017-08-14 00:30:00+00:00"},{"actual":224.22945030325818,"falling_edge":"2017-08-14 01:30:00+00:00","predicted":224.22945030325818,"rising_edge":"2017-08-14 01:00:00+00:00"},{"actual":219.0305586093534,"falling_edge":"2017-08-14 02:00:00+00:00","predicted":219.0305586093534,"rising_edge":"2017-08-14 01:30:00+00:00"},{"actual":214.81592219042983,"falling_edge":"2017-08-14 02:30:00+00:00","predicted":214.81592219042983,"rising_edge":"2017-08-14 02:00:00+00:00"},{"actual":210.40771103411245,"falling_edge":"2017-08-14 03:00:00+00:00","predicted":210.40771103411245,"rising_edge":"2017-08-14 02:30:00+00:00"},{"actual":207.56700972583843,"falling_edge":"2017-08-14 03:30:00+00:00","predicted":207.56700972583843,"rising_edge":"2017-08-14 03:00:00+00:00"},{"actual":198.21565791131096,"falling_edge":"2017-08-14 04:00:00+00:00","predicted":198.21565791131096,"rising_edge":"2017-08-14 03:30:00+00:00"},{"actual":214.5569173382084,"falling_edge":"2017-08-14 04:30:00+00:00","predicted":214.5569173382084,"rising_edge":"2017-08-14 04:00:00+00:00"},{"actual":213.0816592885271,"falling_edge":"2017-08-14 05:00:00+00:00","predicted":213.0816592885271,"rising_edge":"2017-08-14 04:30:00+00:00"},{"actual":207.01765431758798,"falling_edge":"2017-08-14 05:30:00+00:00","predicted":207.01765431758798,"rising_edge":"2017-08-14 05:00:00+00:00"},{"actual":215.61935674666532,"falling_edge":"2017-08-14 06:00:00+00:00","predicted":215.61935674666532,"rising_edge":"2017-08-14 05:30:00+00:00"},{"actual":216.2437695417699,"falling_edge":"2017-08-14 06:30:00+00:00","predicted":216.2437695417699,"rising_edge":"2017-08-14 06:00:00+00:00"},{"actual":218.29810545511577,"falling_edge":"2017-08-14 07:00:00+00:00","predicted":218.29810545511577,"rising_edge":"2017-08-14 06:30:00+00:00"},{"actual":218.46763269483523,"falling_edge":"2017-08-14 07:30:00+00:00","predicted":218.46763269483523,"rising_edge":"2017-08-14 07:00:00+00:00"},{"actual":222.75940936272818,"falling_edge":"2017-08-14 08:00:00+00:00","predicted":222.75940936272818,"rising_edge":"2017-08-14 07:30:00+00:00"},{"actual":222.27192046884926,"falling_edge":"2017-08-14 08:30:00+00:00","predicted":222.27192046884926,"rising_edge":"2017-08-14 08:00:00+00:00"},{"actual":205.4165838121583,"falling_edge":"2017-08-14 09:00:00+00:00","predicted":205.4165838121583,"rising_edge":"2017-08-14 08:30:00+00:00"},{"actual":174.6053009370446,"falling_edge":"2017-08-14 09:30:00+00:00","predicted":174.6053009370446,"rising_edge":"2017-08-14 09:00:00+00:00"},{"actual":160.25454587768988,"falling_edge":"2017-08-14 10:00:00+00:00","predicted":160.25454587768988,"rising_edge":"2017-08-14 09:30:00+00:00"},{"actual":137.0944568123798,"falling_edge":"2017-08-14 10:30:00+00:00","predicted":137.0944568123798,"rising_edge":"2017-08-14 10:00:00+00:00"},{"actual":134.0854462688491,"falling_edge":"2017-08-14 11:00:00+00:00","predicted":134.0854462688491,"rising_edge":"2017-08-14 10:30:00+00:00"},{"actual":125.98992994397707,"falling_edge":"2017-08-14 11:30:00+00:00","predicted":125.98992994397707,"rising_edge":"2017-08-14 11:00:00+00:00"},{"actual":113.62832518209127,"falling_edge":"2017-08-14 12:00:00+00:00","predicted":113.62832518209127,"rising_edge":"2017-08-14 11:30:00+00:00"},{"actual":103.40372991102821,"falling_edge":"2017-08-14 12:30:00+00:00","predicted":103.40372991102821,"rising_edge":"2017-08-14 12:00:00+00:00"},{"actual":94.8309602145741,"falling_edge":"2017-08-14 13:00:00+00:00","predicted":94.8309602145741,"rising_edge":"2017-08-14 12:30:00+00:00"},{"actual":86.90000506604115,"falling_edge":"2017-08-14 13:30:00+00:00","predicted":86.90000506604115,"rising_edge":"2017-08-14 13:00:00+00:00"},{"actual":75.64459543712545,"falling_edge":"2017-08-14 14:00:00+00:00","predicted":75.64459543712545,"rising_edge":"2017-08-14 13:30:00+00:00"},{"actual":65.04155918496963,"falling_edge":"2017-08-14 14:30:00+00:00","predicted":65.04155918496963,"rising_edge":"2017-08-14 14:00:00+00:00"},{"actual":57.72369757960356,"falling_edge":"2017-08-14 15:00:00+00:00","predicted":57.72369757960356,"rising_edge":"2017-08-14 14:30:00+00:00"},{"actual":52.28165489695247,"falling_edge":"2017-08-14 15:30:00+00:00","predicted":52.28165489695247,"rising_edge":"2017-08-14 15:00:00+00:00"},{"actual":47.530994365779,"falling_edge":"2017-08-14 16:00:00+00:00","predicted":47.530994365779,"rising_edge":"2017-08-14 15:30:00+00:00"},{"actual":46.29287610562758,"falling_edge":"2017-08-14 16:30:00+00:00","predicted":46.29287610562758,"rising_edge":"2017-08-14 16:00:00+00:00"},{"actual":45.893381939912885,"falling_edge":"2017-08-14 17:00:00+00:00","predicted":45.893381939912885,"rising_edge":"2017-08-14 16:30:00+00:00"},{"actual":45.46249923545307,"falling_edge":"2017-08-14 17:30:00+00:00","predicted":45.46249923545307,"rising_edge":"2017-08-14 17:00:00+00:00"},{"actual":45.00518187179576,"falling_edge":"2017-08-14 18:00:00+00:00","predicted":45.00518187179576,"rising_edge":"2017-08-14 17:30:00+00:00"},{"actual":44.634748423857836,"falling_edge":"2017-08-14 18:30:00+00:00","predicted":44.634748423857836,"rising_edge":"2017-08-14 18:00:00+00:00"},{"actual":44.00850075644931,"falling_edge":"2017-08-14 19:00:00+00:00","predicted":44.00850075644931,"rising_edge":"2017-08-14 18:30:00+00:00"},{"actual":44.29432335501467,"falling_edge":"2017-08-14 19:30:00+00:00","predicted":44.29432335501467,"rising_edge":"2017-08-14 19:00:00+00:00"},{"actual":43.50832453162324,"falling_edge":"2017-08-14 20:00:00+00:00","predicted":43.50832453162324,"rising_edge":"2017-08-14 19:30:00+00:00"},{"actual":44.84782122717753,"falling_edge":"2017-08-14 20:30:00+00:00","predicted":44.84782122717753,"rising_edge":"2017-08-14 20:00:00+00:00"},{"actual":49.73791707331431,"falling_edge":"2017-08-14 21:00:00+00:00","predicted":49.73791707331431,"rising_edge":"2017-08-14 20:30:00+00:00"},{"actual":66.34890483187816,"falling_edge":"2017-08-14 21:30:00+00:00","predicted":66.34890483187816,"rising_edge":"2017-08-14 21:00:00+00:00"},{"actual":98.03685086957441,"falling_edge":"2017-08-14 22:00:00+00:00","predicted":98.03685086957441,"rising_edge":"2017-08-14 21:30:00+00:00"},{"actual":91.6350979504878,"falling_edge":"2017-08-14 22:30:00+00:00","predicted":91.6350979504878,"rising_edge":"2017-08-14 22:00:00+00:00"},{"actual":113.7773164045531,"falling_edge":"2017-08-14 23:00:00+00:00","predicted":113.7773164045531,"rising_edge":"2017-08-14 22:30:00+00:00"},{"actual":146.17196685480536,"falling_edge":"2017-08-14 23:30:00+00:00","predicted":146.17196685480536,"rising_edge":"2017-08-14 23:00:00+00:00"},{"actual":186.2298591937707,"falling_edge":"2017-08-15 00:00:00+00:00","predicted":186.2298591937707,"rising_edge":"2017-08-14 23:30:00+00:00"},{"actual":205.75979201392732,"falling_edge":"2017-08-15 00:30:00+00:00","predicted":205.75979201392732,"rising_edge":"2017-08-15 00:00:00+00:00"},{"actual":208.88891876555633,"falling_edge":"2017-08-15 01:00:00+00:00","predicted":208.88891876555633,"rising_edge":"2017-08-15 00:30:00+00:00"},{"actual":209.9192490238653,"falling_edge":"2017-08-15 01:30:00+00:00","predicted":209.9192490238653,"rising_edge":"2017-08-15 01:00:00+00:00"},{"actual":215.99942967362946,"falling_edge":"2017-08-15 02:00:00+00:00","predicted":215.99942967362946,"rising_edge":"2017-08-15 01:30:00+00:00"},{"actual":216.58295657172138,"falling_edge":"2017-08-15 02:30:00+00:00","predicted":216.58295657172138,"rising_edge":"2017-08-15 02:00:00+00:00"},{"actual":215.56249213487123,"falling_edge":"2017-08-15 03:00:00+00:00","predicted":215.56249213487123,"rising_edge":"2017-08-15 02:30:00+00:00"},{"actual":204.96496694990472,"falling_edge":"2017-08-15 03:30:00+00:00","predicted":204.96496694990472,"rising_edge":"2017-08-15 03:00:00+00:00"},{"actual":199.1539246656307,"falling_edge":"2017-08-15 04:00:00+00:00","predicted":199.1539246656307,"rising_edge":"2017-08-15 03:30:00+00:00"},{"actual":209.1622734211775,"falling_edge":"2017-08-15 04:30:00+00:00","predicted":209.1622734211775,"rising_edge":"2017-08-15 04:00:00+00:00"},{"actual":208.24374726081865,"falling_edge":"2017-08-15 05:00:00+00:00","predicted":208.24374726081865,"rising_edge":"2017-08-15 04:30:00+00:00"},{"actual":204.603661516441,"falling_edge":"2017-08-15 05:30:00+00:00","predicted":204.603661516441,"rising_edge":"2017-08-15 05:00:00+00:00"},{"actual":209.6219770934909,"falling_edge":"2017-08-15 06:00:00+00:00","predicted":209.6219770934909,"rising_edge":"2017-08-15 05:30:00+00:00"},{"actual":210.61187221106988,"falling_edge":"2017-08-15 06:30:00+00:00","predicted":210.61187221106988,"rising_edge":"2017-08-15 06:00:00+00:00"},{"actual":210.93132627042002,"falling_edge":"2017-08-15 07:00:00+00:00","predicted":210.93132627042002,"rising_edge":"2017-08-15 06:30:00+00:00"},{"actual":211.13717126729307,"falling_edge":"2017-08-15 07:30:00+00:00","predicted":211.13717126729307,"rising_edge":"2017-08-15 07:00:00+00:00"},{"actual":207.33475250487533,"falling_edge":"2017-08-15 08:00:00+00:00","predicted":207.33475250487533,"rising_edge":"2017-08-15 07:30:00+00:00"},{"actual":211.11349353873564,"falling_edge":"2017-08-15 08:30:00+00:00","predicted":211.11349353873564,"rising_edge":"2017-08-15 08:00:00+00:00"},{"actual":203.7407599560672,"falling_edge":"2017-08-15 09:00:00+00:00","predicted":203.7407599560672,"rising_edge":"2017-08-15 08:30:00+00:00"},{"actual":177.9461486971856,"falling_edge":"2017-08-15 09:30:00+00:00","predicted":177.9461486971856,"rising_edge":"2017-08-15 09:00:00+00:00"},{"actual":161.74590188192875,"falling_edge":"2017-08-15 10:00:00+00:00","predicted":161.74590188192875,"rising_edge":"2017-08-15 09:30:00+00:00"},{"actual":142.88696677290307,"falling_edge":"2017-08-15 10:30:00+00:00","predicted":142.88696677290307,"rising_edge":"2017-08-15 10:00:00+00:00"},{"actual":140.15365779258616,"falling_edge":"2017-08-15 11:00:00+00:00","predicted":140.15365779258616,"rising_edge":"2017-08-15 10:30:00+00:00"},{"actual":133.59084681720586,"falling_edge":"2017-08-15 11:30:00+00:00","predicted":133.59084681720586,"rising_edge":"2017-08-15 11:00:00+00:00"},{"actual":124.67849861643799,"falling_edge":"2017-08-15 12:00:00+00:00","predicted":124.67849861643799,"rising_edge":"2017-08-15 11:30:00+00:00"},{"actual":112.59920651437098,"falling_edge":"2017-08-15 12:30:00+00:00","predicted":112.59920651437098,"rising_edge":"2017-08-15 12:00:00+00:00"},{"actual":99.74965307816484,"falling_edge":"2017-08-15 13:00:00+00:00","predicted":99.74965307816484,"rising_edge":"2017-08-15 12:30:00+00:00"},{"actual":90.66583704781327,"falling_edge":"2017-08-15 13:30:00+00:00","predicted":90.66583704781327,"rising_edge":"2017-08-15 13:00:00+00:00"},{"actual":76.67392522242662,"falling_edge":"2017-08-15 14:00:00+00:00","predicted":76.67392522242662,"rising_edge":"2017-08-15 13:30:00+00:00"},{"actual":66.02496691894427,"falling_edge":"2017-08-15 14:30:00+00:00","predicted":66.02496691894427,"rising_edge":"2017-08-15 14:00:00+00:00"},{"actual":58.374468175596746,"falling_edge":"2017-08-15 15:00:00+00:00","predicted":58.374468175596746,"rising_edge":"2017-08-15 14:30:00+00:00"},{"actual":53.53229793465219,"falling_edge":"2017-08-15 15:30:00+00:00","predicted":53.53229793465219,"rising_edge":"2017-08-15 15:00:00+00:00"},{"actual":50.3646915792848,"falling_edge":"2017-08-15 16:00:00+00:00","predicted":50.3646915792848,"rising_edge":"2017-08-15 15:30:00+00:00"},{"actual":51.895767623219676,"falling_edge":"2017-08-15 16:30:00+00:00","predicted":51.895767623219676,"rising_edge":"2017-08-15 16:00:00+00:00"},{"actual":49.45944862494896,"falling_edge":"2017-08-15 17:00:00+00:00","predicted":49.45944862494896,"rising_edge":"2017-08-15 16:30:00+00:00"},{"actual":47.698942698904474,"falling_edge":"2017-08-15 17:30:00+00:00","predicted":47.698942698904474,"rising_edge":"2017-08-15 17:00:00+00:00"},{"actual":47.5402861786553,"falling_edge":"2017-08-15 18:00:00+00:00","predicted":47.5402861786553,"rising_edge":"2017-08-15 17:30:00+00:00"},{"actual":45.58759093808503,"falling_edge":"2017-08-15 18:30:00+00:00","predicted":45.58759093808503,"rising_edge":"2017-08-15 18:00:00+00:00"},{"actual":44.45877146320051,"falling_edge":"2017-08-15 19:00:00+00:00","predicted":44.45877146320051,"rising_edge":"2017-08-15 18:30:00+00:00"},{"actual":45.91259902565705,"falling_edge":"2017-08-15 19:30:00+00:00","predicted":45.91259902565705,"rising_edge":"2017-08-15 19:00:00+00:00"},{"actual":45.71302130123724,"falling_edge":"2017-08-15 20:00:00+00:00","predicted":45.71302130123724,"rising_edge":"2017-08-15 19:30:00+00:00"},{"actual":47.252883912847686,"falling_edge":"2017-08-15 20:30:00+00:00","predicted":47.252883912847686,"rising_edge":"2017-08-15 20:00:00+00:00"},{"actual":52.386545721197784,"falling_edge":"2017-08-15 21:00:00+00:00","predicted":52.386545721197784,"rising_edge":"2017-08-15 20:30:00+00:00"},{"actual":69.59140489486299,"falling_edge":"2017-08-15 21:30:00+00:00","predicted":69.59140489486299,"rising_edge":"2017-08-15 21:00:00+00:00"},{"actual":102.29992404694572,"falling_edge":"2017-08-15 22:00:00+00:00","predicted":102.29992404694572,"rising_edge":"2017-08-15 21:30:00+00:00"},{"actual":98.0827505506442,"falling_edge":"2017-08-15 22:30:00+00:00","predicted":98.0827505506442,"rising_edge":"2017-08-15 22:00:00+00:00"},{"actual":116.85962256898664,"falling_edge":"2017-08-15 23:00:00+00:00","predicted":116.85962256898664,"rising_edge":"2017-08-15 22:30:00+00:00"},{"actual":156.5607377691876,"falling_edge":"2017-08-15 23:30:00+00:00","predicted":156.5607377691876,"rising_edge":"2017-08-15 23:00:00+00:00"},{"actual":204.93710918278018,"falling_edge":"2017-08-16 00:00:00+00:00","predicted":204.93710918278018,"rising_edge":"2017-08-15 23:30:00+00:00"},{"actual":214.06943987471374,"falling_edge":"2017-08-16 00:30:00+00:00","predicted":214.06943987471374,"rising_edge":"2017-08-16 00:00:00+00:00"},{"actual":217.9155701578573,"falling_edge":"2017-08-16 01:00:00+00:00","predicted":217.9155701578573,"rising_edge":"2017-08-16 00:30:00+00:00"},{"actual":228.14621395887505,"falling_edge":"2017-08-16 01:30:00+00:00","predicted":228.14621395887505,"rising_edge":"2017-08-16 01:00:00+00:00"},{"actual":219.884036025844,"falling_edge":"2017-08-16 02:00:00+00:00","predicted":219.884036025844,"rising_edge":"2017-08-16 01:30:00+00:00"},{"actual":220.54682907843767,"falling_edge":"2017-08-16 02:30:00+00:00","predicted":220.54682907843767,"rising_edge":"2017-08-16 02:00:00+00:00"},{"actual":220.19695696640122,"falling_edge":"2017-08-16 03:00:00+00:00","predicted":220.19695696640122,"rising_edge":"2017-08-16 02:30:00+00:00"},{"actual":218.85610740253628,"falling_edge":"2017-08-16 03:30:00+00:00","predicted":218.85610740253628,"rising_edge":"2017-08-16 03:00:00+00:00"},{"actual":206.6043822186573,"falling_edge":"2017-08-16 04:00:00+00:00","predicted":206.6043822186573,"rising_edge":"2017-08-16 03:30:00+00:00"},{"actual":219.51583741280496,"falling_edge":"2017-08-16 04:30:00+00:00","predicted":219.51583741280496,"rising_edge":"2017-08-16 04:00:00+00:00"},{"actual":224.42598741162624,"falling_edge":"2017-08-16 05:00:00+00:00","predicted":224.42598741162624,"rising_edge":"2017-08-16 04:30:00+00:00"},{"actual":219.55884282689283,"falling_edge":"2017-08-16 05:30:00+00:00","predicted":219.55884282689283,"rising_edge":"2017-08-16 05:00:00+00:00"},{"actual":227.68160364751392,"falling_edge":"2017-08-16 06:00:00+00:00","predicted":227.68160364751392,"rising_edge":"2017-08-16 05:30:00+00:00"},{"actual":239.73617709250942,"falling_edge":"2017-08-16 06:30:00+00:00","predicted":239.73617709250942,"rising_edge":"2017-08-16 06:00:00+00:00"},{"actual":236.90348842214718,"falling_edge":"2017-08-16 07:00:00+00:00","predicted":236.90348842214718,"rising_edge":"2017-08-16 06:30:00+00:00"},{"actual":240.00296494961214,"falling_edge":"2017-08-16 07:30:00+00:00","predicted":240.00296494961214,"rising_edge":"2017-08-16 07:00:00+00:00"},{"actual":234.58962020297668,"falling_edge":"2017-08-16 08:00:00+00:00","predicted":234.58962020297668,"rising_edge":"2017-08-16 07:30:00+00:00"},{"actual":228.23717697735316,"falling_edge":"2017-08-16 08:30:00+00:00","predicted":228.23717697735316,"rising_edge":"2017-08-16 08:00:00+00:00"},{"actual":213.3624994660141,"falling_edge":"2017-08-16 09:00:00+00:00","predicted":213.3624994660141,"rising_edge":"2017-08-16 08:30:00+00:00"},{"actual":174.708225488233,"falling_edge":"2017-08-16 09:30:00+00:00","predicted":174.708225488233,"rising_edge":"2017-08-16 09:00:00+00:00"},{"actual":154.2489469037698,"falling_edge":"2017-08-16 10:00:00+00:00","predicted":154.2489469037698,"rising_edge":"2017-08-16 09:30:00+00:00"},{"actual":126.64795336108304,"falling_edge":"2017-08-16 10:30:00+00:00","predicted":126.64795336108304,"rising_edge":"2017-08-16 10:00:00+00:00"},{"actual":120.78602871861456,"falling_edge":"2017-08-16 11:00:00+00:00","predicted":120.78602871861456,"rising_edge":"2017-08-16 10:30:00+00:00"},{"actual":112.18576822071485,"falling_edge":"2017-08-16 11:30:00+00:00","predicted":112.18576822071485,"rising_edge":"2017-08-16 11:00:00+00:00"},{"actual":106.6278311528914,"falling_edge":"2017-08-16 12:00:00+00:00","predicted":106.6278311528914,"rising_edge":"2017-08-16 11:30:00+00:00"},{"actual":99.97976873893994,"falling_edge":"2017-08-16 12:30:00+00:00","predicted":99.97976873893994,"rising_edge":"2017-08-16 12:00:00+00:00"},{"actual":91.5702578536728,"falling_edge":"2017-08-16 13:00:00+00:00","predicted":91.5702578536728,"rising_edge":"2017-08-16 12:30:00+00:00"},{"actual":78.42619381124034,"falling_edge":"2017-08-16 13:30:00+00:00","predicted":78.42619381124034,"rising_edge":"2017-08-16 13:00:00+00:00"},{"actual":69.18371159839943,"falling_edge":"2017-08-16 14:00:00+00:00","predicted":69.18371159839943,"rising_edge":"2017-08-16 13:30:00+00:00"},{"actual":61.23796368580989,"falling_edge":"2017-08-16 14:30:00+00:00","predicted":61.23796368580989,"rising_edge":"2017-08-16 14:00:00+00:00"},{"actual":55.45261361763604,"falling_edge":"2017-08-16 15:00:00+00:00","predicted":55.45261361763604,"rising_edge":"2017-08-16 14:30:00+00:00"},{"actual":51.11510368022427,"falling_edge":"2017-08-16 15:30:00+00:00","predicted":51.11510368022427,"rising_edge":"2017-08-16 15:00:00+00:00"},{"actual":49.18244449537888,"falling_edge":"2017-08-16 16:00:00+00:00","predicted":49.18244449537888,"rising_edge":"2017-08-16 15:30:00+00:00"},{"actual":47.54804613363595,"falling_edge":"2017-08-16 16:30:00+00:00","predicted":47.54804613363595,"rising_edge":"2017-08-16 16:00:00+00:00"},{"actual":47.19974380544478,"falling_edge":"2017-08-16 17:00:00+00:00","predicted":47.19974380544478,"rising_edge":"2017-08-16 16:30:00+00:00"},{"actual":48.02836231708202,"falling_edge":"2017-08-16 17:30:00+00:00","predicted":48.02836231708202,"rising_edge":"2017-08-16 17:00:00+00:00"},{"actual":47.39089483878679,"falling_edge":"2017-08-16 18:00:00+00:00","predicted":47.39089483878679,"rising_edge":"2017-08-16 17:30:00+00:00"},{"actual":46.51110653357058,"falling_edge":"2017-08-16 18:30:00+00:00","predicted":46.51110653357058,"rising_edge":"2017-08-16 18:00:00+00:00"},{"actual":45.92397583045244,"falling_edge":"2017-08-16 19:00:00+00:00","predicted":45.92397583045244,"rising_edge":"2017-08-16 18:30:00+00:00"},{"actual":45.55801581385789,"falling_edge":"2017-08-16 19:30:00+00:00","predicted":45.55801581385789,"rising_edge":"2017-08-16 19:00:00+00:00"},{"actual":45.670398982397614,"falling_edge":"2017-08-16 20:00:00+00:00","predicted":45.670398982397614,"rising_edge":"2017-08-16 19:30:00+00:00"},{"actual":46.771694525730915,"falling_edge":"2017-08-16 20:30:00+00:00","predicted":46.771694525730915,"rising_edge":"2017-08-16 20:00:00+00:00"},{"actual":51.662963042670334,"falling_edge":"2017-08-16 21:00:00+00:00","predicted":51.662963042670334,"rising_edge":"2017-08-16 20:30:00+00:00"},{"actual":70.15026499937325,"falling_edge":"2017-08-16 21:30:00+00:00","predicted":70.15026499937325,"rising_edge":"2017-08-16 21:00:00+00:00"},{"actual":102.74408059743243,"falling_edge":"2017-08-16 22:00:00+00:00","predicted":102.74408059743243,"rising_edge":"2017-08-16 21:30:00+00:00"},{"actual":102.92667668150065,"falling_edge":"2017-08-16 22:30:00+00:00","predicted":102.92667668150065,"rising_edge":"2017-08-16 22:00:00+00:00"},{"actual":124.68224725236412,"falling_edge":"2017-08-16 23:00:00+00:00","predicted":124.68224725236412,"rising_edge":"2017-08-16 22:30:00+00:00"},{"actual":164.026308616838,"falling_edge":"2017-08-16 23:30:00+00:00","predicted":164.026308616838,"rising_edge":"2017-08-16 23:00:00+00:00"},{"actual":201.80509856833464,"falling_edge":"2017-08-17 00:00:00+00:00","predicted":201.80509856833464,"rising_edge":"2017-08-16 23:30:00+00:00"},{"actual":210.70827408142253,"falling_edge":"2017-08-17 00:30:00+00:00","predicted":210.70827408142253,"rising_edge":"2017-08-17 00:00:00+00:00"},{"actual":206.42256130743658,"falling_edge":"2017-08-17 01:00:00+00:00","predicted":206.42256130743658,"rising_edge":"2017-08-17 00:30:00+00:00"},{"actual":214.00911859866068,"falling_edge":"2017-08-17 01:30:00+00:00","predicted":214.00911859866068,"rising_edge":"2017-08-17 01:00:00+00:00"},{"actual":217.03196444314844,"falling_edge":"2017-08-17 02:00:00+00:00","predicted":217.03196444314844,"rising_edge":"2017-08-17 01:30:00+00:00"},{"actual":221.29422849247027,"falling_edge":"2017-08-17 02:30:00+00:00","predicted":221.29422849247027,"rising_edge":"2017-08-17 02:00:00+00:00"},{"actual":214.34722783038745,"falling_edge":"2017-08-17 03:00:00+00:00","predicted":214.34722783038745,"rising_edge":"2017-08-17 02:30:00+00:00"},{"actual":212.7239998248889,"falling_edge":"2017-08-17 03:30:00+00:00","predicted":212.7239998248889,"rising_edge":"2017-08-17 03:00:00+00:00"},{"actual":204.56128176181957,"falling_edge":"2017-08-17 04:00:00+00:00","predicted":204.56128176181957,"rising_edge":"2017-08-17 03:30:00+00:00"},{"actual":213.86255614396325,"falling_edge":"2017-08-17 04:30:00+00:00","predicted":213.86255614396325,"rising_edge":"2017-08-17 04:00:00+00:00"},{"actual":213.99502799069685,"falling_edge":"2017-08-17 05:00:00+00:00","predicted":213.99502799069685,"rising_edge":"2017-08-17 04:30:00+00:00"},{"actual":214.71928159884266,"falling_edge":"2017-08-17 05:30:00+00:00","predicted":214.71928159884266,"rising_edge":"2017-08-17 05:00:00+00:00"},{"actual":224.18779617986533,"falling_edge":"2017-08-17 06:00:00+00:00","predicted":224.18779617986533,"rising_edge":"2017-08-17 05:30:00+00:00"},{"actual":222.08759044084962,"falling_edge":"2017-08-17 06:30:00+00:00","predicted":222.08759044084962,"rising_edge":"2017-08-17 06:00:00+00:00"},{"actual":227.66723227364858,"falling_edge":"2017-08-17 07:00:00+00:00","predicted":227.66723227364858,"rising_edge":"2017-08-17 06:30:00+00:00"},{"actual":226.340365251805,"falling_edge":"2017-08-17 07:30:00+00:00","predicted":226.340365251805,"rising_edge":"2017-08-17 07:00:00+00:00"},{"actual":222.88645406736774,"falling_edge":"2017-08-17 08:00:00+00:00","predicted":222.88645406736774,"rising_edge":"2017-08-17 07:30:00+00:00"},{"actual":220.60803891527786,"falling_edge":"2017-08-17 08:30:00+00:00","predicted":220.60803891527786,"rising_edge":"2017-08-17 08:00:00+00:00"},{"actual":208.08620677993062,"falling_edge":"2017-08-17 09:00:00+00:00","predicted":208.08620677993062,"rising_edge":"2017-08-17 08:30:00+00:00"},{"actual":185.4723843389947,"falling_edge":"2017-08-17 09:30:00+00:00","predicted":185.4723843389947,"rising_edge":"2017-08-17 09:00:00+00:00"},{"actual":167.42697886188955,"falling_edge":"2017-08-17 10:00:00+00:00","predicted":167.42697886188955,"rising_edge":"2017-08-17 09:30:00+00:00"},{"actual":142.05842626413386,"falling_edge":"2017-08-17 10:30:00+00:00","predicted":142.05842626413386,"rising_edge":"2017-08-17 10:00:00+00:00"},{"actual":137.34299471447565,"falling_edge":"2017-08-17 11:00:00+00:00","predicted":137.34299471447565,"rising_edge":"2017-08-17 10:30:00+00:00"},{"actual":130.588676468772,"falling_edge":"2017-08-17 11:30:00+00:00","predicted":130.588676468772,"rising_edge":"2017-08-17 11:00:00+00:00"},{"actual":119.15168350566867,"falling_edge":"2017-08-17 12:00:00+00:00","predicted":119.15168350566867,"rising_edge":"2017-08-17 11:30:00+00:00"},{"actual":108.26379826185983,"falling_edge":"2017-08-17 12:30:00+00:00","predicted":108.26379826185983,"rising_edge":"2017-08-17 12:00:00+00:00"},{"actual":97.03157549039915,"falling_edge":"2017-08-17 13:00:00+00:00","predicted":97.03157549039915,"rising_edge":"2017-08-17 12:30:00+00:00"},{"actual":84.52803476038189,"falling_edge":"2017-08-17 13:30:00+00:00","predicted":84.52803476038189,"rising_edge":"2017-08-17 13:00:00+00:00"},{"actual":74.49312098110914,"falling_edge":"2017-08-17 14:00:00+00:00","predicted":74.49312098110914,"rising_edge":"2017-08-17 13:30:00+00:00"},{"actual":68.26062275829032,"falling_edge":"2017-08-17 14:30:00+00:00","predicted":68.26062275829032,"rising_edge":"2017-08-17 14:00:00+00:00"},{"actual":60.708284937718346,"falling_edge":"2017-08-17 15:00:00+00:00","predicted":60.708284937718346,"rising_edge":"2017-08-17 14:30:00+00:00"},{"actual":52.99304525034161,"falling_edge":"2017-08-17 15:30:00+00:00","predicted":52.99304525034161,"rising_edge":"2017-08-17 15:00:00+00:00"},{"actual":48.54606941263905,"falling_edge":"2017-08-17 16:00:00+00:00","predicted":48.54606941263905,"rising_edge":"2017-08-17 15:30:00+00:00"},{"actual":46.977435302639364,"falling_edge":"2017-08-17 16:30:00+00:00","predicted":46.977435302639364,"rising_edge":"2017-08-17 16:00:00+00:00"},{"actual":47.68211735588635,"falling_edge":"2017-08-17 17:00:00+00:00","predicted":47.68211735588635,"rising_edge":"2017-08-17 16:30:00+00:00"},{"actual":47.59819729488121,"falling_edge":"2017-08-17 17:30:00+00:00","predicted":47.59819729488121,"rising_edge":"2017-08-17 17:00:00+00:00"},{"actual":46.2321568516392,"falling_edge":"2017-08-17 18:00:00+00:00","predicted":46.2321568516392,"rising_edge":"2017-08-17 17:30:00+00:00"},{"actual":46.777472772083556,"falling_edge":"2017-08-17 18:30:00+00:00","predicted":46.777472772083556,"rising_edge":"2017-08-17 18:00:00+00:00"},{"actual":46.3178803957191,"falling_edge":"2017-08-17 19:00:00+00:00","predicted":46.3178803957191,"rising_edge":"2017-08-17 18:30:00+00:00"},{"actual":47.21274588680047,"falling_edge":"2017-08-17 19:30:00+00:00","predicted":47.21274588680047,"rising_edge":"2017-08-17 19:00:00+00:00"},{"actual":46.20709427593958,"falling_edge":"2017-08-17 20:00:00+00:00","predicted":46.20709427593958,"rising_edge":"2017-08-17 19:30:00+00:00"},{"actual":48.1123798761588,"falling_edge":"2017-08-17 20:30:00+00:00","predicted":48.1123798761588,"rising_edge":"2017-08-17 20:00:00+00:00"},{"actual":52.479894587714554,"falling_edge":"2017-08-17 21:00:00+00:00","predicted":52.479894587714554,"rising_edge":"2017-08-17 20:30:00+00:00"},{"actual":68.60769244569806,"falling_edge":"2017-08-17 21:30:00+00:00","predicted":68.60769244569806,"rising_edge":"2017-08-17 21:00:00+00:00"},{"actual":107.27006932391907,"falling_edge":"2017-08-17 22:00:00+00:00","predicted":107.27006932391907,"rising_edge":"2017-08-17 21:30:00+00:00"},{"actual":103.13210455597797,"falling_edge":"2017-08-17 22:30:00+00:00","predicted":103.13210455597797,"rising_edge":"2017-08-17 22:00:00+00:00"},{"actual":122.71196840695627,"falling_edge":"2017-08-17 23:00:00+00:00","predicted":122.71196840695627,"rising_edge":"2017-08-17 22:30:00+00:00"},{"actual":155.24032296065172,"falling_edge":"2017-08-17 23:30:00+00:00","predicted":155.24032296065172,"rising_edge":"2017-08-17 23:00:00+00:00"},{"actual":201.38553486191327,"falling_edge":"2017-08-18 00:00:00+00:00","predicted":201.38553486191327,"rising_edge":"2017-08-17 23:30:00+00:00"},{"actual":214.58835997248812,"falling_edge":"2017-08-18 00:30:00+00:00","predicted":214.58835997248812,"rising_edge":"2017-08-18 00:00:00+00:00"},{"actual":214.97798387577734,"falling_edge":"2017-08-18 01:00:00+00:00","predicted":214.97798387577734,"rising_edge":"2017-08-18 00:30:00+00:00"},{"actual":222.84042101787318,"falling_edge":"2017-08-18 01:30:00+00:00","predicted":222.84042101787318,"rising_edge":"2017-08-18 01:00:00+00:00"},{"actual":221.48725003911113,"falling_edge":"2017-08-18 02:00:00+00:00","predicted":221.48725003911113,"rising_edge":"2017-08-18 01:30:00+00:00"},{"actual":217.5492370815103,"falling_edge":"2017-08-18 02:30:00+00:00","predicted":217.5492370815103,"rising_edge":"2017-08-18 02:00:00+00:00"},{"actual":212.14203479768608,"falling_edge":"2017-08-18 03:00:00+00:00","predicted":212.14203479768608,"rising_edge":"2017-08-18 02:30:00+00:00"},{"actual":207.89686210423895,"falling_edge":"2017-08-18 03:30:00+00:00","predicted":207.89686210423895,"rising_edge":"2017-08-18 03:00:00+00:00"},{"actual":190.85500797368783,"falling_edge":"2017-08-18 04:00:00+00:00","predicted":190.85500797368783,"rising_edge":"2017-08-18 03:30:00+00:00"},{"actual":206.74926621026583,"falling_edge":"2017-08-18 04:30:00+00:00","predicted":206.74926621026583,"rising_edge":"2017-08-18 04:00:00+00:00"},{"actual":211.54615740869934,"falling_edge":"2017-08-18 05:00:00+00:00","predicted":211.54615740869934,"rising_edge":"2017-08-18 04:30:00+00:00"},{"actual":205.73140072088515,"falling_edge":"2017-08-18 05:30:00+00:00","predicted":205.73140072088515,"rising_edge":"2017-08-18 05:00:00+00:00"},{"actual":207.48463220704886,"falling_edge":"2017-08-18 06:00:00+00:00","predicted":207.48463220704886,"rising_edge":"2017-08-18 05:30:00+00:00"},{"actual":208.2734364613314,"falling_edge":"2017-08-18 06:30:00+00:00","predicted":208.2734364613314,"rising_edge":"2017-08-18 06:00:00+00:00"},{"actual":214.27831659876915,"falling_edge":"2017-08-18 07:00:00+00:00","predicted":214.27831659876915,"rising_edge":"2017-08-18 06:30:00+00:00"},{"actual":212.34666346952983,"falling_edge":"2017-08-18 07:30:00+00:00","predicted":212.34666346952983,"rising_edge":"2017-08-18 07:00:00+00:00"},{"actual":216.18317609644436,"falling_edge":"2017-08-18 08:00:00+00:00","predicted":216.18317609644436,"rising_edge":"2017-08-18 07:30:00+00:00"},{"actual":223.72591373252453,"falling_edge":"2017-08-18 08:30:00+00:00","predicted":223.72591373252453,"rising_edge":"2017-08-18 08:00:00+00:00"},{"actual":207.16168122108328,"falling_edge":"2017-08-18 09:00:00+00:00","predicted":207.16168122108328,"rising_edge":"2017-08-18 08:30:00+00:00"},{"actual":182.51303470692767,"falling_edge":"2017-08-18 09:30:00+00:00","predicted":182.51303470692767,"rising_edge":"2017-08-18 09:00:00+00:00"},{"actual":157.8973184496208,"falling_edge":"2017-08-18 10:00:00+00:00","predicted":157.8973184496208,"rising_edge":"2017-08-18 09:30:00+00:00"},{"actual":132.08753023620017,"falling_edge":"2017-08-18 10:30:00+00:00","predicted":132.08753023620017,"rising_edge":"2017-08-18 10:00:00+00:00"},{"actual":124.18617867230817,"falling_edge":"2017-08-18 11:00:00+00:00","predicted":124.18617867230817,"rising_edge":"2017-08-18 10:30:00+00:00"},{"actual":112.06651338716757,"falling_edge":"2017-08-18 11:30:00+00:00","predicted":112.06651338716757,"rising_edge":"2017-08-18 11:00:00+00:00"},{"actual":102.30835719966363,"falling_edge":"2017-08-18 12:00:00+00:00","predicted":102.30835719966363,"rising_edge":"2017-08-18 11:30:00+00:00"},{"actual":91.67200837097808,"falling_edge":"2017-08-18 12:30:00+00:00","predicted":91.67200837097808,"rising_edge":"2017-08-18 12:00:00+00:00"},{"actual":82.0828673350127,"falling_edge":"2017-08-18 13:00:00+00:00","predicted":82.0828673350127,"rising_edge":"2017-08-18 12:30:00+00:00"},{"actual":74.79377140360795,"falling_edge":"2017-08-18 13:30:00+00:00","predicted":74.79377140360795,"rising_edge":"2017-08-18 13:00:00+00:00"},{"actual":69.52017115707453,"falling_edge":"2017-08-18 14:00:00+00:00","predicted":69.52017115707453,"rising_edge":"2017-08-18 13:30:00+00:00"},{"actual":60.276768411446426,"falling_edge":"2017-08-18 14:30:00+00:00","predicted":60.276768411446426,"rising_edge":"2017-08-18 14:00:00+00:00"},{"actual":56.10397585867292,"falling_edge":"2017-08-18 15:00:00+00:00","predicted":56.10397585867292,"rising_edge":"2017-08-18 14:30:00+00:00"},{"actual":50.03234034986765,"falling_edge":"2017-08-18 15:30:00+00:00","predicted":50.03234034986765,"rising_edge":"2017-08-18 15:00:00+00:00"},{"actual":46.94412283434011,"falling_edge":"2017-08-18 16:00:00+00:00","predicted":46.94412283434011,"rising_edge":"2017-08-18 15:30:00+00:00"},{"actual":47.50121253725921,"falling_edge":"2017-08-18 16:30:00+00:00","predicted":47.50121253725921,"rising_edge":"2017-08-18 16:00:00+00:00"},{"actual":46.688722142824716,"falling_edge":"2017-08-18 17:00:00+00:00","predicted":46.688722142824716,"rising_edge":"2017-08-18 16:30:00+00:00"},{"actual":46.66371552520828,"falling_edge":"2017-08-18 17:30:00+00:00","predicted":46.66371552520828,"rising_edge":"2017-08-18 17:00:00+00:00"},{"actual":45.76228894822732,"falling_edge":"2017-08-18 18:00:00+00:00","predicted":45.76228894822732,"rising_edge":"2017-08-18 17:30:00+00:00"},{"actual":47.1692043567471,"falling_edge":"2017-08-18 18:30:00+00:00","predicted":47.1692043567471,"rising_edge":"2017-08-18 18:00:00+00:00"},{"actual":48.04023361784429,"falling_edge":"2017-08-18 19:00:00+00:00","predicted":48.04023361784429,"rising_edge":"2017-08-18 18:30:00+00:00"},{"actual":48.57304793252186,"falling_edge":"2017-08-18 19:30:00+00:00","predicted":48.57304793252186,"rising_edge":"2017-08-18 19:00:00+00:00"},{"actual":47.63466988832237,"falling_edge":"2017-08-18 20:00:00+00:00","predicted":47.63466988832237,"rising_edge":"2017-08-18 19:30:00+00:00"},{"actual":48.096135845556624,"falling_edge":"2017-08-18 20:30:00+00:00","predicted":48.096135845556624,"rising_edge":"2017-08-18 20:00:00+00:00"},{"actual":50.75963986564991,"falling_edge":"2017-08-18 21:00:00+00:00","predicted":50.75963986564991,"rising_edge":"2017-08-18 20:30:00+00:00"},{"actual":59.511190109681806,"falling_edge":"2017-08-18 21:30:00+00:00","predicted":59.511190109681806,"rising_edge":"2017-08-18 21:00:00+00:00"},{"actual":62.61266096566612,"falling_edge":"2017-08-18 22:00:00+00:00","predicted":62.61266096566612,"rising_edge":"2017-08-18 21:30:00+00:00"},{"actual":62.931527323122985,"falling_edge":"2017-08-18 22:30:00+00:00","predicted":62.931527323122985,"rising_edge":"2017-08-18 22:00:00+00:00"},{"actual":63.838485158161,"falling_edge":"2017-08-18 23:00:00+00:00","predicted":63.838485158161,"rising_edge":"2017-08-18 22:30:00+00:00"},{"actual":67.21464115949625,"falling_edge":"2017-08-18 23:30:00+00:00","predicted":67.21464115949625,"rising_edge":"2017-08-18 23:00:00+00:00"},{"actual":72.36901898055109,"falling_edge":"2017-08-19 00:00:00+00:00","predicted":72.36901898055109,"rising_edge":"2017-08-18 23:30:00+00:00"},{"actual":82.75287263559342,"falling_edge":"2017-08-19 00:30:00+00:00","predicted":82.75287263559342,"rising_edge":"2017-08-19 00:00:00+00:00"},{"actual":90.88524621777292,"falling_edge":"2017-08-19 01:00:00+00:00","predicted":90.88524621777292,"rising_edge":"2017-08-19 00:30:00+00:00"},{"actual":90.3075513997582,"falling_edge":"2017-08-19 01:30:00+00:00","predicted":90.3075513997582,"rising_edge":"2017-08-19 01:00:00+00:00"},{"actual":87.27773636554338,"falling_edge":"2017-08-19 02:00:00+00:00","predicted":87.27773636554338,"rising_edge":"2017-08-19 01:30:00+00:00"},{"actual":87.44778837015403,"falling_edge":"2017-08-19 02:30:00+00:00","predicted":87.44778837015403,"rising_edge":"2017-08-19 02:00:00+00:00"},{"actual":91.45841951665396,"falling_edge":"2017-08-19 03:00:00+00:00","predicted":91.45841951665396,"rising_edge":"2017-08-19 02:30:00+00:00"},{"actual":87.52168277190036,"falling_edge":"2017-08-19 03:30:00+00:00","predicted":87.52168277190036,"rising_edge":"2017-08-19 03:00:00+00:00"},{"actual":87.07383311469235,"falling_edge":"2017-08-19 04:00:00+00:00","predicted":87.07383311469235,"rising_edge":"2017-08-19 03:30:00+00:00"},{"actual":94.90723308594981,"falling_edge":"2017-08-19 04:30:00+00:00","predicted":94.90723308594981,"rising_edge":"2017-08-19 04:00:00+00:00"},{"actual":92.51395874508519,"falling_edge":"2017-08-19 05:00:00+00:00","predicted":92.51395874508519,"rising_edge":"2017-08-19 04:30:00+00:00"},{"actual":95.22307412805483,"falling_edge":"2017-08-19 05:30:00+00:00","predicted":95.22307412805483,"rising_edge":"2017-08-19 05:00:00+00:00"},{"actual":90.8606324129045,"falling_edge":"2017-08-19 06:00:00+00:00","predicted":90.8606324129045,"rising_edge":"2017-08-19 05:30:00+00:00"},{"actual":90.94504213806917,"falling_edge":"2017-08-19 06:30:00+00:00","predicted":90.94504213806917,"rising_edge":"2017-08-19 06:00:00+00:00"},{"actual":92.75306688135954,"falling_edge":"2017-08-19 07:00:00+00:00","predicted":92.75306688135954,"rising_edge":"2017-08-19 06:30:00+00:00"},{"actual":94.21000506373996,"falling_edge":"2017-08-19 07:30:00+00:00","predicted":94.21000506373996,"rising_edge":"2017-08-19 07:00:00+00:00"},{"actual":92.6633544670912,"falling_edge":"2017-08-19 08:00:00+00:00","predicted":92.6633544670912,"rising_edge":"2017-08-19 07:30:00+00:00"},{"actual":91.21665767383271,"falling_edge":"2017-08-19 08:30:00+00:00","predicted":91.21665767383271,"rising_edge":"2017-08-19 08:00:00+00:00"},{"actual":83.45885204364761,"falling_edge":"2017-08-19 09:00:00+00:00","predicted":83.45885204364761,"rising_edge":"2017-08-19 08:30:00+00:00"},{"actual":72.56014356710287,"falling_edge":"2017-08-19 09:30:00+00:00","predicted":72.56014356710287,"rising_edge":"2017-08-19 09:00:00+00:00"},{"actual":70.84458781825653,"falling_edge":"2017-08-19 10:00:00+00:00","predicted":70.84458781825653,"rising_edge":"2017-08-19 09:30:00+00:00"},{"actual":67.69511590308991,"falling_edge":"2017-08-19 10:30:00+00:00","predicted":67.69511590308991,"rising_edge":"2017-08-19 10:00:00+00:00"},{"actual":64.48280047238798,"falling_edge":"2017-08-19 11:00:00+00:00","predicted":64.48280047238798,"rising_edge":"2017-08-19 10:30:00+00:00"},{"actual":63.8094944554007,"falling_edge":"2017-08-19 11:30:00+00:00","predicted":63.8094944554007,"rising_edge":"2017-08-19 11:00:00+00:00"},{"actual":61.254723531605016,"falling_edge":"2017-08-19 12:00:00+00:00","predicted":61.254723531605016,"rising_edge":"2017-08-19 11:30:00+00:00"},{"actual":56.531326397281134,"falling_edge":"2017-08-19 12:30:00+00:00","predicted":56.531326397281134,"rising_edge":"2017-08-19 12:00:00+00:00"},{"actual":56.19541771009065,"falling_edge":"2017-08-19 13:00:00+00:00","predicted":56.19541771009065,"rising_edge":"2017-08-19 12:30:00+00:00"},{"actual":54.67493674523082,"falling_edge":"2017-08-19 13:30:00+00:00","predicted":54.67493674523082,"rising_edge":"2017-08-19 13:00:00+00:00"},{"actual":54.389388575090045,"falling_edge":"2017-08-19 14:00:00+00:00","predicted":54.389388575090045,"rising_edge":"2017-08-19 13:30:00+00:00"},{"actual":51.246368654330574,"falling_edge":"2017-08-19 14:30:00+00:00","predicted":51.246368654330574,"rising_edge":"2017-08-19 14:00:00+00:00"},{"actual":50.5631686670717,"falling_edge":"2017-08-19 15:00:00+00:00","predicted":50.5631686670717,"rising_edge":"2017-08-19 14:30:00+00:00"},{"actual":50.57332957984823,"falling_edge":"2017-08-19 15:30:00+00:00","predicted":50.57332957984823,"rising_edge":"2017-08-19 15:00:00+00:00"},{"actual":47.89024786277053,"falling_edge":"2017-08-19 16:00:00+00:00","predicted":47.89024786277053,"rising_edge":"2017-08-19 15:30:00+00:00"},{"actual":48.04091248009773,"falling_edge":"2017-08-19 16:30:00+00:00","predicted":48.04091248009773,"rising_edge":"2017-08-19 16:00:00+00:00"},{"actual":47.047539653473315,"falling_edge":"2017-08-19 17:00:00+00:00","predicted":47.047539653473315,"rising_edge":"2017-08-19 16:30:00+00:00"},{"actual":47.59049905518837,"falling_edge":"2017-08-19 17:30:00+00:00","predicted":47.59049905518837,"rising_edge":"2017-08-19 17:00:00+00:00"},{"actual":47.12958536712267,"falling_edge":"2017-08-19 18:00:00+00:00","predicted":47.12958536712267,"rising_edge":"2017-08-19 17:30:00+00:00"},{"actual":47.77166379936976,"falling_edge":"2017-08-19 18:30:00+00:00","predicted":47.77166379936976,"rising_edge":"2017-08-19 18:00:00+00:00"},{"actual":47.06124030851306,"falling_edge":"2017-08-19 19:00:00+00:00","predicted":47.06124030851306,"rising_edge":"2017-08-19 18:30:00+00:00"},{"actual":46.56817222274265,"falling_edge":"2017-08-19 19:30:00+00:00","predicted":46.56817222274265,"rising_edge":"2017-08-19 19:00:00+00:00"},{"actual":47.15408859180901,"falling_edge":"2017-08-19 20:00:00+00:00","predicted":47.15408859180901,"rising_edge":"2017-08-19 19:30:00+00:00"},{"actual":46.715497662105015,"falling_edge":"2017-08-19 20:30:00+00:00","predicted":46.715497662105015,"rising_edge":"2017-08-19 20:00:00+00:00"},{"actual":47.89464793773185,"falling_edge":"2017-08-19 21:00:00+00:00","predicted":47.89464793773185,"rising_edge":"2017-08-19 20:30:00+00:00"},{"actual":48.46144971478173,"falling_edge":"2017-08-19 21:30:00+00:00","predicted":48.46144971478173,"rising_edge":"2017-08-19 21:00:00+00:00"},{"actual":51.587073421447364,"falling_edge":"2017-08-19 22:00:00+00:00","predicted":51.587073421447364,"rising_edge":"2017-08-19 21:30:00+00:00"},{"actual":53.512029794741785,"falling_edge":"2017-08-19 22:30:00+00:00","predicted":53.512029794741785,"rising_edge":"2017-08-19 22:00:00+00:00"},{"actual":54.17651932184508,"falling_edge":"2017-08-19 23:00:00+00:00","predicted":54.17651932184508,"rising_edge":"2017-08-19 22:30:00+00:00"},{"actual":58.47288823827958,"falling_edge":"2017-08-19 23:30:00+00:00","predicted":58.47288823827958,"rising_edge":"2017-08-19 23:00:00+00:00"},{"actual":62.53703710813934,"falling_edge":"2017-08-20 00:00:00+00:00","predicted":62.53703710813934,"rising_edge":"2017-08-19 23:30:00+00:00"},{"actual":68.96464972803798,"falling_edge":"2017-08-20 00:30:00+00:00","predicted":68.96464972803798,"rising_edge":"2017-08-20 00:00:00+00:00"},{"actual":70.79544407016552,"falling_edge":"2017-08-20 01:00:00+00:00","predicted":70.79544407016552,"rising_edge":"2017-08-20 00:30:00+00:00"},{"actual":71.00251675167247,"falling_edge":"2017-08-20 01:30:00+00:00","predicted":71.00251675167247,"rising_edge":"2017-08-20 01:00:00+00:00"},{"actual":71.22551018974934,"falling_edge":"2017-08-20 02:00:00+00:00","predicted":71.22551018974934,"rising_edge":"2017-08-20 01:30:00+00:00"},{"actual":72.05607142428103,"falling_edge":"2017-08-20 02:30:00+00:00","predicted":72.05607142428103,"rising_edge":"2017-08-20 02:00:00+00:00"},{"actual":72.98552001876897,"falling_edge":"2017-08-20 03:00:00+00:00","predicted":72.98552001876897,"rising_edge":"2017-08-20 02:30:00+00:00"},{"actual":72.26527701789496,"falling_edge":"2017-08-20 03:30:00+00:00","predicted":72.26527701789496,"rising_edge":"2017-08-20 03:00:00+00:00"},{"actual":72.94551424889875,"falling_edge":"2017-08-20 04:00:00+00:00","predicted":72.94551424889875,"rising_edge":"2017-08-20 03:30:00+00:00"},{"actual":77.57633277558344,"falling_edge":"2017-08-20 04:30:00+00:00","predicted":77.57633277558344,"rising_edge":"2017-08-20 04:00:00+00:00"},{"actual":76.75200982556942,"falling_edge":"2017-08-20 05:00:00+00:00","predicted":76.75200982556942,"rising_edge":"2017-08-20 04:30:00+00:00"},{"actual":78.21608317453345,"falling_edge":"2017-08-20 05:30:00+00:00","predicted":78.21608317453345,"rising_edge":"2017-08-20 05:00:00+00:00"},{"actual":78.19550904318189,"falling_edge":"2017-08-20 06:00:00+00:00","predicted":78.19550904318189,"rising_edge":"2017-08-20 05:30:00+00:00"},{"actual":80.9789292766028,"falling_edge":"2017-08-20 06:30:00+00:00","predicted":80.9789292766028,"rising_edge":"2017-08-20 06:00:00+00:00"},{"actual":82.51862236280186,"falling_edge":"2017-08-20 07:00:00+00:00","predicted":82.51862236280186,"rising_edge":"2017-08-20 06:30:00+00:00"},{"actual":84.48423504387804,"falling_edge":"2017-08-20 07:30:00+00:00","predicted":84.48423504387804,"rising_edge":"2017-08-20 07:00:00+00:00"},{"actual":79.55365935246779,"falling_edge":"2017-08-20 08:00:00+00:00","predicted":79.55365935246779,"rising_edge":"2017-08-20 07:30:00+00:00"},{"actual":76.90817039103558,"falling_edge":"2017-08-20 08:30:00+00:00","predicted":76.90817039103558,"rising_edge":"2017-08-20 08:00:00+00:00"},{"actual":72.796089295964,"falling_edge":"2017-08-20 09:00:00+00:00","predicted":72.796089295964,"rising_edge":"2017-08-20 08:30:00+00:00"},{"actual":65.99219528269568,"falling_edge":"2017-08-20 09:30:00+00:00","predicted":65.99219528269568,"rising_edge":"2017-08-20 09:00:00+00:00"},{"actual":64.050351268755,"falling_edge":"2017-08-20 10:00:00+00:00","predicted":64.050351268755,"rising_edge":"2017-08-20 09:30:00+00:00"},{"actual":60.55995579952238,"falling_edge":"2017-08-20 10:30:00+00:00","predicted":60.55995579952238,"rising_edge":"2017-08-20 10:00:00+00:00"},{"actual":60.44839482985264,"falling_edge":"2017-08-20 11:00:00+00:00","predicted":60.44839482985264,"rising_edge":"2017-08-20 10:30:00+00:00"},{"actual":59.64729322719295,"falling_edge":"2017-08-20 11:30:00+00:00","predicted":59.64729322719295,"rising_edge":"2017-08-20 11:00:00+00:00"},{"actual":59.764840597022506,"falling_edge":"2017-08-20 12:00:00+00:00","predicted":59.764840597022506,"rising_edge":"2017-08-20 11:30:00+00:00"},{"actual":55.72113578867496,"falling_edge":"2017-08-20 12:30:00+00:00","predicted":55.72113578867496,"rising_edge":"2017-08-20 12:00:00+00:00"},{"actual":54.18535731249013,"falling_edge":"2017-08-20 13:00:00+00:00","predicted":54.18535731249013,"rising_edge":"2017-08-20 12:30:00+00:00"},{"actual":52.93682958984641,"falling_edge":"2017-08-20 13:30:00+00:00","predicted":52.93682958984641,"rising_edge":"2017-08-20 13:00:00+00:00"},{"actual":50.54702143597513,"falling_edge":"2017-08-20 14:00:00+00:00","predicted":50.54702143597513,"rising_edge":"2017-08-20 13:30:00+00:00"},{"actual":51.75061830652007,"falling_edge":"2017-08-20 14:30:00+00:00","predicted":51.75061830652007,"rising_edge":"2017-08-20 14:00:00+00:00"},{"actual":49.7954881675818,"falling_edge":"2017-08-20 15:00:00+00:00","predicted":49.7954881675818,"rising_edge":"2017-08-20 14:30:00+00:00"},{"actual":49.7698133410026,"falling_edge":"2017-08-20 15:30:00+00:00","predicted":49.7698133410026,"rising_edge":"2017-08-20 15:00:00+00:00"},{"actual":49.02673898960009,"falling_edge":"2017-08-20 16:00:00+00:00","predicted":49.02673898960009,"rising_edge":"2017-08-20 15:30:00+00:00"},{"actual":50.08649554600898,"falling_edge":"2017-08-20 16:30:00+00:00","predicted":50.08649554600898,"rising_edge":"2017-08-20 16:00:00+00:00"},{"actual":48.43425466169822,"falling_edge":"2017-08-20 17:00:00+00:00","predicted":48.43425466169822,"rising_edge":"2017-08-20 16:30:00+00:00"},{"actual":47.6297940467916,"falling_edge":"2017-08-20 17:30:00+00:00","predicted":47.6297940467916,"rising_edge":"2017-08-20 17:00:00+00:00"},{"actual":48.79709696810554,"falling_edge":"2017-08-20 18:00:00+00:00","predicted":48.79709696810554,"rising_edge":"2017-08-20 17:30:00+00:00"},{"actual":47.714017463160786,"falling_edge":"2017-08-20 18:30:00+00:00","predicted":47.714017463160786,"rising_edge":"2017-08-20 18:00:00+00:00"},{"actual":48.29561902471489,"falling_edge":"2017-08-20 19:00:00+00:00","predicted":48.29561902471489,"rising_edge":"2017-08-20 18:30:00+00:00"},{"actual":47.49584316859576,"falling_edge":"2017-08-20 19:30:00+00:00","predicted":47.49584316859576,"rising_edge":"2017-08-20 19:00:00+00:00"},{"actual":48.3854711651553,"falling_edge":"2017-08-20 20:00:00+00:00","predicted":48.3854711651553,"rising_edge":"2017-08-20 19:30:00+00:00"},{"actual":48.97339264059526,"falling_edge":"2017-08-20 20:30:00+00:00","predicted":48.97339264059526,"rising_edge":"2017-08-20 20:00:00+00:00"},{"actual":54.075303363562774,"falling_edge":"2017-08-20 21:00:00+00:00","predicted":54.075303363562774,"rising_edge":"2017-08-20 20:30:00+00:00"},{"actual":71.7178730746807,"falling_edge":"2017-08-20 21:30:00+00:00","predicted":71.7178730746807,"rising_edge":"2017-08-20 21:00:00+00:00"},{"actual":134.26089608536603,"falling_edge":"2017-08-20 22:00:00+00:00","predicted":134.26089608536603,"rising_edge":"2017-08-20 21:30:00+00:00"},{"actual":119.9451715695183,"falling_edge":"2017-08-20 22:30:00+00:00","predicted":119.9451715695183,"rising_edge":"2017-08-20 22:00:00+00:00"},{"actual":141.809652429279,"falling_edge":"2017-08-20 23:00:00+00:00","predicted":141.809652429279,"rising_edge":"2017-08-20 22:30:00+00:00"},{"actual":178.73070737172566,"falling_edge":"2017-08-20 23:30:00+00:00","predicted":178.73070737172566,"rising_edge":"2017-08-20 23:00:00+00:00"},{"actual":219.71685287013358,"falling_edge":"2017-08-21 00:00:00+00:00","predicted":219.71685287013358,"rising_edge":"2017-08-20 23:30:00+00:00"},{"actual":228.96396334560066,"falling_edge":"2017-08-21 00:30:00+00:00","predicted":228.96396334560066,"rising_edge":"2017-08-21 00:00:00+00:00"},{"actual":244.79858900110526,"falling_edge":"2017-08-21 01:00:00+00:00","predicted":244.79858900110526,"rising_edge":"2017-08-21 00:30:00+00:00"},{"actual":254.5578773365205,"falling_edge":"2017-08-21 01:30:00+00:00","predicted":254.5578773365205,"rising_edge":"2017-08-21 01:00:00+00:00"},{"actual":256.6510098568977,"falling_edge":"2017-08-21 02:00:00+00:00","predicted":256.6510098568977,"rising_edge":"2017-08-21 01:30:00+00:00"},{"actual":241.26877275223165,"falling_edge":"2017-08-21 02:30:00+00:00","predicted":241.26877275223165,"rising_edge":"2017-08-21 02:00:00+00:00"},{"actual":239.5095279328234,"falling_edge":"2017-08-21 03:00:00+00:00","predicted":239.5095279328234,"rising_edge":"2017-08-21 02:30:00+00:00"},{"actual":238.2409003583941,"falling_edge":"2017-08-21 03:30:00+00:00","predicted":238.2409003583941,"rising_edge":"2017-08-21 03:00:00+00:00"},{"actual":223.82572997930635,"falling_edge":"2017-08-21 04:00:00+00:00","predicted":223.82572997930635,"rising_edge":"2017-08-21 03:30:00+00:00"},{"actual":232.75336278379848,"falling_edge":"2017-08-21 04:30:00+00:00","predicted":232.75336278379848,"rising_edge":"2017-08-21 04:00:00+00:00"},{"actual":233.0060838862599,"falling_edge":"2017-08-21 05:00:00+00:00","predicted":233.0060838862599,"rising_edge":"2017-08-21 04:30:00+00:00"},{"actual":226.57152628355013,"falling_edge":"2017-08-21 05:30:00+00:00","predicted":226.57152628355013,"rising_edge":"2017-08-21 05:00:00+00:00"},{"actual":234.51704966286667,"falling_edge":"2017-08-21 06:00:00+00:00","predicted":234.51704966286667,"rising_edge":"2017-08-21 05:30:00+00:00"},{"actual":238.16318121958432,"falling_edge":"2017-08-21 06:30:00+00:00","predicted":238.16318121958432,"rising_edge":"2017-08-21 06:00:00+00:00"},{"actual":231.64606901385858,"falling_edge":"2017-08-21 07:00:00+00:00","predicted":231.64606901385858,"rising_edge":"2017-08-21 06:30:00+00:00"},{"actual":230.4465340071954,"falling_edge":"2017-08-21 07:30:00+00:00","predicted":230.4465340071954,"rising_edge":"2017-08-21 07:00:00+00:00"},{"actual":225.35883729366222,"falling_edge":"2017-08-21 08:00:00+00:00","predicted":225.35883729366222,"rising_edge":"2017-08-21 07:30:00+00:00"},{"actual":219.89203996695122,"falling_edge":"2017-08-21 08:30:00+00:00","predicted":219.89203996695122,"rising_edge":"2017-08-21 08:00:00+00:00"},{"actual":206.0442627118794,"falling_edge":"2017-08-21 09:00:00+00:00","predicted":206.0442627118794,"rising_edge":"2017-08-21 08:30:00+00:00"},{"actual":176.27494091338613,"falling_edge":"2017-08-21 09:30:00+00:00","predicted":176.27494091338613,"rising_edge":"2017-08-21 09:00:00+00:00"},{"actual":162.56717673919715,"falling_edge":"2017-08-21 10:00:00+00:00","predicted":162.56717673919715,"rising_edge":"2017-08-21 09:30:00+00:00"},{"actual":139.74615650431753,"falling_edge":"2017-08-21 10:30:00+00:00","predicted":139.74615650431753,"rising_edge":"2017-08-21 10:00:00+00:00"},{"actual":137.67035678974358,"falling_edge":"2017-08-21 11:00:00+00:00","predicted":137.67035678974358,"rising_edge":"2017-08-21 10:30:00+00:00"},{"actual":129.23642921201034,"falling_edge":"2017-08-21 11:30:00+00:00","predicted":129.23642921201034,"rising_edge":"2017-08-21 11:00:00+00:00"},{"actual":116.43282621116552,"falling_edge":"2017-08-21 12:00:00+00:00","predicted":116.43282621116552,"rising_edge":"2017-08-21 11:30:00+00:00"},{"actual":105.57611635022926,"falling_edge":"2017-08-21 12:30:00+00:00","predicted":105.57611635022926,"rising_edge":"2017-08-21 12:00:00+00:00"},{"actual":97.66996373456249,"falling_edge":"2017-08-21 13:00:00+00:00","predicted":97.66996373456249,"rising_edge":"2017-08-21 12:30:00+00:00"},{"actual":88.99308774316597,"falling_edge":"2017-08-21 13:30:00+00:00","predicted":88.99308774316597,"rising_edge":"2017-08-21 13:00:00+00:00"},{"actual":76.73977245289467,"falling_edge":"2017-08-21 14:00:00+00:00","predicted":76.73977245289467,"rising_edge":"2017-08-21 13:30:00+00:00"},{"actual":66.39719287853224,"falling_edge":"2017-08-21 14:30:00+00:00","predicted":66.39719287853224,"rising_edge":"2017-08-21 14:00:00+00:00"},{"actual":59.2419571470056,"falling_edge":"2017-08-21 15:00:00+00:00","predicted":59.2419571470056,"rising_edge":"2017-08-21 14:30:00+00:00"},{"actual":53.568314276086866,"falling_edge":"2017-08-21 15:30:00+00:00","predicted":53.568314276086866,"rising_edge":"2017-08-21 15:00:00+00:00"},{"actual":48.65769105594772,"falling_edge":"2017-08-21 16:00:00+00:00","predicted":48.65769105594772,"rising_edge":"2017-08-21 15:30:00+00:00"},{"actual":48.1610245342573,"falling_edge":"2017-08-21 16:30:00+00:00","predicted":48.1610245342573,"rising_edge":"2017-08-21 16:00:00+00:00"},{"actual":48.26883859826425,"falling_edge":"2017-08-21 17:00:00+00:00","predicted":48.26883859826425,"rising_edge":"2017-08-21 16:30:00+00:00"},{"actual":48.06817665051483,"falling_edge":"2017-08-21 17:30:00+00:00","predicted":48.06817665051483,"rising_edge":"2017-08-21 17:00:00+00:00"},{"actual":46.755633066098234,"falling_edge":"2017-08-21 18:00:00+00:00","predicted":46.755633066098234,"rising_edge":"2017-08-21 17:30:00+00:00"},{"actual":46.60752204487037,"falling_edge":"2017-08-21 18:30:00+00:00","predicted":46.60752204487037,"rising_edge":"2017-08-21 18:00:00+00:00"},{"actual":46.27697928967649,"falling_edge":"2017-08-21 19:00:00+00:00","predicted":46.27697928967649,"rising_edge":"2017-08-21 18:30:00+00:00"},{"actual":46.326282369074846,"falling_edge":"2017-08-21 19:30:00+00:00","predicted":46.326282369074846,"rising_edge":"2017-08-21 19:00:00+00:00"},{"actual":45.61875629265384,"falling_edge":"2017-08-21 20:00:00+00:00","predicted":45.61875629265384,"rising_edge":"2017-08-21 19:30:00+00:00"},{"actual":48.14890695285554,"falling_edge":"2017-08-21 20:30:00+00:00","predicted":48.14890695285554,"rising_edge":"2017-08-21 20:00:00+00:00"},{"actual":52.8670679183288,"falling_edge":"2017-08-21 21:00:00+00:00","predicted":52.8670679183288,"rising_edge":"2017-08-21 20:30:00+00:00"},{"actual":69.45051330263318,"falling_edge":"2017-08-21 21:30:00+00:00","predicted":69.45051330263318,"rising_edge":"2017-08-21 21:00:00+00:00"},{"actual":116.45412880588032,"falling_edge":"2017-08-21 22:00:00+00:00","predicted":116.45412880588032,"rising_edge":"2017-08-21 21:30:00+00:00"},{"actual":119.65359720856654,"falling_edge":"2017-08-21 22:30:00+00:00","predicted":119.65359720856654,"rising_edge":"2017-08-21 22:00:00+00:00"},{"actual":143.95719814118948,"falling_edge":"2017-08-21 23:00:00+00:00","predicted":143.95719814118948,"rising_edge":"2017-08-21 22:30:00+00:00"},{"actual":179.5599246175226,"falling_edge":"2017-08-21 23:30:00+00:00","predicted":179.5599246175226,"rising_edge":"2017-08-21 23:00:00+00:00"},{"actual":217.26244219670042,"falling_edge":"2017-08-22 00:00:00+00:00","predicted":217.26244219670042,"rising_edge":"2017-08-21 23:30:00+00:00"},{"actual":234.71326422888924,"falling_edge":"2017-08-22 00:30:00+00:00","predicted":234.71326422888924,"rising_edge":"2017-08-22 00:00:00+00:00"},{"actual":236.52758982423487,"falling_edge":"2017-08-22 01:00:00+00:00","predicted":236.52758982423487,"rising_edge":"2017-08-22 00:30:00+00:00"},{"actual":240.23516431056422,"falling_edge":"2017-08-22 01:30:00+00:00","predicted":240.23516431056422,"rising_edge":"2017-08-22 01:00:00+00:00"},{"actual":245.7677350245932,"falling_edge":"2017-08-22 02:00:00+00:00","predicted":245.7677350245932,"rising_edge":"2017-08-22 01:30:00+00:00"},{"actual":240.0269266037571,"falling_edge":"2017-08-22 02:30:00+00:00","predicted":240.0269266037571,"rising_edge":"2017-08-22 02:00:00+00:00"},{"actual":230.006701485951,"falling_edge":"2017-08-22 03:00:00+00:00","predicted":230.006701485951,"rising_edge":"2017-08-22 02:30:00+00:00"},{"actual":219.93270811432035,"falling_edge":"2017-08-22 03:30:00+00:00","predicted":219.93270811432035,"rising_edge":"2017-08-22 03:00:00+00:00"},{"actual":217.94415454684338,"falling_edge":"2017-08-22 04:00:00+00:00","predicted":217.94415454684338,"rising_edge":"2017-08-22 03:30:00+00:00"},{"actual":225.4772386549695,"falling_edge":"2017-08-22 04:30:00+00:00","predicted":225.4772386549695,"rising_edge":"2017-08-22 04:00:00+00:00"},{"actual":222.5536517143126,"falling_edge":"2017-08-22 05:00:00+00:00","predicted":222.5536517143126,"rising_edge":"2017-08-22 04:30:00+00:00"},{"actual":225.13765346588494,"falling_edge":"2017-08-22 05:30:00+00:00","predicted":225.13765346588494,"rising_edge":"2017-08-22 05:00:00+00:00"},{"actual":237.6528839990453,"falling_edge":"2017-08-22 06:00:00+00:00","predicted":237.6528839990453,"rising_edge":"2017-08-22 05:30:00+00:00"},{"actual":240.82643778841526,"falling_edge":"2017-08-22 06:30:00+00:00","predicted":240.82643778841526,"rising_edge":"2017-08-22 06:00:00+00:00"},{"actual":230.510155207148,"falling_edge":"2017-08-22 07:00:00+00:00","predicted":230.510155207148,"rising_edge":"2017-08-22 06:30:00+00:00"},{"actual":225.17277011247012,"falling_edge":"2017-08-22 07:30:00+00:00","predicted":225.17277011247012,"rising_edge":"2017-08-22 07:00:00+00:00"},{"actual":219.6806345722554,"falling_edge":"2017-08-22 08:00:00+00:00","predicted":219.6806345722554,"rising_edge":"2017-08-22 07:30:00+00:00"},{"actual":222.9131413978648,"falling_edge":"2017-08-22 08:30:00+00:00","predicted":222.9131413978648,"rising_edge":"2017-08-22 08:00:00+00:00"},{"actual":216.5149470546197,"falling_edge":"2017-08-22 09:00:00+00:00","predicted":216.5149470546197,"rising_edge":"2017-08-22 08:30:00+00:00"},{"actual":187.6260293944933,"falling_edge":"2017-08-22 09:30:00+00:00","predicted":187.6260293944933,"rising_edge":"2017-08-22 09:00:00+00:00"},{"actual":170.84358331865468,"falling_edge":"2017-08-22 10:00:00+00:00","predicted":170.84358331865468,"rising_edge":"2017-08-22 09:30:00+00:00"},{"actual":150.02515403513206,"falling_edge":"2017-08-22 10:30:00+00:00","predicted":150.02515403513206,"rising_edge":"2017-08-22 10:00:00+00:00"},{"actual":149.08986616281965,"falling_edge":"2017-08-22 11:00:00+00:00","predicted":149.08986616281965,"rising_edge":"2017-08-22 10:30:00+00:00"},{"actual":140.7499143892708,"falling_edge":"2017-08-22 11:30:00+00:00","predicted":140.7499143892708,"rising_edge":"2017-08-22 11:00:00+00:00"},{"actual":129.94761449808527,"falling_edge":"2017-08-22 12:00:00+00:00","predicted":129.94761449808527,"rising_edge":"2017-08-22 11:30:00+00:00"},{"actual":118.60856739514368,"falling_edge":"2017-08-22 12:30:00+00:00","predicted":118.60856739514368,"rising_edge":"2017-08-22 12:00:00+00:00"},{"actual":106.41044099377481,"falling_edge":"2017-08-22 13:00:00+00:00","predicted":106.41044099377481,"rising_edge":"2017-08-22 12:30:00+00:00"},{"actual":95.92016171637175,"falling_edge":"2017-08-22 13:30:00+00:00","predicted":95.92016171637175,"rising_edge":"2017-08-22 13:00:00+00:00"},{"actual":80.637896392412,"falling_edge":"2017-08-22 14:00:00+00:00","predicted":80.637896392412,"rising_edge":"2017-08-22 13:30:00+00:00"},{"actual":68.54996904270143,"falling_edge":"2017-08-22 14:30:00+00:00","predicted":68.54996904270143,"rising_edge":"2017-08-22 14:00:00+00:00"},{"actual":60.46595074389639,"falling_edge":"2017-08-22 15:00:00+00:00","predicted":60.46595074389639,"rising_edge":"2017-08-22 14:30:00+00:00"},{"actual":55.958068864021854,"falling_edge":"2017-08-22 15:30:00+00:00","predicted":55.958068864021854,"rising_edge":"2017-08-22 15:00:00+00:00"},{"actual":53.31367054732095,"falling_edge":"2017-08-22 16:00:00+00:00","predicted":53.31367054732095,"rising_edge":"2017-08-22 15:30:00+00:00"},{"actual":55.89346082272261,"falling_edge":"2017-08-22 16:30:00+00:00","predicted":55.89346082272261,"rising_edge":"2017-08-22 16:00:00+00:00"},{"actual":53.01433426677705,"falling_edge":"2017-08-22 17:00:00+00:00","predicted":53.01433426677705,"rising_edge":"2017-08-22 16:30:00+00:00"},{"actual":51.14660084297665,"falling_edge":"2017-08-22 17:30:00+00:00","predicted":51.14660084297665,"rising_edge":"2017-08-22 17:00:00+00:00"},{"actual":50.35380118505304,"falling_edge":"2017-08-22 18:00:00+00:00","predicted":50.35380118505304,"rising_edge":"2017-08-22 17:30:00+00:00"},{"actual":47.67085370667175,"falling_edge":"2017-08-22 18:30:00+00:00","predicted":47.67085370667175,"rising_edge":"2017-08-22 18:00:00+00:00"},{"actual":46.96739548648855,"falling_edge":"2017-08-22 19:00:00+00:00","predicted":46.96739548648855,"rising_edge":"2017-08-22 18:30:00+00:00"},{"actual":48.341082223779274,"falling_edge":"2017-08-22 19:30:00+00:00","predicted":48.341082223779274,"rising_edge":"2017-08-22 19:00:00+00:00"},{"actual":48.077896445967426,"falling_edge":"2017-08-22 20:00:00+00:00","predicted":48.077896445967426,"rising_edge":"2017-08-22 19:30:00+00:00"},{"actual":49.38074559067251,"falling_edge":"2017-08-22 20:30:00+00:00","predicted":49.38074559067251,"rising_edge":"2017-08-22 20:00:00+00:00"},{"actual":55.01803099605362,"falling_edge":"2017-08-22 21:00:00+00:00","predicted":55.01803099605362,"rising_edge":"2017-08-22 20:30:00+00:00"},{"actual":72.28809933680401,"falling_edge":"2017-08-22 21:30:00+00:00","predicted":72.28809933680401,"rising_edge":"2017-08-22 21:00:00+00:00"},{"actual":112.54407452274333,"falling_edge":"2017-08-22 22:00:00+00:00","predicted":112.54407452274333,"rising_edge":"2017-08-22 21:30:00+00:00"},{"actual":109.75511310084832,"falling_edge":"2017-08-22 22:30:00+00:00","predicted":109.75511310084832,"rising_edge":"2017-08-22 22:00:00+00:00"},{"actual":136.23496922781177,"falling_edge":"2017-08-22 23:00:00+00:00","predicted":136.23496922781177,"rising_edge":"2017-08-22 22:30:00+00:00"},{"actual":187.90053576245677,"falling_edge":"2017-08-22 23:30:00+00:00","predicted":187.90053576245677,"rising_edge":"2017-08-22 23:00:00+00:00"},{"actual":230.58856101899767,"falling_edge":"2017-08-23 00:00:00+00:00","predicted":230.58856101899767,"rising_edge":"2017-08-22 23:30:00+00:00"},{"actual":233.33121371140868,"falling_edge":"2017-08-23 00:30:00+00:00","predicted":233.33121371140868,"rising_edge":"2017-08-23 00:00:00+00:00"},{"actual":246.24749142278216,"falling_edge":"2017-08-23 01:00:00+00:00","predicted":246.24749142278216,"rising_edge":"2017-08-23 00:30:00+00:00"},{"actual":246.49442248548482,"falling_edge":"2017-08-23 01:30:00+00:00","predicted":246.49442248548482,"rising_edge":"2017-08-23 01:00:00+00:00"},{"actual":250.43707685061491,"falling_edge":"2017-08-23 02:00:00+00:00","predicted":250.43707685061491,"rising_edge":"2017-08-23 01:30:00+00:00"},{"actual":243.7916765655197,"falling_edge":"2017-08-23 02:30:00+00:00","predicted":243.7916765655197,"rising_edge":"2017-08-23 02:00:00+00:00"},{"actual":248.51518358870862,"falling_edge":"2017-08-23 03:00:00+00:00","predicted":248.51518358870862,"rising_edge":"2017-08-23 02:30:00+00:00"},{"actual":224.92904103600875,"falling_edge":"2017-08-23 03:30:00+00:00","predicted":224.92904103600875,"rising_edge":"2017-08-23 03:00:00+00:00"},{"actual":221.52095872701273,"falling_edge":"2017-08-23 04:00:00+00:00","predicted":221.52095872701273,"rising_edge":"2017-08-23 03:30:00+00:00"},{"actual":226.33421570365627,"falling_edge":"2017-08-23 04:30:00+00:00","predicted":226.33421570365627,"rising_edge":"2017-08-23 04:00:00+00:00"},{"actual":232.57422024807266,"falling_edge":"2017-08-23 05:00:00+00:00","predicted":232.57422024807266,"rising_edge":"2017-08-23 04:30:00+00:00"},{"actual":228.97337555732042,"falling_edge":"2017-08-23 05:30:00+00:00","predicted":228.97337555732042,"rising_edge":"2017-08-23 05:00:00+00:00"},{"actual":241.74256160328272,"falling_edge":"2017-08-23 06:00:00+00:00","predicted":241.74256160328272,"rising_edge":"2017-08-23 05:30:00+00:00"},{"actual":250.27778048484197,"falling_edge":"2017-08-23 06:30:00+00:00","predicted":250.27778048484197,"rising_edge":"2017-08-23 06:00:00+00:00"},{"actual":243.3286530620398,"falling_edge":"2017-08-23 07:00:00+00:00","predicted":243.3286530620398,"rising_edge":"2017-08-23 06:30:00+00:00"},{"actual":241.90788061364043,"falling_edge":"2017-08-23 07:30:00+00:00","predicted":241.90788061364043,"rising_edge":"2017-08-23 07:00:00+00:00"},{"actual":241.92209995779245,"falling_edge":"2017-08-23 08:00:00+00:00","predicted":241.92209995779245,"rising_edge":"2017-08-23 07:30:00+00:00"},{"actual":242.076717636515,"falling_edge":"2017-08-23 08:30:00+00:00","predicted":242.076717636515,"rising_edge":"2017-08-23 08:00:00+00:00"},{"actual":214.72651051792255,"falling_edge":"2017-08-23 09:00:00+00:00","predicted":214.72651051792255,"rising_edge":"2017-08-23 08:30:00+00:00"},{"actual":176.89030390630944,"falling_edge":"2017-08-23 09:30:00+00:00","predicted":176.89030390630944,"rising_edge":"2017-08-23 09:00:00+00:00"},{"actual":154.2489469037693,"falling_edge":"2017-08-23 10:00:00+00:00","predicted":154.2489469037693,"rising_edge":"2017-08-23 09:30:00+00:00"},{"actual":125.55204825992028,"falling_edge":"2017-08-23 10:30:00+00:00","predicted":125.55204825992028,"rising_edge":"2017-08-23 10:00:00+00:00"},{"actual":119.88235703947318,"falling_edge":"2017-08-23 11:00:00+00:00","predicted":119.88235703947318,"rising_edge":"2017-08-23 10:30:00+00:00"},{"actual":111.78757669800585,"falling_edge":"2017-08-23 11:30:00+00:00","predicted":111.78757669800585,"rising_edge":"2017-08-23 11:00:00+00:00"},{"actual":106.6278311528915,"falling_edge":"2017-08-23 12:00:00+00:00","predicted":106.6278311528915,"rising_edge":"2017-08-23 11:30:00+00:00"},{"actual":101.20433589374395,"falling_edge":"2017-08-23 12:30:00+00:00","predicted":101.20433589374395,"rising_edge":"2017-08-23 12:00:00+00:00"},{"actual":93.01543263512967,"falling_edge":"2017-08-23 13:00:00+00:00","predicted":93.01543263512967,"rising_edge":"2017-08-23 12:30:00+00:00"},{"actual":79.49431867609884,"falling_edge":"2017-08-23 13:30:00+00:00","predicted":79.49431867609884,"rising_edge":"2017-08-23 13:00:00+00:00"},{"actual":69.89088064122589,"falling_edge":"2017-08-23 14:00:00+00:00","predicted":69.89088064122589,"rising_edge":"2017-08-23 13:30:00+00:00"},{"actual":62.21634276626863,"falling_edge":"2017-08-23 14:30:00+00:00","predicted":62.21634276626863,"rising_edge":"2017-08-23 14:00:00+00:00"},{"actual":55.9448071289387,"falling_edge":"2017-08-23 15:00:00+00:00","predicted":55.9448071289387,"rising_edge":"2017-08-23 14:30:00+00:00"},{"actual":51.726747984905096,"falling_edge":"2017-08-23 15:30:00+00:00","predicted":51.726747984905096,"rising_edge":"2017-08-23 15:00:00+00:00"},{"actual":49.64956469603807,"falling_edge":"2017-08-23 16:00:00+00:00","predicted":49.64956469603807,"rising_edge":"2017-08-23 15:30:00+00:00"},{"actual":48.05754588878204,"falling_edge":"2017-08-23 16:30:00+00:00","predicted":48.05754588878204,"rising_edge":"2017-08-23 16:00:00+00:00"},{"actual":47.82390627401296,"falling_edge":"2017-08-23 17:00:00+00:00","predicted":47.82390627401296,"rising_edge":"2017-08-23 16:30:00+00:00"},{"actual":48.36252535502485,"falling_edge":"2017-08-23 17:30:00+00:00","predicted":48.36252535502485,"rising_edge":"2017-08-23 17:00:00+00:00"},{"actual":47.96248496064657,"falling_edge":"2017-08-23 18:00:00+00:00","predicted":47.96248496064657,"rising_edge":"2017-08-23 17:30:00+00:00"},{"actual":47.22651265318574,"falling_edge":"2017-08-23 18:30:00+00:00","predicted":47.22651265318574,"rising_edge":"2017-08-23 18:00:00+00:00"},{"actual":46.77555845677217,"falling_edge":"2017-08-23 19:00:00+00:00","predicted":46.77555845677217,"rising_edge":"2017-08-23 18:30:00+00:00"},{"actual":46.179518257957156,"falling_edge":"2017-08-23 19:30:00+00:00","predicted":46.179518257957156,"rising_edge":"2017-08-23 19:00:00+00:00"},{"actual":46.53469182782241,"falling_edge":"2017-08-23 20:00:00+00:00","predicted":46.53469182782241,"rising_edge":"2017-08-23 19:30:00+00:00"},{"actual":47.362406582463706,"falling_edge":"2017-08-23 20:30:00+00:00","predicted":47.362406582463706,"rising_edge":"2017-08-23 20:00:00+00:00"},{"actual":52.88696789035689,"falling_edge":"2017-08-23 21:00:00+00:00","predicted":52.88696789035689,"rising_edge":"2017-08-23 20:30:00+00:00"},{"actual":71.97076854229805,"falling_edge":"2017-08-23 21:30:00+00:00","predicted":71.97076854229805,"rising_edge":"2017-08-23 21:00:00+00:00"},{"actual":108.96072124417996,"falling_edge":"2017-08-23 22:00:00+00:00","predicted":108.96072124417996,"rising_edge":"2017-08-23 21:30:00+00:00"},{"actual":110.3032271830057,"falling_edge":"2017-08-23 22:30:00+00:00","predicted":110.3032271830057,"rising_edge":"2017-08-23 22:00:00+00:00"},{"actual":137.37201838327786,"falling_edge":"2017-08-23 23:00:00+00:00","predicted":137.37201838327786,"rising_edge":"2017-08-23 22:30:00+00:00"},{"actual":180.45779614733442,"falling_edge":"2017-08-23 23:30:00+00:00","predicted":180.45779614733442,"rising_edge":"2017-08-23 23:00:00+00:00"},{"actual":231.59125744537022,"falling_edge":"2017-08-24 00:00:00+00:00","predicted":231.59125744537022,"rising_edge":"2017-08-23 23:30:00+00:00"},{"actual":241.53770003200157,"falling_edge":"2017-08-24 00:30:00+00:00","predicted":241.53770003200157,"rising_edge":"2017-08-24 00:00:00+00:00"},{"actual":240.8482149625205,"falling_edge":"2017-08-24 01:00:00+00:00","predicted":240.8482149625205,"rising_edge":"2017-08-24 00:30:00+00:00"},{"actual":255.37413926440183,"falling_edge":"2017-08-24 01:30:00+00:00","predicted":255.37413926440183,"rising_edge":"2017-08-24 01:00:00+00:00"},{"actual":254.59250999954003,"falling_edge":"2017-08-24 02:00:00+00:00","predicted":254.59250999954003,"rising_edge":"2017-08-24 01:30:00+00:00"},{"actual":251.07519596194732,"falling_edge":"2017-08-24 02:30:00+00:00","predicted":251.07519596194732,"rising_edge":"2017-08-24 02:00:00+00:00"},{"actual":248.77982382830018,"falling_edge":"2017-08-24 03:00:00+00:00","predicted":248.77982382830018,"rising_edge":"2017-08-24 02:30:00+00:00"},{"actual":241.4668961167791,"falling_edge":"2017-08-24 03:30:00+00:00","predicted":241.4668961167791,"rising_edge":"2017-08-24 03:00:00+00:00"},{"actual":230.8813689350076,"falling_edge":"2017-08-24 04:00:00+00:00","predicted":230.8813689350076,"rising_edge":"2017-08-24 03:30:00+00:00"},{"actual":238.26201666433684,"falling_edge":"2017-08-24 04:30:00+00:00","predicted":238.26201666433684,"rising_edge":"2017-08-24 04:00:00+00:00"},{"actual":240.39066070266523,"falling_edge":"2017-08-24 05:00:00+00:00","predicted":240.39066070266523,"rising_edge":"2017-08-24 04:30:00+00:00"},{"actual":235.10289753980663,"falling_edge":"2017-08-24 05:30:00+00:00","predicted":235.10289753980663,"rising_edge":"2017-08-24 05:00:00+00:00"},{"actual":240.17691572385274,"falling_edge":"2017-08-24 06:00:00+00:00","predicted":240.17691572385274,"rising_edge":"2017-08-24 05:30:00+00:00"},{"actual":243.6523247193495,"falling_edge":"2017-08-24 06:30:00+00:00","predicted":243.6523247193495,"rising_edge":"2017-08-24 06:00:00+00:00"},{"actual":259.1225607739112,"falling_edge":"2017-08-24 07:00:00+00:00","predicted":259.1225607739112,"rising_edge":"2017-08-24 06:30:00+00:00"},{"actual":250.68285157226487,"falling_edge":"2017-08-24 07:30:00+00:00","predicted":250.68285157226487,"rising_edge":"2017-08-24 07:00:00+00:00"},{"actual":247.53530159396303,"falling_edge":"2017-08-24 08:00:00+00:00","predicted":247.53530159396303,"rising_edge":"2017-08-24 07:30:00+00:00"},{"actual":239.21441302328518,"falling_edge":"2017-08-24 08:30:00+00:00","predicted":239.21441302328518,"rising_edge":"2017-08-24 08:00:00+00:00"},{"actual":227.7914419078212,"falling_edge":"2017-08-24 09:00:00+00:00","predicted":227.7914419078212,"rising_edge":"2017-08-24 08:30:00+00:00"},{"actual":197.51875006708102,"falling_edge":"2017-08-24 09:30:00+00:00","predicted":197.51875006708102,"rising_edge":"2017-08-24 09:00:00+00:00"},{"actual":177.0996231379843,"falling_edge":"2017-08-24 10:00:00+00:00","predicted":177.0996231379843,"rising_edge":"2017-08-24 09:30:00+00:00"},{"actual":149.26982488267024,"falling_edge":"2017-08-24 10:30:00+00:00","predicted":149.26982488267024,"rising_edge":"2017-08-24 10:00:00+00:00"},{"actual":144.15277071199,"falling_edge":"2017-08-24 11:00:00+00:00","predicted":144.15277071199,"rising_edge":"2017-08-24 10:30:00+00:00"},{"actual":136.19545125599953,"falling_edge":"2017-08-24 11:30:00+00:00","predicted":136.19545125599953,"rising_edge":"2017-08-24 11:00:00+00:00"},{"actual":123.41156446485586,"falling_edge":"2017-08-24 12:00:00+00:00","predicted":123.41156446485586,"rising_edge":"2017-08-24 11:30:00+00:00"},{"actual":112.1541562798666,"falling_edge":"2017-08-24 12:30:00+00:00","predicted":112.1541562798666,"rising_edge":"2017-08-24 12:00:00+00:00"},{"actual":99.58275476412473,"falling_edge":"2017-08-24 13:00:00+00:00","predicted":99.58275476412473,"rising_edge":"2017-08-24 12:30:00+00:00"},{"actual":86.53700170636336,"falling_edge":"2017-08-24 13:30:00+00:00","predicted":86.53700170636336,"rising_edge":"2017-08-24 13:00:00+00:00"},{"actual":76.21920343239324,"falling_edge":"2017-08-24 14:00:00+00:00","predicted":76.21920343239324,"rising_edge":"2017-08-24 13:30:00+00:00"},{"actual":70.03246291131575,"falling_edge":"2017-08-24 14:30:00+00:00","predicted":70.03246291131575,"rising_edge":"2017-08-24 14:00:00+00:00"},{"actual":62.489041785346004,"falling_edge":"2017-08-24 15:00:00+00:00","predicted":62.489041785346004,"rising_edge":"2017-08-24 14:30:00+00:00"},{"actual":54.64308943804317,"falling_edge":"2017-08-24 15:30:00+00:00","predicted":54.64308943804317,"rising_edge":"2017-08-24 15:00:00+00:00"},{"actual":49.930728506158786,"falling_edge":"2017-08-24 16:00:00+00:00","predicted":49.930728506158786,"rising_edge":"2017-08-24 15:30:00+00:00"},{"actual":48.176134752473466,"falling_edge":"2017-08-24 16:30:00+00:00","predicted":48.176134752473466,"rising_edge":"2017-08-24 16:00:00+00:00"},{"actual":48.74926032060059,"falling_edge":"2017-08-24 17:00:00+00:00","predicted":48.74926032060059,"rising_edge":"2017-08-24 16:30:00+00:00"},{"actual":48.2039603296167,"falling_edge":"2017-08-24 17:30:00+00:00","predicted":48.2039603296167,"rising_edge":"2017-08-24 17:00:00+00:00"},{"actual":46.56726767169574,"falling_edge":"2017-08-24 18:00:00+00:00","predicted":46.56726767169574,"rising_edge":"2017-08-24 17:30:00+00:00"},{"actual":47.27787587685194,"falling_edge":"2017-08-24 18:30:00+00:00","predicted":47.27787587685194,"rising_edge":"2017-08-24 18:00:00+00:00"},{"actual":46.967225028670406,"falling_edge":"2017-08-24 19:00:00+00:00","predicted":46.967225028670406,"rising_edge":"2017-08-24 18:30:00+00:00"},{"actual":47.85691120535328,"falling_edge":"2017-08-24 19:30:00+00:00","predicted":47.85691120535328,"rising_edge":"2017-08-24 19:00:00+00:00"},{"actual":46.58454688324614,"falling_edge":"2017-08-24 20:00:00+00:00","predicted":46.58454688324614,"rising_edge":"2017-08-24 19:30:00+00:00"},{"actual":48.58539897601122,"falling_edge":"2017-08-24 20:30:00+00:00","predicted":48.58539897601122,"rising_edge":"2017-08-24 20:00:00+00:00"},{"actual":53.22854749842335,"falling_edge":"2017-08-24 21:00:00+00:00","predicted":53.22854749842335,"rising_edge":"2017-08-24 20:30:00+00:00"},{"actual":69.79138643064003,"falling_edge":"2017-08-24 21:30:00+00:00","predicted":69.79138643064003,"rising_edge":"2017-08-24 21:00:00+00:00"},{"actual":113.77380597639694,"falling_edge":"2017-08-24 22:00:00+00:00","predicted":113.77380597639694,"rising_edge":"2017-08-24 21:30:00+00:00"},{"actual":121.50003038944092,"falling_edge":"2017-08-24 22:30:00+00:00","predicted":121.50003038944092,"rising_edge":"2017-08-24 22:00:00+00:00"},{"actual":135.0422306372602,"falling_edge":"2017-08-24 23:00:00+00:00","predicted":135.0422306372602,"rising_edge":"2017-08-24 22:30:00+00:00"},{"actual":175.66406743208546,"falling_edge":"2017-08-24 23:30:00+00:00","predicted":175.66406743208546,"rising_edge":"2017-08-24 23:00:00+00:00"},{"actual":224.50079758657535,"falling_edge":"2017-08-25 00:00:00+00:00","predicted":224.50079758657535,"rising_edge":"2017-08-24 23:30:00+00:00"},{"actual":233.42877488004345,"falling_edge":"2017-08-25 00:30:00+00:00","predicted":233.42877488004345,"rising_edge":"2017-08-25 00:00:00+00:00"},{"actual":236.97421872808428,"falling_edge":"2017-08-25 01:00:00+00:00","predicted":236.97421872808428,"rising_edge":"2017-08-25 00:30:00+00:00"},{"actual":243.12642865431445,"falling_edge":"2017-08-25 01:30:00+00:00","predicted":243.12642865431445,"rising_edge":"2017-08-25 01:00:00+00:00"},{"actual":243.14284613199533,"falling_edge":"2017-08-25 02:00:00+00:00","predicted":243.14284613199533,"rising_edge":"2017-08-25 01:30:00+00:00"},{"actual":234.44557846622158,"falling_edge":"2017-08-25 02:30:00+00:00","predicted":234.44557846622158,"rising_edge":"2017-08-25 02:00:00+00:00"},{"actual":231.52665423146783,"falling_edge":"2017-08-25 03:00:00+00:00","predicted":231.52665423146783,"rising_edge":"2017-08-25 02:30:00+00:00"},{"actual":228.13630724309255,"falling_edge":"2017-08-25 03:30:00+00:00","predicted":228.13630724309255,"rising_edge":"2017-08-25 03:00:00+00:00"},{"actual":221.0693771750899,"falling_edge":"2017-08-25 04:00:00+00:00","predicted":221.0693771750899,"rising_edge":"2017-08-25 03:30:00+00:00"},{"actual":222.39054296095526,"falling_edge":"2017-08-25 04:30:00+00:00","predicted":222.39054296095526,"rising_edge":"2017-08-25 04:00:00+00:00"},{"actual":228.49273344400504,"falling_edge":"2017-08-25 05:00:00+00:00","predicted":228.49273344400504,"rising_edge":"2017-08-25 04:30:00+00:00"},{"actual":220.5635196449913,"falling_edge":"2017-08-25 05:30:00+00:00","predicted":220.5635196449913,"rising_edge":"2017-08-25 05:00:00+00:00"},{"actual":227.3440366108437,"falling_edge":"2017-08-25 06:00:00+00:00","predicted":227.3440366108437,"rising_edge":"2017-08-25 05:30:00+00:00"},{"actual":236.85706789500225,"falling_edge":"2017-08-25 06:30:00+00:00","predicted":236.85706789500225,"rising_edge":"2017-08-25 06:00:00+00:00"},{"actual":240.1897671069759,"falling_edge":"2017-08-25 07:00:00+00:00","predicted":240.1897671069759,"rising_edge":"2017-08-25 06:30:00+00:00"},{"actual":238.02131250329927,"falling_edge":"2017-08-25 07:30:00+00:00","predicted":238.02131250329927,"rising_edge":"2017-08-25 07:00:00+00:00"},{"actual":237.495251851486,"falling_edge":"2017-08-25 08:00:00+00:00","predicted":237.495251851486,"rising_edge":"2017-08-25 07:30:00+00:00"},{"actual":232.76798121020195,"falling_edge":"2017-08-25 08:30:00+00:00","predicted":232.76798121020195,"rising_edge":"2017-08-25 08:00:00+00:00"},{"actual":221.96784985992318,"falling_edge":"2017-08-25 09:00:00+00:00","predicted":221.96784985992318,"rising_edge":"2017-08-25 08:30:00+00:00"},{"actual":184.0824445626709,"falling_edge":"2017-08-25 09:30:00+00:00","predicted":184.0824445626709,"rising_edge":"2017-08-25 09:00:00+00:00"},{"actual":164.75529845919027,"falling_edge":"2017-08-25 10:00:00+00:00","predicted":164.75529845919027,"rising_edge":"2017-08-25 09:30:00+00:00"},{"actual":134.39781958795407,"falling_edge":"2017-08-25 10:30:00+00:00","predicted":134.39781958795407,"rising_edge":"2017-08-25 10:00:00+00:00"},{"actual":126.61398476249236,"falling_edge":"2017-08-25 11:00:00+00:00","predicted":126.61398476249236,"rising_edge":"2017-08-25 10:30:00+00:00"},{"actual":114.92342484552022,"falling_edge":"2017-08-25 11:30:00+00:00","predicted":114.92342484552022,"rising_edge":"2017-08-25 11:00:00+00:00"},{"actual":104.28991070109532,"falling_edge":"2017-08-25 12:00:00+00:00","predicted":104.28991070109532,"rising_edge":"2017-08-25 11:30:00+00:00"},{"actual":92.62503686585758,"falling_edge":"2017-08-25 12:30:00+00:00","predicted":92.62503686585758,"rising_edge":"2017-08-25 12:00:00+00:00"},{"actual":83.08339968889892,"falling_edge":"2017-08-25 13:00:00+00:00","predicted":83.08339968889892,"rising_edge":"2017-08-25 12:30:00+00:00"},{"actual":75.650273973978,"falling_edge":"2017-08-25 13:30:00+00:00","predicted":75.650273973978,"rising_edge":"2017-08-25 13:00:00+00:00"},{"actual":71.69597241200051,"falling_edge":"2017-08-25 14:00:00+00:00","predicted":71.69597241200051,"rising_edge":"2017-08-25 13:30:00+00:00"},{"actual":61.33182278836684,"falling_edge":"2017-08-25 14:30:00+00:00","predicted":61.33182278836684,"rising_edge":"2017-08-25 14:00:00+00:00"},{"actual":57.663369572164655,"falling_edge":"2017-08-25 15:00:00+00:00","predicted":57.663369572164655,"rising_edge":"2017-08-25 14:30:00+00:00"},{"actual":50.96228500332693,"falling_edge":"2017-08-25 15:30:00+00:00","predicted":50.96228500332693,"rising_edge":"2017-08-25 15:00:00+00:00"},{"actual":47.758329467468364,"falling_edge":"2017-08-25 16:00:00+00:00","predicted":47.758329467468364,"rising_edge":"2017-08-25 15:30:00+00:00"},{"actual":48.97895837502632,"falling_edge":"2017-08-25 16:30:00+00:00","predicted":48.97895837502632,"rising_edge":"2017-08-25 16:00:00+00:00"},{"actual":48.003385812233276,"falling_edge":"2017-08-25 17:00:00+00:00","predicted":48.003385812233276,"rising_edge":"2017-08-25 16:30:00+00:00"},{"actual":48.54219252750607,"falling_edge":"2017-08-25 17:30:00+00:00","predicted":48.54219252750607,"rising_edge":"2017-08-25 17:00:00+00:00"},{"actual":46.94358096170771,"falling_edge":"2017-08-25 18:00:00+00:00","predicted":46.94358096170771,"rising_edge":"2017-08-25 17:30:00+00:00"},{"actual":48.81619414863874,"falling_edge":"2017-08-25 18:30:00+00:00","predicted":48.81619414863874,"rising_edge":"2017-08-25 18:00:00+00:00"},{"actual":50.70450275270199,"falling_edge":"2017-08-25 19:00:00+00:00","predicted":50.70450275270199,"rising_edge":"2017-08-25 18:30:00+00:00"},{"actual":50.858805827804574,"falling_edge":"2017-08-25 19:30:00+00:00","predicted":50.858805827804574,"rising_edge":"2017-08-25 19:00:00+00:00"},{"actual":49.209759148241346,"falling_edge":"2017-08-25 20:00:00+00:00","predicted":49.209759148241346,"rising_edge":"2017-08-25 19:30:00+00:00"},{"actual":49.67167764951064,"falling_edge":"2017-08-25 20:30:00+00:00","predicted":49.67167764951064,"rising_edge":"2017-08-25 20:00:00+00:00"},{"actual":50.60698475163703,"falling_edge":"2017-08-25 21:00:00+00:00","predicted":50.60698475163703,"rising_edge":"2017-08-25 20:30:00+00:00"},{"actual":59.08217177974717,"falling_edge":"2017-08-25 21:30:00+00:00","predicted":59.08217177974717,"rising_edge":"2017-08-25 21:00:00+00:00"},{"actual":62.3165793810723,"falling_edge":"2017-08-25 22:00:00+00:00","predicted":62.3165793810723,"rising_edge":"2017-08-25 21:30:00+00:00"},{"actual":62.085116557687584,"falling_edge":"2017-08-25 22:30:00+00:00","predicted":62.085116557687584,"rising_edge":"2017-08-25 22:00:00+00:00"},{"actual":61.24161721901523,"falling_edge":"2017-08-25 23:00:00+00:00","predicted":61.24161721901523,"rising_edge":"2017-08-25 22:30:00+00:00"},{"actual":62.54360822482756,"falling_edge":"2017-08-25 23:30:00+00:00","predicted":62.54360822482756,"rising_edge":"2017-08-25 23:00:00+00:00"},{"actual":66.68078377134027,"falling_edge":"2017-08-26 00:00:00+00:00","predicted":66.68078377134027,"rising_edge":"2017-08-25 23:30:00+00:00"},{"actual":72.85217182466425,"falling_edge":"2017-08-26 00:30:00+00:00","predicted":72.85217182466425,"rising_edge":"2017-08-26 00:00:00+00:00"},{"actual":77.48634190173243,"falling_edge":"2017-08-26 01:00:00+00:00","predicted":77.48634190173243,"rising_edge":"2017-08-26 00:30:00+00:00"},{"actual":77.59211270179308,"falling_edge":"2017-08-26 01:30:00+00:00","predicted":77.59211270179308,"rising_edge":"2017-08-26 01:00:00+00:00"},{"actual":79.32401408084314,"falling_edge":"2017-08-26 02:00:00+00:00","predicted":79.32401408084314,"rising_edge":"2017-08-26 01:30:00+00:00"},{"actual":78.2873505951933,"falling_edge":"2017-08-26 02:30:00+00:00","predicted":78.2873505951933,"rising_edge":"2017-08-26 02:00:00+00:00"},{"actual":79.91047116094619,"falling_edge":"2017-08-26 03:00:00+00:00","predicted":79.91047116094619,"rising_edge":"2017-08-26 02:30:00+00:00"},{"actual":80.9137337268733,"falling_edge":"2017-08-26 03:30:00+00:00","predicted":80.9137337268733,"rising_edge":"2017-08-26 03:00:00+00:00"},{"actual":80.89758112314233,"falling_edge":"2017-08-26 04:00:00+00:00","predicted":80.89758112314233,"rising_edge":"2017-08-26 03:30:00+00:00"},{"actual":83.50691626978868,"falling_edge":"2017-08-26 04:30:00+00:00","predicted":83.50691626978868,"rising_edge":"2017-08-26 04:00:00+00:00"},{"actual":83.53419586891147,"falling_edge":"2017-08-26 05:00:00+00:00","predicted":83.53419586891147,"rising_edge":"2017-08-26 04:30:00+00:00"},{"actual":82.06970342096608,"falling_edge":"2017-08-26 05:30:00+00:00","predicted":82.06970342096608,"rising_edge":"2017-08-26 05:00:00+00:00"},{"actual":81.29197059018803,"falling_edge":"2017-08-26 06:00:00+00:00","predicted":81.29197059018803,"rising_edge":"2017-08-26 05:30:00+00:00"},{"actual":83.17090285609159,"falling_edge":"2017-08-26 06:30:00+00:00","predicted":83.17090285609159,"rising_edge":"2017-08-26 06:00:00+00:00"},{"actual":84.6775293432803,"falling_edge":"2017-08-26 07:00:00+00:00","predicted":84.6775293432803,"rising_edge":"2017-08-26 06:30:00+00:00"},{"actual":85.0037554582271,"falling_edge":"2017-08-26 07:30:00+00:00","predicted":85.0037554582271,"rising_edge":"2017-08-26 07:00:00+00:00"},{"actual":82.58486863699045,"falling_edge":"2017-08-26 08:00:00+00:00","predicted":82.58486863699045,"rising_edge":"2017-08-26 07:30:00+00:00"},{"actual":81.9987901821271,"falling_edge":"2017-08-26 08:30:00+00:00","predicted":81.9987901821271,"rising_edge":"2017-08-26 08:00:00+00:00"},{"actual":76.17649141597977,"falling_edge":"2017-08-26 09:00:00+00:00","predicted":76.17649141597977,"rising_edge":"2017-08-26 08:30:00+00:00"},{"actual":68.32923397897878,"falling_edge":"2017-08-26 09:30:00+00:00","predicted":68.32923397897878,"rising_edge":"2017-08-26 09:00:00+00:00"},{"actual":66.9617546346988,"falling_edge":"2017-08-26 10:00:00+00:00","predicted":66.9617546346988,"rising_edge":"2017-08-26 09:30:00+00:00"},{"actual":64.53479100396072,"falling_edge":"2017-08-26 10:30:00+00:00","predicted":64.53479100396072,"rising_edge":"2017-08-26 10:00:00+00:00"},{"actual":62.10031854643941,"falling_edge":"2017-08-26 11:00:00+00:00","predicted":62.10031854643941,"rising_edge":"2017-08-26 10:30:00+00:00"},{"actual":61.4842305458131,"falling_edge":"2017-08-26 11:30:00+00:00","predicted":61.4842305458131,"rising_edge":"2017-08-26 11:00:00+00:00"},{"actual":59.25578531512499,"falling_edge":"2017-08-26 12:00:00+00:00","predicted":59.25578531512499,"rising_edge":"2017-08-26 11:30:00+00:00"},{"actual":54.9275211459996,"falling_edge":"2017-08-26 12:30:00+00:00","predicted":54.9275211459996,"rising_edge":"2017-08-26 12:00:00+00:00"},{"actual":53.48372094343743,"falling_edge":"2017-08-26 13:00:00+00:00","predicted":53.48372094343743,"rising_edge":"2017-08-26 12:30:00+00:00"},{"actual":52.74780513488866,"falling_edge":"2017-08-26 13:30:00+00:00","predicted":52.74780513488866,"rising_edge":"2017-08-26 13:00:00+00:00"},{"actual":52.06274223120345,"falling_edge":"2017-08-26 14:00:00+00:00","predicted":52.06274223120345,"rising_edge":"2017-08-26 13:30:00+00:00"},{"actual":49.793261954829546,"falling_edge":"2017-08-26 14:30:00+00:00","predicted":49.793261954829546,"rising_edge":"2017-08-26 14:00:00+00:00"},{"actual":48.64906737867296,"falling_edge":"2017-08-26 15:00:00+00:00","predicted":48.64906737867296,"rising_edge":"2017-08-26 14:30:00+00:00"},{"actual":48.54802912738517,"falling_edge":"2017-08-26 15:30:00+00:00","predicted":48.54802912738517,"rising_edge":"2017-08-26 15:00:00+00:00"},{"actual":46.562505720319734,"falling_edge":"2017-08-26 16:00:00+00:00","predicted":46.562505720319734,"rising_edge":"2017-08-26 15:30:00+00:00"},{"actual":46.688722544585204,"falling_edge":"2017-08-26 16:30:00+00:00","predicted":46.688722544585204,"rising_edge":"2017-08-26 16:00:00+00:00"},{"actual":46.23307963984327,"falling_edge":"2017-08-26 17:00:00+00:00","predicted":46.23307963984327,"rising_edge":"2017-08-26 16:30:00+00:00"},{"actual":46.67401002105915,"falling_edge":"2017-08-26 17:30:00+00:00","predicted":46.67401002105915,"rising_edge":"2017-08-26 17:00:00+00:00"},{"actual":46.18330210646805,"falling_edge":"2017-08-26 18:00:00+00:00","predicted":46.18330210646805,"rising_edge":"2017-08-26 17:30:00+00:00"},{"actual":46.56640361682772,"falling_edge":"2017-08-26 18:30:00+00:00","predicted":46.56640361682772,"rising_edge":"2017-08-26 18:00:00+00:00"},{"actual":46.006606676644424,"falling_edge":"2017-08-26 19:00:00+00:00","predicted":46.006606676644424,"rising_edge":"2017-08-26 18:30:00+00:00"},{"actual":45.210339986119216,"falling_edge":"2017-08-26 19:30:00+00:00","predicted":45.210339986119216,"rising_edge":"2017-08-26 19:00:00+00:00"},{"actual":45.739054470426524,"falling_edge":"2017-08-26 20:00:00+00:00","predicted":45.739054470426524,"rising_edge":"2017-08-26 19:30:00+00:00"},{"actual":45.36200363180318,"falling_edge":"2017-08-26 20:30:00+00:00","predicted":45.36200363180318,"rising_edge":"2017-08-26 20:00:00+00:00"},{"actual":46.42421948837546,"falling_edge":"2017-08-26 21:00:00+00:00","predicted":46.42421948837546,"rising_edge":"2017-08-26 20:30:00+00:00"},{"actual":47.26407788048688,"falling_edge":"2017-08-26 21:30:00+00:00","predicted":47.26407788048688,"rising_edge":"2017-08-26 21:00:00+00:00"},{"actual":49.639982000968686,"falling_edge":"2017-08-26 22:00:00+00:00","predicted":49.639982000968686,"rising_edge":"2017-08-26 21:30:00+00:00"},{"actual":52.063665580011055,"falling_edge":"2017-08-26 22:30:00+00:00","predicted":52.063665580011055,"rising_edge":"2017-08-26 22:00:00+00:00"},{"actual":52.17406699634041,"falling_edge":"2017-08-26 23:00:00+00:00","predicted":52.17406699634041,"rising_edge":"2017-08-26 22:30:00+00:00"},{"actual":56.04627013202364,"falling_edge":"2017-08-26 23:30:00+00:00","predicted":56.04627013202364,"rising_edge":"2017-08-26 23:00:00+00:00"},{"actual":61.49510214532531,"falling_edge":"2017-08-27 00:00:00+00:00","predicted":61.49510214532531,"rising_edge":"2017-08-26 23:30:00+00:00"},{"actual":67.08147858129624,"falling_edge":"2017-08-27 00:30:00+00:00","predicted":67.08147858129624,"rising_edge":"2017-08-27 00:00:00+00:00"},{"actual":70.3872044724828,"falling_edge":"2017-08-27 01:00:00+00:00","predicted":70.3872044724828,"rising_edge":"2017-08-27 00:30:00+00:00"},{"actual":70.07689925397294,"falling_edge":"2017-08-27 01:30:00+00:00","predicted":70.07689925397294,"rising_edge":"2017-08-27 01:00:00+00:00"},{"actual":68.28006234154641,"falling_edge":"2017-08-27 02:00:00+00:00","predicted":68.28006234154641,"rising_edge":"2017-08-27 01:30:00+00:00"},{"actual":70.1365143208309,"falling_edge":"2017-08-27 02:30:00+00:00","predicted":70.1365143208309,"rising_edge":"2017-08-27 02:00:00+00:00"},{"actual":70.93923238124118,"falling_edge":"2017-08-27 03:00:00+00:00","predicted":70.93923238124118,"rising_edge":"2017-08-27 02:30:00+00:00"},{"actual":70.13241800877181,"falling_edge":"2017-08-27 03:30:00+00:00","predicted":70.13241800877181,"rising_edge":"2017-08-27 03:00:00+00:00"},{"actual":70.71564695669288,"falling_edge":"2017-08-27 04:00:00+00:00","predicted":70.71564695669288,"rising_edge":"2017-08-27 03:30:00+00:00"},{"actual":77.19016977109575,"falling_edge":"2017-08-27 04:30:00+00:00","predicted":77.19016977109575,"rising_edge":"2017-08-27 04:00:00+00:00"},{"actual":76.96121449914237,"falling_edge":"2017-08-27 05:00:00+00:00","predicted":76.96121449914237,"rising_edge":"2017-08-27 04:30:00+00:00"},{"actual":77.24371949424845,"falling_edge":"2017-08-27 05:30:00+00:00","predicted":77.24371949424845,"rising_edge":"2017-08-27 05:00:00+00:00"},{"actual":77.22897311526162,"falling_edge":"2017-08-27 06:00:00+00:00","predicted":77.22897311526162,"rising_edge":"2017-08-27 05:30:00+00:00"},{"actual":80.32010159729037,"falling_edge":"2017-08-27 06:30:00+00:00","predicted":80.32010159729037,"rising_edge":"2017-08-27 06:00:00+00:00"},{"actual":81.22886258327215,"falling_edge":"2017-08-27 07:00:00+00:00","predicted":81.22886258327215,"rising_edge":"2017-08-27 06:30:00+00:00"},{"actual":79.84597351852292,"falling_edge":"2017-08-27 07:30:00+00:00","predicted":79.84597351852292,"rising_edge":"2017-08-27 07:00:00+00:00"},{"actual":78.8268131286161,"falling_edge":"2017-08-27 08:00:00+00:00","predicted":78.8268131286161,"rising_edge":"2017-08-27 07:30:00+00:00"},{"actual":77.34057663746307,"falling_edge":"2017-08-27 08:30:00+00:00","predicted":77.34057663746307,"rising_edge":"2017-08-27 08:00:00+00:00"},{"actual":74.18400595368315,"falling_edge":"2017-08-27 09:00:00+00:00","predicted":74.18400595368315,"rising_edge":"2017-08-27 08:30:00+00:00"},{"actual":68.1435437112664,"falling_edge":"2017-08-27 09:30:00+00:00","predicted":68.1435437112664,"rising_edge":"2017-08-27 09:00:00+00:00"},{"actual":64.52418315857481,"falling_edge":"2017-08-27 10:00:00+00:00","predicted":64.52418315857481,"rising_edge":"2017-08-27 09:30:00+00:00"},{"actual":61.8312039171997,"falling_edge":"2017-08-27 10:30:00+00:00","predicted":61.8312039171997,"rising_edge":"2017-08-27 10:00:00+00:00"},{"actual":61.175705023081825,"falling_edge":"2017-08-27 11:00:00+00:00","predicted":61.175705023081825,"rising_edge":"2017-08-27 10:30:00+00:00"},{"actual":59.64729322719295,"falling_edge":"2017-08-27 11:30:00+00:00","predicted":59.64729322719295,"rising_edge":"2017-08-27 11:00:00+00:00"},{"actual":58.88587758001058,"falling_edge":"2017-08-27 12:00:00+00:00","predicted":58.88587758001058,"rising_edge":"2017-08-27 11:30:00+00:00"},{"actual":55.03788243387727,"falling_edge":"2017-08-27 12:30:00+00:00","predicted":55.03788243387727,"rising_edge":"2017-08-27 12:00:00+00:00"},{"actual":52.87925202493206,"falling_edge":"2017-08-27 13:00:00+00:00","predicted":52.87925202493206,"rising_edge":"2017-08-27 12:30:00+00:00"},{"actual":52.118881658565094,"falling_edge":"2017-08-27 13:30:00+00:00","predicted":52.118881658565094,"rising_edge":"2017-08-27 13:00:00+00:00"},{"actual":50.201289920879006,"falling_edge":"2017-08-27 14:00:00+00:00","predicted":50.201289920879006,"rising_edge":"2017-08-27 13:30:00+00:00"},{"actual":51.19394591011561,"falling_edge":"2017-08-27 14:30:00+00:00","predicted":51.19394591011561,"rising_edge":"2017-08-27 14:00:00+00:00"},{"actual":49.364650625380364,"falling_edge":"2017-08-27 15:00:00+00:00","predicted":49.364650625380364,"rising_edge":"2017-08-27 14:30:00+00:00"},{"actual":48.94627028724958,"falling_edge":"2017-08-27 15:30:00+00:00","predicted":48.94627028724958,"rising_edge":"2017-08-27 15:00:00+00:00"},{"actual":48.56793532115857,"falling_edge":"2017-08-27 16:00:00+00:00","predicted":48.56793532115857,"rising_edge":"2017-08-27 15:30:00+00:00"},{"actual":49.292689871310124,"falling_edge":"2017-08-27 16:30:00+00:00","predicted":49.292689871310124,"rising_edge":"2017-08-27 16:00:00+00:00"},{"actual":47.606945959854386,"falling_edge":"2017-08-27 17:00:00+00:00","predicted":47.606945959854386,"rising_edge":"2017-08-27 16:30:00+00:00"},{"actual":46.63334836509177,"falling_edge":"2017-08-27 17:30:00+00:00","predicted":46.63334836509177,"rising_edge":"2017-08-27 17:00:00+00:00"},{"actual":47.38886498921942,"falling_edge":"2017-08-27 18:00:00+00:00","predicted":47.38886498921942,"rising_edge":"2017-08-27 17:30:00+00:00"},{"actual":46.66787789611666,"falling_edge":"2017-08-27 18:30:00+00:00","predicted":46.66787789611666,"rising_edge":"2017-08-27 18:00:00+00:00"},{"actual":46.95401820872757,"falling_edge":"2017-08-27 19:00:00+00:00","predicted":46.95401820872757,"rising_edge":"2017-08-27 18:30:00+00:00"},{"actual":46.29208391806045,"falling_edge":"2017-08-27 19:30:00+00:00","predicted":46.29208391806045,"rising_edge":"2017-08-27 19:00:00+00:00"},{"actual":47.112584288709954,"falling_edge":"2017-08-27 20:00:00+00:00","predicted":47.112584288709954,"rising_edge":"2017-08-27 19:30:00+00:00"},{"actual":47.83862170602993,"falling_edge":"2017-08-27 20:30:00+00:00","predicted":47.83862170602993,"rising_edge":"2017-08-27 20:00:00+00:00"},{"actual":53.15775680011349,"falling_edge":"2017-08-27 21:00:00+00:00","predicted":53.15775680011349,"rising_edge":"2017-08-27 20:30:00+00:00"},{"actual":70.97252671075805,"falling_edge":"2017-08-27 21:30:00+00:00","predicted":70.97252671075805,"rising_edge":"2017-08-27 21:00:00+00:00"},{"actual":130.56681239337854,"falling_edge":"2017-08-27 22:00:00+00:00","predicted":130.56681239337854,"rising_edge":"2017-08-27 21:30:00+00:00"},{"actual":116.82654782313554,"falling_edge":"2017-08-27 22:30:00+00:00","predicted":116.82654782313554,"rising_edge":"2017-08-27 22:00:00+00:00"},{"actual":137.03165543228664,"falling_edge":"2017-08-27 23:00:00+00:00","predicted":137.03165543228664,"rising_edge":"2017-08-27 22:30:00+00:00"},{"actual":171.665509303965,"falling_edge":"2017-08-27 23:30:00+00:00","predicted":171.665509303965,"rising_edge":"2017-08-27 23:00:00+00:00"},{"actual":216.3620956853549,"falling_edge":"2017-08-28 00:00:00+00:00","predicted":216.3620956853549,"rising_edge":"2017-08-27 23:30:00+00:00"},{"actual":223.8972606468126,"falling_edge":"2017-08-28 00:30:00+00:00","predicted":223.8972606468126,"rising_edge":"2017-08-28 00:00:00+00:00"},{"actual":233.72676631446345,"falling_edge":"2017-08-28 01:00:00+00:00","predicted":233.72676631446345,"rising_edge":"2017-08-28 00:30:00+00:00"},{"actual":239.0093196079246,"falling_edge":"2017-08-28 01:30:00+00:00","predicted":239.0093196079246,"rising_edge":"2017-08-28 01:00:00+00:00"},{"actual":233.08922466892858,"falling_edge":"2017-08-28 02:00:00+00:00","predicted":233.08922466892858,"rising_edge":"2017-08-28 01:30:00+00:00"},{"actual":233.74688956207078,"falling_edge":"2017-08-28 02:30:00+00:00","predicted":233.74688956207078,"rising_edge":"2017-08-28 02:00:00+00:00"},{"actual":225.14315137440016,"falling_edge":"2017-08-28 03:00:00+00:00","predicted":225.14315137440016,"rising_edge":"2017-08-28 02:30:00+00:00"},{"actual":227.95533548404305,"falling_edge":"2017-08-28 03:30:00+00:00","predicted":227.95533548404305,"rising_edge":"2017-08-28 03:00:00+00:00"},{"actual":215.8481332263646,"falling_edge":"2017-08-28 04:00:00+00:00","predicted":215.8481332263646,"rising_edge":"2017-08-28 03:30:00+00:00"},{"actual":224.35211292621005,"falling_edge":"2017-08-28 04:30:00+00:00","predicted":224.35211292621005,"rising_edge":"2017-08-28 04:00:00+00:00"},{"actual":220.94561744382864,"falling_edge":"2017-08-28 05:00:00+00:00","predicted":220.94561744382864,"rising_edge":"2017-08-28 04:30:00+00:00"},{"actual":218.50152737848782,"falling_edge":"2017-08-28 05:30:00+00:00","predicted":218.50152737848782,"rising_edge":"2017-08-28 05:00:00+00:00"},{"actual":214.08042632927894,"falling_edge":"2017-08-28 06:00:00+00:00","predicted":214.08042632927894,"rising_edge":"2017-08-28 05:30:00+00:00"},{"actual":219.57018852134794,"falling_edge":"2017-08-28 06:30:00+00:00","predicted":219.57018852134794,"rising_edge":"2017-08-28 06:00:00+00:00"},{"actual":219.07862450996197,"falling_edge":"2017-08-28 07:00:00+00:00","predicted":219.07862450996197,"rising_edge":"2017-08-28 06:30:00+00:00"},{"actual":221.74374816292075,"falling_edge":"2017-08-28 07:30:00+00:00","predicted":221.74374816292075,"rising_edge":"2017-08-28 07:00:00+00:00"},{"actual":216.13813059628032,"falling_edge":"2017-08-28 08:00:00+00:00","predicted":216.13813059628032,"rising_edge":"2017-08-28 07:30:00+00:00"},{"actual":216.05483689411807,"falling_edge":"2017-08-28 08:30:00+00:00","predicted":216.05483689411807,"rising_edge":"2017-08-28 08:00:00+00:00"},{"actual":203.5654609291023,"falling_edge":"2017-08-28 09:00:00+00:00","predicted":203.5654609291023,"rising_edge":"2017-08-28 08:30:00+00:00"},{"actual":173.39458723936818,"falling_edge":"2017-08-28 09:30:00+00:00","predicted":173.39458723936818,"rising_edge":"2017-08-28 09:00:00+00:00"},{"actual":159.88207230071205,"falling_edge":"2017-08-28 10:00:00+00:00","predicted":159.88207230071205,"rising_edge":"2017-08-28 09:30:00+00:00"},{"actual":137.9559108785642,"falling_edge":"2017-08-28 10:30:00+00:00","predicted":137.9559108785642,"rising_edge":"2017-08-28 10:00:00+00:00"},{"actual":134.08544626884918,"falling_edge":"2017-08-28 11:00:00+00:00","predicted":134.08544626884918,"rising_edge":"2017-08-28 10:30:00+00:00"},{"actual":125.6791672097238,"falling_edge":"2017-08-28 11:30:00+00:00","predicted":125.6791672097238,"rising_edge":"2017-08-28 11:00:00+00:00"},{"actual":114.11878620761766,"falling_edge":"2017-08-28 12:00:00+00:00","predicted":114.11878620761766,"rising_edge":"2017-08-28 11:30:00+00:00"},{"actual":103.19690473090515,"falling_edge":"2017-08-28 12:30:00+00:00","predicted":103.19690473090515,"rising_edge":"2017-08-28 12:00:00+00:00"},{"actual":95.80591347825622,"falling_edge":"2017-08-28 13:00:00+00:00","predicted":95.80591347825622,"rising_edge":"2017-08-28 12:30:00+00:00"},{"actual":87.8384252501844,"falling_edge":"2017-08-28 13:30:00+00:00","predicted":87.8384252501844,"rising_edge":"2017-08-28 13:00:00+00:00"},{"actual":76.61400397730246,"falling_edge":"2017-08-28 14:00:00+00:00","predicted":76.61400397730246,"rising_edge":"2017-08-28 13:30:00+00:00"},{"actual":65.83322849806915,"falling_edge":"2017-08-28 14:30:00+00:00","predicted":65.83322849806915,"rising_edge":"2017-08-28 14:00:00+00:00"},{"actual":58.8170323627074,"falling_edge":"2017-08-28 15:00:00+00:00","predicted":58.8170323627074,"rising_edge":"2017-08-28 14:30:00+00:00"},{"actual":52.98806862041048,"falling_edge":"2017-08-28 15:30:00+00:00","predicted":52.98806862041048,"rising_edge":"2017-08-28 15:00:00+00:00"},{"actual":48.349435429842266,"falling_edge":"2017-08-28 16:00:00+00:00","predicted":48.349435429842266,"rising_edge":"2017-08-28 15:30:00+00:00"},{"actual":47.600787642936744,"falling_edge":"2017-08-28 16:30:00+00:00","predicted":47.600787642936744,"rising_edge":"2017-08-28 16:00:00+00:00"},{"actual":47.60316900763263,"falling_edge":"2017-08-28 17:00:00+00:00","predicted":47.60316900763263,"rising_edge":"2017-08-28 16:30:00+00:00"},{"actual":47.50867467688474,"falling_edge":"2017-08-28 17:30:00+00:00","predicted":47.50867467688474,"rising_edge":"2017-08-28 17:00:00+00:00"},{"actual":46.34722021989913,"falling_edge":"2017-08-28 18:00:00+00:00","predicted":46.34722021989913,"rising_edge":"2017-08-28 17:30:00+00:00"},{"actual":46.158627953182325,"falling_edge":"2017-08-28 18:30:00+00:00","predicted":46.158627953182325,"rising_edge":"2017-08-28 18:00:00+00:00"},{"actual":45.60882615402432,"falling_edge":"2017-08-28 19:00:00+00:00","predicted":45.60882615402432,"rising_edge":"2017-08-28 18:30:00+00:00"},{"actual":45.89170859147767,"falling_edge":"2017-08-28 19:30:00+00:00","predicted":45.89170859147767,"rising_edge":"2017-08-28 19:00:00+00:00"},{"actual":44.98751060426954,"falling_edge":"2017-08-28 20:00:00+00:00","predicted":44.98751060426954,"rising_edge":"2017-08-28 19:30:00+00:00"},{"actual":47.137936702280506,"falling_edge":"2017-08-28 20:30:00+00:00","predicted":47.137936702280506,"rising_edge":"2017-08-28 20:00:00+00:00"},{"actual":52.23166919318614,"falling_edge":"2017-08-28 21:00:00+00:00","predicted":52.23166919318614,"rising_edge":"2017-08-28 20:30:00+00:00"},{"actual":68.81005874370354,"falling_edge":"2017-08-28 21:30:00+00:00","predicted":68.81005874370354,"rising_edge":"2017-08-28 21:00:00+00:00"},{"actual":110.53891521609471,"falling_edge":"2017-08-28 22:00:00+00:00","predicted":110.53891521609471,"rising_edge":"2017-08-28 21:30:00+00:00"},{"actual":113.38821943679599,"falling_edge":"2017-08-28 22:30:00+00:00","predicted":113.38821943679599,"rising_edge":"2017-08-28 22:00:00+00:00"},{"actual":139.33682975703925,"falling_edge":"2017-08-28 23:00:00+00:00","predicted":139.33682975703925,"rising_edge":"2017-08-28 22:30:00+00:00"},{"actual":176.6999472426274,"falling_edge":"2017-08-28 23:30:00+00:00","predicted":176.6999472426274,"rising_edge":"2017-08-28 23:00:00+00:00"},{"actual":218.23816278351714,"falling_edge":"2017-08-29 00:00:00+00:00","predicted":218.23816278351714,"rising_edge":"2017-08-28 23:30:00+00:00"},{"actual":227.63291834992643,"falling_edge":"2017-08-29 00:30:00+00:00","predicted":227.63291834992643,"rising_edge":"2017-08-29 00:00:00+00:00"},{"actual":238.71139928792874,"falling_edge":"2017-08-29 01:00:00+00:00","predicted":238.71139928792874,"rising_edge":"2017-08-29 00:30:00+00:00"},{"actual":239.17528628164885,"falling_edge":"2017-08-29 01:30:00+00:00","predicted":239.17528628164885,"rising_edge":"2017-08-29 01:00:00+00:00"},{"actual":241.45503841484992,"falling_edge":"2017-08-29 02:00:00+00:00","predicted":241.45503841484992,"rising_edge":"2017-08-29 01:30:00+00:00"},{"actual":238.9866426449217,"falling_edge":"2017-08-29 02:30:00+00:00","predicted":238.9866426449217,"rising_edge":"2017-08-29 02:00:00+00:00"},{"actual":239.03893220199026,"falling_edge":"2017-08-29 03:00:00+00:00","predicted":239.03893220199026,"rising_edge":"2017-08-29 02:30:00+00:00"},{"actual":227.59352456964933,"falling_edge":"2017-08-29 03:30:00+00:00","predicted":227.59352456964933,"rising_edge":"2017-08-29 03:00:00+00:00"},{"actual":224.2513217040057,"falling_edge":"2017-08-29 04:00:00+00:00","predicted":224.2513217040057,"rising_edge":"2017-08-29 03:30:00+00:00"},{"actual":237.2229043640622,"falling_edge":"2017-08-29 04:30:00+00:00","predicted":237.2229043640622,"rising_edge":"2017-08-29 04:00:00+00:00"},{"actual":233.8614422313151,"falling_edge":"2017-08-29 05:00:00+00:00","predicted":233.8614422313151,"rising_edge":"2017-08-29 04:30:00+00:00"},{"actual":228.39349890207887,"falling_edge":"2017-08-29 05:30:00+00:00","predicted":228.39349890207887,"rising_edge":"2017-08-29 05:00:00+00:00"},{"actual":239.56026593660195,"falling_edge":"2017-08-29 06:00:00+00:00","predicted":239.56026593660195,"rising_edge":"2017-08-29 05:30:00+00:00"},{"actual":238.0890384846819,"falling_edge":"2017-08-29 06:30:00+00:00","predicted":238.0890384846819,"rising_edge":"2017-08-29 06:00:00+00:00"},{"actual":235.64933930670972,"falling_edge":"2017-08-29 07:00:00+00:00","predicted":235.64933930670972,"rising_edge":"2017-08-29 06:30:00+00:00"},{"actual":233.4489756015393,"falling_edge":"2017-08-29 07:30:00+00:00","predicted":233.4489756015393,"rising_edge":"2017-08-29 07:00:00+00:00"},{"actual":224.98054573676473,"falling_edge":"2017-08-29 08:00:00+00:00","predicted":224.98054573676473,"rising_edge":"2017-08-29 07:30:00+00:00"},{"actual":227.73646227474515,"falling_edge":"2017-08-29 08:30:00+00:00","predicted":227.73646227474515,"rising_edge":"2017-08-29 08:00:00+00:00"},{"actual":217.97292347033198,"falling_edge":"2017-08-29 09:00:00+00:00","predicted":217.97292347033198,"rising_edge":"2017-08-29 08:30:00+00:00"},{"actual":186.53120754784635,"falling_edge":"2017-08-29 09:30:00+00:00","predicted":186.53120754784635,"rising_edge":"2017-08-29 09:00:00+00:00"},{"actual":169.43942090251048,"falling_edge":"2017-08-29 10:00:00+00:00","predicted":169.43942090251048,"rising_edge":"2017-08-29 09:30:00+00:00"},{"actual":149.2239860535773,"falling_edge":"2017-08-29 10:30:00+00:00","predicted":149.2239860535773,"rising_edge":"2017-08-29 10:00:00+00:00"},{"actual":146.27078053290023,"falling_edge":"2017-08-29 11:00:00+00:00","predicted":146.27078053290023,"rising_edge":"2017-08-29 10:30:00+00:00"},{"actual":139.34265608305415,"falling_edge":"2017-08-29 11:30:00+00:00","predicted":139.34265608305415,"rising_edge":"2017-08-29 11:00:00+00:00"},{"actual":129.5237402463715,"falling_edge":"2017-08-29 12:00:00+00:00","predicted":129.5237402463715,"rising_edge":"2017-08-29 11:30:00+00:00"},{"actual":118.23326264857914,"falling_edge":"2017-08-29 12:30:00+00:00","predicted":118.23326264857914,"rising_edge":"2017-08-29 12:00:00+00:00"},{"actual":105.75704752632885,"falling_edge":"2017-08-29 13:00:00+00:00","predicted":105.75704752632885,"rising_edge":"2017-08-29 12:30:00+00:00"},{"actual":95.92016171637175,"falling_edge":"2017-08-29 13:30:00+00:00","predicted":95.92016171637175,"rising_edge":"2017-08-29 13:00:00+00:00"},{"actual":81.21509754134647,"falling_edge":"2017-08-29 14:00:00+00:00","predicted":81.21509754134647,"rising_edge":"2017-08-29 13:30:00+00:00"},{"actual":68.31754933908493,"falling_edge":"2017-08-29 14:30:00+00:00","predicted":68.31754933908493,"rising_edge":"2017-08-29 14:00:00+00:00"},{"actual":59.93785412125844,"falling_edge":"2017-08-29 15:00:00+00:00","predicted":59.93785412125844,"rising_edge":"2017-08-29 14:30:00+00:00"},{"actual":55.48418828534067,"falling_edge":"2017-08-29 15:30:00+00:00","predicted":55.48418828534067,"rising_edge":"2017-08-29 15:00:00+00:00"},{"actual":52.85063670627772,"falling_edge":"2017-08-29 16:00:00+00:00","predicted":52.85063670627772,"rising_edge":"2017-08-29 15:30:00+00:00"},{"actual":55.374906531683294,"falling_edge":"2017-08-29 16:30:00+00:00","predicted":55.374906531683294,"rising_edge":"2017-08-29 16:00:00+00:00"},{"actual":52.55206469446504,"falling_edge":"2017-08-29 17:00:00+00:00","predicted":52.55206469446504,"rising_edge":"2017-08-29 16:30:00+00:00"},{"actual":50.343140915320944,"falling_edge":"2017-08-29 17:30:00+00:00","predicted":50.343140915320944,"rising_edge":"2017-08-29 17:00:00+00:00"},{"actual":49.72370126916211,"falling_edge":"2017-08-29 18:00:00+00:00","predicted":49.72370126916211,"rising_edge":"2017-08-29 17:30:00+00:00"},{"actual":47.15051773220452,"falling_edge":"2017-08-29 18:30:00+00:00","predicted":47.15051773220452,"rising_edge":"2017-08-29 18:00:00+00:00"},{"actual":46.304602892055726,"falling_edge":"2017-08-29 19:00:00+00:00","predicted":46.304602892055726,"rising_edge":"2017-08-29 18:30:00+00:00"},{"actual":47.835052227095574,"falling_edge":"2017-08-29 19:30:00+00:00","predicted":47.835052227095574,"rising_edge":"2017-08-29 19:00:00+00:00"},{"actual":47.87147256592839,"falling_edge":"2017-08-29 20:00:00+00:00","predicted":47.87147256592839,"rising_edge":"2017-08-29 19:30:00+00:00"},{"actual":48.999943669820816,"falling_edge":"2017-08-29 20:30:00+00:00","predicted":48.999943669820816,"rising_edge":"2017-08-29 20:00:00+00:00"},{"actual":54.583612410082296,"falling_edge":"2017-08-29 21:00:00+00:00","predicted":54.583612410082296,"rising_edge":"2017-08-29 20:30:00+00:00"},{"actual":71.47934714586066,"falling_edge":"2017-08-29 21:30:00+00:00","predicted":71.47934714586066,"rising_edge":"2017-08-29 21:00:00+00:00"},{"actual":107.08586691551488,"falling_edge":"2017-08-29 22:00:00+00:00","predicted":107.08586691551488,"rising_edge":"2017-08-29 21:30:00+00:00"},{"actual":102.34678599363704,"falling_edge":"2017-08-29 22:30:00+00:00","predicted":102.34678599363704,"rising_edge":"2017-08-29 22:00:00+00:00"},{"actual":117.35210992155919,"falling_edge":"2017-08-29 23:00:00+00:00","predicted":117.35210992155919,"rising_edge":"2017-08-29 22:30:00+00:00"},{"actual":161.3142166141603,"falling_edge":"2017-08-29 23:30:00+00:00","predicted":161.3142166141603,"rising_edge":"2017-08-29 23:00:00+00:00"},{"actual":203.12408998977887,"falling_edge":"2017-08-30 00:00:00+00:00","predicted":203.12408998977887,"rising_edge":"2017-08-29 23:30:00+00:00"},{"actual":213.24395295298865,"falling_edge":"2017-08-30 00:30:00+00:00","predicted":213.24395295298865,"rising_edge":"2017-08-30 00:00:00+00:00"},{"actual":213.87732094778593,"falling_edge":"2017-08-30 01:00:00+00:00","predicted":213.87732094778593,"rising_edge":"2017-08-30 00:30:00+00:00"},{"actual":232.9607135313103,"falling_edge":"2017-08-30 01:30:00+00:00","predicted":232.9607135313103,"rising_edge":"2017-08-30 01:00:00+00:00"},{"actual":221.5532288572365,"falling_edge":"2017-08-30 02:00:00+00:00","predicted":221.5532288572365,"rising_edge":"2017-08-30 01:30:00+00:00"},{"actual":224.79592079532648,"falling_edge":"2017-08-30 02:30:00+00:00","predicted":224.79592079532648,"rising_edge":"2017-08-30 02:00:00+00:00"},{"actual":220.97278606536915,"falling_edge":"2017-08-30 03:00:00+00:00","predicted":220.97278606536915,"rising_edge":"2017-08-30 02:30:00+00:00"},{"actual":212.49496617718708,"falling_edge":"2017-08-30 03:30:00+00:00","predicted":212.49496617718708,"rising_edge":"2017-08-30 03:00:00+00:00"},{"actual":207.3281254619544,"falling_edge":"2017-08-30 04:00:00+00:00","predicted":207.3281254619544,"rising_edge":"2017-08-30 03:30:00+00:00"},{"actual":217.58485105137433,"falling_edge":"2017-08-30 04:30:00+00:00","predicted":217.58485105137433,"rising_edge":"2017-08-30 04:00:00+00:00"},{"actual":223.71855075151453,"falling_edge":"2017-08-30 05:00:00+00:00","predicted":223.71855075151453,"rising_edge":"2017-08-30 04:30:00+00:00"},{"actual":223.78824455398612,"falling_edge":"2017-08-30 05:30:00+00:00","predicted":223.78824455398612,"rising_edge":"2017-08-30 05:00:00+00:00"},{"actual":225.37667187024604,"falling_edge":"2017-08-30 06:00:00+00:00","predicted":225.37667187024604,"rising_edge":"2017-08-30 05:30:00+00:00"},{"actual":225.06419064139703,"falling_edge":"2017-08-30 06:30:00+00:00","predicted":225.06419064139703,"rising_edge":"2017-08-30 06:00:00+00:00"},{"actual":223.41073294656252,"falling_edge":"2017-08-30 07:00:00+00:00","predicted":223.41073294656252,"rising_edge":"2017-08-30 06:30:00+00:00"},{"actual":224.04258777571442,"falling_edge":"2017-08-30 07:30:00+00:00","predicted":224.04258777571442,"rising_edge":"2017-08-30 07:00:00+00:00"},{"actual":216.48058736643975,"falling_edge":"2017-08-30 08:00:00+00:00","predicted":216.48058736643975,"rising_edge":"2017-08-30 07:30:00+00:00"},{"actual":212.34343559137875,"falling_edge":"2017-08-30 08:30:00+00:00","predicted":212.34343559137875,"rising_edge":"2017-08-30 08:00:00+00:00"},{"actual":200.79428085260778,"falling_edge":"2017-08-30 09:00:00+00:00","predicted":200.79428085260778,"rising_edge":"2017-08-30 08:30:00+00:00"},{"actual":167.95668530842795,"falling_edge":"2017-08-30 09:30:00+00:00","predicted":167.95668530842795,"rising_edge":"2017-08-30 09:00:00+00:00"},{"actual":149.64987943582682,"falling_edge":"2017-08-30 10:00:00+00:00","predicted":149.64987943582682,"rising_edge":"2017-08-30 09:30:00+00:00"},{"actual":122.73517927214134,"falling_edge":"2017-08-30 10:30:00+00:00","predicted":122.73517927214134,"rising_edge":"2017-08-30 10:00:00+00:00"},{"actual":116.34447499618285,"falling_edge":"2017-08-30 11:00:00+00:00","predicted":116.34447499618285,"rising_edge":"2017-08-30 10:30:00+00:00"},{"actual":108.65085450593054,"falling_edge":"2017-08-30 11:30:00+00:00","predicted":108.65085450593054,"rising_edge":"2017-08-30 11:00:00+00:00"},{"actual":102.13924321076708,"falling_edge":"2017-08-30 12:00:00+00:00","predicted":102.13924321076708,"rising_edge":"2017-08-30 11:30:00+00:00"},{"actual":95.53999176442598,"falling_edge":"2017-08-30 12:30:00+00:00","predicted":95.53999176442598,"rising_edge":"2017-08-30 12:00:00+00:00"},{"actual":88.25162653057592,"falling_edge":"2017-08-30 13:00:00+00:00","predicted":88.25162653057592,"rising_edge":"2017-08-30 12:30:00+00:00"},{"actual":75.85156058048831,"falling_edge":"2017-08-30 13:30:00+00:00","predicted":75.85156058048831,"rising_edge":"2017-08-30 13:00:00+00:00"},{"actual":67.59498720071574,"falling_edge":"2017-08-30 14:00:00+00:00","predicted":67.59498720071574,"rising_edge":"2017-08-30 13:30:00+00:00"},{"actual":59.97930034224666,"falling_edge":"2017-08-30 14:30:00+00:00","predicted":59.97930034224666,"rising_edge":"2017-08-30 14:00:00+00:00"},{"actual":54.51208195451208,"falling_edge":"2017-08-30 15:00:00+00:00","predicted":54.51208195451208,"rising_edge":"2017-08-30 14:30:00+00:00"},{"actual":50.420447332801,"falling_edge":"2017-08-30 15:30:00+00:00","predicted":50.420447332801,"rising_edge":"2017-08-30 15:00:00+00:00"},{"actual":48.50046422313588,"falling_edge":"2017-08-30 16:00:00+00:00","predicted":48.50046422313588,"rising_edge":"2017-08-30 15:30:00+00:00"},{"actual":46.52473285912675,"falling_edge":"2017-08-30 16:30:00+00:00","predicted":46.52473285912675,"rising_edge":"2017-08-30 16:00:00+00:00"},{"actual":46.0995685419462,"falling_edge":"2017-08-30 17:00:00+00:00","predicted":46.0995685419462,"rising_edge":"2017-08-30 16:30:00+00:00"},{"actual":46.541813032013984,"falling_edge":"2017-08-30 17:30:00+00:00","predicted":46.541813032013984,"rising_edge":"2017-08-30 17:00:00+00:00"},{"actual":46.25414144681234,"falling_edge":"2017-08-30 18:00:00+00:00","predicted":46.25414144681234,"rising_edge":"2017-08-30 17:30:00+00:00"},{"actual":45.56932064482285,"falling_edge":"2017-08-30 18:30:00+00:00","predicted":45.56932064482285,"rising_edge":"2017-08-30 18:00:00+00:00"},{"actual":45.256157114510124,"falling_edge":"2017-08-30 19:00:00+00:00","predicted":45.256157114510124,"rising_edge":"2017-08-30 18:30:00+00:00"},{"actual":44.838463318516936,"falling_edge":"2017-08-30 19:30:00+00:00","predicted":44.838463318516936,"rising_edge":"2017-08-30 19:00:00+00:00"},{"actual":45.06475637598762,"falling_edge":"2017-08-30 20:00:00+00:00","predicted":45.06475637598762,"rising_edge":"2017-08-30 19:30:00+00:00"},{"actual":46.09363863409076,"falling_edge":"2017-08-30 20:30:00+00:00","predicted":46.09363863409076,"rising_edge":"2017-08-30 20:00:00+00:00"},{"actual":50.70457392763327,"falling_edge":"2017-08-30 21:00:00+00:00","predicted":50.70457392763327,"rising_edge":"2017-08-30 20:30:00+00:00"},{"actual":69.00102178114534,"falling_edge":"2017-08-30 21:30:00+00:00","predicted":69.00102178114534,"rising_edge":"2017-08-30 21:00:00+00:00"},{"actual":98.33020303809533,"falling_edge":"2017-08-30 22:00:00+00:00","predicted":98.33020303809533,"rising_edge":"2017-08-30 21:30:00+00:00"},{"actual":96.80099386131518,"falling_edge":"2017-08-30 22:30:00+00:00","predicted":96.80099386131518,"rising_edge":"2017-08-30 22:00:00+00:00"},{"actual":118.53536466031017,"falling_edge":"2017-08-30 23:00:00+00:00","predicted":118.53536466031017,"rising_edge":"2017-08-30 22:30:00+00:00"},{"actual":164.026308616838,"falling_edge":"2017-08-30 23:30:00+00:00","predicted":164.026308616838,"rising_edge":"2017-08-30 23:00:00+00:00"},{"actual":201.80509856833504,"falling_edge":"2017-08-31 00:00:00+00:00","predicted":201.80509856833504,"rising_edge":"2017-08-30 23:30:00+00:00"},{"actual":223.24768495732542,"falling_edge":"2017-08-31 00:30:00+00:00","predicted":223.24768495732542,"rising_edge":"2017-08-31 00:00:00+00:00"},{"actual":217.3273424149589,"falling_edge":"2017-08-31 01:00:00+00:00","predicted":217.3273424149589,"rising_edge":"2017-08-31 00:30:00+00:00"},{"actual":225.50373278849048,"falling_edge":"2017-08-31 01:30:00+00:00","predicted":225.50373278849048,"rising_edge":"2017-08-31 01:00:00+00:00"},{"actual":236.9373957634939,"falling_edge":"2017-08-31 02:00:00+00:00","predicted":236.9373957634939,"rising_edge":"2017-08-31 01:30:00+00:00"},{"actual":226.94528871999387,"falling_edge":"2017-08-31 02:30:00+00:00","predicted":226.94528871999387,"rising_edge":"2017-08-31 02:00:00+00:00"},{"actual":220.92745309823496,"falling_edge":"2017-08-31 03:00:00+00:00","predicted":220.92745309823496,"rising_edge":"2017-08-31 02:30:00+00:00"},{"actual":215.52780973782404,"falling_edge":"2017-08-31 03:30:00+00:00","predicted":215.52780973782404,"rising_edge":"2017-08-31 03:00:00+00:00"},{"actual":207.04183013866438,"falling_edge":"2017-08-31 04:00:00+00:00","predicted":207.04183013866438,"rising_edge":"2017-08-31 03:30:00+00:00"},{"actual":217.33796311319384,"falling_edge":"2017-08-31 04:30:00+00:00","predicted":217.33796311319384,"rising_edge":"2017-08-31 04:00:00+00:00"},{"actual":216.35235439381592,"falling_edge":"2017-08-31 05:00:00+00:00","predicted":216.35235439381592,"rising_edge":"2017-08-31 04:30:00+00:00"},{"actual":215.3733770405934,"falling_edge":"2017-08-31 05:30:00+00:00","predicted":215.3733770405934,"rising_edge":"2017-08-31 05:00:00+00:00"},{"actual":219.13924159069083,"falling_edge":"2017-08-31 06:00:00+00:00","predicted":219.13924159069083,"rising_edge":"2017-08-31 05:30:00+00:00"},{"actual":222.83824213368737,"falling_edge":"2017-08-31 06:30:00+00:00","predicted":222.83824213368737,"rising_edge":"2017-08-31 06:00:00+00:00"},{"actual":220.3638146436531,"falling_edge":"2017-08-31 07:00:00+00:00","predicted":220.3638146436531,"rising_edge":"2017-08-31 06:30:00+00:00"},{"actual":218.67593393519283,"falling_edge":"2017-08-31 07:30:00+00:00","predicted":218.67593393519283,"rising_edge":"2017-08-31 07:00:00+00:00"},{"actual":214.3160437480958,"falling_edge":"2017-08-31 08:00:00+00:00","predicted":214.3160437480958,"rising_edge":"2017-08-31 07:30:00+00:00"},{"actual":211.60045067351425,"falling_edge":"2017-08-31 08:30:00+00:00","predicted":211.60045067351425,"rising_edge":"2017-08-31 08:00:00+00:00"},{"actual":198.7107423426917,"falling_edge":"2017-08-31 09:00:00+00:00","predicted":198.7107423426917,"rising_edge":"2017-08-31 08:30:00+00:00"},{"actual":175.76334817204688,"falling_edge":"2017-08-31 09:30:00+00:00","predicted":175.76334817204688,"rising_edge":"2017-08-31 09:00:00+00:00"},{"actual":158.8560424215228,"falling_edge":"2017-08-31 10:00:00+00:00","predicted":158.8560424215228,"rising_edge":"2017-08-31 09:30:00+00:00"},{"actual":135.70154714945997,"falling_edge":"2017-08-31 10:30:00+00:00","predicted":135.70154714945997,"rising_edge":"2017-08-31 10:00:00+00:00"},{"actual":129.95040079230643,"falling_edge":"2017-08-31 11:00:00+00:00","predicted":129.95040079230643,"rising_edge":"2017-08-31 10:30:00+00:00"},{"actual":123.1410386355076,"falling_edge":"2017-08-31 11:30:00+00:00","predicted":123.1410386355076,"rising_edge":"2017-08-31 11:00:00+00:00"},{"actual":113.72735070957384,"falling_edge":"2017-08-31 12:00:00+00:00","predicted":113.72735070957384,"rising_edge":"2017-08-31 11:30:00+00:00"},{"actual":103.3105252471514,"falling_edge":"2017-08-31 12:30:00+00:00","predicted":103.3105252471514,"rising_edge":"2017-08-31 12:00:00+00:00"},{"actual":93.47660894253639,"falling_edge":"2017-08-31 13:00:00+00:00","predicted":93.47660894253639,"rising_edge":"2017-08-31 12:30:00+00:00"},{"actual":82.24025126294356,"falling_edge":"2017-08-31 13:30:00+00:00","predicted":82.24025126294356,"rising_edge":"2017-08-31 13:00:00+00:00"},{"actual":72.27583898851799,"falling_edge":"2017-08-31 14:00:00+00:00","predicted":72.27583898851799,"rising_edge":"2017-08-31 13:30:00+00:00"},{"actual":65.4660879635429,"falling_edge":"2017-08-31 14:30:00+00:00","predicted":65.4660879635429,"rising_edge":"2017-08-31 14:00:00+00:00"},{"actual":58.051664897163405,"falling_edge":"2017-08-31 15:00:00+00:00","predicted":58.051664897163405,"rising_edge":"2017-08-31 14:30:00+00:00"},{"actual":50.02966901230315,"falling_edge":"2017-08-31 15:30:00+00:00","predicted":50.02966901230315,"rising_edge":"2017-08-31 15:00:00+00:00"},{"actual":45.828646741283706,"falling_edge":"2017-08-31 16:00:00+00:00","predicted":45.828646741283706,"rising_edge":"2017-08-31 15:30:00+00:00"},{"actual":44.638274570932985,"falling_edge":"2017-08-31 16:30:00+00:00","predicted":44.638274570932985,"rising_edge":"2017-08-31 16:00:00+00:00"},{"actual":44.410076032167225,"falling_edge":"2017-08-31 17:00:00+00:00","predicted":44.410076032167225,"rising_edge":"2017-08-31 16:30:00+00:00"},{"actual":44.31766050335138,"falling_edge":"2017-08-31 17:30:00+00:00","predicted":44.31766050335138,"rising_edge":"2017-08-31 17:00:00+00:00"},{"actual":43.60816846845904,"falling_edge":"2017-08-31 18:00:00+00:00","predicted":43.60816846845904,"rising_edge":"2017-08-31 17:30:00+00:00"},{"actual":44.26389112427131,"falling_edge":"2017-08-31 18:30:00+00:00","predicted":44.26389112427131,"rising_edge":"2017-08-31 18:00:00+00:00"},{"actual":43.78951682992339,"falling_edge":"2017-08-31 19:00:00+00:00","predicted":43.78951682992339,"rising_edge":"2017-08-31 18:30:00+00:00"},{"actual":44.809294983563476,"falling_edge":"2017-08-31 19:30:00+00:00","predicted":44.809294983563476,"rising_edge":"2017-08-31 19:00:00+00:00"},{"actual":44.46311094395747,"falling_edge":"2017-08-31 20:00:00+00:00","predicted":44.46311094395747,"rising_edge":"2017-08-31 19:30:00+00:00"},{"actual":46.48037415826052,"falling_edge":"2017-08-31 20:30:00+00:00","predicted":46.48037415826052,"rising_edge":"2017-08-31 20:00:00+00:00"},{"actual":50.2584678859032,"falling_edge":"2017-08-31 21:00:00+00:00","predicted":50.2584678859032,"rising_edge":"2017-08-31 20:30:00+00:00"},{"actual":67.05107556407731,"falling_edge":"2017-08-31 21:30:00+00:00","predicted":67.05107556407731,"rising_edge":"2017-08-31 21:00:00+00:00"},{"actual":98.04369578644803,"falling_edge":"2017-08-31 22:00:00+00:00","predicted":98.04369578644803,"rising_edge":"2017-08-31 21:30:00+00:00"},{"actual":93.65667486419719,"falling_edge":"2017-08-31 22:30:00+00:00","predicted":93.65667486419719,"rising_edge":"2017-08-31 22:00:00+00:00"},{"actual":110.6278582376425,"falling_edge":"2017-08-31 23:00:00+00:00","predicted":110.6278582376425,"rising_edge":"2017-08-31 22:30:00+00:00"},{"actual":144.08269026808338,"falling_edge":"2017-08-31 23:30:00+00:00","predicted":144.08269026808338,"rising_edge":"2017-08-31 23:00:00+00:00"},{"actual":190.83707856042065,"falling_edge":"2017-09-01 00:00:00+00:00","predicted":190.83707856042065,"rising_edge":"2017-08-31 23:30:00+00:00"},{"actual":205.6029533033786,"falling_edge":"2017-09-01 00:30:00+00:00","predicted":205.6029533033786,"rising_edge":"2017-09-01 00:00:00+00:00"},{"actual":213.4763145612078,"falling_edge":"2017-09-01 01:00:00+00:00","predicted":213.4763145612078,"rising_edge":"2017-09-01 00:30:00+00:00"},{"actual":217.4131182100183,"falling_edge":"2017-09-01 01:30:00+00:00","predicted":217.4131182100183,"rising_edge":"2017-09-01 01:00:00+00:00"},{"actual":209.94633048534956,"falling_edge":"2017-09-01 02:00:00+00:00","predicted":209.94633048534956,"rising_edge":"2017-09-01 01:30:00+00:00"},{"actual":207.94313484804908,"falling_edge":"2017-09-01 02:30:00+00:00","predicted":207.94313484804908,"rising_edge":"2017-09-01 02:00:00+00:00"},{"actual":207.80684664549023,"falling_edge":"2017-09-01 03:00:00+00:00","predicted":207.80684664549023,"rising_edge":"2017-09-01 02:30:00+00:00"},{"actual":200.03581515497189,"falling_edge":"2017-09-01 03:30:00+00:00","predicted":200.03581515497189,"rising_edge":"2017-09-01 03:00:00+00:00"},{"actual":189.3746622266831,"falling_edge":"2017-09-01 04:00:00+00:00","predicted":189.3746622266831,"rising_edge":"2017-09-01 03:30:00+00:00"},{"actual":207.22354019771737,"falling_edge":"2017-09-01 04:30:00+00:00","predicted":207.22354019771737,"rising_edge":"2017-09-01 04:00:00+00:00"},{"actual":209.04358874252588,"falling_edge":"2017-09-01 05:00:00+00:00","predicted":209.04358874252588,"rising_edge":"2017-09-01 04:30:00+00:00"},{"actual":200.91169710753059,"falling_edge":"2017-09-01 05:30:00+00:00","predicted":200.91169710753059,"rising_edge":"2017-09-01 05:00:00+00:00"},{"actual":202.2481350083064,"falling_edge":"2017-09-01 06:00:00+00:00","predicted":202.2481350083064,"rising_edge":"2017-09-01 05:30:00+00:00"},{"actual":203.18418021018934,"falling_edge":"2017-09-01 06:30:00+00:00","predicted":203.18418021018934,"rising_edge":"2017-09-01 06:00:00+00:00"},{"actual":205.1662514419398,"falling_edge":"2017-09-01 07:00:00+00:00","predicted":205.1662514419398,"rising_edge":"2017-09-01 06:30:00+00:00"},{"actual":200.14712974432643,"falling_edge":"2017-09-01 07:30:00+00:00","predicted":200.14712974432643,"rising_edge":"2017-09-01 07:00:00+00:00"},{"actual":198.79638451926877,"falling_edge":"2017-09-01 08:00:00+00:00","predicted":198.79638451926877,"rising_edge":"2017-09-01 07:30:00+00:00"},{"actual":195.46601695065283,"falling_edge":"2017-09-01 08:30:00+00:00","predicted":195.46601695065283,"rising_edge":"2017-09-01 08:00:00+00:00"},{"actual":184.79329647196445,"falling_edge":"2017-09-01 09:00:00+00:00","predicted":184.79329647196445,"rising_edge":"2017-09-01 08:30:00+00:00"},{"actual":163.24000625439137,"falling_edge":"2017-09-01 09:30:00+00:00","predicted":163.24000625439137,"rising_edge":"2017-09-01 09:00:00+00:00"},{"actual":145.12551696883384,"falling_edge":"2017-09-01 10:00:00+00:00","predicted":145.12551696883384,"rising_edge":"2017-09-01 09:30:00+00:00"},{"actual":122.36951109094652,"falling_edge":"2017-09-01 10:30:00+00:00","predicted":122.36951109094652,"rising_edge":"2017-09-01 10:00:00+00:00"},{"actual":114.7728572577824,"falling_edge":"2017-09-01 11:00:00+00:00","predicted":114.7728572577824,"rising_edge":"2017-09-01 10:30:00+00:00"},{"actual":105.64857100742125,"falling_edge":"2017-09-01 11:30:00+00:00","predicted":105.64857100742125,"rising_edge":"2017-09-01 11:00:00+00:00"},{"actual":97.38441444532162,"falling_edge":"2017-09-01 12:00:00+00:00","predicted":97.38441444532162,"rising_edge":"2017-09-01 11:30:00+00:00"},{"actual":88.5664483221547,"falling_edge":"2017-09-01 12:30:00+00:00","predicted":88.5664483221547,"rising_edge":"2017-09-01 12:00:00+00:00"},{"actual":80.02231759103326,"falling_edge":"2017-09-01 13:00:00+00:00","predicted":80.02231759103326,"rising_edge":"2017-09-01 12:30:00+00:00"},{"actual":73.31356151468212,"falling_edge":"2017-09-01 13:30:00+00:00","predicted":73.31356151468212,"rising_edge":"2017-09-01 13:00:00+00:00"},{"actual":66.47945618048382,"falling_edge":"2017-09-01 14:00:00+00:00","predicted":66.47945618048382,"rising_edge":"2017-09-01 13:30:00+00:00"},{"actual":58.880661375814405,"falling_edge":"2017-09-01 14:30:00+00:00","predicted":58.880661375814405,"rising_edge":"2017-09-01 14:00:00+00:00"},{"actual":54.08327566184613,"falling_edge":"2017-09-01 15:00:00+00:00","predicted":54.08327566184613,"rising_edge":"2017-09-01 14:30:00+00:00"},{"actual":48.9121773555799,"falling_edge":"2017-09-01 15:30:00+00:00","predicted":48.9121773555799,"rising_edge":"2017-09-01 15:00:00+00:00"},{"actual":45.7231586149443,"falling_edge":"2017-09-01 16:00:00+00:00","predicted":45.7231586149443,"rising_edge":"2017-09-01 15:30:00+00:00"},{"actual":45.32230209513062,"falling_edge":"2017-09-01 16:30:00+00:00","predicted":45.32230209513062,"rising_edge":"2017-09-01 16:00:00+00:00"},{"actual":44.69367919100392,"falling_edge":"2017-09-01 17:00:00+00:00","predicted":44.69367919100392,"rising_edge":"2017-09-01 16:30:00+00:00"},{"actual":44.79702640910878,"falling_edge":"2017-09-01 17:30:00+00:00","predicted":44.79702640910878,"rising_edge":"2017-09-01 17:00:00+00:00"},{"actual":43.99552586753569,"falling_edge":"2017-09-01 18:00:00+00:00","predicted":43.99552586753569,"rising_edge":"2017-09-01 17:30:00+00:00"},{"actual":44.994897375119045,"falling_edge":"2017-09-01 18:30:00+00:00","predicted":44.994897375119045,"rising_edge":"2017-09-01 18:00:00+00:00"},{"actual":44.896571606683196,"falling_edge":"2017-09-01 19:00:00+00:00","predicted":44.896571606683196,"rising_edge":"2017-09-01 18:30:00+00:00"},{"actual":45.61170143877896,"falling_edge":"2017-09-01 19:30:00+00:00","predicted":45.61170143877896,"rising_edge":"2017-09-01 19:00:00+00:00"},{"actual":44.90611132857175,"falling_edge":"2017-09-01 20:00:00+00:00","predicted":44.90611132857175,"rising_edge":"2017-09-01 19:30:00+00:00"},{"actual":45.71823989824657,"falling_edge":"2017-09-01 20:30:00+00:00","predicted":45.71823989824657,"rising_edge":"2017-09-01 20:00:00+00:00"},{"actual":48.42491366906053,"falling_edge":"2017-09-01 21:00:00+00:00","predicted":48.42491366906053,"rising_edge":"2017-09-01 20:30:00+00:00"},{"actual":56.083592464882344,"falling_edge":"2017-09-01 21:30:00+00:00","predicted":56.083592464882344,"rising_edge":"2017-09-01 21:00:00+00:00"},{"actual":59.941811671749505,"falling_edge":"2017-09-01 22:00:00+00:00","predicted":59.941811671749505,"rising_edge":"2017-09-01 21:30:00+00:00"},{"actual":59.60112023940781,"falling_edge":"2017-09-01 22:30:00+00:00","predicted":59.60112023940781,"rising_edge":"2017-09-01 22:00:00+00:00"},{"actual":60.208253159371715,"falling_edge":"2017-09-01 23:00:00+00:00","predicted":60.208253159371715,"rising_edge":"2017-09-01 22:30:00+00:00"},{"actual":63.45012943974007,"falling_edge":"2017-09-01 23:30:00+00:00","predicted":63.45012943974007,"rising_edge":"2017-09-01 23:00:00+00:00"},{"actual":67.6237242289411,"falling_edge":"2017-09-02 00:00:00+00:00","predicted":67.6237242289411,"rising_edge":"2017-09-01 23:30:00+00:00"},{"actual":74.1779084008318,"falling_edge":"2017-09-02 00:30:00+00:00","predicted":74.1779084008318,"rising_edge":"2017-09-02 00:00:00+00:00"},{"actual":81.08314508114931,"falling_edge":"2017-09-02 01:00:00+00:00","predicted":81.08314508114931,"rising_edge":"2017-09-02 00:30:00+00:00"},{"actual":81.88661187454618,"falling_edge":"2017-09-02 01:30:00+00:00","predicted":81.88661187454618,"rising_edge":"2017-09-02 01:00:00+00:00"},{"actual":83.33953361030919,"falling_edge":"2017-09-02 02:00:00+00:00","predicted":83.33953361030919,"rising_edge":"2017-09-02 01:30:00+00:00"},{"actual":80.72371006906253,"falling_edge":"2017-09-02 02:30:00+00:00","predicted":80.72371006906253,"rising_edge":"2017-09-02 02:00:00+00:00"},{"actual":83.83006652364712,"falling_edge":"2017-09-02 03:00:00+00:00","predicted":83.83006652364712,"rising_edge":"2017-09-02 02:30:00+00:00"},{"actual":83.6723372832892,"falling_edge":"2017-09-02 03:30:00+00:00","predicted":83.6723372832892,"rising_edge":"2017-09-02 03:00:00+00:00"},{"actual":82.09577270937541,"falling_edge":"2017-09-02 04:00:00+00:00","predicted":82.09577270937541,"rising_edge":"2017-09-02 03:30:00+00:00"},{"actual":86.11831032741566,"falling_edge":"2017-09-02 04:30:00+00:00","predicted":86.11831032741566,"rising_edge":"2017-09-02 04:00:00+00:00"},{"actual":83.98994734218647,"falling_edge":"2017-09-02 05:00:00+00:00","predicted":83.98994734218647,"rising_edge":"2017-09-02 04:30:00+00:00"},{"actual":82.50705411324131,"falling_edge":"2017-09-02 05:30:00+00:00","predicted":82.50705411324131,"rising_edge":"2017-09-02 05:00:00+00:00"},{"actual":81.68334604905094,"falling_edge":"2017-09-02 06:00:00+00:00","predicted":81.68334604905094,"rising_edge":"2017-09-02 05:30:00+00:00"},{"actual":81.47706410568242,"falling_edge":"2017-09-02 06:30:00+00:00","predicted":81.47706410568242,"rising_edge":"2017-09-02 06:00:00+00:00"},{"actual":82.43094907599374,"falling_edge":"2017-09-02 07:00:00+00:00","predicted":82.43094907599374,"rising_edge":"2017-09-02 06:30:00+00:00"},{"actual":81.58021493108622,"falling_edge":"2017-09-02 07:30:00+00:00","predicted":81.58021493108622,"rising_edge":"2017-09-02 07:00:00+00:00"},{"actual":78.4654196210524,"falling_edge":"2017-09-02 08:00:00+00:00","predicted":78.4654196210524,"rising_edge":"2017-09-02 07:30:00+00:00"},{"actual":77.7320753578484,"falling_edge":"2017-09-02 08:30:00+00:00","predicted":77.7320753578484,"rising_edge":"2017-09-02 08:00:00+00:00"},{"actual":72.36401730307065,"falling_edge":"2017-09-02 09:00:00+00:00","predicted":72.36401730307065,"rising_edge":"2017-09-02 08:30:00+00:00"},{"actual":64.85886975738175,"falling_edge":"2017-09-02 09:30:00+00:00","predicted":64.85886975738175,"rising_edge":"2017-09-02 09:00:00+00:00"},{"actual":62.78079849545464,"falling_edge":"2017-09-02 10:00:00+00:00","predicted":62.78079849545464,"rising_edge":"2017-09-02 09:30:00+00:00"},{"actual":60.384517541471425,"falling_edge":"2017-09-02 10:30:00+00:00","predicted":60.384517541471425,"rising_edge":"2017-09-02 10:00:00+00:00"},{"actual":58.78728321274703,"falling_edge":"2017-09-02 11:00:00+00:00","predicted":58.78728321274703,"rising_edge":"2017-09-02 10:30:00+00:00"},{"actual":58.03894094653403,"falling_edge":"2017-09-02 11:30:00+00:00","predicted":58.03894094653403,"rising_edge":"2017-09-02 11:00:00+00:00"},{"actual":56.29327272592667,"falling_edge":"2017-09-02 12:00:00+00:00","predicted":56.29327272592667,"rising_edge":"2017-09-02 11:30:00+00:00"},{"actual":52.35718484916157,"falling_edge":"2017-09-02 12:30:00+00:00","predicted":52.35718484916157,"rising_edge":"2017-09-02 12:00:00+00:00"},{"actual":50.553622026500335,"falling_edge":"2017-09-02 13:00:00+00:00","predicted":50.553622026500335,"rising_edge":"2017-09-02 12:30:00+00:00"},{"actual":49.923285490804055,"falling_edge":"2017-09-02 13:30:00+00:00","predicted":49.923285490804055,"rising_edge":"2017-09-02 13:00:00+00:00"},{"actual":49.05772273640695,"falling_edge":"2017-09-02 14:00:00+00:00","predicted":49.05772273640695,"rising_edge":"2017-09-02 13:30:00+00:00"},{"actual":47.34692502242274,"falling_edge":"2017-09-02 14:30:00+00:00","predicted":47.34692502242274,"rising_edge":"2017-09-02 14:00:00+00:00"},{"actual":46.40184087502746,"falling_edge":"2017-09-02 15:00:00+00:00","predicted":46.40184087502746,"rising_edge":"2017-09-02 14:30:00+00:00"}] ================================================ FILE: examples/sankeyChart.html ================================================

Sankey Chart

Basic CSS for Sankey chart:
.node rect {
    cursor: move;
    fill-opacity: .9;
    shape-rendering: crispEdges;
}

.node text {
    pointer-events: none;
    text-shadow: 0 1px 0 #fff;
}

.link {
    fill: none;
    stroke: #000;
    stroke-opacity: .2;
}

.link:hover {
    stroke-opacity: .5;
}
================================================ FILE: examples/scatter.html ================================================ ================================================ FILE: examples/scatterChart.html ================================================
================================================ FILE: examples/scatterPlusLineChart.html ================================================
================================================ FILE: examples/site.html ================================================ Nvd3 - reusable charts for D3.js

Nvd3

A reusable chart library for d3.js

================================================ FILE: examples/sparkline.html ================================================

Sparkline:

================================================ FILE: examples/sparklinePlus.html ================================================

================================================ FILE: examples/stackedArea.html ================================================
================================================ FILE: examples/stackedAreaChart.html ================================================ ================================================ FILE: examples/stackedAreaWithFocusChart.html ================================================ ================================================ FILE: examples/stylesheets/pygment_trac.css ================================================ .highlight .hll { background-color: #404040 } .highlight { color: #d0d0d0 } .highlight .c { color: #999999; font-style: italic } /* Comment */ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ .highlight .g { color: #d0d0d0 } /* Generic */ .highlight .k { color: #6ab825; font-weight: normal } /* Keyword */ .highlight .l { color: #d0d0d0 } /* Literal */ .highlight .n { color: #d0d0d0 } /* Name */ .highlight .o { color: #d0d0d0 } /* Operator */ .highlight .x { color: #d0d0d0 } /* Other */ .highlight .p { color: #d0d0d0 } /* Punctuation */ .highlight .cm { color: #999999; font-style: italic } /* Comment.Multiline */ .highlight .cp { color: #cd2828; font-weight: normal } /* Comment.Preproc */ .highlight .c1 { color: #999999; font-style: italic } /* Comment.Single */ .highlight .cs { color: #e50808; font-weight: normal; background-color: #520000 } /* Comment.Special */ .highlight .gd { color: #d22323 } /* Generic.Deleted */ .highlight .ge { color: #d0d0d0; font-style: italic } /* Generic.Emph */ .highlight .gr { color: #d22323 } /* Generic.Error */ .highlight .gh { color: #ffffff; font-weight: normal } /* Generic.Heading */ .highlight .gi { color: #589819 } /* Generic.Inserted */ .highlight .go { color: #cccccc } /* Generic.Output */ .highlight .gp { color: #aaaaaa } /* Generic.Prompt */ .highlight .gs { color: #d0d0d0; font-weight: normal } /* Generic.Strong */ .highlight .gu { color: #ffffff; text-decoration: underline } /* Generic.Subheading */ .highlight .gt { color: #d22323 } /* Generic.Traceback */ .highlight .kc { color: #6ab825; font-weight: normal } /* Keyword.Constant */ .highlight .kd { color: #6ab825; font-weight: normal } /* Keyword.Declaration */ .highlight .kn { color: #6ab825; font-weight: normal } /* Keyword.Namespace */ .highlight .kp { color: #6ab825 } /* Keyword.Pseudo */ .highlight .kr { color: #6ab825; font-weight: normal } /* Keyword.Reserved */ .highlight .kt { color: #6ab825; font-weight: normal } /* Keyword.Type */ .highlight .ld { color: #d0d0d0 } /* Literal.Date */ .highlight .m { color: #3677a9 } /* Literal.Number */ .highlight .s { color: #ff8 } /* Literal.String */ .highlight .na { color: #bbbbbb } /* Name.Attribute */ .highlight .nb { color: #24909d } /* Name.Builtin */ .highlight .nc { color: #447fcf; text-decoration: underline } /* Name.Class */ .highlight .no { color: #40ffff } /* Name.Constant */ .highlight .nd { color: #ffa500 } /* Name.Decorator */ .highlight .ni { color: #d0d0d0 } /* Name.Entity */ .highlight .ne { color: #bbbbbb } /* Name.Exception */ .highlight .nf { color: #447fcf } /* Name.Function */ .highlight .nl { color: #d0d0d0 } /* Name.Label */ .highlight .nn { color: #447fcf; text-decoration: underline } /* Name.Namespace */ .highlight .nx { color: #d0d0d0 } /* Name.Other */ .highlight .py { color: #d0d0d0 } /* Name.Property */ .highlight .nt { color: #6ab825;} /* Name.Tag */ .highlight .nv { color: #40ffff } /* Name.Variable */ .highlight .ow { color: #6ab825; font-weight: normal } /* Operator.Word */ .highlight .w { color: #666666 } /* Text.Whitespace */ .highlight .mf { color: #3677a9 } /* Literal.Number.Float */ .highlight .mh { color: #3677a9 } /* Literal.Number.Hex */ .highlight .mi { color: #3677a9 } /* Literal.Number.Integer */ .highlight .mo { color: #3677a9 } /* Literal.Number.Oct */ .highlight .sb { color: #ff8 } /* Literal.String.Backtick */ .highlight .sc { color: #ff8 } /* Literal.String.Char */ .highlight .sd { color: #ff8 } /* Literal.String.Doc */ .highlight .s2 { color: #ff8 } /* Literal.String.Double */ .highlight .se { color: #ff8 } /* Literal.String.Escape */ .highlight .sh { color: #ff8 } /* Literal.String.Heredoc */ .highlight .si { color: #ff8 } /* Literal.String.Interpol */ .highlight .sx { color: #ffa500 } /* Literal.String.Other */ .highlight .sr { color: #ff8 } /* Literal.String.Regex */ .highlight .s1 { color: #ff8 } /* Literal.String.Single */ .highlight .ss { color: #ff8 } /* Literal.String.Symbol */ .highlight .bp { color: #24909d } /* Name.Builtin.Pseudo */ .highlight .vc { color: #40ffff } /* Name.Variable.Class */ .highlight .vg { color: #40ffff } /* Name.Variable.Global */ .highlight .vi { color: #40ffff } /* Name.Variable.Instance */ .highlight .il { color: #3677a9 } /* Literal.Number.Integer.Long */ ================================================ FILE: examples/stylesheets/styles.css ================================================ /* Leap Day for GitHub Pages by Matt Graham */ /* normalize.css 2012-02-07T12:37 UTC - http://github.com/necolas/normalize.css */ /* ============================================================================= HTML5 display definitions ========================================================================== */ /* * Corrects block display not defined in IE6/7/8/9 & FF3 */ article, aside, details, figcaption, figure, footer, header, hgroup, nav, section, summary { display: block; } /* * Corrects inline-block display not defined in IE6/7/8/9 & FF3 */ audio, canvas, video { display: inline-block; *display: inline; *zoom: 1; } /* * Prevents modern browsers from displaying 'audio' without controls */ audio:not([controls]) { display: none; } /* * Addresses styling for 'hidden' attribute not present in IE7/8/9, FF3, S4 * Known issue: no IE6 support */ [hidden] { display: none; } /* ============================================================================= Base ========================================================================== */ /* * 1. Corrects text resizing oddly in IE6/7 when body font-size is set using em units * http://clagnut.com/blog/348/#c790 * 2. Prevents iOS text size adjust after orientation change, without disabling user zoom * www.456bereastreet.com/archive/201012/controlling_text_size_in_safari_for_ios_without_disabling_user_zoom/ */ html { font-size: 100%; /* 1 */ -webkit-text-size-adjust: 100%; /* 2 */ -ms-text-size-adjust: 100%; /* 2 */ } /* * Addresses font-family inconsistency between 'textarea' and other form elements. */ html, button, input, select, textarea { font-family: sans-serif; } /* * Addresses margins handled incorrectly in IE6/7 */ body { margin: 0; } /* ============================================================================= Links ========================================================================== */ /* * Addresses outline displayed oddly in Chrome */ a:focus { outline: thin dotted; } /* * Improves readability when focused and also mouse hovered in all browsers * people.opera.com/patrickl/experiments/keyboard/test */ a:hover, a:active { outline: 0; } /* ============================================================================= Typography ========================================================================== */ /* * Addresses font sizes and margins set differently in IE6/7 * Addresses font sizes within 'section' and 'article' in FF4+, Chrome, S5 */ h1 { font-size: 2em; margin: 0.67em 0; } h2 { font-size: 1.5em; margin: 0.83em 0; } h3 { font-size: 1.17em; margin: 1em 0; } h4 { font-size: 1em; margin: 1.33em 0; } h5 { font-size: 0.83em; margin: 1.67em 0; } h6 { font-size: 0.75em; margin: 2.33em 0; } /* * Addresses styling not present in IE7/8/9, S5, Chrome */ abbr[title] { border-bottom: 1px dotted; } /* * Addresses style set to 'bolder' in FF3+, S4/5, Chrome */ b, strong { font-weight: bold; } blockquote { margin: 1em 40px; } /* * Addresses styling not present in S5, Chrome */ dfn { font-style: italic; } /* * Addresses styling not present in IE6/7/8/9 */ mark { background: #ff0; color: #000; } /* * Addresses margins set differently in IE6/7 */ p, pre { margin: 1em 0; } /* * Corrects font family set oddly in IE6, S4/5, Chrome * en.wikipedia.org/wiki/User:Davidgothberg/Test59 */ pre, code, kbd, samp { font-family: monospace, serif; _font-family: 'courier new', monospace; font-size: 1em; } /* * 1. Addresses CSS quotes not supported in IE6/7 * 2. Addresses quote property not supported in S4 */ /* 1 */ q { quotes: none; } /* 2 */ q:before, q:after { content: ''; content: none; } small { font-size: 75%; } /* * Prevents sub and sup affecting line-height in all browsers * gist.github.com/413930 */ sub, sup { font-size: 75%; line-height: 0; position: relative; vertical-align: baseline; } sup { top: -0.5em; } sub { bottom: -0.25em; } /* ============================================================================= Lists ========================================================================== */ /* * Addresses margins set differently in IE6/7 */ dl, menu, ol, ul { margin: 1em 0; } dd { margin: 0 0 0 40px; } /* * Addresses paddings set differently in IE6/7 */ menu, ol, ul { padding: 0 0 0 40px; } /* * Corrects list images handled incorrectly in IE7 */ nav ul, nav ol { list-style: none; list-style-image: none; } li span.inherited { display: inline-block; color: #CCC; } /* ============================================================================= Embedded content ========================================================================== */ /* * 1. Removes border when inside 'a' element in IE6/7/8/9, FF3 * 2. Improves image quality when scaled in IE7 * code.flickr.com/blog/2008/11/12/on-ui-quality-the-little-things-client-side-image-resizing/ */ img { border: 0; /* 1 */ -ms-interpolation-mode: bicubic; /* 2 */ } /* * Corrects overflow displayed oddly in IE9 */ svg:not(:root) { overflow: hidden; } /* ============================================================================= Figures ========================================================================== */ /* * Addresses margin not present in IE6/7/8/9, S5, O11 */ figure { margin: 0; } /* ============================================================================= Forms ========================================================================== */ /* * Corrects margin displayed oddly in IE6/7 */ form { margin: 0; } /* * Define consistent border, margin, and padding */ fieldset { border: 1px solid #c0c0c0; margin: 0 2px; padding: 0.35em 0.625em 0.75em; } /* * 1. Corrects color not being inherited in IE6/7/8/9 * 2. Corrects text not wrapping in FF3 * 3. Corrects alignment displayed oddly in IE6/7 */ legend { border: 0; /* 1 */ padding: 0; white-space: normal; /* 2 */ *margin-left: -7px; /* 3 */ } /* * 1. Corrects font size not being inherited in all browsers * 2. Addresses margins set differently in IE6/7, FF3+, S5, Chrome * 3. Improves appearance and consistency in all browsers */ button, input, select, textarea { font-size: 100%; /* 1 */ margin: 0; /* 2 */ vertical-align: baseline; /* 3 */ *vertical-align: middle; /* 3 */ } /* * Addresses FF3/4 setting line-height on 'input' using !important in the UA stylesheet */ button, input { line-height: normal; /* 1 */ } /* * 1. Improves usability and consistency of cursor style between image-type 'input' and others * 2. Corrects inability to style clickable 'input' types in iOS * 3. Removes inner spacing in IE7 without affecting normal text inputs * Known issue: inner spacing remains in IE6 */ button, input[type="button"], input[type="reset"], input[type="submit"] { cursor: pointer; /* 1 */ -webkit-appearance: button; /* 2 */ *overflow: visible; /* 3 */ } /* * Re-set default cursor for disabled elements */ button[disabled], input[disabled] { cursor: default; } /* * 1. Addresses box sizing set to content-box in IE8/9 * 2. Removes excess padding in IE8/9 * 3. Removes excess padding in IE7 Known issue: excess padding remains in IE6 */ input[type="checkbox"], input[type="radio"] { box-sizing: border-box; /* 1 */ padding: 0; /* 2 */ *height: 13px; /* 3 */ *width: 13px; /* 3 */ } /* * 1. Addresses appearance set to searchfield in S5, Chrome * 2. Addresses box-sizing set to border-box in S5, Chrome (include -moz to future-proof) */ input[type="search"] { -webkit-appearance: textfield; /* 1 */ -moz-box-sizing: content-box; -webkit-box-sizing: content-box; /* 2 */ box-sizing: content-box; } /* * Removes inner padding and search cancel button in S5, Chrome on OS X */ input[type="search"]::-webkit-search-decoration, input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; } /* * Removes inner padding and border in FF3+ * www.sitepen.com/blog/2008/05/14/the-devils-in-the-details-fixing-dojos-toolbar-buttons/ */ button::-moz-focus-inner, input::-moz-focus-inner { border: 0; padding: 0; } /* * 1. Removes default vertical scrollbar in IE6/7/8/9 * 2. Improves readability and alignment in all browsers */ textarea { overflow: auto; /* 1 */ vertical-align: top; /* 2 */ } li.option { cursor: pointer; } li.option:hover { color: #FF9900; } li.option-selected { color: #FF9900; border-bottom: 1px solid #AAA; } li.option-selected:last-child { border-bottom: 0px; } li.option div.option-info{ color: #999; margin-top: 5px; margin-bottom: 10px; padding-left: 30px; } li.option div.option-info .part { font-weight: bold; color: #666; } li.option div.option-info .example { display: inline-block; border: 1px solid #CCC; background: #EEE; margin-top: 3px; color: #666; width: 100%; box-sizing: border-box; } li.option div.option-info .example code { white-space: pre; padding: 5px; font-family: "Courier New"; background: inherit ! important; } /* ============================================================================= Tables ========================================================================== */ /* * Remove most spacing between table cells */ table { border-collapse: collapse; border-spacing: 0; } body { font: 14px/22px "Quattrocento Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; color: #666; font-weight: 300; margin: 0px; padding: 0px 0 20px 0px; background: url(../images/body-background.png) #eae6d1; } h1, h2, h3, h4, h5, h6 { color: #333; margin: 0 0 10px; } p, ul, ol, table, pre, dl { margin: 0 0 20px; } h1, h2, h3 { line-height: 1.1; } h1 { font-size: 28px; } h2 { font-size: 24px; color: #393939; } h3, h4, h5, h6 { color: #666666; } h3 { font-size: 18px; line-height: 24px; } h3.option { background-color: #F2F2F2; padding: 5px; padding-left: 10px; border-top: 5px solid #CCC; margin-top: 10px; min-height: 24px; } h3 .expand { font-size: 14px; position: relative; margin-right: 10px; float: right; font-weight: normal; } a { color: #3399cc; font-weight: 400; text-decoration: none; } a small { font-size: 11px; color: #666; margin-top: -0.6em; display: block; } ul { list-style-image: url("../images/bullet.png"); } strong { font-weight: bold; color: #333; } .wrapper { width: 900px; margin: 0 auto; position: relative; } section img { max-width: 100%; } blockquote { border-left: 1px solid #ffcc00; margin: 0; padding: 0 0 0 20px; font-style: italic; } pre { padding: 8px 15px; background: #EEE; -moz-border-radius: 3px; -webkit-border-radius: 3px; -o-border-radius: 3px; -ms-border-radius: 3px; -khtml-border-radius: 3px; border-radius: 3px; border: 1px solid #c7c7c7; overflow: auto; overflow-y: hidden; } table { width: 100%; border-collapse: collapse; } th { text-align: left; padding: 5px 10px; border-bottom: 1px solid #e5e5e5; color: #444; } td { text-align: left; padding: 5px 10px; border-bottom: 1px solid #e5e5e5; border-right: 1px solid #ffcc00; } td:first-child { border-left: 1px solid #ffcc00; } hr { border: 0; outline: none; height: 11px; background: transparent url("../images/hr.gif") center center repeat-x; margin: 0 0 20px; } dt { color: #444; font-weight: 700; } header { margin: 0; top: 0; left: 0; right: 0; width: 100%; text-align: center; background: url(../images/background.png) #4276b6; -moz-box-shadow: 1px 0px 2px rgba(0, 0, 0, 0.75); -webkit-box-shadow: 1px 0px 2px rgba(0, 0, 0, 0.75); -o-box-shadow: 1px 0px 2px rgba(0, 0, 0, 0.75); box-shadow: 1px 0px 2px rgba(0, 0, 0, 0.75); z-index: 99; -webkit-font-smoothing: antialiased; min-height: 76px; } header h1 { font: 40px/48px "Copse", "Helvetica Neue", Helvetica, Arial, sans-serif; color: #f3f3f3; text-shadow: 0px 2px 0px #235796; margin: 0px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; -o-text-overflow: ellipsis; -ms-text-overflow: ellipsis; } header p { color: #d8d8d8; text-shadow: rgba(0, 0, 0, 0.2) 0 1px 0; font-size: 18px; margin: 0px; } #banner { z-index: 100; left: 0; height: 50px; width: 100%; box-sizing: border-box; top: 75px; background: #ffcc00; border: 1px solid #f0b500; -moz-box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.25); -webkit-box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.25); -o-box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.25); box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.25); -moz-border-radius: 0px 2px 2px 0px; -webkit-border-radius: 0px 2px 2px 0px; -o-border-radius: 0px 2px 2px 0px; -ms-border-radius: 0px 2px 2px 0px; -khtml-border-radius: 0px 2px 2px 0px; border-radius: 0px 2px 2px 0px; } #banner .button { border: 1px solid #dba500; background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #ffe788), color-stop(100%, #ffce38)); background: -webkit-linear-gradient(#ffe788, #ffce38); background: -moz-linear-gradient(#ffe788, #ffce38); background: -o-linear-gradient(#ffe788, #ffce38); background: -ms-linear-gradient(#ffe788, #ffce38); background: linear-gradient(#ffe788, #ffce38); -moz-border-radius: 2px; -webkit-border-radius: 2px; -o-border-radius: 2px; -ms-border-radius: 2px; -khtml-border-radius: 2px; border-radius: 2px; -moz-box-shadow: inset 0px 1px 0px rgba(255, 255, 255, 0.4), 0px 1px 1px rgba(0, 0, 0, 0.1); -webkit-box-shadow: inset 0px 1px 0px rgba(255, 255, 255, 0.4), 0px 1px 1px rgba(0, 0, 0, 0.1); -o-box-shadow: inset 0px 1px 0px rgba(255, 255, 255, 0.4), 0px 1px 1px rgba(0, 0, 0, 0.1); box-shadow: inset 0px 1px 0px rgba(255, 255, 255, 0.4), 0px 1px 1px rgba(0, 0, 0, 0.1); background-color: #FFE788; margin-left: 5px; padding: 10px 12px; margin-top: 6px; line-height: 14px; font-size: 14px; color: #333; font-weight: bold; display: inline-block; text-align: center; } #banner .button:hover { background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #ffe788), color-stop(100%, #ffe788)); background: -webkit-linear-gradient(#ffe788, #ffe788); background: -moz-linear-gradient(#ffe788, #ffe788); background: -o-linear-gradient(#ffe788, #ffe788); background: -ms-linear-gradient(#ffe788, #ffe788); background: linear-gradient(#ffe788, #ffe788); background-color: #ffeca0; } #banner .fork { left: 50%; padding: 10px 12px; margin-top: 6px; margin-left: 0px; line-height: 14px; font-size: 14px; background-color: #FFE788; } #banner .docs { margin-left: 10px !important; } #banner .button.selected { background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #ffe788), color-stop(100%, #ffe788)); background: -webkit-linear-gradient(#ffe788, #ffe788); background: -moz-linear-gradient(#ffe788, #ffe788); background: -o-linear-gradient(#ffe788, #ffe788); background: -ms-linear-gradient(#ffe788, #ffe788); background: linear-gradient(#ffe788, #ffe788); background-color: #ffeca0; } #banner .downloads { float: right; margin: 0 0 0 0; margin-right: 2px; } #banner .downloads span { float: left; line-height: 52px; font-size: 90%; color: #9d7f0d; text-transform: uppercase; text-shadow: rgba(255, 255, 255, 0.2) 0 1px 0; } #banner ul { list-style: none; height: 40px; padding: 0; float: left; margin-left: 10px; } #banner ul li { display: inline; } #banner ul li a.button { background-color: #FFE788; } #banner #logo { position: absolute; height: 36px; width: 36px; right: -60px; top: 7px; display: block; background: url(../images/octocat-logo.png); } #banner > div { width: 900px; margin: 0 auto; position: relative; } section { width: 100%; box-sizing: border-box; padding: 15px 30px 50px 30px; position: relative; background: #fbfbfb; -moz-border-radius: 3px; -webkit-border-radius: 3px; -o-border-radius: 3px; -ms-border-radius: 3px; -khtml-border-radius: 3px; border-radius: 3px; border: 1px solid #cbcbcb; -moz-box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.09), inset 0px 0px 2px 2px rgba(255, 255, 255, 0.5), inset 0 0 5px 5px rgba(255, 255, 255, 0.4); -webkit-box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.09), inset 0px 0px 2px 2px rgba(255, 255, 255, 0.5), inset 0 0 5px 5px rgba(255, 255, 255, 0.4); -o-box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.09), inset 0px 0px 2px 2px rgba(255, 255, 255, 0.5), inset 0 0 5px 5px rgba(255, 255, 255, 0.4); box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.09), inset 0px 0px 2px 2px rgba(255, 255, 255, 0.5), inset 0 0 5px 5px rgba(255, 255, 255, 0.4); } small { font-size: 12px; } nav { width: 230px; top: 220px; left: 50%; margin-left: -580px; text-align: right; } nav ul { list-style: none; list-style-image: none; font-size: 14px; line-height: 24px; } nav ul li { padding: 5px 0px; line-height: 16px; } nav ul li.tag-h1 { font-size: 1.2em; } nav ul li.tag-h1 a { font-weight: bold; color: #333; } nav ul li.tag-h2 + .tag-h1 { margin-top: 10px; } nav ul a { color: #666; } nav ul a:hover { color: #999; } footer { width: 180px; position: fixed; left: 50%; margin-left: -530px; bottom: 20px; text-align: right; line-height: 16px; } #banner { width: 100%; } #banner .downloads { margin-right: 0px; } #banner #logo { margin-right: 15px; } #banner .fork { float: left; margin-left: 0px; display: inline-block; left: 20px; } .showcharts, .showbases { display: inline-block; font-family: arial; font-size: 14px; color: #666; padding: 2px; padding-right: 5px; padding-left: 5px; background-color: #EEE; border: 1px solid #CCC; border-radius: 5px; position: absolute; right: 0; margin: 10px; top: 0; } .baselinks, .showcharts { display: none; } .showcharts:hover, .showbases:hover { background-color: #ffffcc; } .examplelinks a { text-decoration: none; font-size: 12px; font-family: arial; outline: none; padding: 3px; padding-left: 6px; padding-right: 6px; } .examplelinks a.selected { border: 1px solid #666; background-color: #FFFF88; padding: 2px; padding-left: 5px; padding-right: 5px; } .propdom { height: 0; } .propdom.populated { height: auto; padding: 5px 10px; } .propdom .label { font-weight: bold; } iframe { display: inline-block; width: 100%; height: 100%; border: 0px; } #show_wrapper { border: 1px solid #666; width: 100%; margin-top: 10px; height: 400px; } @media print, screen and (max-width: 1060px) { div.wrapper { width: auto; margin: 0; } #banner > div { width: auto; margin: 0; } nav { display: none; } header, section, footer { float: none; } header h1, section h1, footer h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; -o-text-overflow: ellipsis; -ms-text-overflow: ellipsis; } #banner { width: 100%; } #banner .downloads { margin-right: 30px; } #banner #logo { margin-right: 15px; } footer { text-align: center; margin: 20px auto; position: relative; left: auto; bottom: auto; width: auto; } body { word-wrap: break-word; } header h1 { font-size: 32px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; -o-text-overflow: ellipsis; -ms-text-overflow: ellipsis; } #banner .fork { float: left; display: inline-block; margin-left: 30px; left: 20px; } section { margin-bottom: 0px; width: auto; box-sizing: border-box; } header ul, header p.view { position: static; } } @media print, screen and (max-width: 480px) { header { position: relative; padding: 5px 0px; min-height: 0px; } header h1 { font-size: 24px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; -o-text-overflow: ellipsis; -ms-text-overflow: ellipsis; } section { margin-top: 5px !important; box-sizing: border-box; } #banner { display: none; } header ul { display: none; } .showcharts, .showbases { position: relative !important; } } @media print { body { padding: 0.4in; font-size: 12pt; color: #444; } } @media print, screen and (max-height: 680px) { footer { text-align: center; margin: 20px auto; position: relative; left: auto; bottom: auto; width: auto; } } @media print, screen and (max-height: 480px) { nav { display: none; } footer { text-align: center; margin: 20px auto; position: relative; left: auto; bottom: auto; width: auto; } } ================================================ FILE: examples/sunburst.html ================================================ ================================================ FILE: examples/tooltip.html ================================================
================================================ FILE: index.html ================================================ ================================================ FILE: meteor/export.js ================================================ /*global nv:true*/ // Meteor creates a file-scope global for exporting. This comment prevents a potential JSHint warning. nv = window.nv; delete window.nv; ================================================ FILE: package.js ================================================ // Package metadata for Meteor.js full stack web framework // This file is defined in Meteor documentation at http://docs.meteor.com/#/full/packagejs // and used by Meteor https://www.meteor.com/ and its package repository Atmosphere https://atmospherejs.com Package.describe({ "name": 'nvd3:nvd3', summary: 'Nvd3.org charts.', version: '1.8.6-dev', git: "https://github.com/novus/nvd3.git" }); Package.on_use(function (api) { api.versionsFrom("METEOR@1.0"); api.use('d3js:d3@3.5.5', 'client'); api.add_files('build/nv.d3.js', 'client'); api.add_files('build/nv.d3.css', 'client'); api.add_files('meteor/export.js', 'client'); api.export("nv"); }); Package.onTest(function(api) { api.use(['tinytest', 'test-helpers']); api.use('d3js:d3', 'client'); api.addFiles(['build/nv.d3.js', 'meteor/export.js'], "client"); api.addFiles('test/tinytest/nv-is-defined-test.js', "client"); }); ================================================ FILE: package.json ================================================ { "name": "nvd3", "version": "1.8.6-dev", "description": "A reusable charting library written in d3.js", "url": "https://github.com/novus/nvd3", "main": "build/nv.d3.js", "scripts": { "test": "grunt", "build": "grunt" }, "repository": { "type": "git", "url": "https://github.com/novus/nvd3" }, "keywords": [ "nvd3", "d3", "chart", "graph" ], "readmeFilename": "README.md", "license": "Apache-2.0", "peerDependencies": { "d3": "^3.4.4" }, "devDependencies": { "autoprefixer": "^6.5.0", "es6-promise": "^4.0.3", "grunt": "^0.4.5", "grunt-cli": "^1.2.0", "grunt-contrib-concat": "~1.0.1", "grunt-contrib-copy": "~0.4.1", "grunt-contrib-cssmin": "~0.13.0", "grunt-contrib-jshint": "^0.11.0", "grunt-contrib-uglify": "~0.9.1", "grunt-contrib-watch": "~0.3.1", "grunt-karma": "^0.9.0", "grunt-postcss": "^0.8.0", "grunt-text-replace": "^0.4.0", "karma": "^0.12.23", "karma-chrome-launcher": "^0.1.4", "karma-coffee-preprocessor": "^0.2.1", "karma-coverage": "^0.2.6", "karma-firefox-launcher": "^0.1.4", "karma-junit-reporter": "^0.2.2", "karma-mocha": "^0.1.9", "karma-sinon-chai": "^0.2.0", "karma-spec-reporter": "0.0.13", "mocha": "^1.21.4", "moment": "^2.18.1" } } ================================================ FILE: src/core.js ================================================ // set up main nv object var nv = {}; // the major global objects under the nv namespace nv.dev = false; //set false when in production nv.tooltip = nv.tooltip || {}; // For the tooltip system nv.utils = nv.utils || {}; // Utility subsystem nv.models = nv.models || {}; //stores all the possible models/components nv.charts = {}; //stores all the ready to use charts nv.logs = {}; //stores some statistics and potential error messages nv.dom = {}; //DOM manipulation functions // Node/CommonJS - require D3 if (typeof(module) !== 'undefined' && typeof(exports) !== 'undefined' && typeof(d3) == 'undefined') { d3 = require('d3'); } nv.dispatch = d3.dispatch('render_start', 'render_end'); // Function bind polyfill // Needed ONLY for phantomJS as it's missing until version 2.0 which is unreleased as of this comment // https://github.com/ariya/phantomjs/issues/10522 // http://kangax.github.io/compat-table/es5/#Function.prototype.bind // phantomJS is used for running the test suite if (!Function.prototype.bind) { Function.prototype.bind = function (oThis) { if (typeof this !== "function") { // closest thing possible to the ECMAScript 5 internal IsCallable function throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable"); } var aArgs = Array.prototype.slice.call(arguments, 1), fToBind = this, fNOP = function () {}, fBound = function () { return fToBind.apply(this instanceof fNOP && oThis ? this : oThis, aArgs.concat(Array.prototype.slice.call(arguments))); }; fNOP.prototype = this.prototype; fBound.prototype = new fNOP(); return fBound; }; } // Development render timers - disabled if dev = false if (nv.dev) { nv.dispatch.on('render_start', function(e) { nv.logs.startTime = +new Date(); }); nv.dispatch.on('render_end', function(e) { nv.logs.endTime = +new Date(); nv.logs.totalTime = nv.logs.endTime - nv.logs.startTime; nv.log('total', nv.logs.totalTime); // used for development, to keep track of graph generation times }); } // Logs all arguments, and returns the last so you can test things in place // Note: in IE8 console.log is an object not a function, and if modernizr is used // then calling Function.prototype.bind with with anything other than a function // causes a TypeError to be thrown. nv.log = function() { if (nv.dev && window.console && console.log && console.log.apply) console.log.apply(console, arguments); else if (nv.dev && window.console && typeof console.log == "function" && Function.prototype.bind) { var log = Function.prototype.bind.call(console.log, console); log.apply(console, arguments); } return arguments[arguments.length - 1]; }; // print console warning, should be used by deprecated functions nv.deprecated = function(name, info) { if (console && console.warn) { console.warn('nvd3 warning: `' + name + '` has been deprecated. ', info || ''); } }; // The nv.render function is used to queue up chart rendering // in non-blocking async functions. // When all queued charts are done rendering, nv.dispatch.render_end is invoked. nv.render = function render(step) { // number of graphs to generate in each timeout loop step = step || 1; nv.render.active = true; nv.dispatch.render_start(); var renderLoop = function() { var chart, graph; for (var i = 0; i < step && (graph = nv.render.queue[i]); i++) { chart = graph.generate(); if (typeof graph.callback == typeof(Function)) graph.callback(chart); } nv.render.queue.splice(0, i); if (nv.render.queue.length) { setTimeout(renderLoop); } else { nv.dispatch.render_end(); nv.render.active = false; } }; setTimeout(renderLoop); }; nv.render.active = false; nv.render.queue = []; /* Adds a chart to the async rendering queue. This method can take arguments in two forms: nv.addGraph({ generate: callback: }) or nv.addGraph(, ) The generate function should contain code that creates the NVD3 model, sets options on it, adds data to an SVG element, and invokes the chart model. The generate function should return the chart model. See examples/lineChart.html for a usage example. The callback function is optional, and it is called when the generate function completes. */ nv.addGraph = function(obj) { if (typeof arguments[0] === typeof(Function)) { obj = {generate: arguments[0], callback: arguments[1]}; } nv.render.queue.push(obj); if (!nv.render.active) { nv.render(); } }; // Node/CommonJS exports if (typeof(module) !== 'undefined' && typeof(exports) !== 'undefined') { module.exports = nv; } if (typeof(window) !== 'undefined') { window.nv = nv; } ================================================ FILE: src/css/axis.css ================================================ .nvd3 .nv-axis { pointer-events:none; opacity: 1; } .nvd3 .nv-axis path { fill: none; stroke: #000; stroke-opacity: .75; shape-rendering: crispEdges; } .nvd3 .nv-axis path.domain { stroke-opacity: .75; } .nvd3 .nv-axis.nv-x path.domain { stroke-opacity: 0; } .nvd3 .nv-axis line { fill: none; stroke: #e5e5e5; shape-rendering: crispEdges; } .nvd3 .nv-axis .zero line, /*this selector may not be necessary*/ .nvd3 .nv-axis line.zero { stroke-opacity: .75; } .nvd3 .nv-axis .nv-axisMaxMin text { font-weight: bold; } .nvd3 .x .nv-axis .nv-axisMaxMin text, .nvd3 .x2 .nv-axis .nv-axisMaxMin text, .nvd3 .x3 .nv-axis .nv-axisMaxMin text { text-anchor: middle; } .nvd3 .nv-axis.nv-disabled { opacity: 0; } ================================================ FILE: src/css/bars.css ================================================ .nvd3 .nv-bars rect { fill-opacity: .75; transition: fill-opacity 250ms linear; } .nvd3 .nv-bars rect.hover { fill-opacity: 1; } .nvd3 .nv-bars .hover rect { fill: lightblue; } .nvd3 .nv-bars text { fill: rgba(0,0,0,0); } .nvd3 .nv-bars .hover text { fill: rgba(0,0,0,1); } .nvd3 .nv-multibar .nv-groups rect, .nvd3 .nv-multibarHorizontal .nv-groups rect, .nvd3 .nv-discretebar .nv-groups rect { stroke-opacity: 0; transition: fill-opacity 250ms linear; } .nvd3 .nv-multibar .nv-groups rect:hover, .nvd3 .nv-multibarHorizontal .nv-groups rect:hover, .nvd3 .nv-candlestickBar .nv-ticks rect:hover, .nvd3 .nv-discretebar .nv-groups rect:hover { fill-opacity: 1; } .nvd3 .nv-discretebar .nv-groups text, .nvd3 .nv-multibarHorizontal .nv-groups text { font-weight: bold; fill: rgba(0,0,0,1); stroke: rgba(0,0,0,0); } ================================================ FILE: src/css/boxplot.css ================================================ /* boxplot CSS */ .nvd3 .nv-boxplot circle { fill-opacity: 0.5; } .nvd3 .nv-boxplot circle:hover { fill-opacity: 1; } .nvd3 .nv-boxplot rect:hover { fill-opacity: 1; } .nvd3 line.nv-boxplot-median { stroke: black; } .nv-boxplot-tick:hover { stroke-width: 2.5px; } ================================================ FILE: src/css/bullet.css ================================================ /* bullet */ .nvd3.nv-bullet { font: 10px sans-serif; } .nvd3.nv-bullet .nv-measure { fill-opacity: .8; } .nvd3.nv-bullet .nv-measure:hover { fill-opacity: 1; } .nvd3.nv-bullet .nv-marker { stroke: #000; stroke-width: 2px; } .nvd3.nv-bullet .nv-markerTriangle { stroke: #000; fill: #fff; stroke-width: 1.5px; } .nvd3.nv-bullet .nv-markerLine { stroke: #000; stroke-width: 1.5px; } .nvd3.nv-bullet .nv-tick line { stroke: #666; stroke-width: .5px; } .nvd3.nv-bullet .nv-range.nv-s0 { fill: #eee; } .nvd3.nv-bullet .nv-range.nv-s1 { fill: #ddd; } .nvd3.nv-bullet .nv-range.nv-s2 { fill: #ccc; } .nvd3.nv-bullet .nv-title { font-size: 14px; font-weight: bold; } .nvd3.nv-bullet .nv-subtitle { fill: #999; } .nvd3.nv-bullet .nv-range { fill: #bababa; fill-opacity: .4; } .nvd3.nv-bullet .nv-range:hover { fill-opacity: .7; } ================================================ FILE: src/css/candlestick.css ================================================ .nvd3.nv-candlestickBar .nv-ticks .nv-tick { stroke-width: 1px; } .nvd3.nv-candlestickBar .nv-ticks .nv-tick.hover { stroke-width: 2px; } .nvd3.nv-candlestickBar .nv-ticks .nv-tick.positive rect { stroke: #2ca02c; fill: #2ca02c; } .nvd3.nv-candlestickBar .nv-ticks .nv-tick.negative rect { stroke: #d62728; fill: #d62728; } .with-transitions .nv-candlestickBar .nv-ticks .nv-tick { transition: stroke-width 250ms linear, stroke-opacity 250ms linear; } .nvd3.nv-candlestickBar .nv-ticks line { stroke: #333; } ================================================ FILE: src/css/forceDirectedGraph.css ================================================ .nv-force-node { stroke: #fff; stroke-width: 1.5px; } .nv-force-link { stroke: #999; stroke-opacity: .6; } .nv-force-node text { stroke-width: 0px; } ================================================ FILE: src/css/furiousLegend.css ================================================ .nvd3 .nv-legend .nv-disabled rect { /*fill-opacity: 0;*/ } .nvd3 .nv-check-box .nv-box { fill-opacity:0; stroke-width:2; } .nvd3 .nv-check-box .nv-check { fill-opacity:0; stroke-width:4; } .nvd3 .nv-series.nv-disabled .nv-check-box .nv-check { fill-opacity:0; stroke-opacity:0; } .nvd3 .nv-controlsWrap .nv-legend .nv-check-box .nv-check { opacity: 0; } ================================================ FILE: src/css/lineplusbar.css ================================================ /* line plus bar */ .nvd3.nv-linePlusBar .nv-bar rect { fill-opacity: .75; } .nvd3.nv-linePlusBar .nv-bar rect:hover { fill-opacity: 1; } ================================================ FILE: src/css/lines.css ================================================ .nvd3 .nv-groups path.nv-line { fill: none; } .nvd3 .nv-groups path.nv-area { stroke: none; } .nvd3.nv-line .nvd3.nv-scatter .nv-groups .nv-point { fill-opacity: 0; stroke-opacity: 0; } .nvd3.nv-scatter.nv-single-point .nv-groups .nv-point { fill-opacity: .5 !important; stroke-opacity: .5 !important; } .with-transitions .nvd3 .nv-groups .nv-point { transition: stroke-width 250ms linear, stroke-opacity 250ms linear; } .nvd3.nv-scatter .nv-groups .nv-point.hover, .nvd3 .nv-groups .nv-point.hover { stroke-width: 7px; fill-opacity: .95 !important; stroke-opacity: .95 !important; } .nvd3 .nv-point-paths path { stroke: #aaa; stroke-opacity: 0; fill: #eee; fill-opacity: 0; } .nvd3 .nv-indexLine { cursor: ew-resize; } ================================================ FILE: src/css/main.css ================================================ /******************** * SVG CSS */ /******************** Default CSS for an svg element nvd3 used */ svg.nvd3-svg { user-select: none; display: block; width:100%; height:100%; } /******************** Box shadow and border radius styling */ .nvtooltip.with-3d-shadow, .with-3d-shadow .nvtooltip { box-shadow: 0 5px 10px rgba(0,0,0,.2); border-radius: 5px; } .nvd3 text { font: normal 12px Arial, sans-serif; } .nvd3 .title { font: bold 14px Arial, sans-serif; } .nvd3 .nv-background { fill: white; fill-opacity: 0; } .nvd3.nv-noData { font-size: 18px; font-weight: bold; } /********** * Brush */ .nv-brush .extent { fill-opacity: .125; shape-rendering: crispEdges; } .nv-brush .resize path { fill: #eee; stroke: #666; } /********** * Legend */ .nvd3 .nv-legend .nv-series { cursor: pointer; } .nvd3 .nv-legend .nv-disabled circle { fill-opacity: 0; } /* focus */ .nvd3 .nv-brush .extent { fill-opacity: 0 !important; } .nvd3 .nv-brushBackground rect { stroke: #000; stroke-width: .4; fill: #fff; fill-opacity: .7; } /********** * Print */ @media print { .nvd3 text { stroke-width: 0; fill-opacity: 1; } } ================================================ FILE: src/css/ohlc.css ================================================ .nvd3.nv-ohlcBar .nv-ticks .nv-tick { stroke-width: 1px; } .nvd3.nv-ohlcBar .nv-ticks .nv-tick.hover { stroke-width: 2px; } .nvd3.nv-ohlcBar .nv-ticks .nv-tick.positive { stroke: #2ca02c; } .nvd3.nv-ohlcBar .nv-ticks .nv-tick.negative { stroke: #d62728; } ================================================ FILE: src/css/parallelcoordinates.css ================================================ .nvd3 .background path { fill: none; stroke: #EEE; stroke-opacity: .4; shape-rendering: crispEdges; } .nvd3 .foreground path { fill: none; stroke-opacity: .7; } .nvd3 .nv-parallelCoordinates-brush .extent { fill: #fff; fill-opacity: .6; stroke: gray; shape-rendering: crispEdges; } .nvd3 .nv-parallelCoordinates .hover { fill-opacity: 1; stroke-width: 3px; } .nvd3 .missingValuesline line { fill: none; stroke: black; stroke-width: 1; stroke-opacity: 1; stroke-dasharray: 5, 5; } ================================================ FILE: src/css/pie.css ================================================ .nvd3.nv-pie path { stroke-opacity: 0; transition: fill-opacity 250ms linear, stroke-width 250ms linear, stroke-opacity 250ms linear; } .nvd3.nv-pie .nv-pie-title { font-size: 24px; fill: rgba(19, 196, 249, 0.59); } .nvd3.nv-pie .nv-slice text { stroke: #000; stroke-width: 0; } .nvd3.nv-pie path { stroke: #fff; stroke-width: 1px; stroke-opacity: 1; } .nvd3.nv-pie path { fill-opacity: .7; } .nvd3.nv-pie .hover path { fill-opacity: 1; } .nvd3.nv-pie .nv-label { pointer-events: none; } .nvd3.nv-pie .nv-label rect { fill-opacity: 0; stroke-opacity: 0; } ================================================ FILE: src/css/scatter.css ================================================ /* scatter */ .nvd3 .nv-groups .nv-point.hover { stroke-width: 20px; stroke-opacity: .5; } .nvd3 .nv-scatter .nv-point.hover { fill-opacity: 1; } .nv-noninteractive { pointer-events: none; } .nv-distx, .nv-disty { pointer-events: none; } ================================================ FILE: src/css/sparkline.css ================================================ /* sparkline */ .nvd3.nv-sparkline path { fill: none; } .nvd3.nv-sparklineplus g.nv-hoverValue { pointer-events: none; } .nvd3.nv-sparklineplus .nv-hoverValue line { stroke: #333; stroke-width: 1.5px; } .nvd3.nv-sparklineplus, .nvd3.nv-sparklineplus g { pointer-events: all; } .nvd3 .nv-hoverArea { fill-opacity: 0; stroke-opacity: 0; } .nvd3.nv-sparklineplus .nv-xValue, .nvd3.nv-sparklineplus .nv-yValue { stroke-width: 0; font-size: .9em; font-weight: normal; } .nvd3.nv-sparklineplus .nv-yValue { stroke: #f66; } .nvd3.nv-sparklineplus .nv-maxValue { stroke: #2ca02c; fill: #2ca02c; } .nvd3.nv-sparklineplus .nv-minValue { stroke: #d62728; fill: #d62728; } .nvd3.nv-sparklineplus .nv-currentValue { font-weight: bold; font-size: 1.1em; } ================================================ FILE: src/css/stackedarea.css ================================================ /* stacked area */ .nvd3.nv-stackedarea path.nv-area { fill-opacity: .7; stroke-opacity: 0; transition: fill-opacity 250ms linear, stroke-opacity 250ms linear; } .nvd3.nv-stackedarea path.nv-area.hover { fill-opacity: .9; } .nvd3.nv-stackedarea .nv-groups .nv-point { stroke-opacity: 0; fill-opacity: 0; } ================================================ FILE: src/css/tooltip.css ================================================ .nvtooltip { position: absolute; background-color: rgba(255,255,255,1.0); color: rgba(0,0,0,1.0); padding: 1px; border: 1px solid rgba(0,0,0,.2); z-index: 10000; display: block; font-family: Arial, sans-serif; font-size: 13px; text-align: left; pointer-events: none; white-space: nowrap; user-select: none; } .nvtooltip { background: rgba(255,255,255, 0.8); border: 1px solid rgba(0,0,0,0.5); border-radius: 4px; } /*Give tooltips that old fade in transition by putting a "with-transitions" class on the container div. */ .nvtooltip.with-transitions, .with-transitions .nvtooltip { transition: opacity 50ms linear; transition-delay: 200ms; } .nvtooltip.x-nvtooltip, .nvtooltip.y-nvtooltip { padding: 8px; } .nvtooltip h3 { margin: 0; padding: 4px 14px; line-height: 18px; font-weight: normal; background-color: rgba(247,247,247,0.75); color: rgba(0,0,0,1.0); text-align: center; border-bottom: 1px solid #ebebeb; border-radius: 5px 5px 0 0; } .nvtooltip p { margin: 0; padding: 5px 14px; text-align: center; } .nvtooltip span { display: inline-block; margin: 2px 0; } .nvtooltip table { margin: 6px; border-spacing:0; } .nvtooltip table td { padding: 2px 9px 2px 0; vertical-align: middle; } .nvtooltip table td.key { font-weight: normal; } .nvtooltip table td.key.total { font-weight: bold; } .nvtooltip table td.value { text-align: right; font-weight: bold; } .nvtooltip table td.percent { color: darkgray; } .nvtooltip table tr.highlight td { padding: 1px 9px 1px 0; border-bottom-style: solid; border-bottom-width: 1px; border-top-style: solid; border-top-width: 1px; } .nvtooltip table td.legend-color-guide div { width: 8px; height: 8px; vertical-align: middle; } .nvtooltip table td.legend-color-guide div { width: 12px; height: 12px; border: 1px solid #999; } .nvtooltip .footer { padding: 3px; text-align: center; } .nvtooltip-pending-removal { pointer-events: none; display: none; } /**** Interactive Layer */ .nvd3 .nv-interactiveGuideLine { pointer-events:none; } .nvd3 line.nv-guideline { stroke: #ccc; } ================================================ FILE: src/dom.js ================================================ /* Facade for queueing DOM write operations * with Fastdom (https://github.com/wilsonpage/fastdom) * if available. * This could easily be extended to support alternate * implementations in the future. */ nv.dom.write = function(callback) { if (window.fastdom !== undefined) { return fastdom.mutate(callback); } return callback(); }; /* Facade for queueing DOM read operations * with Fastdom (https://github.com/wilsonpage/fastdom) * if available. * This could easily be extended to support alternate * implementations in the future. */ nv.dom.read = function(callback) { if (window.fastdom !== undefined) { return fastdom.measure(callback); } return callback(); }; ================================================ FILE: src/interactiveLayer.js ================================================ /* Utility class to handle creation of an interactive layer. This places a rectangle on top of the chart. When you mouse move over it, it sends a dispatch containing the X-coordinate. It can also render a vertical line where the mouse is located. dispatch.elementMousemove is the important event to latch onto. It is fired whenever the mouse moves over the rectangle. The dispatch is given one object which contains the mouseX/Y location. It also has 'pointXValue', which is the conversion of mouseX to the x-axis scale. */ nv.interactiveGuideline = function() { "use strict"; var margin = { left: 0, top: 0 } //Pass the chart's top and left magins. Used to calculate the mouseX/Y. , width = null , height = null , xScale = d3.scale.linear() , dispatch = d3.dispatch('elementMousemove', 'elementMouseout', 'elementClick', 'elementDblclick', 'elementMouseDown', 'elementMouseUp') , showGuideLine = true , svgContainer = null // Must pass the chart's svg, we'll use its mousemove event. , tooltip = nv.models.tooltip() , isMSIE = window.ActiveXObject// Checkt if IE by looking for activeX. (excludes IE11) ; tooltip .duration(0) .hideDelay(0) .hidden(false); function layer(selection) { selection.each(function(data) { var container = d3.select(this); var availableWidth = (width || 960), availableHeight = (height || 400); var wrap = container.selectAll("g.nv-wrap.nv-interactiveLineLayer") .data([data]); var wrapEnter = wrap.enter() .append("g").attr("class", " nv-wrap nv-interactiveLineLayer"); wrapEnter.append("g").attr("class","nv-interactiveGuideLine"); if (!svgContainer) { return; } function mouseHandler() { var mouseX = d3.event.clientX - this.getBoundingClientRect().left; var mouseY = d3.event.clientY - this.getBoundingClientRect().top; var subtractMargin = true; var mouseOutAnyReason = false; if (isMSIE) { /* D3.js (or maybe SVG.getScreenCTM) has a nasty bug in Internet Explorer 10. d3.mouse() returns incorrect X,Y mouse coordinates when mouse moving over a rect in IE 10. However, d3.event.offsetX/Y also returns the mouse coordinates relative to the triggering . So we use offsetX/Y on IE. */ mouseX = d3.event.offsetX; mouseY = d3.event.offsetY; /* On IE, if you attach a mouse event listener to the container, it will actually trigger it for all the child elements (like , , etc). When this happens on IE, the offsetX/Y is set to where ever the child element is located. As a result, we do NOT need to subtract margins to figure out the mouse X/Y position under this scenario. Removing the line below *will* cause the interactive layer to not work right on IE. */ if(d3.event.target.tagName !== "svg") { subtractMargin = false; } if (d3.event.target.className.baseVal.match("nv-legend")) { mouseOutAnyReason = true; } } if(subtractMargin) { mouseX -= margin.left; mouseY -= margin.top; } /* If mouseX/Y is outside of the chart's bounds, trigger a mouseOut event. */ if (d3.event.type === 'mouseout' || mouseX < 0 || mouseY < 0 || mouseX > availableWidth || mouseY > availableHeight || (d3.event.relatedTarget && d3.event.relatedTarget.ownerSVGElement === undefined) || mouseOutAnyReason ) { if (isMSIE) { if (d3.event.relatedTarget && d3.event.relatedTarget.ownerSVGElement === undefined && (d3.event.relatedTarget.className === undefined || d3.event.relatedTarget.className.match(tooltip.nvPointerEventsClass))) { return; } } dispatch.elementMouseout({ mouseX: mouseX, mouseY: mouseY }); layer.renderGuideLine(null); //hide the guideline tooltip.hidden(true); return; } else { tooltip.hidden(false); } var scaleIsOrdinal = typeof xScale.rangeBands === 'function'; var pointXValue = undefined; // Ordinal scale has no invert method if (scaleIsOrdinal) { var elementIndex = d3.bisect(xScale.range(), mouseX) - 1; // Check if mouseX is in the range band if (xScale.range()[elementIndex] + xScale.rangeBand() >= mouseX) { pointXValue = xScale.domain()[d3.bisect(xScale.range(), mouseX) - 1]; } else { dispatch.elementMouseout({ mouseX: mouseX, mouseY: mouseY }); layer.renderGuideLine(null); //hide the guideline tooltip.hidden(true); return; } } else { pointXValue = xScale.invert(mouseX); } dispatch.elementMousemove({ mouseX: mouseX, mouseY: mouseY, pointXValue: pointXValue }); //If user double clicks the layer, fire a elementDblclick if (d3.event.type === "dblclick") { dispatch.elementDblclick({ mouseX: mouseX, mouseY: mouseY, pointXValue: pointXValue }); } // if user single clicks the layer, fire elementClick if (d3.event.type === 'click') { dispatch.elementClick({ mouseX: mouseX, mouseY: mouseY, pointXValue: pointXValue }); } // if user presses mouse down the layer, fire elementMouseDown if (d3.event.type === 'mousedown') { dispatch.elementMouseDown({ mouseX: mouseX, mouseY: mouseY, pointXValue: pointXValue }); } // if user presses mouse down the layer, fire elementMouseUp if (d3.event.type === 'mouseup') { dispatch.elementMouseUp({ mouseX: mouseX, mouseY: mouseY, pointXValue: pointXValue }); } } svgContainer .on("touchmove",mouseHandler) .on("mousemove",mouseHandler, true) .on("mouseout" ,mouseHandler,true) .on("mousedown" ,mouseHandler,true) .on("mouseup" ,mouseHandler,true) .on("dblclick" ,mouseHandler) .on("click", mouseHandler) ; layer.guideLine = null; //Draws a vertical guideline at the given X postion. layer.renderGuideLine = function(x) { if (!showGuideLine) return; if (layer.guideLine && layer.guideLine.attr("x1") === x) return; nv.dom.write(function() { var line = wrap.select(".nv-interactiveGuideLine") .selectAll("line") .data((x != null) ? [nv.utils.NaNtoZero(x)] : [], String); line.enter() .append("line") .attr("class", "nv-guideline") .attr("x1", function(d) { return d;}) .attr("x2", function(d) { return d;}) .attr("y1", availableHeight) .attr("y2",0); line.exit().remove(); }); } }); } layer.dispatch = dispatch; layer.tooltip = tooltip; layer.margin = function(_) { if (!arguments.length) return margin; margin.top = typeof _.top != 'undefined' ? _.top : margin.top; margin.left = typeof _.left != 'undefined' ? _.left : margin.left; return layer; }; layer.width = function(_) { if (!arguments.length) return width; width = _; return layer; }; layer.height = function(_) { if (!arguments.length) return height; height = _; return layer; }; layer.xScale = function(_) { if (!arguments.length) return xScale; xScale = _; return layer; }; layer.showGuideLine = function(_) { if (!arguments.length) return showGuideLine; showGuideLine = _; return layer; }; layer.svgContainer = function(_) { if (!arguments.length) return svgContainer; svgContainer = _; return layer; }; return layer; }; /* Utility class that uses d3.bisect to find the index in a given array, where a search value can be inserted. This is different from normal bisectLeft; this function finds the nearest index to insert the search value. For instance, lets say your array is [1,2,3,5,10,30], and you search for 28. Normal d3.bisectLeft will return 4, because 28 is inserted after the number 10. But interactiveBisect will return 5 because 28 is closer to 30 than 10. Unit tests can be found in: interactiveBisectTest.html Has the following known issues: * Will not work if the data points move backwards (ie, 10,9,8,7, etc) or if the data points are in random order. * Won't work if there are duplicate x coordinate values. */ nv.interactiveBisect = function (values, searchVal, xAccessor) { "use strict"; if (! (values instanceof Array)) { return null; } var _xAccessor; if (typeof xAccessor !== 'function') { _xAccessor = function(d) { return d.x; } } else { _xAccessor = xAccessor; } var _cmp = function(d, v) { // Accessors are no longer passed the index of the element along with // the element itself when invoked by d3.bisector. // // Starting at D3 v3.4.4, d3.bisector() started inspecting the // function passed to determine if it should consider it an accessor // or a comparator. This meant that accessors that take two arguments // (expecting an index as the second parameter) are treated as // comparators where the second argument is the search value against // which the first argument is compared. return _xAccessor(d) - v; }; var bisect = d3.bisector(_cmp).left; var index = d3.max([0, bisect(values,searchVal) - 1]); var currentValue = _xAccessor(values[index]); if (typeof currentValue === 'undefined') { currentValue = index; } if (currentValue === searchVal) { return index; //found exact match } var nextIndex = d3.min([index+1, values.length - 1]); var nextValue = _xAccessor(values[nextIndex]); if (typeof nextValue === 'undefined') { nextValue = nextIndex; } if (Math.abs(nextValue - searchVal) >= Math.abs(currentValue - searchVal)) { return index; } else { return nextIndex } }; /* Returns the index in the array "values" that is closest to searchVal. Only returns an index if searchVal is within some "threshold". Otherwise, returns null. */ nv.nearestValueIndex = function (values, searchVal, threshold) { "use strict"; var yDistMax = Infinity, indexToHighlight = null; values.forEach(function(d,i) { var delta = Math.abs(searchVal - d); if ( d != null && delta <= yDistMax && delta < threshold) { yDistMax = delta; indexToHighlight = i; } }); return indexToHighlight; }; ================================================ FILE: src/models/axis.js ================================================ nv.models.axis = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var axis = d3.svg.axis(); var scale = d3.scale.linear(); var margin = {top: 0, right: 0, bottom: 0, left: 0} , width = 75 //only used for tickLabel currently , height = 60 //only used for tickLabel currently , axisLabelText = null , showMaxMin = true //TODO: showMaxMin should be disabled on all ordinal scaled axes , rotateLabels = 0 , rotateYLabel = true , staggerLabels = false , isOrdinal = false , ticks = null , axisLabelDistance = 0 , fontSize = undefined , duration = 250 , dispatch = d3.dispatch('renderEnd') , tickFormatMaxMin ; axis .scale(scale) .orient('bottom') .tickFormat(function(d) { return d }) ; //============================================================ // Private Variables //------------------------------------------------------------ var scale0; var renderWatch = nv.utils.renderWatch(dispatch, duration); function chart(selection) { renderWatch.reset(); selection.each(function(data) { var container = d3.select(this); nv.utils.initSVG(container); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-axis').data([data]); var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-axis'); var gEnter = wrapEnter.append('g'); var g = wrap.select('g'); if (ticks !== null) axis.ticks(ticks); else if (axis.orient() == 'top' || axis.orient() == 'bottom') axis.ticks(Math.abs(scale.range()[1] - scale.range()[0]) / 100); //TODO: consider calculating width/height based on whether or not label is added, for reference in charts using this component g.watchTransition(renderWatch, 'axis').call(axis); scale0 = scale0 || axis.scale(); var fmt = axis.tickFormat(); if (fmt == null) { fmt = scale0.tickFormat(); } var axisLabel = g.selectAll('text.nv-axislabel') .data([axisLabelText || null]); axisLabel.exit().remove(); //only skip when fontSize is undefined so it can be cleared with a null or blank string if (fontSize !== undefined) { g.selectAll('g').select("text").style('font-size', fontSize); } var xLabelMargin; var axisMaxMin; var w; switch (axis.orient()) { case 'top': xLabelMargin = axisLabelDistance + 36; axisLabel.enter().append('text').attr('class', 'nv-axislabel'); w = 0; if (scale.range().length === 1) { w = isOrdinal ? scale.range()[0] * 2 + scale.rangeBand() : 0; } else if (scale.range().length === 2) { w = isOrdinal ? scale.range()[0] + scale.range()[1] + scale.rangeBand() : scale.range()[1]; } else if ( scale.range().length > 2){ w = scale.range()[scale.range().length-1]+(scale.range()[1]-scale.range()[0]); }; axisLabel .attr('text-anchor', 'middle') .attr('y', -xLabelMargin) .attr('x', w/2); if (showMaxMin) { axisMaxMin = wrap.selectAll('g.nv-axisMaxMin') .data(scale.domain()); axisMaxMin.enter().append('g').attr('class',function(d,i){ return ['nv-axisMaxMin','nv-axisMaxMin-x',(i == 0 ? 'nv-axisMin-x':'nv-axisMax-x')].join(' ') }).append('text'); axisMaxMin.exit().remove(); axisMaxMin .attr('transform', function(d,i) { return 'translate(' + nv.utils.NaNtoZero(scale(d)) + ',0)' }) .select('text') .attr('dy', '-0.5em') .attr('y', -axis.tickPadding()) .attr('text-anchor', 'middle') .text(function(d,i) { var formatter = tickFormatMaxMin || fmt; var v = formatter(d); return ('' + v).match('NaN') ? '' : v; }); axisMaxMin.watchTransition(renderWatch, 'min-max top') .attr('transform', function(d,i) { return 'translate(' + nv.utils.NaNtoZero(scale.range()[i]) + ',0)' }); } break; case 'bottom': xLabelMargin = axisLabelDistance + 36; var maxTextWidth = 30; var textHeight = 0; var xTicks = g.selectAll('g').select("text"); var rotateLabelsRule = ''; if (rotateLabels%360) { //Reset transform on ticks so textHeight can be calculated correctly xTicks.attr('transform', ''); //Calculate the longest xTick width xTicks.each(function(d,i){ var box = this.getBoundingClientRect(); var width = box.width; textHeight = box.height; if(width > maxTextWidth) maxTextWidth = width; }); rotateLabelsRule = 'rotate(' + rotateLabels + ' 0,' + (textHeight/2 + axis.tickPadding()) + ')'; //Convert to radians before calculating sin. Add 30 to margin for healthy padding. var sin = Math.abs(Math.sin(rotateLabels*Math.PI/180)); xLabelMargin = (sin ? sin*maxTextWidth : maxTextWidth)+30; //Rotate all xTicks xTicks .attr('transform', rotateLabelsRule) .style('text-anchor', rotateLabels%360 > 0 ? 'start' : 'end'); } else { if (staggerLabels) { xTicks .attr('transform', function(d,i) { return 'translate(0,' + (i % 2 == 0 ? '0' : '12') + ')' }); } else { xTicks.attr('transform', "translate(0,0)"); } } axisLabel.enter().append('text').attr('class', 'nv-axislabel'); w = 0; if (scale.range().length === 1) { w = isOrdinal ? scale.range()[0] * 2 + scale.rangeBand() : 0; } else if (scale.range().length === 2) { w = isOrdinal ? scale.range()[0] + scale.range()[1] + scale.rangeBand() : scale.range()[1]; } else if ( scale.range().length > 2){ w = scale.range()[scale.range().length-1]+(scale.range()[1]-scale.range()[0]); }; axisLabel .attr('text-anchor', 'middle') .attr('y', xLabelMargin) .attr('x', w/2); if (showMaxMin) { //if (showMaxMin && !isOrdinal) { axisMaxMin = wrap.selectAll('g.nv-axisMaxMin') //.data(scale.domain()) .data([scale.domain()[0], scale.domain()[scale.domain().length - 1]]); axisMaxMin.enter().append('g').attr('class',function(d,i){ return ['nv-axisMaxMin','nv-axisMaxMin-x',(i == 0 ? 'nv-axisMin-x':'nv-axisMax-x')].join(' ') }).append('text'); axisMaxMin.exit().remove(); axisMaxMin .attr('transform', function(d,i) { return 'translate(' + nv.utils.NaNtoZero((scale(d) + (isOrdinal ? scale.rangeBand() / 2 : 0))) + ',0)' }) .select('text') .attr('dy', '.71em') .attr('y', axis.tickPadding()) .attr('transform', rotateLabelsRule) .style('text-anchor', rotateLabels ? (rotateLabels%360 > 0 ? 'start' : 'end') : 'middle') .text(function(d,i) { var formatter = tickFormatMaxMin || fmt; var v = formatter(d); return ('' + v).match('NaN') ? '' : v; }); axisMaxMin.watchTransition(renderWatch, 'min-max bottom') .attr('transform', function(d,i) { return 'translate(' + nv.utils.NaNtoZero((scale(d) + (isOrdinal ? scale.rangeBand() / 2 : 0))) + ',0)' }); } break; case 'right': axisLabel.enter().append('text').attr('class', 'nv-axislabel'); axisLabel .style('text-anchor', rotateYLabel ? 'middle' : 'begin') .attr('transform', rotateYLabel ? 'rotate(90)' : '') .attr('y', rotateYLabel ? (-Math.max(margin.right, width) + 12 - (axisLabelDistance || 0)) : -10) //TODO: consider calculating this based on largest tick width... OR at least expose this on chart .attr('x', rotateYLabel ? (d3.max(scale.range()) / 2) : axis.tickPadding()); if (showMaxMin) { axisMaxMin = wrap.selectAll('g.nv-axisMaxMin') .data(scale.domain()); axisMaxMin.enter().append('g').attr('class',function(d,i){ return ['nv-axisMaxMin','nv-axisMaxMin-y',(i == 0 ? 'nv-axisMin-y':'nv-axisMax-y')].join(' ') }).append('text') .style('opacity', 0); axisMaxMin.exit().remove(); axisMaxMin .attr('transform', function(d,i) { return 'translate(0,' + nv.utils.NaNtoZero(scale(d)) + ')' }) .select('text') .attr('dy', '.32em') .attr('y', 0) .attr('x', axis.tickPadding()) .style('text-anchor', 'start') .text(function(d, i) { var formatter = tickFormatMaxMin || fmt; var v = formatter(d); return ('' + v).match('NaN') ? '' : v; }); axisMaxMin.watchTransition(renderWatch, 'min-max right') .attr('transform', function(d,i) { return 'translate(0,' + nv.utils.NaNtoZero(scale.range()[i]) + ')' }) .select('text') .style('opacity', 1); } break; case 'left': /* //For dynamically placing the label. Can be used with dynamically-sized chart axis margins var yTicks = g.selectAll('g').select("text"); yTicks.each(function(d,i){ var labelPadding = this.getBoundingClientRect().width + axis.tickPadding() + 16; if(labelPadding > width) width = labelPadding; }); */ axisLabel.enter().append('text').attr('class', 'nv-axislabel'); axisLabel .style('text-anchor', rotateYLabel ? 'middle' : 'end') .attr('transform', rotateYLabel ? 'rotate(-90)' : '') .attr('y', rotateYLabel ? (-Math.max(margin.left, width) + 25 - (axisLabelDistance || 0)) : -10) .attr('x', rotateYLabel ? (-d3.max(scale.range()) / 2) : -axis.tickPadding()); if (showMaxMin) { axisMaxMin = wrap.selectAll('g.nv-axisMaxMin') .data(scale.domain()); axisMaxMin.enter().append('g').attr('class',function(d,i){ return ['nv-axisMaxMin','nv-axisMaxMin-y',(i == 0 ? 'nv-axisMin-y':'nv-axisMax-y')].join(' ') }).append('text') .style('opacity', 0); axisMaxMin.exit().remove(); axisMaxMin .attr('transform', function(d,i) { return 'translate(0,' + nv.utils.NaNtoZero(scale0(d)) + ')' }) .select('text') .attr('dy', '.32em') .attr('y', 0) .attr('x', -axis.tickPadding()) .attr('text-anchor', 'end') .text(function(d,i) { var formatter = tickFormatMaxMin || fmt; var v = formatter(d); return ('' + v).match('NaN') ? '' : v; }); axisMaxMin.watchTransition(renderWatch, 'min-max right') .attr('transform', function(d,i) { return 'translate(0,' + nv.utils.NaNtoZero(scale.range()[i]) + ')' }) .select('text') .style('opacity', 1); } break; } axisLabel.text(function(d) { return d }); if (showMaxMin && (axis.orient() === 'left' || axis.orient() === 'right')) { //check if max and min overlap other values, if so, hide the values that overlap g.selectAll('g') // the g's wrapping each tick .each(function(d,i) { d3.select(this).select('text').attr('opacity', 1); if (scale(d) < scale.range()[1] + 10 || scale(d) > scale.range()[0] - 10) { // 10 is assuming text height is 16... if d is 0, leave it! if (d > 1e-10 || d < -1e-10) // accounts for minor floating point errors... though could be problematic if the scale is EXTREMELY SMALL d3.select(this).attr('opacity', 0); d3.select(this).select('text').attr('opacity', 0); // Don't remove the ZERO line!! } }); //if Max and Min = 0 only show min, Issue #281 if (scale.domain()[0] == scale.domain()[1] && scale.domain()[0] == 0) { wrap.selectAll('g.nv-axisMaxMin').style('opacity', function (d, i) { return !i ? 1 : 0 }); } } if (showMaxMin && (axis.orient() === 'top' || axis.orient() === 'bottom')) { var maxMinRange = []; wrap.selectAll('g.nv-axisMaxMin') .each(function(d,i) { try { if (i) // i== 1, max position maxMinRange.push(scale(d) - this.getBoundingClientRect().width - 4); //assuming the max and min labels are as wide as the next tick (with an extra 4 pixels just in case) else // i==0, min position maxMinRange.push(scale(d) + this.getBoundingClientRect().width + 4) }catch (err) { if (i) // i== 1, max position maxMinRange.push(scale(d) - 4); //assuming the max and min labels are as wide as the next tick (with an extra 4 pixels just in case) else // i==0, min position maxMinRange.push(scale(d) + 4); } }); // the g's wrapping each tick g.selectAll('g').each(function(d, i) { if (scale(d) < maxMinRange[0] || scale(d) > maxMinRange[1]) { if (d > 1e-10 || d < -1e-10) // accounts for minor floating point errors... though could be problematic if the scale is EXTREMELY SMALL d3.select(this).remove(); else d3.select(this).select('text').remove(); // Don't remove the ZERO line!! } }); } //Highlight zero tick line g.selectAll('.tick') .filter(function (d) { /* The filter needs to return only ticks at or near zero. Numbers like 0.00001 need to count as zero as well, and the arithmetic trick below solves that. */ return !parseFloat(Math.round(d * 100000) / 1000000) && (d !== undefined) }) .classed('zero', true); //store old scales for use in transitions on update scale0 = scale.copy(); }); renderWatch.renderEnd('axis immediate'); return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ // expose chart's sub-components chart.axis = axis; chart.dispatch = dispatch; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values axisLabelDistance: {get: function(){return axisLabelDistance;}, set: function(_){axisLabelDistance=_;}}, staggerLabels: {get: function(){return staggerLabels;}, set: function(_){staggerLabels=_;}}, rotateLabels: {get: function(){return rotateLabels;}, set: function(_){rotateLabels=_;}}, rotateYLabel: {get: function(){return rotateYLabel;}, set: function(_){rotateYLabel=_;}}, showMaxMin: {get: function(){return showMaxMin;}, set: function(_){showMaxMin=_;}}, axisLabel: {get: function(){return axisLabelText;}, set: function(_){axisLabelText=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, ticks: {get: function(){return ticks;}, set: function(_){ticks=_;}}, width: {get: function(){return width;}, set: function(_){width=_;}}, fontSize: {get: function(){return fontSize;}, set: function(_){fontSize=_;}}, tickFormatMaxMin: {get: function(){return tickFormatMaxMin;}, set: function(_){tickFormatMaxMin=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, duration: {get: function(){return duration;}, set: function(_){ duration=_; renderWatch.reset(duration); }}, scale: {get: function(){return scale;}, set: function(_){ scale = _; axis.scale(scale); isOrdinal = typeof scale.rangeBands === 'function'; nv.utils.inheritOptionsD3(chart, scale, ['domain', 'range', 'rangeBand', 'rangeBands']); }} }); nv.utils.initOptions(chart); nv.utils.inheritOptionsD3(chart, axis, ['orient', 'tickValues', 'tickSubdivide', 'tickSize', 'tickPadding', 'tickFormat']); nv.utils.inheritOptionsD3(chart, scale, ['domain', 'range', 'rangeBand', 'rangeBands']); return chart; }; ================================================ FILE: src/models/boxPlot.js ================================================ nv.models.boxPlot = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 0, right: 0, bottom: 0, left: 0}, width = 960, height = 500, id = Math.floor(Math.random() * 10000), // Create semi-unique ID in case user doesn't select one xScale = d3.scale.ordinal(), yScale = d3.scale.linear(), getX = function(d) { return d.label }, // Default data model selectors. getQ1 = function(d) { return d.values.Q1 }, getQ2 = function(d) { return d.values.Q2 }, getQ3 = function(d) { return d.values.Q3 }, getWl = function(d) { return d.values.whisker_low }, getWh = function(d) { return d.values.whisker_high }, getColor = function(d) { return d.color }, getOlItems = function(d) { return d.values.outliers }, getOlValue = function(d, i, j) { return d }, getOlLabel = function(d, i, j) { return d }, getOlColor = function(d, i, j) { return undefined }, color = nv.utils.defaultColor(), container = null, xDomain, xRange, yDomain, yRange, dispatch = d3.dispatch('elementMouseover', 'elementMouseout', 'elementMousemove', 'renderEnd'), duration = 250, maxBoxWidth = null; //============================================================ // Private Variables //------------------------------------------------------------ var xScale0, yScale0; var renderWatch = nv.utils.renderWatch(dispatch, duration); function chart(selection) { renderWatch.reset(); selection.each(function(data) { var availableWidth = width - margin.left - margin.right, availableHeight = height - margin.top - margin.bottom; container = d3.select(this); nv.utils.initSVG(container); // Setup Scales xScale.domain(xDomain || data.map(function(d,i) { return getX(d,i); })) .rangeBands(xRange || [0, availableWidth], 0.1); // if we know yDomain, no need to calculate var yData = [] if (!yDomain) { // (y-range is based on quartiles, whiskers and outliers) var values = [], yMin, yMax; data.forEach(function (d, i) { var q1 = getQ1(d), q3 = getQ3(d), wl = getWl(d), wh = getWh(d); var olItems = getOlItems(d); if (olItems) { olItems.forEach(function (e, i) { values.push(getOlValue(e, i, undefined)); }); } if (wl) { values.push(wl) } if (q1) { values.push(q1) } if (q3) { values.push(q3) } if (wh) { values.push(wh) } }); yMin = d3.min(values); yMax = d3.max(values); yData = [ yMin, yMax ] ; } yScale.domain(yDomain || yData); yScale.range(yRange || [availableHeight, 0]); //store old scales if they exist xScale0 = xScale0 || xScale; yScale0 = yScale0 || yScale.copy().range([yScale(0),yScale(0)]); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap').data([data]); var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); var boxplots = wrap.selectAll('.nv-boxplot').data(function(d) { return d }); var boxEnter = boxplots.enter().append('g').style('stroke-opacity', 1e-6).style('fill-opacity', 1e-6); boxplots .attr('class', 'nv-boxplot') .attr('transform', function(d,i,j) { return 'translate(' + (xScale(getX(d,i)) + xScale.rangeBand() * 0.05) + ', 0)'; }) .classed('hover', function(d) { return d.hover }); boxplots .watchTransition(renderWatch, 'nv-boxplot: boxplots') .style('stroke-opacity', 1) .style('fill-opacity', 0.75) .delay(function(d,i) { return i * duration / data.length }) .attr('transform', function(d,i) { return 'translate(' + (xScale(getX(d,i)) + xScale.rangeBand() * 0.05) + ', 0)'; }); boxplots.exit().remove(); // ----- add the SVG elements for each boxPlot ----- // conditionally append whisker lines boxEnter.each(function(d,i) { var box = d3.select(this); [getWl, getWh].forEach(function (f) { if (f(d) !== undefined && f(d) !== null) { var key = (f === getWl) ? 'low' : 'high'; box.append('line') .style('stroke', getColor(d) || color(d,i)) .attr('class', 'nv-boxplot-whisker nv-boxplot-' + key); box.append('line') .style('stroke', getColor(d) || color(d,i)) .attr('class', 'nv-boxplot-tick nv-boxplot-' + key); } }); }); var box_width = function() { return (maxBoxWidth === null ? xScale.rangeBand() * 0.9 : Math.min(75, xScale.rangeBand() * 0.9)); }; var box_left = function() { return xScale.rangeBand() * 0.45 - box_width()/2; }; var box_right = function() { return xScale.rangeBand() * 0.45 + box_width()/2; }; // update whisker lines and ticks [getWl, getWh].forEach(function (f) { var key = (f === getWl) ? 'low' : 'high'; var endpoint = (f === getWl) ? getQ1 : getQ3; boxplots.select('line.nv-boxplot-whisker.nv-boxplot-' + key) .watchTransition(renderWatch, 'nv-boxplot: boxplots') .attr('x1', xScale.rangeBand() * 0.45 ) .attr('y1', function(d,i) { return yScale(f(d)); }) .attr('x2', xScale.rangeBand() * 0.45 ) .attr('y2', function(d,i) { return yScale(endpoint(d)); }); boxplots.select('line.nv-boxplot-tick.nv-boxplot-' + key) .watchTransition(renderWatch, 'nv-boxplot: boxplots') .attr('x1', box_left ) .attr('y1', function(d,i) { return yScale(f(d)); }) .attr('x2', box_right ) .attr('y2', function(d,i) { return yScale(f(d)); }); }); [getWl, getWh].forEach(function (f) { var key = (f === getWl) ? 'low' : 'high'; boxEnter.selectAll('.nv-boxplot-' + key) .on('mouseover', function(d,i,j) { d3.select(this).classed('hover', true); dispatch.elementMouseover({ series: { key: f(d), color: getColor(d) || color(d,j) }, e: d3.event }); }) .on('mouseout', function(d,i,j) { d3.select(this).classed('hover', false); dispatch.elementMouseout({ series: { key: f(d), color: getColor(d) || color(d,j) }, e: d3.event }); }) .on('mousemove', function(d,i) { dispatch.elementMousemove({e: d3.event}); }); }); // boxes boxEnter.append('rect') .attr('class', 'nv-boxplot-box') // tooltip events .on('mouseover', function(d,i) { d3.select(this).classed('hover', true); dispatch.elementMouseover({ key: getX(d), value: getX(d), series: [ { key: 'Q3', value: getQ3(d), color: getColor(d) || color(d,i) }, { key: 'Q2', value: getQ2(d), color: getColor(d) || color(d,i) }, { key: 'Q1', value: getQ1(d), color: getColor(d) || color(d,i) } ], data: d, index: i, e: d3.event }); }) .on('mouseout', function(d,i) { d3.select(this).classed('hover', false); dispatch.elementMouseout({ key: getX(d), value: getX(d), series: [ { key: 'Q3', value: getQ3(d), color: getColor(d) || color(d,i) }, { key: 'Q2', value: getQ2(d), color: getColor(d) || color(d,i) }, { key: 'Q1', value: getQ1(d), color: getColor(d) || color(d,i) } ], data: d, index: i, e: d3.event }); }) .on('mousemove', function(d,i) { dispatch.elementMousemove({e: d3.event}); }); // box transitions boxplots.select('rect.nv-boxplot-box') .watchTransition(renderWatch, 'nv-boxplot: boxes') .attr('y', function(d,i) { return yScale(getQ3(d)); }) .attr('width', box_width) .attr('x', box_left ) .attr('height', function(d,i) { return Math.abs(yScale(getQ3(d)) - yScale(getQ1(d))) || 1 }) .style('fill', function(d,i) { return getColor(d) || color(d,i) }) .style('stroke', function(d,i) { return getColor(d) || color(d,i) }); // median line boxEnter.append('line').attr('class', 'nv-boxplot-median'); boxplots.select('line.nv-boxplot-median') .watchTransition(renderWatch, 'nv-boxplot: boxplots line') .attr('x1', box_left) .attr('y1', function(d,i) { return yScale(getQ2(d)); }) .attr('x2', box_right) .attr('y2', function(d,i) { return yScale(getQ2(d)); }); // outliers var outliers = boxplots.selectAll('.nv-boxplot-outlier').data(function(d) { return getOlItems(d) || []; }); outliers.enter().append('circle') .style('fill', function(d,i,j) { return getOlColor(d,i,j) || color(d,j) }) .style('stroke', function(d,i,j) { return getOlColor(d,i,j) || color(d,j) }) .style('z-index', 9000) .on('mouseover', function(d,i,j) { d3.select(this).classed('hover', true); dispatch.elementMouseover({ series: { key: getOlLabel(d,i,j), color: getOlColor(d,i,j) || color(d,j) }, e: d3.event }); }) .on('mouseout', function(d,i,j) { d3.select(this).classed('hover', false); dispatch.elementMouseout({ series: { key: getOlLabel(d,i,j), color: getOlColor(d,i,j) || color(d,j) }, e: d3.event }); }) .on('mousemove', function(d,i) { dispatch.elementMousemove({e: d3.event}); }); outliers.attr('class', 'nv-boxplot-outlier'); outliers .watchTransition(renderWatch, 'nv-boxplot: nv-boxplot-outlier') .attr('cx', xScale.rangeBand() * 0.45) .attr('cy', function(d,i,j) { return yScale(getOlValue(d,i,j)); }) .attr('r', '3'); outliers.exit().remove(); //store old scales for use in transitions on update xScale0 = xScale.copy(); yScale0 = yScale.copy(); }); renderWatch.renderEnd('nv-boxplot immediate'); return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.dispatch = dispatch; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, maxBoxWidth: {get: function(){return maxBoxWidth;}, set: function(_){maxBoxWidth=_;}}, x: {get: function(){return getX;}, set: function(_){getX=_;}}, q1: {get: function(){return getQ1;}, set: function(_){getQ1=_;}}, q2: {get: function(){return getQ2;}, set: function(_){getQ2=_;}}, q3: {get: function(){return getQ3;}, set: function(_){getQ3=_;}}, wl: {get: function(){return getWl;}, set: function(_){getWl=_;}}, wh: {get: function(){return getWh;}, set: function(_){getWh=_;}}, itemColor: {get: function(){return getColor;}, set: function(_){getColor=_;}}, outliers: {get: function(){return getOlItems;}, set: function(_){getOlItems=_;}}, outlierValue: {get: function(){return getOlValue;}, set: function(_){getOlValue=_;}}, outlierLabel: {get: function(){return getOlLabel;}, set: function(_){getOlLabel=_;}}, outlierColor: {get: function(){return getOlColor;}, set: function(_){getOlColor=_;}}, xScale: {get: function(){return xScale;}, set: function(_){xScale=_;}}, yScale: {get: function(){return yScale;}, set: function(_){yScale=_;}}, xDomain: {get: function(){return xDomain;}, set: function(_){xDomain=_;}}, yDomain: {get: function(){return yDomain;}, set: function(_){yDomain=_;}}, xRange: {get: function(){return xRange;}, set: function(_){xRange=_;}}, yRange: {get: function(){return yRange;}, set: function(_){yRange=_;}}, id: {get: function(){return id;}, set: function(_){id=_;}}, // rectClass: {get: function(){return rectClass;}, set: function(_){rectClass=_;}}, y: { get: function() { console.warn('BoxPlot \'y\' chart option is deprecated. Please use model overrides instead.'); return {}; }, set: function(_) { console.warn('BoxPlot \'y\' chart option is deprecated. Please use model overrides instead.'); } }, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; renderWatch.reset(duration); }} }); nv.utils.initOptions(chart); return chart; }; ================================================ FILE: src/models/boxPlotChart.js ================================================ nv.models.boxPlotChart = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var boxplot = nv.models.boxPlot(), xAxis = nv.models.axis(), yAxis = nv.models.axis(); var margin = {top: 15, right: 10, bottom: 50, left: 60}, width = null, height = null, color = nv.utils.getColor(), showXAxis = true, showYAxis = true, rightAlignYAxis = false, staggerLabels = false, tooltip = nv.models.tooltip(), x, y, noData = 'No Data Available.', dispatch = d3.dispatch('beforeUpdate', 'renderEnd'), duration = 250; xAxis .orient('bottom') .showMaxMin(false) .tickFormat(function(d) { return d }) ; yAxis .orient((rightAlignYAxis) ? 'right' : 'left') .tickFormat(d3.format(',.1f')) ; tooltip.duration(0); //============================================================ // Private Variables //------------------------------------------------------------ var renderWatch = nv.utils.renderWatch(dispatch, duration); function chart(selection) { renderWatch.reset(); renderWatch.models(boxplot); if (showXAxis) renderWatch.models(xAxis); if (showYAxis) renderWatch.models(yAxis); selection.each(function(data) { var container = d3.select(this), that = this; nv.utils.initSVG(container); var availableWidth = (width || parseInt(container.style('width')) || 960) - margin.left - margin.right; var availableHeight = (height || parseInt(container.style('height')) || 400) - margin.top - margin.bottom; chart.update = function() { dispatch.beforeUpdate(); container.transition().duration(duration).call(chart); }; chart.container = this; // TODO still need to find a way to validate quartile data presence using boxPlot callbacks. // Display No Data message if there's nothing to show. (quartiles required at minimum). if (!data || !data.length) { var noDataText = container.selectAll('.nv-noData').data([noData]); noDataText.enter().append('text') .attr('class', 'nvd3 nv-noData') .attr('dy', '-.7em') .style('text-anchor', 'middle'); noDataText .attr('x', margin.left + availableWidth / 2) .attr('y', margin.top + availableHeight / 2) .text(function(d) { return d }); return chart; } else { container.selectAll('.nv-noData').remove(); } // Setup Scales x = boxplot.xScale(); y = boxplot.yScale().clamp(true); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-boxPlotWithAxes').data([data]); var gEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-boxPlotWithAxes').append('g'); var defsEnter = gEnter.append('defs'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-x nv-axis'); gEnter.append('g').attr('class', 'nv-y nv-axis') .append('g').attr('class', 'nv-zeroLine') .append('line'); gEnter.append('g').attr('class', 'nv-barsWrap'); g.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); if (rightAlignYAxis) { g.select('.nv-y.nv-axis') .attr('transform', 'translate(' + availableWidth + ',0)'); } // Main Chart Component(s) boxplot.width(availableWidth).height(availableHeight); var barsWrap = g.select('.nv-barsWrap') .datum(data.filter(function(d) { return !d.disabled })) barsWrap.transition().call(boxplot); defsEnter.append('clipPath') .attr('id', 'nv-x-label-clip-' + boxplot.id()) .append('rect'); g.select('#nv-x-label-clip-' + boxplot.id() + ' rect') .attr('width', x.rangeBand() * (staggerLabels ? 2 : 1)) .attr('height', 16) .attr('x', -x.rangeBand() / (staggerLabels ? 1 : 2 )); // Setup Axes if (showXAxis) { xAxis .scale(x) .ticks( nv.utils.calcTicksX(availableWidth/100, data) ) .tickSize(-availableHeight, 0); g.select('.nv-x.nv-axis').attr('transform', 'translate(0,' + y.range()[0] + ')'); g.select('.nv-x.nv-axis').call(xAxis); var xTicks = g.select('.nv-x.nv-axis').selectAll('g'); if (staggerLabels) { xTicks .selectAll('text') .attr('transform', function(d,i,j) { return 'translate(0,' + (j % 2 === 0 ? '5' : '17') + ')' }) } } if (showYAxis) { yAxis .scale(y) .ticks( Math.floor(availableHeight/36) ) // can't use nv.utils.calcTicksY with Object data .tickSize( -availableWidth, 0); g.select('.nv-y.nv-axis').call(yAxis); } // Zero line g.select('.nv-zeroLine line') .attr('x1',0) .attr('x2',availableWidth) .attr('y1', y(0)) .attr('y2', y(0)) ; //============================================================ // Event Handling/Dispatching (in chart's scope) //------------------------------------------------------------ }); renderWatch.renderEnd('nv-boxplot chart immediate'); return chart; } //============================================================ // Event Handling/Dispatching (out of chart's scope) //------------------------------------------------------------ boxplot.dispatch.on('elementMouseover.tooltip', function(evt) { tooltip.data(evt).hidden(false); }); boxplot.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.data(evt).hidden(true); }); boxplot.dispatch.on('elementMousemove.tooltip', function(evt) { tooltip(); }); //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.dispatch = dispatch; chart.boxplot = boxplot; chart.xAxis = xAxis; chart.yAxis = yAxis; chart.tooltip = tooltip; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, staggerLabels: {get: function(){return staggerLabels;}, set: function(_){staggerLabels=_;}}, showXAxis: {get: function(){return showXAxis;}, set: function(_){showXAxis=_;}}, showYAxis: {get: function(){return showYAxis;}, set: function(_){showYAxis=_;}}, tooltipContent: {get: function(){return tooltip;}, set: function(_){tooltip=_;}}, noData: {get: function(){return noData;}, set: function(_){noData=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; renderWatch.reset(duration); boxplot.duration(duration); xAxis.duration(duration); yAxis.duration(duration); }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); boxplot.color(color); }}, rightAlignYAxis: {get: function(){return rightAlignYAxis;}, set: function(_){ rightAlignYAxis = _; yAxis.orient( (_) ? 'right' : 'left'); }} }); nv.utils.inheritOptions(chart, boxplot); nv.utils.initOptions(chart); return chart; } ================================================ FILE: src/models/bullet.js ================================================ // Chart design based on the recommendations of Stephen Few. Implementation // based on the work of Clint Ivy, Jamie Love, and Jason Davies. // http://projects.instantcognition.com/protovis/bulletchart/ nv.models.bullet = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 0, right: 0, bottom: 0, left: 0} , orient = 'left' // TODO top & bottom , reverse = false , ranges = function(d) { return d.ranges } , markers = function(d) { return d.markers ? d.markers : [] } , markerLines = function(d) { return d.markerLines ? d.markerLines : [0] } , measures = function(d) { return d.measures } , rangeLabels = function(d) { return d.rangeLabels ? d.rangeLabels : [] } , markerLabels = function(d) { return d.markerLabels ? d.markerLabels : [] } , markerLineLabels = function(d) { return d.markerLineLabels ? d.markerLineLabels : [] } , measureLabels = function(d) { return d.measureLabels ? d.measureLabels : [] } , forceX = [0] // List of numbers to Force into the X scale (ie. 0, or a max / min, etc.) , width = 380 , height = 30 , container = null , tickFormat = null , color = nv.utils.getColor(['#1f77b4']) , dispatch = d3.dispatch('elementMouseover', 'elementMouseout', 'elementMousemove') , defaultRangeLabels = ["Maximum", "Mean", "Minimum"] , legacyRangeClassNames = ["Max", "Avg", "Min"] , duration = 1000 ; function sortLabels(labels, values){ var lz = labels.slice(); labels.sort(function(a, b){ var iA = lz.indexOf(a); var iB = lz.indexOf(b); return d3.descending(values[iA], values[iB]); }); }; function chart(selection) { selection.each(function(d, i) { var availableWidth = width - margin.left - margin.right, availableHeight = height - margin.top - margin.bottom; container = d3.select(this); nv.utils.initSVG(container); var rangez = ranges.call(this, d, i).slice(), markerz = markers.call(this, d, i).slice(), markerLinez = markerLines.call(this, d, i).slice(), measurez = measures.call(this, d, i).slice(), rangeLabelz = rangeLabels.call(this, d, i).slice(), markerLabelz = markerLabels.call(this, d, i).slice(), markerLineLabelz = markerLineLabels.call(this, d, i).slice(), measureLabelz = measureLabels.call(this, d, i).slice(); // Sort labels according to their sorted values sortLabels(rangeLabelz, rangez); sortLabels(markerLabelz, markerz); sortLabels(markerLineLabelz, markerLinez); sortLabels(measureLabelz, measurez); // sort values descending rangez.sort(d3.descending); markerz.sort(d3.descending); markerLinez.sort(d3.descending); measurez.sort(d3.descending); // Setup Scales // Compute the new x-scale. var x1 = d3.scale.linear() .domain( d3.extent(d3.merge([forceX, rangez])) ) .range(reverse ? [availableWidth, 0] : [0, availableWidth]); // Retrieve the old x-scale, if this is an update. var x0 = this.__chart__ || d3.scale.linear() .domain([0, Infinity]) .range(x1.range()); // Stash the new scale. this.__chart__ = x1; var rangeMin = d3.min(rangez), //rangez[2] rangeMax = d3.max(rangez), //rangez[0] rangeAvg = rangez[1]; // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-bullet').data([d]); var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-bullet'); var gEnter = wrapEnter.append('g'); var g = wrap.select('g'); for(var i=0,il=rangez.length; i getClose(d, i) ? 'nv-tick negative' : 'nv-tick positive') + ' nv-tick-' + j + '-' + i}); var lines = tickGroups.append('line') .attr('class', 'nv-candlestick-lines') .attr('transform', function(d, i) { return 'translate(' + x(getX(d, i)) + ',0)'; }) .attr('x1', 0) .attr('y1', function(d, i) { return y(getHigh(d, i)); }) .attr('x2', 0) .attr('y2', function(d, i) { return y(getLow(d, i)); }); var rects = tickGroups.append('rect') .attr('class', 'nv-candlestick-rects nv-bars') .attr('transform', function(d, i) { return 'translate(' + (x(getX(d, i)) - barWidth/2) + ',' + (y(getY(d, i)) - (getOpen(d, i) > getClose(d, i) ? (y(getClose(d, i)) - y(getOpen(d, i))) : 0)) + ')'; }) .attr('x', 0) .attr('y', 0) .attr('width', barWidth) .attr('height', function(d, i) { var open = getOpen(d, i); var close = getClose(d, i); return open > close ? y(close) - y(open) : y(open) - y(close); }); ticks.select('.nv-candlestick-lines').transition() .attr('transform', function(d, i) { return 'translate(' + x(getX(d, i)) + ',0)'; }) .attr('x1', 0) .attr('y1', function(d, i) { return y(getHigh(d, i)); }) .attr('x2', 0) .attr('y2', function(d, i) { return y(getLow(d, i)); }); ticks.select('.nv-candlestick-rects').transition() .attr('transform', function(d, i) { return 'translate(' + (x(getX(d, i)) - barWidth/2) + ',' + (y(getY(d, i)) - (getOpen(d, i) > getClose(d, i) ? (y(getClose(d, i)) - y(getOpen(d, i))) : 0)) + ')'; }) .attr('x', 0) .attr('y', 0) .attr('width', barWidth) .attr('height', function(d, i) { var open = getOpen(d, i); var close = getClose(d, i); return open > close ? y(close) - y(open) : y(open) - y(close); }); }); return chart; } //Create methods to allow outside functions to highlight a specific bar. chart.highlightPoint = function(pointIndex, isHoverOver) { chart.clearHighlights(); container.select(".nv-candlestickBar .nv-tick-0-" + pointIndex) .classed("hover", isHoverOver) ; }; chart.clearHighlights = function() { container.select(".nv-candlestickBar .nv-tick.hover") .classed("hover", false) ; }; //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.dispatch = dispatch; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, xScale: {get: function(){return x;}, set: function(_){x=_;}}, yScale: {get: function(){return y;}, set: function(_){y=_;}}, xDomain: {get: function(){return xDomain;}, set: function(_){xDomain=_;}}, yDomain: {get: function(){return yDomain;}, set: function(_){yDomain=_;}}, xRange: {get: function(){return xRange;}, set: function(_){xRange=_;}}, yRange: {get: function(){return yRange;}, set: function(_){yRange=_;}}, forceX: {get: function(){return forceX;}, set: function(_){forceX=_;}}, forceY: {get: function(){return forceY;}, set: function(_){forceY=_;}}, padData: {get: function(){return padData;}, set: function(_){padData=_;}}, clipEdge: {get: function(){return clipEdge;}, set: function(_){clipEdge=_;}}, id: {get: function(){return id;}, set: function(_){id=_;}}, interactive: {get: function(){return interactive;}, set: function(_){interactive=_;}}, x: {get: function(){return getX;}, set: function(_){getX=_;}}, y: {get: function(){return getY;}, set: function(_){getY=_;}}, open: {get: function(){return getOpen();}, set: function(_){getOpen=_;}}, close: {get: function(){return getClose();}, set: function(_){getClose=_;}}, high: {get: function(){return getHigh;}, set: function(_){getHigh=_;}}, low: {get: function(){return getLow;}, set: function(_){getLow=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top != undefined ? _.top : margin.top; margin.right = _.right != undefined ? _.right : margin.right; margin.bottom = _.bottom != undefined ? _.bottom : margin.bottom; margin.left = _.left != undefined ? _.left : margin.left; }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); }} }); nv.utils.initOptions(chart); return chart; }; ================================================ FILE: src/models/cumulativeLineChart.js ================================================ nv.models.cumulativeLineChart = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var lines = nv.models.line() , xAxis = nv.models.axis() , yAxis = nv.models.axis() , legend = nv.models.legend() , controls = nv.models.legend() , interactiveLayer = nv.interactiveGuideline() , tooltip = nv.models.tooltip() ; var margin = {top: 30, right: 30, bottom: 50, left: 60} , marginTop = null , color = nv.utils.defaultColor() , width = null , height = null , showLegend = true , showXAxis = true , showYAxis = true , rightAlignYAxis = false , showControls = true , useInteractiveGuideline = false , rescaleY = true , x //can be accessed via chart.xScale() , y //can be accessed via chart.yScale() , id = lines.id() , state = nv.utils.state() , defaultState = null , noData = null , average = function(d) { return d.average } , dispatch = d3.dispatch('stateChange', 'changeState', 'renderEnd') , transitionDuration = 250 , duration = 250 , noErrorCheck = false //if set to TRUE, will bypass an error check in the indexify function. ; state.index = 0; state.rescaleY = rescaleY; xAxis.orient('bottom').tickPadding(7); yAxis.orient((rightAlignYAxis) ? 'right' : 'left'); tooltip.valueFormatter(function(d, i) { return yAxis.tickFormat()(d, i); }).headerFormatter(function(d, i) { return xAxis.tickFormat()(d, i); }); controls.updateState(false); //============================================================ // Private Variables //------------------------------------------------------------ var dx = d3.scale.linear() , index = {i: 0, x: 0} , renderWatch = nv.utils.renderWatch(dispatch, duration) , currentYDomain ; var stateGetter = function(data) { return function(){ return { active: data.map(function(d) { return !d.disabled }), index: index.i, rescaleY: rescaleY }; } }; var stateSetter = function(data) { return function(state) { if (state.index !== undefined) index.i = state.index; if (state.rescaleY !== undefined) rescaleY = state.rescaleY; if (state.active !== undefined) data.forEach(function(series,i) { series.disabled = !state.active[i]; }); } }; function chart(selection) { renderWatch.reset(); renderWatch.models(lines); if (showXAxis) renderWatch.models(xAxis); if (showYAxis) renderWatch.models(yAxis); selection.each(function(data) { var container = d3.select(this); nv.utils.initSVG(container); container.classed('nv-chart-' + id, true); var that = this; var availableWidth = nv.utils.availableWidth(width, container, margin), availableHeight = nv.utils.availableHeight(height, container, margin); chart.update = function() { if (duration === 0) container.call(chart); else container.transition().duration(duration).call(chart) }; chart.container = this; state .setter(stateSetter(data), chart.update) .getter(stateGetter(data)) .update(); // DEPRECATED set state.disableddisabled state.disabled = data.map(function(d) { return !!d.disabled }); if (!defaultState) { var key; defaultState = {}; for (key in state) { if (state[key] instanceof Array) defaultState[key] = state[key].slice(0); else defaultState[key] = state[key]; } } var indexDrag = d3.behavior.drag() .on('dragstart', dragStart) .on('drag', dragMove) .on('dragend', dragEnd); function dragStart(d,i) { d3.select(chart.container) .style('cursor', 'ew-resize'); } function dragMove(d,i) { index.x = d3.event.x; index.i = Math.round(dx.invert(index.x)); updateZero(); } function dragEnd(d,i) { d3.select(chart.container) .style('cursor', 'auto'); // update state and send stateChange with new index state.index = index.i; dispatch.stateChange(state); } // Display No Data message if there's nothing to show. if (!data || !data.length || !data.filter(function(d) { return d.values.length }).length) { nv.utils.noData(chart, container) return chart; } else { container.selectAll('.nv-noData').remove(); } // Setup Scales x = lines.xScale(); y = lines.yScale(); dx.domain([0, data[0].values.length - 1]) //Assumes all series have same length .range([0, availableWidth]) .clamp(true); var data = indexify(index.i, data); // initialize the starting yDomain for the not-rescale case after indexify (to have calculated point.display) if (typeof(currentYDomain) === "undefined") { currentYDomain = getCurrentYDomain(data); } if (!rescaleY) { lines.yDomain(currentYDomain); lines.clipEdge(true); } else { lines.yDomain(null); } // Setup containers and skeleton of chart var interactivePointerEvents = (useInteractiveGuideline) ? "none" : "all"; var wrap = container.selectAll('g.nv-wrap.nv-cumulativeLine').data([data]); var gEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-cumulativeLine').append('g'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-interactive'); gEnter.append('g').attr('class', 'nv-x nv-axis').style("pointer-events","none"); gEnter.append('g').attr('class', 'nv-y nv-axis'); gEnter.append('g').attr('class', 'nv-background'); gEnter.append('g').attr('class', 'nv-linesWrap').style("pointer-events",interactivePointerEvents); gEnter.append('g').attr('class', 'nv-avgLinesWrap').style("pointer-events","none"); gEnter.append('g').attr('class', 'nv-legendWrap'); gEnter.append('g').attr('class', 'nv-controlsWrap'); // Legend if (!showLegend) { g.select('.nv-legendWrap').selectAll('*').remove(); } else { legend.width(availableWidth); g.select('.nv-legendWrap') .datum(data) .call(legend); if (!marginTop && legend.height() !== margin.top) { margin.top = legend.height(); availableHeight = nv.utils.availableHeight(height, container, margin); } g.select('.nv-legendWrap') .attr('transform', 'translate(0,' + (-margin.top) +')') } // Controls if (!showControls) { g.select('.nv-controlsWrap').selectAll('*').remove(); } else { var controlsData = [ { key: 'Re-scale y-axis', disabled: !rescaleY } ]; controls .width(140) .color(['#444', '#444', '#444']) .rightAlign(false) .margin({top: 5, right: 0, bottom: 5, left: 20}) ; g.select('.nv-controlsWrap') .datum(controlsData) .attr('transform', 'translate(0,' + (-margin.top) +')') .call(controls); } wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); if (rightAlignYAxis) { g.select(".nv-y.nv-axis") .attr("transform", "translate(" + availableWidth + ",0)"); } // Show error if index point value is 0 (division by zero avoided) var tempDisabled = data.filter(function(d) { return d.tempDisabled }); wrap.select('.tempDisabled').remove(); //clean-up and prevent duplicates if (tempDisabled.length) { wrap.append('text').attr('class', 'tempDisabled') .attr('x', availableWidth / 2) .attr('y', '-.71em') .style('text-anchor', 'end') .text(tempDisabled.map(function(d) { return d.key }).join(', ') + ' values cannot be calculated for this time period.'); } //Set up interactive layer if (useInteractiveGuideline) { interactiveLayer .width(availableWidth) .height(availableHeight) .margin({left:margin.left,top:margin.top}) .svgContainer(container) .xScale(x); wrap.select(".nv-interactive").call(interactiveLayer); } gEnter.select('.nv-background') .append('rect'); g.select('.nv-background rect') .attr('width', availableWidth) .attr('height', availableHeight); lines //.x(function(d) { return d.x }) .y(function(d) { return d.display.y }) .width(availableWidth) .height(availableHeight) .color(data.map(function(d,i) { return d.color || color(d, i); }).filter(function(d,i) { return !data[i].disabled && !data[i].tempDisabled; })); var linesWrap = g.select('.nv-linesWrap') .datum(data.filter(function(d) { return !d.disabled && !d.tempDisabled })); linesWrap.call(lines); //Store a series index number in the data array. data.forEach(function(d,i) { d.seriesIndex = i; }); var avgLineData = data.filter(function(d) { return !d.disabled && !!average(d); }); var avgLines = g.select(".nv-avgLinesWrap").selectAll("line") .data(avgLineData, function(d) { return d.key; }); var getAvgLineY = function(d) { //If average lines go off the svg element, clamp them to the svg bounds. var yVal = y(average(d)); if (yVal < 0) return 0; if (yVal > availableHeight) return availableHeight; return yVal; }; avgLines.enter() .append('line') .style('stroke-width',2) .style('stroke-dasharray','10,10') .style('stroke',function (d,i) { return lines.color()(d,d.seriesIndex); }) .attr('x1',0) .attr('x2',availableWidth) .attr('y1', getAvgLineY) .attr('y2', getAvgLineY); avgLines .style('stroke-opacity',function(d){ //If average lines go offscreen, make them transparent var yVal = y(average(d)); if (yVal < 0 || yVal > availableHeight) return 0; return 1; }) .attr('x1',0) .attr('x2',availableWidth) .attr('y1', getAvgLineY) .attr('y2', getAvgLineY); avgLines.exit().remove(); //Create index line var indexLine = linesWrap.selectAll('.nv-indexLine') .data([index]); indexLine.enter().append('rect').attr('class', 'nv-indexLine') .attr('width', 3) .attr('x', -2) .attr('fill', 'red') .attr('fill-opacity', .5) .style("pointer-events","all") .call(indexDrag); indexLine .attr('transform', function(d) { return 'translate(' + dx(d.i) + ',0)' }) .attr('height', availableHeight); // Setup Axes if (showXAxis) { xAxis .scale(x) ._ticks( nv.utils.calcTicksX(availableWidth/70, data) ) .tickSize(-availableHeight, 0); g.select('.nv-x.nv-axis') .attr('transform', 'translate(0,' + y.range()[0] + ')'); g.select('.nv-x.nv-axis') .call(xAxis); } if (showYAxis) { yAxis .scale(y) ._ticks( nv.utils.calcTicksY(availableHeight/36, data) ) .tickSize( -availableWidth, 0); g.select('.nv-y.nv-axis') .call(yAxis); } //============================================================ // Event Handling/Dispatching (in chart's scope) //------------------------------------------------------------ function updateZero() { indexLine .data([index]); //When dragging the index line, turn off line transitions. // Then turn them back on when done dragging. var oldDuration = chart.duration(); chart.duration(0); chart.update(); chart.duration(oldDuration); } g.select('.nv-background rect') .on('click', function() { index.x = d3.mouse(this)[0]; index.i = Math.round(dx.invert(index.x)); // update state and send stateChange with new index state.index = index.i; dispatch.stateChange(state); updateZero(); }); lines.dispatch.on('elementClick', function(e) { index.i = e.pointIndex; index.x = dx(index.i); // update state and send stateChange with new index state.index = index.i; dispatch.stateChange(state); updateZero(); }); controls.dispatch.on('legendClick', function(d,i) { d.disabled = !d.disabled; rescaleY = !d.disabled; state.rescaleY = rescaleY; if (!rescaleY) { currentYDomain = getCurrentYDomain(data); // rescale is turned off, so set the currentYDomain } dispatch.stateChange(state); chart.update(); }); legend.dispatch.on('stateChange', function(newState) { for (var key in newState) state[key] = newState[key]; dispatch.stateChange(state); chart.update(); }); interactiveLayer.dispatch.on('elementMousemove', function(e) { lines.clearHighlights(); var singlePoint, pointIndex, pointXLocation, allData = []; data .filter(function(series, i) { series.seriesIndex = i; return !(series.disabled || series.tempDisabled); }) .forEach(function(series,i) { pointIndex = nv.interactiveBisect(series.values, e.pointXValue, chart.x()); lines.highlightPoint(i, pointIndex, true); var point = series.values[pointIndex]; if (typeof point === 'undefined') return; if (typeof singlePoint === 'undefined') singlePoint = point; if (typeof pointXLocation === 'undefined') pointXLocation = chart.xScale()(chart.x()(point,pointIndex)); allData.push({ key: series.key, value: chart.y()(point, pointIndex), color: color(series,series.seriesIndex) }); }); //Highlight the tooltip entry based on which point the mouse is closest to. if (allData.length > 2) { var yValue = chart.yScale().invert(e.mouseY); var domainExtent = Math.abs(chart.yScale().domain()[0] - chart.yScale().domain()[1]); var threshold = 0.03 * domainExtent; var indexToHighlight = nv.nearestValueIndex(allData.map(function(d){return d.value}),yValue,threshold); if (indexToHighlight !== null) allData[indexToHighlight].highlight = true; } var xValue = xAxis.tickFormat()(chart.x()(singlePoint,pointIndex), pointIndex); interactiveLayer.tooltip .valueFormatter(function(d,i) { return yAxis.tickFormat()(d); }) .data( { value: xValue, series: allData } )(); interactiveLayer.renderGuideLine(pointXLocation); }); interactiveLayer.dispatch.on("elementMouseout",function(e) { lines.clearHighlights(); }); // Update chart from a state object passed to event handler dispatch.on('changeState', function(e) { if (typeof e.disabled !== 'undefined') { data.forEach(function(series,i) { series.disabled = e.disabled[i]; }); state.disabled = e.disabled; } if (typeof e.index !== 'undefined') { index.i = e.index; index.x = dx(index.i); state.index = e.index; indexLine .data([index]); } if (typeof e.rescaleY !== 'undefined') { rescaleY = e.rescaleY; } chart.update(); }); }); renderWatch.renderEnd('cumulativeLineChart immediate'); return chart; } //============================================================ // Event Handling/Dispatching (out of chart's scope) //------------------------------------------------------------ lines.dispatch.on('elementMouseover.tooltip', function(evt) { var point = { x: chart.x()(evt.point), y: chart.y()(evt.point), color: evt.point.color }; evt.point = point; tooltip.data(evt).hidden(false); }); lines.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true) }); //============================================================ // Functions //------------------------------------------------------------ var indexifyYGetter = null; /* Normalize the data according to an index point. */ function indexify(idx, data) { if (!indexifyYGetter) indexifyYGetter = lines.y(); return data.map(function(line, i) { if (!line.values) { return line; } var indexValue = line.values[idx]; if (indexValue == null) { return line; } var v = indexifyYGetter(indexValue, idx); // avoid divide by zero if (Math.abs(v) < 0.00001 && !noErrorCheck) { line.tempDisabled = true; return line; } line.tempDisabled = false; line.values = line.values.map(function(point, pointIndex) { point.display = {'y': (indexifyYGetter(point, pointIndex) - v) / v }; return point; }); return line; }) } function getCurrentYDomain(data) { var seriesDomains = data .filter(function(series) { return !(series.disabled || series.tempDisabled)}) .map(function(series,i) { return d3.extent(series.values, function (d) { return d.display.y }); }); return [ d3.min(seriesDomains, function(d) { return d[0] }), d3.max(seriesDomains, function(d) { return d[1] }) ]; } //============================================================ // Expose Public Variables //------------------------------------------------------------ // expose chart's sub-components chart.dispatch = dispatch; chart.lines = lines; chart.legend = legend; chart.controls = controls; chart.xAxis = xAxis; chart.yAxis = yAxis; chart.interactiveLayer = interactiveLayer; chart.state = state; chart.tooltip = tooltip; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, showControls: {get: function(){return showControls;}, set: function(_){showControls=_;}}, showLegend: {get: function(){return showLegend;}, set: function(_){showLegend=_;}}, average: {get: function(){return average;}, set: function(_){average=_;}}, defaultState: {get: function(){return defaultState;}, set: function(_){defaultState=_;}}, noData: {get: function(){return noData;}, set: function(_){noData=_;}}, showXAxis: {get: function(){return showXAxis;}, set: function(_){showXAxis=_;}}, showYAxis: {get: function(){return showYAxis;}, set: function(_){showYAxis=_;}}, noErrorCheck: {get: function(){return noErrorCheck;}, set: function(_){noErrorCheck=_;}}, // options that require extra logic in the setter rescaleY: {get: function(){return rescaleY;}, set: function(_){ rescaleY = _; chart.state.rescaleY = _; // also update state }}, margin: {get: function(){return margin;}, set: function(_){ if (_.top !== undefined) { margin.top = _.top; marginTop = _.top; } margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); legend.color(color); }}, useInteractiveGuideline: {get: function(){return useInteractiveGuideline;}, set: function(_){ useInteractiveGuideline = _; if (_ === true) { chart.interactive(false); chart.useVoronoi(false); } }}, rightAlignYAxis: {get: function(){return rightAlignYAxis;}, set: function(_){ rightAlignYAxis = _; yAxis.orient( (_) ? 'right' : 'left'); }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; lines.duration(duration); xAxis.duration(duration); yAxis.duration(duration); renderWatch.reset(duration); }} }); nv.utils.inheritOptions(chart, lines); nv.utils.initOptions(chart); return chart; }; ================================================ FILE: src/models/differenceChart.js ================================================ 'use strict'; nv.models.differenceChart = function () { 'use strict'; var container = void 0; var multiChart = nv.models.multiChart(); var focus = nv.models.focus(nv.models.line()); // const dispatch = d3.dispatch(); // yAccessor for multi chart // Not modifiable by end user. They can // overload yAccessor which is used during the processData step var yForMultiChart = function yForMultiChart(d) { // check if the data is for an area chart // which has y0 and y1 values if (isDefined(d.y0)) { return d.y0; } // otherwise assume it's for a line chart return d.y; }; var xForMultiChart = function xForMultiChart(d) { return d.x; }; var xAccessor = function xAccessor(d) { return d.x; }; var keyForXValue = 'x'; var yAccessor = function yAccessor(d) { return d.y; }; var duration = 300; var keyForActualLessThanPredicted = null; var keyForActualGreaterThanPredicted = null; var height = null; var width = null; var margin = { top: 30, right: 50, bottom: 20, left: 70 }; var focusMargin = { top: 0, right: 0, bottom: 0, left: 0 }; var showPredictedLine = true; var interpolate = 'linear'; var strokeWidth = 1; var xScale = d3.time.scale(); var tickFormat = d3.time.format.multi([['%I:%M', function (d) { return d.getMinutes(); }], ['%I %p', function (d) { return d.getHours(); }], ['%a %d', function (d) { return d.getDay() && d.getDate() != 1; }], ['%b %d', function (d) { return d.getDate() != 1; }], ['%B', function (d) { return d.getMonth(); }], ['%Y', function () { return true; }]]); function chart(selection) { selection.each(function (data) { container = d3.select(this); var dataWithoutDisabledSeries = (data || []).filter(function (dataset) { return !dataset.disabled; }); if (!data || !dataWithoutDisabledSeries.length) { nv.utils.noData(chart, container); return chart; } var processedData = processData(data); var availableHeight = nv.utils.availableHeight(height, container, margin) - focus.height(); var availableWidth = nv.utils.availableWidth(width, container, margin); container.attr('class', 'nv-differenceChart'); nv.utils.initSVG(container); chart.container = this; multiChart.margin(margin).color(d3.scale.category10().range()).y(yForMultiChart).width(width).height(availableHeight).interpolate(interpolate).useInteractiveGuideline(true); multiChart.interactiveLayer.tooltip.valueFormatter(function (value, i, datum) { if (datum.key === keyForActualGreaterThanPredicted || datum.key === keyForActualLessThanPredicted) { var diff = Math.abs(datum.data.y0 - datum.data.y1); if (diff === 0) { return '-'; } return diff; } return value; }); multiChart.stack1.areaY1(function (d) { return multiChart.stack1.scatter.yScale()(d.display.y); }); multiChart.stack1.transformData(function (d) { d.display = { y: d.y1, y0: d.y0 }; }); multiChart.xAxis.scale(xScale); multiChart.xAxis.tickFormat(tickFormat); var allValues = processedData.filter(function (dataset) { return !dataset.disabled; }).map(function (dataset) { return dataset.values; }); var dateExtent = d3.extent(d3.merge(allValues), function (d) { return xForMultiChart(d); }); multiChart.xAxis.domain(dateExtent).range([0, availableWidth]); var yExtent = d3.extent(d3.merge(allValues), function (d) { return yForMultiChart(d); }); multiChart.yDomain1(yExtent); multiChart.yAxis1.tickFormat(d3.format(',.1f')); multiChart.yAxis2.tickFormat(d3.format(',.1f')); focus.width(availableWidth); focus.margin(focusMargin); focus.xScale(xScale.copy()); focus.xAxis.tickFormat(tickFormat); focus.xAxis.rotateLabels(0); container.append('g').attr('class', 'nv-focusWrap').style('display', 'initial').attr('transform', 'translate(' + margin.left + ', ' + (availableHeight + focus.margin().top) + ')').datum(processedData.filter(function (dataset) { return dataset.type === 'line'; })).call(focus); container.datum(processedData).call(multiChart); focus.dispatch.on('onBrush', function (extent) { var filteredData = processedData.map(function (datum) { var leftIndex = -1; var rightIndex = -1; datum.values.some(function (val, index) { if (leftIndex === -1 && val.x >= extent[0]) { leftIndex = index; } if (rightIndex === -1 && val.x >= extent[1]) { rightIndex = index; return true; } return false; }); var filteredValues = datum.values.slice(leftIndex, rightIndex); var iterations = 0; // don't want to end up with an empty dataset as this will // break the viewfinder. while (filteredValues.length < 2 && iterations < 5) { leftIndex -= 1; rightIndex += 1; filteredValues = datum.values.slice(leftIndex, rightIndex); iterations++; } return Object.assign({}, datum, { values: filteredValues }); }); container.datum(filteredData); multiChart.xAxis.domain(extent); multiChart.update(); }); chart.update = function () { container.selectAll('*').remove(); if (duration === 0) { container.call(chart); } else { container.transition().duration(duration).call(chart); } }; return chart; }); } chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { width: { get: function get() { return width; }, set: function set(_) { width = _; } }, height: { get: function get() { return height; }, set: function set(_) { height = _; } }, strokeWidth: { get: function get() { return strokeWidth; }, set: function set(_) { strokeWidth = _; } }, x: { get: function get() { return xAccessor; }, set: function set(_) { xAccessor = _; } }, keyForXValue: { get: function get() { return keyForXValue; }, set: function set(_) { keyForXValue = _; } }, y: { get: function get() { return yAccessor; }, set: function set(_) { yAccessor = _; } }, xScale: { get: function get() { return xScale; }, set: function set(_) { xScale = _; } }, keyForActualLessThanPredicted: { get: function get() { return keyForActualLessThanPredicted; }, set: function set(_) { keyForActualLessThanPredicted = _; } }, keyForActualGreaterThanPredicted: { get: function get() { return keyForActualGreaterThanPredicted; }, set: function set(_) { keyForActualGreaterThanPredicted = _; } }, showPredictedLine: { get: function get() { return showPredictedLine; }, set: function set(_) { showPredictedLine = _; } }, tickFormat: { get: function get() { return tickFormat; }, set: function set(_) { tickFormat = _; } }, interpolate: { get: function get() { return interpolate; }, set: function set(_) { interpolate = _; } }, focusMargin: { get: function get() { return focusMargin; }, set: function set(_) { focusMargin.top = _.top !== undefined ? _.top : focusMargin.top; focusMargin.right = _.right !== undefined ? _.right : focusMargin.right; focusMargin.bottom = _.bottom !== undefined ? _.bottom : focusMargin.bottom; focusMargin.left = _.left !== undefined ? _.left : focusMargin.left; } }, margin: { get: function get() { return margin; }, set: function set(_) { margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; } } }); function processData(data) { var clonedData = data.slice(0); var allProcessed = clonedData.every(function (dataset) { return dataset.processed; }); var actualData = clonedData.filter(function (dataSet) { return dataSet.type === 'actual'; }); var predictedData = clonedData.filter(function (dataSet) { return dataSet.type === 'expected'; }); if (allProcessed) { return clonedData; } else if (!actualData.length || !predictedData.length) { return []; } var defaultKeyForActualLessThanPredicted = predictedData[0].key + ' minus ' + actualData[0].key + ' (Predicted > Actual)'; var defaultKeyForActualGreaterThanPredicted = predictedData[0].key + ' minus ' + actualData[0].key + ' (Predicted < Actual)'; // processedData is mapped as follows: // [0] => Savings (actual under predicted) area // [1] => 'Loss' (actual over predicted) area // [2] => Actual profile // [3] => Predicted profile var processedData = [{ key: keyForActualLessThanPredicted || defaultKeyForActualLessThanPredicted, type: 'area', values: [], yAxis: 1, color: 'rgba(44,160,44,.9)', processed: true, noHighlightSeries: true }, { key: keyForActualGreaterThanPredicted || defaultKeyForActualGreaterThanPredicted, type: 'area', values: [], yAxis: 1, color: 'rgba(234,39,40,.9)', processed: true, noHighlightSeries: true }, { key: actualData[0].key, type: 'line', values: [], yAxis: 1, color: '#666666', processed: true, strokeWidth: strokeWidth }]; if (showPredictedLine) { processedData[3] = { key: predictedData[0].key, type: 'line', values: [], yAxis: 1, color: '#aec7e8', processed: true, strokeWidth: strokeWidth }; } var actualDataAsMap = actualData[0].values.reduce(function (result, datum, idx) { result[xAccessor(datum)] = yAccessor(datum); return result; }, {}); var predictedDataAsMap = predictedData[0].values.reduce(function (result, datum, idx) { result[xAccessor(datum)] = yAccessor(datum); return result; }, {}); Object.keys(actualDataAsMap).forEach(function (stringifiedXValue, idx) { var actualUsage = actualDataAsMap[stringifiedXValue]; var predictedUsage = predictedDataAsMap[stringifiedXValue]; var fakeDatumToGetProperXValue = {}; // NB - stringifiedXValue will not be the correct data type // e.g. you might want to use a number/date. Pass the stringified // version back through xAccessor. fakeDatumToGetProperXValue[keyForXValue] = stringifiedXValue; var correctlyFormattedXValue = xAccessor(fakeDatumToGetProperXValue); var predictedActualDelta = predictedUsage - actualUsage; // The below code generates data for the difference chart. // We have four series: two for the area (processedData[0] and processedData[1]) charts // and two for the line charts ([2] and [3]). The way we achieve difference chart // is that for each datapoint, we calculate whether it represents a 'savings' // (actual less than predicted) or a 'loss' (actual greater than predicted). // The two areas are different colours (e.g. out of the box, a loss is red and a // saving is green). // If it's a loss, then we add an area datapoint in the loss dataset ranging from actual to predicted // (the area represents the magnitude of the loss). // At the same time, for the savings dataset, we make the datapoint equivalent to actual usage so that // a dot renders rather than a proper area. This basically makes the savings area invisible // when there is a loss. // // The opposite occurs when predicted is greater than savings (a saving). if (isNaN(predictedActualDelta)) { // if there is no predicted value for this point, just use actual usage processedData[1].values[idx] = { x: correctlyFormattedXValue, y0: actualUsage, y1: actualUsage }; processedData[0].values[idx] = { x: correctlyFormattedXValue, y0: actualUsage, y1: actualUsage }; } else if (predictedActualDelta < 0) { // actual greater than predicted - this is a loss // add area for loss between actualUsage (y0) and predictedUsage(y1) processedData[1].values[idx] = { x: correctlyFormattedXValue, y0: actualUsage, y1: predictedUsage }; // for the saving data series, render a dot (y0 and y1) at actualUsage - need // this rather than NaN because otherwise if the next datapoint is a saving, // D3 won't be able to link the two areas together processedData[0].values[idx] = { x: correctlyFormattedXValue, y0: actualUsage, y1: actualUsage }; } else { processedData[0].values[idx] = { x: correctlyFormattedXValue, y0: actualUsage, y1: predictedUsage }; processedData[1].values[idx] = { x: correctlyFormattedXValue, y0: actualUsage, y1: actualUsage }; } // Set actual processedData[2].values[idx] = { x: correctlyFormattedXValue, y: actualUsage }; // Set predicted if (showPredictedLine) { processedData[3].values[idx] = { x: correctlyFormattedXValue, y: predictedUsage }; } }); return processedData; } function isDefined(thingToCheck) { // NB: void 0 === undefined return thingToCheck !== void 0; } chart.xAxis = multiChart.xAxis; chart.yAxis = multiChart.yAxis1; chart.multiChart = multiChart; chart.focus = focus; chart.processData = processData; nv.utils.inheritOptions(chart, multiChart); nv.utils.initOptions(chart); return chart; }; ================================================ FILE: src/models/discreteBar.js ================================================ //TODO: consider deprecating by adding necessary features to multiBar model nv.models.discreteBar = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 0, right: 0, bottom: 0, left: 0} , width = 960 , height = 500 , id = Math.floor(Math.random() * 10000) //Create semi-unique ID in case user doesn't select one , container , x = d3.scale.ordinal() , y = d3.scale.linear() , getX = function(d) { return d.x } , getY = function(d) { return d.y } , forceY = [0] // 0 is forced by default.. this makes sense for the majority of bar graphs... user can always do chart.forceY([]) to remove , color = nv.utils.defaultColor() , cornerRadius = 0 // sets corner radius (in pixels) to each bar , showValues = false , valueFormat = d3.format(',.2f') , xDomain , yDomain , xRange , yRange , dispatch = d3.dispatch('chartClick', 'elementClick', 'elementDblClick', 'elementMouseover', 'elementMouseout', 'elementMousemove', 'renderEnd') , rectClass = 'discreteBar' , duration = 250 ; //============================================================ // Private Variables //------------------------------------------------------------ var x0, y0; var renderWatch = nv.utils.renderWatch(dispatch, duration); function chart(selection) { renderWatch.reset(); selection.each(function(data) { var availableWidth = width - margin.left - margin.right, availableHeight = height - margin.top - margin.bottom; container = d3.select(this); nv.utils.initSVG(container); //add series index to each data point for reference data.forEach(function(series, i) { series.values.forEach(function(point) { point.series = i; }); }); // Setup Scales // remap and flatten the data for use in calculating the scales' domains var seriesData = (xDomain && yDomain) ? [] : // if we know xDomain and yDomain, no need to calculate data.map(function(d) { return d.values.map(function(d,i) { return { x: getX(d,i), y: getY(d,i), y0: d.y0 } }) }); x .domain(xDomain || d3.merge(seriesData).map(function(d) { return d.x })) .rangeBands(xRange || [0, availableWidth], .1); y .domain(yDomain || d3.extent(d3.merge(seriesData).map(function(d) { return d.y }).concat(forceY))); // If showValues, pad the Y axis range to account for label height if (showValues) y.range(yRange || [availableHeight - (y.domain()[0] < 0 ? 12 : 0), y.domain()[1] > 0 ? 12 : 0]); else y.range(yRange || [availableHeight, 0]); //store old scales if they exist x0 = x0 || x; y0 = y0 || y.copy().range([y(0),y(0)]); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-discretebar').data([data]); var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-discretebar'); var gEnter = wrapEnter.append('g'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-groups'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); //TODO: by definition, the discrete bar should not have multiple groups, will modify/remove later var groups = wrap.select('.nv-groups').selectAll('.nv-group') .data(function(d) { return d }, function(d) { return d.key }); groups.enter().append('g') .style('stroke-opacity', 1e-6) .style('fill-opacity', 1e-6); groups.exit() .watchTransition(renderWatch, 'discreteBar: exit groups') .style('stroke-opacity', 1e-6) .style('fill-opacity', 1e-6) .remove(); groups .attr('class', function(d,i) { return 'nv-group nv-series-' + i }) .classed('hover', function(d) { return d.hover }); groups .watchTransition(renderWatch, 'discreteBar: groups') .style('stroke-opacity', 1) .style('fill-opacity', .75); var bars = groups.selectAll('g.nv-bar') .data(function(d) { return d.values }); bars.exit().remove(); var barsEnter = bars.enter().append('g') .attr('transform', function(d,i,j) { return 'translate(' + (x(getX(d,i)) + x.rangeBand() * .05 ) + ', ' + y(0) + ')' }) .on('mouseover', function(d,i) { //TODO: figure out why j works above, but not here d3.select(this).classed('hover', true); dispatch.elementMouseover({ data: d, index: i, color: d3.select(this).style("fill") }); }) .on('mouseout', function(d,i) { d3.select(this).classed('hover', false); dispatch.elementMouseout({ data: d, index: i, color: d3.select(this).style("fill") }); }) .on('mousemove', function(d,i) { dispatch.elementMousemove({ data: d, index: i, color: d3.select(this).style("fill") }); }) .on('click', function(d,i) { var element = this; dispatch.elementClick({ data: d, index: i, color: d3.select(this).style("fill"), event: d3.event, element: element }); d3.event.stopPropagation(); }) .on('dblclick', function(d,i) { dispatch.elementDblClick({ data: d, index: i, color: d3.select(this).style("fill") }); d3.event.stopPropagation(); }); barsEnter.append('rect') .attr('height', 0) .attr('width', x.rangeBand() * .9 / data.length ) if (showValues) { barsEnter.append('text') .attr('text-anchor', 'middle') ; bars.select('text') .text(function(d,i) { return valueFormat(getY(d,i)) }) .watchTransition(renderWatch, 'discreteBar: bars text') .attr('x', x.rangeBand() * .9 / 2) .attr('y', function(d,i) { return getY(d,i) < 0 ? y(getY(d,i)) - y(0) + 12 : -4 }) ; } else { bars.selectAll('text').remove(); } bars .attr('class', function(d,i) { return getY(d,i) < 0 ? 'nv-bar negative' : 'nv-bar positive' }) .style('fill', function(d,i) { return d.color || color(d,i) }) .style('stroke', function(d,i) { return d.color || color(d,i) }) .select('rect') .attr('rx', cornerRadius) .attr('class', rectClass) .watchTransition(renderWatch, 'discreteBar: bars rect') .attr('width', x.rangeBand() * .9 / data.length); bars.watchTransition(renderWatch, 'discreteBar: bars') //.delay(function(d,i) { return i * 1200 / data[0].values.length }) .attr('transform', function(d,i) { var left = x(getX(d,i)) + x.rangeBand() * .05, top = getY(d,i) < 0 ? y(0) : y(0) - y(getY(d,i)) < 1 ? y(0) - 1 : //make 1 px positive bars show up above y=0 y(getY(d,i)); return 'translate(' + left + ', ' + top + ')' }) .select('rect') .attr('height', function(d,i) { return Math.max(Math.abs(y(getY(d,i)) - y(0)), 1) }); //store old scales for use in transitions on update x0 = x.copy(); y0 = y.copy(); }); renderWatch.renderEnd('discreteBar immediate'); return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.dispatch = dispatch; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, forceY: {get: function(){return forceY;}, set: function(_){forceY=_;}}, showValues: {get: function(){return showValues;}, set: function(_){showValues=_;}}, cornerRadius: {get: function(){return cornerRadius;}, set: function(_){cornerRadius=_}}, x: {get: function(){return getX;}, set: function(_){getX=_;}}, y: {get: function(){return getY;}, set: function(_){getY=_;}}, xScale: {get: function(){return x;}, set: function(_){x=_;}}, yScale: {get: function(){return y;}, set: function(_){y=_;}}, xDomain: {get: function(){return xDomain;}, set: function(_){xDomain=_;}}, yDomain: {get: function(){return yDomain;}, set: function(_){yDomain=_;}}, xRange: {get: function(){return xRange;}, set: function(_){xRange=_;}}, yRange: {get: function(){return yRange;}, set: function(_){yRange=_;}}, valueFormat: {get: function(){return valueFormat;}, set: function(_){valueFormat=_;}}, id: {get: function(){return id;}, set: function(_){id=_;}}, rectClass: {get: function(){return rectClass;}, set: function(_){rectClass=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; renderWatch.reset(duration); }} }); nv.utils.initOptions(chart); return chart; }; ================================================ FILE: src/models/discreteBarChart.js ================================================ nv.models.discreteBarChart = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var discretebar = nv.models.discreteBar() , xAxis = nv.models.axis() , yAxis = nv.models.axis() , legend = nv.models.legend() , tooltip = nv.models.tooltip() ; var margin = {top: 15, right: 10, bottom: 50, left: 60} , marginTop = null , width = null , height = null , color = nv.utils.getColor() , showLegend = false , showXAxis = true , showYAxis = true , rightAlignYAxis = false , staggerLabels = false , wrapLabels = false , rotateLabels = 0 , x , y , noData = null , dispatch = d3.dispatch('beforeUpdate','renderEnd') , duration = 250 ; xAxis .orient('bottom') .showMaxMin(false) .tickFormat(function(d) { return d }) ; yAxis .orient((rightAlignYAxis) ? 'right' : 'left') .tickFormat(d3.format(',.1f')) ; tooltip .duration(0) .headerEnabled(false) .valueFormatter(function(d, i) { return yAxis.tickFormat()(d, i); }) .keyFormatter(function(d, i) { return xAxis.tickFormat()(d, i); }); //============================================================ // Private Variables //------------------------------------------------------------ var renderWatch = nv.utils.renderWatch(dispatch, duration); function chart(selection) { renderWatch.reset(); renderWatch.models(discretebar); if (showXAxis) renderWatch.models(xAxis); if (showYAxis) renderWatch.models(yAxis); selection.each(function(data) { var container = d3.select(this), that = this; nv.utils.initSVG(container); var availableWidth = nv.utils.availableWidth(width, container, margin), availableHeight = nv.utils.availableHeight(height, container, margin); chart.update = function() { dispatch.beforeUpdate(); container.transition().duration(duration).call(chart); }; chart.container = this; // Display No Data message if there's nothing to show. if (!data || !data.length || !data.filter(function(d) { return d.values.length }).length) { nv.utils.noData(chart, container); return chart; } else { container.selectAll('.nv-noData').remove(); } // Setup Scales x = discretebar.xScale(); y = discretebar.yScale().clamp(true); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-discreteBarWithAxes').data([data]); var gEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-discreteBarWithAxes').append('g'); var defsEnter = gEnter.append('defs'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-x nv-axis'); gEnter.append('g').attr('class', 'nv-y nv-axis') .append('g').attr('class', 'nv-zeroLine') .append('line'); gEnter.append('g').attr('class', 'nv-barsWrap'); gEnter.append('g').attr('class', 'nv-legendWrap'); g.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); // Legend if (!showLegend) { g.select('.nv-legendWrap').selectAll('*').remove(); } else { legend.width(availableWidth); g.select('.nv-legendWrap') .datum(data) .call(legend); if (!marginTop && legend.height() !== margin.top) { margin.top = legend.height(); availableHeight = nv.utils.availableHeight(height, container, margin); } wrap.select('.nv-legendWrap') .attr('transform', 'translate(0,' + (-margin.top) +')') } if (rightAlignYAxis) { g.select(".nv-y.nv-axis") .attr("transform", "translate(" + availableWidth + ",0)"); } // Main Chart Component(s) discretebar .width(availableWidth) .height(availableHeight); var barsWrap = g.select('.nv-barsWrap') .datum(data.filter(function(d) { return !d.disabled })); barsWrap.transition().call(discretebar); defsEnter.append('clipPath') .attr('id', 'nv-x-label-clip-' + discretebar.id()) .append('rect'); g.select('#nv-x-label-clip-' + discretebar.id() + ' rect') .attr('width', x.rangeBand() * (staggerLabels ? 2 : 1)) .attr('height', 16) .attr('x', -x.rangeBand() / (staggerLabels ? 1 : 2 )); // Setup Axes if (showXAxis) { xAxis .scale(x) ._ticks( nv.utils.calcTicksX(availableWidth/100, data) ) .tickSize(-availableHeight, 0); g.select('.nv-x.nv-axis') .attr('transform', 'translate(0,' + (y.range()[0] + ((discretebar.showValues() && y.domain()[0] < 0) ? 16 : 0)) + ')'); g.select('.nv-x.nv-axis').call(xAxis); var xTicks = g.select('.nv-x.nv-axis').selectAll('g'); if (staggerLabels) { xTicks .selectAll('text') .attr('transform', function(d,i,j) { return 'translate(0,' + (j % 2 == 0 ? '5' : '17') + ')' }) } if (rotateLabels) { xTicks .selectAll('.tick text') .attr('transform', 'rotate(' + rotateLabels + ' 0,0)') .style('text-anchor', rotateLabels > 0 ? 'start' : 'end'); } if (wrapLabels) { g.selectAll('.tick text') .call(nv.utils.wrapTicks, chart.xAxis.rangeBand()) } } if (showYAxis) { yAxis .scale(y) ._ticks( nv.utils.calcTicksY(availableHeight/36, data, discretebar.y()) ) .tickSize( -availableWidth, 0); g.select('.nv-y.nv-axis').call(yAxis); } // Zero line g.select(".nv-zeroLine line") .attr("x1",0) .attr("x2",(rightAlignYAxis) ? -availableWidth : availableWidth) .attr("y1", y(0)) .attr("y2", y(0)) ; }); renderWatch.renderEnd('discreteBar chart immediate'); return chart; } //============================================================ // Event Handling/Dispatching (out of chart's scope) //------------------------------------------------------------ discretebar.dispatch.on('elementMouseover.tooltip', function(evt) { evt['series'] = { key: chart.x()(evt.data), value: chart.y()(evt.data), color: evt.color }; tooltip.data(evt).hidden(false); }); discretebar.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true); }); discretebar.dispatch.on('elementMousemove.tooltip', function(evt) { tooltip(); }); //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.dispatch = dispatch; chart.discretebar = discretebar; chart.legend = legend; chart.xAxis = xAxis; chart.yAxis = yAxis; chart.tooltip = tooltip; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, showLegend: {get: function(){return showLegend;}, set: function(_){showLegend=_;}}, staggerLabels: {get: function(){return staggerLabels;}, set: function(_){staggerLabels=_;}}, rotateLabels: {get: function(){return rotateLabels;}, set: function(_){rotateLabels=_;}}, wrapLabels: {get: function(){return wrapLabels;}, set: function(_){wrapLabels=!!_;}}, showXAxis: {get: function(){return showXAxis;}, set: function(_){showXAxis=_;}}, showYAxis: {get: function(){return showYAxis;}, set: function(_){showYAxis=_;}}, noData: {get: function(){return noData;}, set: function(_){noData=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ if (_.top !== undefined) { margin.top = _.top; marginTop = _.top; } margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; renderWatch.reset(duration); discretebar.duration(duration); xAxis.duration(duration); yAxis.duration(duration); }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); discretebar.color(color); legend.color(color); }}, rightAlignYAxis: {get: function(){return rightAlignYAxis;}, set: function(_){ rightAlignYAxis = _; yAxis.orient( (_) ? 'right' : 'left'); }} }); nv.utils.inheritOptions(chart, discretebar); nv.utils.initOptions(chart); return chart; } ================================================ FILE: src/models/distribution.js ================================================ nv.models.distribution = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 0, right: 0, bottom: 0, left: 0} , width = 400 //technically width or height depending on x or y.... , size = 8 , axis = 'x' // 'x' or 'y'... horizontal or vertical , getData = function(d) { return d[axis] } // defaults d.x or d.y , color = nv.utils.defaultColor() , scale = d3.scale.linear() , domain , duration = 250 , dispatch = d3.dispatch('renderEnd') ; //============================================================ //============================================================ // Private Variables //------------------------------------------------------------ var scale0; var renderWatch = nv.utils.renderWatch(dispatch, duration); //============================================================ function chart(selection) { renderWatch.reset(); selection.each(function(data) { var availableLength = width - (axis === 'x' ? margin.left + margin.right : margin.top + margin.bottom), naxis = axis == 'x' ? 'y' : 'x', container = d3.select(this); nv.utils.initSVG(container); //------------------------------------------------------------ // Setup Scales scale0 = scale0 || scale; //------------------------------------------------------------ //------------------------------------------------------------ // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-distribution').data([data]); var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-distribution'); var gEnter = wrapEnter.append('g'); var g = wrap.select('g'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')') //------------------------------------------------------------ var distWrap = g.selectAll('g.nv-dist') .data(function(d) { return d }, function(d) { return d.key }); distWrap.enter().append('g'); distWrap .attr('class', function(d,i) { return 'nv-dist nv-series-' + i }) .style('stroke', function(d,i) { return color(d, i) }); var dist = distWrap.selectAll('line.nv-dist' + axis) .data(function(d) { return d.values }) dist.enter().append('line') .attr(axis + '1', function(d,i) { return scale0(getData(d,i)) }) .attr(axis + '2', function(d,i) { return scale0(getData(d,i)) }) renderWatch.transition(distWrap.exit().selectAll('line.nv-dist' + axis), 'dist exit') // .transition() .attr(axis + '1', function(d,i) { return scale(getData(d,i)) }) .attr(axis + '2', function(d,i) { return scale(getData(d,i)) }) .style('stroke-opacity', 0) .remove(); dist .attr('class', function(d,i) { return 'nv-dist' + axis + ' nv-dist' + axis + '-' + i }) .attr(naxis + '1', 0) .attr(naxis + '2', size); renderWatch.transition(dist, 'dist') // .transition() .attr(axis + '1', function(d,i) { return scale(getData(d,i)) }) .attr(axis + '2', function(d,i) { return scale(getData(d,i)) }) scale0 = scale.copy(); }); renderWatch.renderEnd('distribution immediate'); return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.options = nv.utils.optionsFunc.bind(chart); chart.dispatch = dispatch; chart.margin = function(_) { if (!arguments.length) return margin; margin.top = typeof _.top != 'undefined' ? _.top : margin.top; margin.right = typeof _.right != 'undefined' ? _.right : margin.right; margin.bottom = typeof _.bottom != 'undefined' ? _.bottom : margin.bottom; margin.left = typeof _.left != 'undefined' ? _.left : margin.left; return chart; }; chart.width = function(_) { if (!arguments.length) return width; width = _; return chart; }; chart.axis = function(_) { if (!arguments.length) return axis; axis = _; return chart; }; chart.size = function(_) { if (!arguments.length) return size; size = _; return chart; }; chart.getData = function(_) { if (!arguments.length) return getData; getData = d3.functor(_); return chart; }; chart.scale = function(_) { if (!arguments.length) return scale; scale = _; return chart; }; chart.color = function(_) { if (!arguments.length) return color; color = nv.utils.getColor(_); return chart; }; chart.duration = function(_) { if (!arguments.length) return duration; duration = _; renderWatch.reset(duration); return chart; }; //============================================================ return chart; } ================================================ FILE: src/models/distroPlot.js ================================================ nv.models.distroPlot = function() { "use strict"; // IMPROVEMENTS: // - cleanup tooltip to look like candlestick example (don't need color square for everything) // - extend y scale range to min/max data better visually // - tips of violins need to be cut off if very long // - transition from box to violin not great since box only has a few points, and violin has many - need to generate box with as many points as violin // - when providing colorGroup, should color boxes by either parent or child group category (e.g. isolator) //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 0, right: 0, bottom: 0, left: 0}, width = 960, height = 500, id = Math.floor(Math.random() * 10000), // Create semi-unique ID in case user doesn't select one xScale = d3.scale.ordinal(), yScale = d3.scale.linear(), getX = function(d) { return d.label }, // Default data model selectors. getY = function(d) { return d.value }, getColor = function(d) { return d.color }, getQ1 = function(d) { return d.values.q1 }, getQ2 = function(d) { return d.values.q2 }, getQ3 = function(d) { return d.values.q3 }, getNl = function(d) { return (centralTendency == 'mean' ? getMean(d) : getQ2(d)) - d.values.notch }, getNu = function(d) { return (centralTendency == 'mean' ? getMean(d) : getQ2(d)) + d.values.notch }, getMean = function(d) { return d.values.mean }, getWl = function(d) { return d.values.wl[whiskerDef] }, getWh = function(d) { return d.values.wu[whiskerDef] }, getMin = function(d) { return d.values.min }, getMax = function(d) { return d.values.max }, getDev = function(d) { return d.values.dev }, getValsObj = function(d) { return d.values.observations; }, getValsArr = function(d) { return d.values.observations.map(function(e) { return e.y }); }, plotType, // type of background: 'box', 'violin', 'none'/false - default: 'box' - 'none' will activate random scatter automatically observationType = false, // type of observations to show: 'random', 'swarm', 'line', 'centered' - default: false (don't show any observations, even if an outlier) whiskerDef = 'iqr', // type of whisker to render: 'iqr', 'minmax', 'stddev' - default: iqr hideWhiskers = false, notchBox = false, // bool whether to notch box colorGroup = false, // if specified, each x-category will be split into groups, each colored centralTendency = false, showOnlyOutliers = true, // show only outliers in box plot jitter = 0.7, // faction of that jitter should take up in 'random' observationType, must be in range [0,1]; see jitterX(), default 0.7 squash = true, // whether to remove the x-axis positions for empty data groups, default is true bandwidth = 'scott', // bandwidth for kde calculation, can be float or str, if str, must be one of scott or silverman clampViolin = true, // whether to clamp the "tails" of the violin; prevents long 0-density area resolution = 50, pointSize = 3, color = nv.utils.defaultColor(), container = null, xDomain, xRange, yDomain, yRange, dispatch = d3.dispatch('elementMouseover', 'elementMouseout', 'elementMousemove', 'renderEnd'), duration = 250, maxBoxWidth = null; //============================================================ // Helper Functions //------------------------------------------------------------ /* Returns the smaller of std(X, ddof=1) or normalized IQR(X) over axis 0. * * @param (list) x - input x formatted as a single list of values * * @return float * * Source: https://github.com/statsmodels/statsmodels/blob/master/statsmodels/nonparametric/bandwidths.py#L9 */ function select_sigma(x) { var sorted = x.sort(d3.ascending); // sort our dat var normalize = 1.349; var IQR = (d3.quantile(sorted, 0.75) - d3.quantile(sorted, 0.25))/normalize; // normalized IQR return d3.min([d3.deviation(sorted), IQR]); } /* Scott's Rule of Thumb Parameters ---------- x : array-like Array for which to get the bandwidth type : string The type of estimate to use, must be one of scott or silverman Returns ------- bw : float The estimate of the bandwidth Notes ----- Returns 1.059 * A * n ** (-1/5.) where :: A = min(std(x, ddof=1), IQR/1.349) IQR = np.subtract.reduce(np.percentile(x, [75,25])) References ---------- Scott, D.W. (1992) Multivariate Density Estimation: Theory, Practice, and Visualization. */ function calcBandwidth(x, type) { if (typeof type === 'undefined') type = 'scott'; // TODO: consider using https://github.com/jasondavies/science.js var A = select_sigma(x); var n = x.length; return type==='scott' ? Math.pow(1.059 * A * n, -0.2) : Math.pow(.9 * A * n, -0.2); } /* * Prep data for use with distroPlot by grouping data * by .x() option set by user and then calculating * count, sum, mean, q1, q2 (median), q3, lower whisker (wl) * upper whisker (wu), iqr, min, max, and standard dev. * * NOTE: preparing this data can be resource intensive, and * is therefore only run once on plot load. It can * manually be run by calling recalcData(). This should * be re-run any time the axis accessors are changed or * when bandwidth/resolution are updated. * * NOTE: this will also setup the individual vertical scales * for the violins. * * @param (list) dat - input data formatted as list of objects, * with an object key that must exist when accessed by getX() * * @return prepared data in the form for box plotType: * [{ * key : YY, * values: { * count: XX, * sum: XX, * mean: XX, * q1: XX, * q2: XX, * q3: XX, * wl: XX, * wu: XX, * iqr: XX, * min: XX, * max: XX, * dev: XX, * observations: [{y:XX,..},..], * key: XX, * kdeDat: XX, * notch: XX, * } * }, * ... * ] * for violin plotType: * [{ * key : YY, * values: { * original: [{y:XX,..},..] * } * }, * ... * ] * where YY are those keys in dat that define the * x-axis and which are defined by .x() */ function prepData(dat) { // helper function to calcuate the various boxplot stats function calcStats(g, xGroup) { // sort data by Y so we can calc quartiles var v = g.map(function(d) { if (colorGroup) allColorGroups.add(colorGroup(d)); // list of all colorGroups; used to set x-axis return getY(d); }).sort(d3.ascending); var q1 = d3.quantile(v, 0.25); var q3 = d3.quantile(v, 0.75); var iqr = q3 - q1; var upper = q3 + 1.5 * iqr; var lower = q1 - 1.5 * iqr; /* whisker definitions: * - iqr: also known as Tukey boxplot, the lowest datum still within 1.5 IQR of the lower quartile, and the highest datum still within 1.5 IQR of the upper quartile * - minmax: the minimum and maximum of all of the data * - sttdev: one standard deviation above and below the mean of the data * Note that the central tendency type (median or mean) does not impact the whisker location */ var wl = {iqr: d3.max([d3.min(v), d3.min(v.filter(function(d) {return d > lower}))]), minmax: d3.min(v), stddev: d3.mean(v) - d3.deviation(v)}; var wu = {iqr: d3.min([d3.max(v), d3.max(v.filter(function(d) {return d < upper}))]), minmax: d3.max(v), stddev: d3.mean(v) + d3.deviation(v)}; var median = d3.median(v); var mean = d3.mean(v); var observations = []; // d3-beeswarm library must be externally loaded if being used // https://github.com/Kcnarf/d3-beeswarm if (typeof d3.beeswarm !== 'undefined') { observations = d3.beeswarm() .data(g.map(function(e) { return getY(e); })) .radius(pointSize+1) .orientation('vertical') .side('symmetric') .distributeOn(function(e) { return yScale(e); }) .arrange() // add group info for tooltip observations.map(function(e,i) { e.key = xGroup; e.object_constancy = g[i].object_constancy; e.isOutlier = (e.datum < wl.iqr || e.datum > wu.iqr) // add isOulier meta for proper class assignment e.isOutlierStdDev = (e.datum < wl.stddev || e.datum > wu.stddev) // add isOulier meta for proper class assignment e.randX = Math.random() * jitter * (Math.floor(Math.random()*2) == 1 ? 1 : -1) // calculate random x-position only once for each point }) } else { v.forEach(function(e,i) { observations.push({ object_constancy: e.object_constancy, datum: e, key: xGroup, isOutlier: (e < wl.iqr || e > wu.iqr), // add isOulier meta for proper class assignment isOutlierStdDev: (e < wl.stddev || e > wu.stddev), // add isOulier meta for proper class assignment randX: Math.random() * jitter * (Math.floor(Math.random()*2) == 1 ? 1 : -1) }) }) } // calculate bandwidth if no number is provided if(isNaN(parseFloat(bandwidth))) { // if not is float var bandwidthCalc; if (['scott','silverman'].indexOf(bandwidth) != -1) { bandwidthCalc = calcBandwidth(v, bandwidth); } else { bandwidthCalc = calcBandwidth(v); // calculate with default 'scott' } } var kde = kernelDensityEstimator(eKernel(bandwidthCalc), yScale.ticks(resolution)); var kdeDat = clampViolin ? clampViolinKDE(kde(v), d3.extent(v)) : kde(v); // make a new vertical scale for each group var tmpScale = d3.scale.linear() .domain([0, d3.max(kdeDat, function (e) { return e.y;})]) .clamp(true); yVScale.push(tmpScale); var reformat = { count: v.length, num_outlier: observations.filter(function (e) { return e.isOutlier; }).length, sum: d3.sum(v), mean: mean, q1: q1, q2: median, q3: q3, wl: wl, wu: wu, iqr: iqr, min: d3.min(v), max: d3.max(v), dev: d3.deviation(v), observations: observations, key: xGroup, kde: kdeDat, notch: 1.57 * iqr / Math.sqrt(v.length), // notch distance from mean/median }; if (colorGroup) {reformatDatFlat.push({key: xGroup, values: reformat});} return reformat; } // assign a unique identifier for each point for object constancy // this makes updating data possible dat.forEach(function(d,i) { d.object_constancy = i + '_' + getY(d) + '_' + getX(d); }) // TODO not DRY // couldn't find a conditional way of doing the key() grouping var formatted; if (!colorGroup) { formatted = d3.nest() .key(function(d) { return getX(d); }) .rollup(function(v,i) { return calcStats(v); }) .entries(dat); } else { allColorGroups = d3.set() // reset var tmp = d3.nest() .key(function(d) { return getX(d); }) .key(function(d) { return colorGroup(d); }) .rollup(function(v) { return calcStats(v, getX(v[0])); }) .entries(dat); // generate a final list of all x & colorGroup combinations // this is used to properly set the x-axis domain allColorGroups = allColorGroups.values(); // convert from d3.set to list var xGroups = tmp.map(function(d) { return d.key; }); var allGroups = []; for (var i = 0; i < xGroups.length; i++) { for (var j = 0; j < allColorGroups.length; j++) { allGroups.push(xGroups[i] + '_' + allColorGroups[j]); } } allColorGroups = allGroups; // flatten the inner most level so that // the plot retains the same DOM structure // to allow for smooth updating between // all groups. formatted = []; tmp.forEach(function(d) { d.values.forEach(function(e) { e.key = d.key +'_'+e.key }) // generate a combo key so that each boxplot has a distinct x-position formatted.push.apply(formatted, d.values) }); } return formatted; } // https://bl.ocks.org/mbostock/4341954 function kernelDensityEstimator(kernel, X) { return function (sample) { return X.map(function(x) { var y = d3.mean(sample, function (v) {return kernel(x - v);}); return {x:x, y:y}; }); }; } /* * Limit whether the density extends past the extreme datapoints * of the violin. * * @param (list) kde - x & y kde cooridinates * @param (list) extent - min/max y-values used for clamping violing */ function clampViolinKDE(kde, extent) { // this handles the case when all the x-values are equal // which means no kde could be properly calculated // just return the kde data so we can continue plotting successfully if (extent[0] === extent[1]) return kde; var clamped = kde.reduce(function(res, d) { if (d.x >= extent[0] && d.x <= extent[1]) res.push(d); return res; },[]); // add the extreme data points back in if (extent[0] < clamped[0].x) clamped.unshift({x:extent[0], y:clamped[0].y}) if (extent[1] > clamped[clamped.length-1].x) clamped.push({x:extent[1], y:clamped[clamped.length-1].y}) return clamped; } // https://bl.ocks.org/mbostock/4341954 function eKernel(scale) { return function (u) { return Math.abs(u /= scale) <= 1 ? .75 * (1 - u * u) / scale : 0; }; } /** * Makes the svg polygon string for a boxplot in either a notched * or square version * * NOTE: this actually only draws the left half of the box, since * the shape is symmetric (and since this is how violins are drawn) * we can simply generate half the box and mirror it. * * @param boxLeft {float} - left position of box * @param notchLeft {float} - left position of notch * @param dat {obj} - box plot data that was run through prepDat, must contain * data for Q1, median, Q2, notch upper and notch lower * @returns {string} A string in the proper format for a svg polygon */ function makeNotchBox(boxLeft, notchLeft, boxCenter, dat) { var boxPoints; var y = centralTendency == 'mean' ? getMean(dat) : getQ2(dat); // if centralTendency is not specified, we still want to notch boxes on 'median' if (notchBox) { boxPoints = [ {x:boxCenter, y:yScale(getQ1(dat))}, {x:boxLeft, y:yScale(getQ1(dat))}, {x:boxLeft, y:yScale(getNl(dat))}, {x:notchLeft, y:yScale(y)}, {x:boxLeft, y:yScale(getNu(dat))}, {x:boxLeft, y:yScale(getQ3(dat))}, {x:boxCenter, y:yScale(getQ3(dat))}, ]; } else { boxPoints = [ {x:boxCenter, y:yScale(getQ1(dat))}, {x:boxLeft, y:yScale(getQ1(dat))}, {x:boxLeft, y:yScale(y)}, // repeated point so that transition between notched/regular more smooth {x:boxLeft, y:yScale(y)}, {x:boxLeft, y:yScale(y)}, // repeated point so that transition between notched/regular more smooth {x:boxLeft, y:yScale(getQ3(dat))}, {x:boxCenter, y:yScale(getQ3(dat))}, ]; } return boxPoints; } /** * Given an x-axis group, return the available color groups within it * provided that colorGroups is set, if not, x-axis group is returned */ function getAvailableColorGroups(x) { if (!colorGroup) return x; var tmp = reformatDat.find(function(d) { return d.key == x }); return tmp.values.map(function(d) { return d.key }).sort(d3.ascending); } // return true if point is an outlier function isOutlier(d) { return (whiskerDef == 'iqr' && d.isOutlier) || (whiskerDef == 'stddev' && d.isOutlierStdDev) } //============================================================ // Private Variables //------------------------------------------------------------ var allColorGroups = d3.set() var yVScale = [], reformatDat, reformatDatFlat = []; var renderWatch = nv.utils.renderWatch(dispatch, duration); var availableWidth, availableHeight; function chart(selection) { renderWatch.reset(); selection.each(function(data) { availableWidth = width - margin.left - margin.right, availableHeight = height - margin.top - margin.bottom; container = d3.select(this); nv.utils.initSVG(container); // Setup y-scale so that beeswarm layout can use it in prepData() yScale.domain(yDomain || d3.extent(data.map(function(d) { return getY(d)}))).nice() .range(yRange || [availableHeight, 0]); if (typeof reformatDat === 'undefined') reformatDat = prepData(data); // this prevents us from recalculating data all the time // Setup x-scale xScale.rangeBands(xRange || [0, availableWidth], 0.1) .domain(xDomain || (colorGroup && !squash) ? allColorGroups : reformatDat.map(function(d) { return d.key })) // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap').data([reformatDat]); var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap'); wrap.watchTransition(renderWatch, 'nv-wrap: wrap') .attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); var areaEnter, distroplots = wrap.selectAll('.nv-distroplot-x-group') .data(function(d) { return d; }); // rebind new data // we don't rebuild individual x-axis groups so that we can update transition them // however the data associated with each x-axis group needs to be updated // so we manually update it here distroplots.each(function(d,i) { d3.select(this).selectAll('line.nv-distroplot-middle').datum(d); }) areaEnter = distroplots.enter() .append('g') .attr('class', 'nv-distroplot-x-group') .style('stroke-opacity', 1e-6).style('fill-opacity', 1e-6) .style('fill', function(d,i) { return getColor(d) || color(d,i) }) .style('stroke', function(d,i) { return getColor(d) || color(d,i) }) distroplots.exit().remove(); var rangeBand = function() { return xScale.rangeBand() }; var areaWidth = function() { return d3.min([maxBoxWidth,rangeBand() * 0.9]); }; var areaCenter = function() { return areaWidth()/2; }; var areaLeft = function() { return areaCenter() - areaWidth()/2; }; var areaRight = function() { return areaCenter() + areaWidth()/2; }; var tickLeft = function() { return areaCenter() - areaWidth()/5; }; var tickRight = function() { return areaCenter() + areaWidth()/5; }; areaEnter.attr('transform', function(d) { return 'translate(' + (xScale(d.key) + (rangeBand() - areaWidth()) * 0.5) + ', 0)'; }); distroplots .watchTransition(renderWatch, 'nv-distroplot-x-group: distroplots') .style('stroke-opacity', 1) .style('fill-opacity', 0.5) .attr('transform', function(d) { return 'translate(' + (xScale(d.key) + (rangeBand() - areaWidth()) * 0.5) + ', 0)'; }); // set range for violin scale yVScale.map(function(d) { d.range([areaWidth()/2, 0]) }); // ----- add the SVG elements for each plot type ----- // scatter plot type if (!plotType) { showOnlyOutliers = false; // force all observations to be seen if (!observationType) observationType = 'random' } // conditionally append whisker lines areaEnter.each(function(d,i) { var box = d3.select(this); [getWl, getWh].forEach(function (f) { var key = (f === getWl) ? 'low' : 'high'; box.append('line') .style('opacity', function() { return !hideWhiskers ? '0' : '1' }) .attr('class', 'nv-distroplot-whisker nv-distroplot-' + key) box.append('line') .style('opacity', function() { return hideWhiskers ? '0' : '1' }) .attr('class', 'nv-distroplot-tick nv-distroplot-' + key) }); }); // update whisker lines and ticks [getWl, getWh].forEach(function (f) { var key = (f === getWl) ? 'low' : 'high'; var endpoint = (f === getWl) ? getQ1 : getQ3; distroplots.select('line.nv-distroplot-whisker.nv-distroplot-' + key) .watchTransition(renderWatch, 'nv-distroplot-x-group: distroplots') .attr('x1', areaCenter()) .attr('y1', function(d) { return plotType!='violin' ? yScale(f(d)) : yScale(getQ2(d)); }) .attr('x2', areaCenter()) .attr('y2', function(d) { return plotType=='box' ? yScale(endpoint(d)) : yScale(getQ2(d)); }) .style('opacity', function() { return hideWhiskers ? '0' : '1' }) distroplots.select('line.nv-distroplot-tick.nv-distroplot-' + key) .watchTransition(renderWatch, 'nv-distroplot-x-group: distroplots') .attr('x1', function(d) { return plotType!='violin' ? tickLeft() : areaCenter()} ) .attr('y1', function(d,i) { return plotType!='violin' ? yScale(f(d)) : yScale(getQ2(d)); }) .attr('x2', function(d) { return plotType!='violin' ? tickRight() : areaCenter()} ) .attr('y2', function(d,i) { return plotType!='violin' ? yScale(f(d)) : yScale(getQ2(d)); }) .style('opacity', function() { return hideWhiskers ? '0' : '1' }) }); [getWl, getWh].forEach(function (f) { var key = (f === getWl) ? 'low' : 'high'; areaEnter.selectAll('.nv-distroplot-' + key) .on('mouseover', function(d,i,j) { d3.select(this.parentNode).selectAll('line.nv-distroplot-'+key).classed('hover',true); dispatch.elementMouseover({ value: key == 'low' ? 'Lower whisker' : 'Upper whisker', series: { key: f(d).toFixed(2), color: getColor(d) || color(d,j) }, e: d3.event }); }) .on('mouseout', function(d,i,j) { d3.select(this.parentNode).selectAll('line.nv-distroplot-'+key).classed('hover',false); dispatch.elementMouseout({ value: key == 'low' ? 'Lower whisker' : 'Upper whisker', series: { key: f(d).toFixed(2), color: getColor(d) || color(d,j) }, e: d3.event }); }) .on('mousemove', function(d,i) { dispatch.elementMousemove({e: d3.event}); }); }); // setup boxes as 4 parts: left-area, left-line, right-area, right-line, // this way we can transition to a violin areaEnter.each(function(d,i) { var violin = d3.select(this); ['left','right'].forEach(function(side) { ['line','area'].forEach(function(d) { violin.append('path') .attr('class', 'nv-distribution-' + d + ' nv-distribution-' + side) .attr("transform", "rotate(90,0,0) translate(0," + (side == 'left' ? -areaWidth() : 0) + ")" + (side == 'left' ? '' : ' scale(1,-1)')); // rotate violin }) }) areaEnter.selectAll('.nv-distribution-line') .style('fill','none') areaEnter.selectAll('.nv-distribution-area') .style('stroke','none') .style('opacity',0.7) }); // transitions distroplots.each(function(d,i) { var violin = d3.select(this); var objData = plotType == 'box' ? makeNotchBox(areaLeft(), tickLeft(), areaCenter(), d) : d.values.kde; violin.selectAll('path') .datum(objData) var tmpScale = yVScale[i]; var interp = plotType=='box' ? 'linear' : 'basis'; if (plotType == 'box' || plotType == 'violin') { ['left','right'].forEach(function(side) { // line distroplots.selectAll('.nv-distribution-line.nv-distribution-' + side) //.watchTransition(renderWatch, 'nv-distribution-line: distroplots') // disable transition for now because it's jaring .attr("d", d3.svg.line() .x(function(e) { return plotType=='box' ? e.y : yScale(e.x); }) .y(function(e) { return plotType=='box' ? e.x : tmpScale(e.y) }) .interpolate(interp) ) .attr("transform", "rotate(90,0,0) translate(0," + (side == 'left' ? -areaWidth() : 0) + ")" + (side == 'left' ? '' : ' scale(1,-1)')) // rotate violin .style('opacity', !plotType ? '0' : '1'); // area distroplots.selectAll('.nv-distribution-area.nv-distribution-' + side) //.watchTransition(renderWatch, 'nv-distribution-line: distroplots') // disable transition for now because it's jaring .attr("d", d3.svg.area() .x(function(e) { return plotType=='box' ? e.y : yScale(e.x); }) .y(function(e) { return plotType=='box' ? e.x : tmpScale(e.y) }) .y0(areaWidth()/2) .interpolate(interp) ) .attr("transform", "rotate(90,0,0) translate(0," + (side == 'left' ? -areaWidth() : 0) + ")" + (side == 'left' ? '' : ' scale(1,-1)')) // rotate violin .style('opacity', !plotType ? '0' : '1'); }) } else { // scatter type, hide areas distroplots.selectAll('.nv-distribution-area') .watchTransition(renderWatch, 'nv-distribution-area: distroplots') .style('opacity', !plotType ? '0' : '1'); distroplots.selectAll('.nv-distribution-line') .watchTransition(renderWatch, 'nv-distribution-line: distroplots') .style('opacity', !plotType ? '0' : '1'); } }) // tooltip events distroplots.selectAll('path') .on('mouseover', function(d,i,j) { d = d3.select(this.parentNode).datum(); // grab data from parent g d3.select(this).classed('hover', true); dispatch.elementMouseover({ key: d.key, value: 'Group ' + d.key + ' stats', series: [ { key: 'max', value: getMax(d).toFixed(2), color: getColor(d) || color(d,j) }, { key: 'Q3', value: getQ3(d).toFixed(2), color: getColor(d) || color(d,j) }, { key: 'Q2', value: getQ2(d).toFixed(2), color: getColor(d) || color(d,j) }, { key: 'Q1', value: getQ1(d).toFixed(2), color: getColor(d) || color(d,j) }, { key: 'min', value: getMin(d).toFixed(2), color: getColor(d) || color(d,j) }, { key: 'mean', value: getMean(d).toFixed(2), color: getColor(d) || color(d,j) }, { key: 'std. dev.', value: getDev(d).toFixed(2), color: getColor(d) || color(d,j) }, { key: 'count', value: d.values.count, color: getColor(d) || color(d,j) }, { key: 'num. outliers', value: d.values.num_outlier, color: getColor(d) || color(d,j) }, ], data: d, index: i, e: d3.event }); }) .on('mouseout', function(d,i,j) { d3.select(this).classed('hover', false); d = d3.select(this.parentNode).datum(); // grab data from parent g dispatch.elementMouseout({ key: d.key, value: 'Group ' + d.key + ' stats', series: [ { key: 'max', value: getMax(d).toFixed(2), color: getColor(d) || color(d,j) }, { key: 'Q3', value: getQ3(d).toFixed(2), color: getColor(d) || color(d,j) }, { key: 'Q2', value: getQ2(d).toFixed(2), color: getColor(d) || color(d,j) }, { key: 'Q1', value: getQ1(d).toFixed(2), color: getColor(d) || color(d,j) }, { key: 'min', value: getMin(d).toFixed(2), color: getColor(d) || color(d,j) }, { key: 'mean', value: getMean(d).toFixed(2), color: getColor(d) || color(d,j) }, { key: 'std. dev.', value: getDev(d).toFixed(2), color: getColor(d) || color(d,j) }, { key: 'count', value: d.values.count, color: getColor(d) || color(d,j) }, { key: 'num. outliers', value: d.values.num_outlier, color: getColor(d) || color(d,j) }, ], data: d, index: i, e: d3.event }); }) .on('mousemove', function(d,i) { dispatch.elementMousemove({e: d3.event}); }); // median/mean line areaEnter.append('line') .attr('class', function(d) { return 'nv-distroplot-middle'}) distroplots.selectAll('line.nv-distroplot-middle') .watchTransition(renderWatch, 'nv-distroplot-x-group: distroplots line') .attr('x1', notchBox ? tickLeft : plotType != 'violin' ? areaLeft : tickLeft()) .attr('y1', function(d,i,j) { return centralTendency == 'mean' ? yScale(getMean(d)) : yScale(getQ2(d)); }) .attr('x2', notchBox ? tickRight : plotType != 'violin' ? areaRight : tickRight()) .attr('y2', function(d,i) { return centralTendency == 'mean' ? yScale(getMean(d)) : yScale(getQ2(d)); }) .style('opacity', centralTendency ? '1' : '0'); // tooltip distroplots.selectAll('.nv-distroplot-middle') .on('mouseover', function(d,i,j) { if (d3.select(this).style('opacity') == 0) return; // don't show tooltip for hidden lines var fillColor = d3.select(this.parentNode).style('fill'); // color set by parent g fill d3.select(this).classed('hover', true); dispatch.elementMouseover({ value: centralTendency == 'mean' ? 'Mean' : 'Median', series: { key: centralTendency == 'mean' ? getMean(d).toFixed(2) : getQ2(d).toFixed(2), color: fillColor }, e: d3.event }); }) .on('mouseout', function(d,i,j) { if (d3.select(this).style('opacity') == 0) return; // don't show tooltip for hidden lines d3.select(this).classed('hover', false); var fillColor = d3.select(this.parentNode).style('fill'); // color set by parent g fill dispatch.elementMouseout({ value: centralTendency == 'mean' ? 'Mean' : 'Median', series: { key: centralTendency == 'mean' ? getMean(d).toFixed(2) : getQ2(d).toFixed(2), color: fillColor }, e: d3.event }); }) .on('mousemove', function(d,i) { dispatch.elementMousemove({e: d3.event}); }); // setup observations // create DOMs even if not requested (and hide them), so that // we can do transitions on them var obsWrap = distroplots.selectAll('g.nv-distroplot-observation') .data(function(d) { return getValsObj(d) }, function(d) { return d.object_constancy; }); var obsGroup = obsWrap.enter() .append('g') .attr('class', 'nv-distroplot-observation') obsGroup.append('circle') .style({'opacity': 0}) obsGroup.append('line') .style('stroke-width', 1) .style({'stroke': d3.rgb(85, 85, 85), 'opacity': 0}) obsWrap.exit().remove(); obsWrap.attr('class', function(d) { return 'nv-distroplot-observation ' + (isOutlier(d) && plotType == 'box' ? 'nv-distroplot-outlier' : 'nv-distroplot-non-outlier')}) // transition observations if (observationType == 'line') { distroplots.selectAll('g.nv-distroplot-observation line') .watchTransition(renderWatch, 'nv-distrolot-x-group: nv-distoplot-observation') .attr("x1", tickLeft() + areaWidth()/4) .attr("x2", tickRight() - areaWidth()/4) .attr('y1', function(d) { return yScale(d.datum)}) .attr('y2', function(d) { return yScale(d.datum)}); } else { distroplots.selectAll('g.nv-distroplot-observation circle') .watchTransition(renderWatch, 'nv-distroplot: nv-distroplot-observation') .attr('cy', function(d) { return yScale(d.datum); }) .attr('r', pointSize); // NOTE: this update can be slow when re-sizing window when many point visible // TODO: filter selection down to only visible points, no need to update x-position // of the hidden points distroplots.selectAll('g.nv-distroplot-observation circle') .watchTransition(renderWatch, 'nv-distroplot: nv-distroplot-observation') .attr('cx', function(d) { return observationType == 'swarm' ? d.x + areaWidth()/2 : observationType == 'random' ? areaWidth()/2 + d.randX * areaWidth()/2 : areaWidth()/2; }) } // set opacity on outliers/non-outliers // any circle/line entering has opacity 0 if (observationType !== false) { // observationType is False when hidding all circle/lines if (!showOnlyOutliers) { // show all line/circle distroplots.selectAll(observationType== 'line' ? 'line':'circle') .watchTransition(renderWatch, 'nv-distroplot: nv-distroplot-observation') .style('opacity',1) } else { // show only outliers distroplots.selectAll('.nv-distroplot-outlier '+ (observationType== 'line' ? 'line':'circle')) .watchTransition(renderWatch, 'nv-distroplot: nv-distroplot-observation') .style('opacity',1) distroplots.selectAll('.nv-distroplot-non-outlier '+ (observationType== 'line' ? 'line':'circle')) .watchTransition(renderWatch, 'nv-distroplot: nv-distroplot-observation') .style('opacity',0) } } // hide all other observations distroplots.selectAll('.nv-distroplot-observation' + (observationType=='line'?' circle':' line')) .watchTransition(renderWatch, 'nv-distroplot: nv-distoplot-observation') .style('opacity',0) // tooltip events for observations distroplots.selectAll('.nv-distroplot-observation') .on('mouseover', function(d,i,j) { var pt = d3.select(this); if (showOnlyOutliers && plotType == 'box' && !isOutlier(d)) return; // don't show tooltip for hidden observation var fillColor = d3.select(this.parentNode).style('fill'); // color set by parent g fill pt.classed('hover', true); dispatch.elementMouseover({ value: (plotType == 'box' && isOutlier(d)) ? 'Outlier' : 'Observation', series: { key: d.datum.toFixed(2), color: fillColor }, e: d3.event }); }) .on('mouseout', function(d,i,j) { var pt = d3.select(this); var fillColor = d3.select(this.parentNode).style('fill'); // color set by parent g fill pt.classed('hover', false); dispatch.elementMouseout({ value: (plotType == 'box' && isOutlier(d)) ? 'Outlier' : 'Observation', series: { key: d.datum.toFixed(2), color: fillColor }, e: d3.event }); }) .on('mousemove', function(d,i) { dispatch.elementMousemove({e: d3.event}); }); }); renderWatch.renderEnd('nv-distroplot-x-group immediate'); return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.dispatch = dispatch; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, maxBoxWidth: {get: function(){return maxBoxWidth;}, set: function(_){maxBoxWidth=_;}}, x: {get: function(){return getX;}, set: function(_){getX=_;}}, y: {get: function(){return getY;}, set: function(_){getY=_;}}, plotType: {get: function(){return plotType;}, set: function(_){plotType=_;}}, // plotType of background: 'box', 'violin' - default: 'box' observationType: {get: function(){return observationType;}, set: function(_){observationType=_;}}, // type of observations to show: 'random', 'swarm', 'line', 'point' - default: false (don't show observations) whiskerDef: {get: function(){return whiskerDef;}, set: function(_){whiskerDef=_;}}, // type of whisker to render: 'iqr', 'minmax', 'stddev' - default: iqr notchBox: {get: function(){return notchBox;}, set: function(_){notchBox=_;}}, // bool whether to notch box hideWhiskers: {get: function(){return hideWhiskers;}, set: function(_){hideWhiskers=_;}}, colorGroup: {get: function(){return colorGroup;}, set: function(_){colorGroup=_;}}, // data key to use to set color group of each x-category - default: don't group centralTendency: {get: function(){return centralTendency;}, set: function(_){centralTendency=_;}}, // add a mean or median line to the data - default: don't show, must be one of 'mean' or 'median' bandwidth: {get: function(){return bandwidth;}, set: function(_){bandwidth=_;}}, // bandwidth for kde calculation, can be float or str, if str, must be one of scott or silverman clampViolin: {get: function(){return clampViolin;}, set: function(_){clampViolin=_;}}, resolution: {get: function(){return resolution;}, set: function(_){resolution=_;}}, // resolution for kde calculation, default 50 xScale: {get: function(){return xScale;}, set: function(_){xScale=_;}}, yScale: {get: function(){return yScale;}, set: function(_){yScale=_;}}, showOnlyOutliers: {get: function(){return showOnlyOutliers;}, set: function(_){showOnlyOutliers=_;}}, // show only outliers in box plot, default true jitter: {get: function(){return jitter;}, set: function(_){jitter=_;}}, // faction of that jitter should take up in 'random' observationType, must be in range [0,1]; see jitterX(), default 0.7 squash: {get: function(){return squash;}, set: function(_){squash=_;}}, // whether to squash sparse distribution of color groups towards middle of x-axis position pointSize: {get: function(){return pointSize;}, set: function(_){pointSize=_;}}, xDomain: {get: function(){return xDomain;}, set: function(_){xDomain=_;}}, yDomain: {get: function(){return yDomain;}, set: function(_){yDomain=_;}}, xRange: {get: function(){return xRange;}, set: function(_){xRange=_;}}, yRange: {get: function(){return yRange;}, set: function(_){yRange=_;}}, recalcData: {get: function() { reformatDat = prepData(container.datum()); } }, itemColor: {get: function(){return getColor;}, set: function(_){getColor=_;}}, id: {get: function(){return id;}, set: function(_){id=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; renderWatch.reset(duration); }} }); nv.utils.initOptions(chart); return chart; }; ================================================ FILE: src/models/distroPlotChart.js ================================================ nv.models.distroPlotChart = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var distroplot = nv.models.distroPlot(), xAxis = nv.models.axis(), yAxis = nv.models.axis() var margin = {top: 25, right: 10, bottom: 40, left: 60}, width = null, height = null, color = nv.utils.getColor(), showXAxis = true, showYAxis = true, rightAlignYAxis = false, staggerLabels = false, xLabel = false, yLabel = false, tooltip = nv.models.tooltip(), x, y, noData = 'No Data Available.', dispatch = d3.dispatch('stateChange', 'beforeUpdate', 'renderEnd'), duration = 500; xAxis .orient('bottom') .showMaxMin(false) .tickFormat(function(d) { return d }) ; yAxis .orient((rightAlignYAxis) ? 'right' : 'left') .tickFormat(d3.format(',.1f')) ; tooltip.duration(0); //============================================================ // Private Variables //------------------------------------------------------------ var renderWatch = nv.utils.renderWatch(dispatch, duration); var colorGroup0, marginTop0 = margin.top, x0, y0, resolution0, bandwidth0, clampViolin0; var dataCache; // return true if data has changed somehow after // an .update() was called // works by comparing current data set to the // one previously cached // TODO - since we keep another version of the dataset // around for comparison, it doubles the memory usage :( function dataHasChanged(d) { if (arraysEqual(d, dataCache)) { return false; } else { dataCache = JSON.parse(JSON.stringify(d)) // deep copy return true; } } // return true if array of objects equivalent function arraysEqual(arr1, arr2) { if(arr1.length !== arr2.length) return false; for(var i = arr1.length; i--;) { if ('object_constancy' in arr1[i]) delete arr1[i].object_constancy if ('object_constancy' in arr2[i]) delete arr2[i].object_constancy if(!objectEquals(arr1[i], arr2[i])) { return false; } } return true; } // return true if objects are equivalent function objectEquals(a, b) { // Create arrays of property names var aProps = Object.getOwnPropertyNames(a); var bProps = Object.getOwnPropertyNames(b); // If number of properties is different, // objects are not equivalent if (aProps.length != bProps.length) { return false; } for (var i = 0; i < aProps.length; i++) { var propName = aProps[i]; // If values of same property are not equal, // objects are not equivalent if (a[propName] !== b[propName]) { return false; } } return true; } function chart(selection) { renderWatch.reset(); renderWatch.models(distroplot); if (showXAxis) renderWatch.models(xAxis); if (showYAxis) renderWatch.models(yAxis); selection.each(function(data) { var container = d3.select(this), that = this; nv.utils.initSVG(container); var availableWidth = (width || parseInt(container.style('width')) || 960) - margin.left - margin.right; var availableHeight = (height || parseInt(container.style('height')) || 400) - margin.top - margin.bottom; if (typeof dataCache === 'undefined') { dataCache = JSON.parse(JSON.stringify(data)) // deep copy } chart.update = function() { dispatch.beforeUpdate(); var opts = distroplot.options() if (colorGroup0 !== opts.colorGroup() || // recalc data when any of the axis accessors are changed x0 !== opts.x() || y0 !== opts.y() || bandwidth0 !== opts.bandwidth() || resolution0 !== opts.resolution() || clampViolin0 !== opts.clampViolin() || dataHasChanged(data) ) { distroplot.recalcData(); } container.transition().duration(duration).call(chart); }; chart.container = this; if (typeof d3.beeswarm !== 'function' && chart.options().observationType() == 'swarm') { var xPos = margin.left + availableWidth/2; noData = 'Please include the library https://github.com/Kcnarf/d3-beeswarm to use "swarm".' nv.utils.noData(chart, container); return chart; } else if (!data || !data.length) { nv.utils.noData(chart, container); return chart; } else { container.selectAll('.nv-noData').remove(); } // Setup Scales x = distroplot.xScale(); y = distroplot.yScale().clamp(true); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-distroPlot').data([data]); var gEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-distroPlot').append('g'); var defsEnter = gEnter.append('defs'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-x nv-axis'); gEnter.append('g').attr('class', 'nv-y nv-axis') .append('g').attr('class', 'nv-zeroLine') .append('line'); gEnter.append('g').attr('class', 'nv-distroWrap'); gEnter.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); g.watchTransition(renderWatch, 'nv-wrap: wrap') .attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); if (rightAlignYAxis) { g.select('.nv-y.nv-axis') .attr('transform', 'translate(' + availableWidth + ',0)'); } // Main Chart Component(s) distroplot.width(availableWidth).height(availableHeight); var distroWrap = g.select('.nv-distroWrap') .datum(data) distroWrap.transition().call(distroplot); defsEnter.append('clipPath') .attr('id', 'nv-x-label-clip-' + distroplot.id()) .append('rect'); g.select('#nv-x-label-clip-' + distroplot.id() + ' rect') .attr('width', x.rangeBand() * (staggerLabels ? 2 : 1)) .attr('height', 16) .attr('x', -x.rangeBand() / (staggerLabels ? 1 : 2 )); // Setup Axes if (showXAxis) { xAxis .scale(x) .ticks( nv.utils.calcTicksX(availableWidth/100, data) ) .tickSize(-availableHeight, 0); g.select('.nv-x.nv-axis').attr('transform', 'translate(0,' + y.range()[0] + ')') g.select('.nv-x.nv-axis').call(xAxis); //g.select('.nv-x.nv-axis').select('.nv-axislabel') // .style('font-size', d3.min([availableWidth * 0.05,20]) + 'px') var xTicks = g.select('.nv-x.nv-axis').selectAll('g'); if (staggerLabels) { xTicks .selectAll('text') .attr('transform', function(d,i,j) { return 'translate(0,' + (j % 2 === 0 ? '5' : '17') + ')' }) } } if (showYAxis) { yAxis .scale(y) .ticks( Math.floor(availableHeight/36) ) // can't use nv.utils.calcTicksY with Object data .tickSize( -availableWidth, 0); g.select('.nv-y.nv-axis').call(yAxis); //g.select('.nv-y.nv-axis').select('.nv-axislabel') // .style('font-size', d3.min([availableHeight * 0.05,20]) + 'px') } // Zero line on chart bottom g.select('.nv-zeroLine line') .attr('x1',0) .attr('x2',availableWidth) .attr('y1', y(0)) .attr('y2', y(0)) ; // store original values so that we can // call 'recalcData()' if needed colorGroup0 = distroplot.options().colorGroup(); x0 = distroplot.options().x(); y0 = distroplot.options().y(); bandwidth0 = distroplot.options().bandwidth(); resolution0 = distroplot.options().resolution(); clampViolin0 = distroplot.options().clampViolin(); //============================================================ // Event Handling/Dispatching (in chart's scope) //------------------------------------------------------------ }); renderWatch.renderEnd('nv-distroplot chart immediate'); return chart; } //============================================================ // Event Handling/Dispatching (out of chart's scope) //------------------------------------------------------------ distroplot.dispatch.on('elementMouseover.tooltip', function(evt) { tooltip.data(evt).hidden(false); }); distroplot.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.data(evt).hidden(true); }); distroplot.dispatch.on('elementMousemove.tooltip', function(evt) { tooltip(); }); //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.dispatch = dispatch; chart.distroplot = distroplot; chart.xAxis = xAxis; chart.yAxis = yAxis; chart.tooltip = tooltip; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, staggerLabels: {get: function(){return staggerLabels;}, set: function(_){staggerLabels=_;}}, showXAxis: {get: function(){return showXAxis;}, set: function(_){showXAxis=_;}}, showYAxis: {get: function(){return showYAxis;}, set: function(_){showYAxis=_;}}, tooltipContent: {get: function(){return tooltip;}, set: function(_){tooltip=_;}}, noData: {get: function(){return noData;}, set: function(_){noData=_;}}, defaultState: {get: function(){return defaultState;}, set: function(_){defaultState=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; renderWatch.reset(duration); distroplot.duration(duration); xAxis.duration(duration); yAxis.duration(duration); }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); distroplot.color(color); }}, rightAlignYAxis: {get: function(){return rightAlignYAxis;}, set: function(_){ rightAlignYAxis = _; yAxis.orient( (_) ? 'right' : 'left'); }}, xLabel: {get: function(){return xLabel;}, set: function(_){ xLabel=_; xAxis.axisLabel(xLabel); }}, yLabel: {get: function(){return yLabel;}, set: function(_){ yLabel=_; yAxis.axisLabel(yLabel); }}, }); nv.utils.inheritOptions(chart, distroplot); nv.utils.initOptions(chart); return chart; } ================================================ FILE: src/models/focus.js ================================================ nv.models.focus = function(content) { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var content = content || nv.models.line() , xAxis = nv.models.axis() , yAxis = nv.models.axis() , brush = d3.svg.brush() ; var margin = {top: 10, right: 0, bottom: 30, left: 0} , color = nv.utils.defaultColor() , width = null , height = 70 , showXAxis = true , showYAxis = false , rightAlignYAxis = false , ticks = null , x , y , brushExtent = null , duration = 250 , dispatch = d3.dispatch('brush', 'onBrush', 'renderEnd') , syncBrushing = true ; content.interactive(false); content.pointActive(function(d) { return false; }); //============================================================ // Private Variables //------------------------------------------------------------ var renderWatch = nv.utils.renderWatch(dispatch, duration); function chart(selection) { renderWatch.reset(); renderWatch.models(content); if (showXAxis) renderWatch.models(xAxis); if (showYAxis) renderWatch.models(yAxis); selection.each(function(data) { var container = d3.select(this); nv.utils.initSVG(container); var availableWidth = nv.utils.availableWidth(width, container, margin), availableHeight = height - margin.top - margin.bottom; chart.update = function() { if( duration === 0 ) { container.call( chart ); } else { container.transition().duration(duration).call(chart); } }; chart.container = this; // Setup Scales x = content.xScale(); y = content.yScale(); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-focus').data([data]); var gEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-focus').append('g'); var g = wrap.select('g'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); gEnter.append('g').attr('class', 'nv-background').append('rect'); gEnter.append('g').attr('class', 'nv-x nv-axis'); gEnter.append('g').attr('class', 'nv-y nv-axis'); gEnter.append('g').attr('class', 'nv-contentWrap'); gEnter.append('g').attr('class', 'nv-brushBackground'); gEnter.append('g').attr('class', 'nv-x nv-brush'); if (rightAlignYAxis) { g.select(".nv-y.nv-axis") .attr("transform", "translate(" + availableWidth + ",0)"); } g.select('.nv-background rect') .attr('width', availableWidth) .attr('height', availableHeight); content .width(availableWidth) .height(availableHeight) .color(data.map(function(d,i) { return d.color || color(d, i); }).filter(function(d,i) { return !data[i].disabled; })); var contentWrap = g.select('.nv-contentWrap') .datum(data.filter(function(d) { return !d.disabled; })); d3.transition(contentWrap).call(content); // Setup Brush brush .x(x) .on('brush', function() { onBrush(syncBrushing); }); brush.on('brushend', function () { if (!syncBrushing) { dispatch.onBrush(brush.empty() ? x.domain() : brush.extent()); } }); if (brushExtent) brush.extent(brushExtent); var brushBG = g.select('.nv-brushBackground').selectAll('g') .data([brushExtent || brush.extent()]); var brushBGenter = brushBG.enter() .append('g'); brushBGenter.append('rect') .attr('class', 'left') .attr('x', 0) .attr('y', 0) .attr('height', availableHeight); brushBGenter.append('rect') .attr('class', 'right') .attr('x', 0) .attr('y', 0) .attr('height', availableHeight); var gBrush = g.select('.nv-x.nv-brush') .call(brush); gBrush.selectAll('rect') .attr('height', availableHeight); gBrush.selectAll('.resize').append('path').attr('d', resizePath); onBrush(true); g.select('.nv-background rect') .attr('width', availableWidth) .attr('height', availableHeight); if (showXAxis) { xAxis.scale(x) ._ticks( nv.utils.calcTicksX(availableWidth/100, data) ) .tickSize(-availableHeight, 0); g.select('.nv-x.nv-axis') .attr('transform', 'translate(0,' + y.range()[0] + ')'); d3.transition(g.select('.nv-x.nv-axis')) .call(xAxis); } if (showYAxis) { yAxis .scale(y) ._ticks( nv.utils.calcTicksY(availableHeight/36, data) ) .tickSize( -availableWidth, 0); d3.transition(g.select('.nv-y.nv-axis')) .call(yAxis); } g.select('.nv-x.nv-axis') .attr('transform', 'translate(0,' + y.range()[0] + ')'); //============================================================ // Event Handling/Dispatching (in chart's scope) //------------------------------------------------------------ //============================================================ // Functions //------------------------------------------------------------ // Taken from crossfilter (http://square.github.com/crossfilter/) function resizePath(d) { var e = +(d == 'e'), x = e ? 1 : -1, y = availableHeight / 3; return 'M' + (0.5 * x) + ',' + y + 'A6,6 0 0 ' + e + ' ' + (6.5 * x) + ',' + (y + 6) + 'V' + (2 * y - 6) + 'A6,6 0 0 ' + e + ' ' + (0.5 * x) + ',' + (2 * y) + 'Z' + 'M' + (2.5 * x) + ',' + (y + 8) + 'V' + (2 * y - 8) + 'M' + (4.5 * x) + ',' + (y + 8) + 'V' + (2 * y - 8); } function updateBrushBG() { if (!brush.empty()) brush.extent(brushExtent); brushBG .data([brush.empty() ? x.domain() : brushExtent]) .each(function(d,i) { var leftWidth = x(d[0]) - x.range()[0], rightWidth = availableWidth - x(d[1]); d3.select(this).select('.left') .attr('width', leftWidth < 0 ? 0 : leftWidth); d3.select(this).select('.right') .attr('x', x(d[1])) .attr('width', rightWidth < 0 ? 0 : rightWidth); }); } function onBrush(shouldDispatch) { brushExtent = brush.empty() ? null : brush.extent(); var extent = brush.empty() ? x.domain() : brush.extent(); dispatch.brush({extent: extent, brush: brush}); updateBrushBG(); if (shouldDispatch) { dispatch.onBrush(extent); } } }); renderWatch.renderEnd('focus immediate'); return chart; } //============================================================ // Event Handling/Dispatching (out of chart's scope) //------------------------------------------------------------ //============================================================ // Expose Public Variables //------------------------------------------------------------ // expose chart's sub-components chart.dispatch = dispatch; chart.content = content; chart.brush = brush; chart.xAxis = xAxis; chart.yAxis = yAxis; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, showXAxis: {get: function(){return showXAxis;}, set: function(_){showXAxis=_;}}, showYAxis: {get: function(){return showYAxis;}, set: function(_){showYAxis=_;}}, brushExtent: {get: function(){return brushExtent;}, set: function(_){brushExtent=_;}}, syncBrushing: {get: function(){return syncBrushing;}, set: function(_){syncBrushing=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; renderWatch.reset(duration); content.duration(duration); xAxis.duration(duration); yAxis.duration(duration); }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); content.color(color); }}, interpolate: {get: function(){return content.interpolate();}, set: function(_){ content.interpolate(_); }}, xTickFormat: {get: function(){return xAxis.tickFormat();}, set: function(_){ xAxis.tickFormat(_); }}, yTickFormat: {get: function(){return yAxis.tickFormat();}, set: function(_){ yAxis.tickFormat(_); }}, x: {get: function(){return content.x();}, set: function(_){ content.x(_); }}, y: {get: function(){return content.y();}, set: function(_){ content.y(_); }}, rightAlignYAxis: {get: function(){return rightAlignYAxis;}, set: function(_){ rightAlignYAxis = _; yAxis.orient( rightAlignYAxis ? 'right' : 'left'); }} }); nv.utils.inheritOptions(chart, content); nv.utils.initOptions(chart); return chart; }; ================================================ FILE: src/models/forceDirectedGraph.js ================================================ nv.models.forceDirectedGraph = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 2, right: 0, bottom: 2, left: 0} , width = 400 , height = 32 , container = null , dispatch = d3.dispatch('renderEnd') , color = nv.utils.getColor(['#000']) , tooltip = nv.models.tooltip() , noData = null // Force directed graph specific parameters [default values] , linkStrength = 0.1 , friction = 0.9 , linkDist = 30 , charge = -120 , gravity = 0.1 , theta = 0.8 , alpha = 0.1 , radius = 5 // These functions allow to add extra attributes to ndes and links ,nodeExtras = function(nodes) { /* Do nothing */ } ,linkExtras = function(links) { /* Do nothing */ } , getX=d3.functor(0.0) , getY=d3.functor(0.0) ; //============================================================ // Private Variables //------------------------------------------------------------ var renderWatch = nv.utils.renderWatch(dispatch); function chart(selection) { renderWatch.reset(); selection.each(function(data) { container = d3.select(this); nv.utils.initSVG(container); var availableWidth = nv.utils.availableWidth(width, container, margin), availableHeight = nv.utils.availableHeight(height, container, margin); container .attr("width", availableWidth) .attr("height", availableHeight); // Display No Data message if there's nothing to show. if (!data || !data.links || !data.nodes) { nv.utils.noData(chart, container) return chart; } else { container.selectAll('.nv-noData').remove(); } container.selectAll('*').remove(); // Collect names of all fields in the nodes var nodeFieldSet = new Set(); data.nodes.forEach(function(node) { var keys = Object.keys(node); keys.forEach(function(key) { nodeFieldSet.add(key); }); }); var force = d3.layout.force() .nodes(data.nodes) .links(data.links) .size([availableWidth, availableHeight]) .linkStrength(linkStrength) .friction(friction) .linkDistance(linkDist) .charge(charge) .gravity(gravity) .theta(theta) .alpha(alpha) .start(); var link = container.selectAll(".link") .data(data.links) .enter().append("line") .attr("class", "nv-force-link") .style("stroke-width", function(d) { return Math.sqrt(d.value); }); var node = container.selectAll(".node") .data(data.nodes) .enter() .append("g") .attr("class", "nv-force-node") .call(force.drag); node .append("circle") .attr("r", radius) .style("fill", function(d) { return color(d) } ) .on("mouseover", function(evt) { container.select('.nv-series-' + evt.seriesIndex + ' .nv-distx-' + evt.pointIndex) .attr('y1', evt.py); container.select('.nv-series-' + evt.seriesIndex + ' .nv-disty-' + evt.pointIndex) .attr('x2', evt.px); // Add 'series' object to var nodeColor = color(evt); evt.series = []; nodeFieldSet.forEach(function(field) { evt.series.push({ color: nodeColor, key: field, value: evt[field] }); }); tooltip.data(evt).hidden(false); }) .on("mouseout", function(d) { tooltip.hidden(true); }); tooltip.headerFormatter(function(d) {return "Node";}); // Apply extra attributes to nodes and links (if any) linkExtras(link); nodeExtras(node); force.on("tick", function() { link.attr("x1", function(d) { return d.source.x; }) .attr("y1", function(d) { return d.source.y; }) .attr("x2", function(d) { return d.target.x; }) .attr("y2", function(d) { return d.target.y; }); node.attr("transform", function(d) { return "translate(" + d.x + ", " + d.y + ")"; }); }); }); return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, // Force directed graph specific parameters linkStrength:{get: function(){return linkStrength;}, set: function(_){linkStrength=_;}}, friction: {get: function(){return friction;}, set: function(_){friction=_;}}, linkDist: {get: function(){return linkDist;}, set: function(_){linkDist=_;}}, charge: {get: function(){return charge;}, set: function(_){charge=_;}}, gravity: {get: function(){return gravity;}, set: function(_){gravity=_;}}, theta: {get: function(){return theta;}, set: function(_){theta=_;}}, alpha: {get: function(){return alpha;}, set: function(_){alpha=_;}}, radius: {get: function(){return radius;}, set: function(_){radius=_;}}, //functor options x: {get: function(){return getX;}, set: function(_){getX=d3.functor(_);}}, y: {get: function(){return getY;}, set: function(_){getY=d3.functor(_);}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); }}, noData: {get: function(){return noData;}, set: function(_){noData=_;}}, nodeExtras: {get: function(){return nodeExtras;}, set: function(_){ nodeExtras = _; }}, linkExtras: {get: function(){return linkExtras;}, set: function(_){ linkExtras = _; }} }); chart.dispatch = dispatch; chart.tooltip = tooltip; nv.utils.initOptions(chart); return chart; }; ================================================ FILE: src/models/furiousLegend.js ================================================ nv.models.furiousLegend = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 5, right: 0, bottom: 5, left: 0} , width = 400 , height = 20 , getKey = function(d) { return d.key } , keyFormatter = function (d) { return d } , color = nv.utils.getColor() , maxKeyLength = 20 //default value for key lengths , align = true , padding = 28 //define how much space between legend items. - recommend 32 for furious version , rightAlign = true , updateState = true //If true, legend will update data.disabled and trigger a 'stateChange' dispatch. , radioButtonMode = false //If true, clicking legend items will cause it to behave like a radio button. (only one can be selected at a time) , expanded = false , dispatch = d3.dispatch('legendClick', 'legendDblclick', 'legendMouseover', 'legendMouseout', 'stateChange') , vers = 'classic' //Options are "classic" and "furious" ; function chart(selection) { selection.each(function(data) { var availableWidth = width - margin.left - margin.right, container = d3.select(this); nv.utils.initSVG(container); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-legend').data([data]); var gEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-legend').append('g'); var g = wrap.select('g'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); var series = g.selectAll('.nv-series') .data(function(d) { if(vers != 'furious') return d; return d.filter(function(n) { return expanded ? true : !n.disengaged; }); }); var seriesEnter = series.enter().append('g').attr('class', 'nv-series') var seriesShape; if(vers == 'classic') { seriesEnter.append('circle') .style('stroke-width', 2) .attr('class','nv-legend-symbol') .attr('r', 5); seriesShape = series.select('circle'); } else if (vers == 'furious') { seriesEnter.append('rect') .style('stroke-width', 2) .attr('class','nv-legend-symbol') .attr('rx', 3) .attr('ry', 3); seriesShape = series.select('rect'); seriesEnter.append('g') .attr('class', 'nv-check-box') .property('innerHTML','') .attr('transform', 'translate(-10,-8)scale(0.5)'); var seriesCheckbox = series.select('.nv-check-box'); seriesCheckbox.each(function(d,i) { d3.select(this).selectAll('path') .attr('stroke', setTextColor(d,i)); }); } seriesEnter.append('text') .attr('text-anchor', 'start') .attr('class','nv-legend-text') .attr('dy', '.32em') .attr('dx', '8'); var seriesText = series.select('text.nv-legend-text'); series .on('mouseover', function(d,i) { dispatch.legendMouseover(d,i); //TODO: Make consistent with other event objects }) .on('mouseout', function(d,i) { dispatch.legendMouseout(d,i); }) .on('click', function(d,i) { dispatch.legendClick(d,i); // make sure we re-get data in case it was modified var data = series.data(); if (updateState) { if(vers =='classic') { if (radioButtonMode) { //Radio button mode: set every series to disabled, // and enable the clicked series. data.forEach(function(series) { series.disabled = true}); d.disabled = false; } else { d.disabled = !d.disabled; if (data.every(function(series) { return series.disabled})) { //the default behavior of NVD3 legends is, if every single series // is disabled, turn all series' back on. data.forEach(function(series) { series.disabled = false}); } } } else if(vers == 'furious') { if(expanded) { d.disengaged = !d.disengaged; d.userDisabled = d.userDisabled == undefined ? !!d.disabled : d.userDisabled; d.disabled = d.disengaged || d.userDisabled; } else if (!expanded) { d.disabled = !d.disabled; d.userDisabled = d.disabled; var engaged = data.filter(function(d) { return !d.disengaged; }); if (engaged.every(function(series) { return series.userDisabled })) { //the default behavior of NVD3 legends is, if every single series // is disabled, turn all series' back on. data.forEach(function(series) { series.disabled = series.userDisabled = false; }); } } } dispatch.stateChange({ disabled: data.map(function(d) { return !!d.disabled }), disengaged: data.map(function(d) { return !!d.disengaged }) }); } }) .on('dblclick', function(d,i) { if(vers == 'furious' && expanded) return; dispatch.legendDblclick(d,i); if (updateState) { // make sure we re-get data in case it was modified var data = series.data(); //the default behavior of NVD3 legends, when double clicking one, // is to set all other series' to false, and make the double clicked series enabled. data.forEach(function(series) { series.disabled = true; if(vers == 'furious') series.userDisabled = series.disabled; }); d.disabled = false; if(vers == 'furious') d.userDisabled = d.disabled; dispatch.stateChange({ disabled: data.map(function(d) { return !!d.disabled }) }); } }); series.classed('nv-disabled', function(d) { return d.userDisabled }); series.exit().remove(); seriesText .attr('fill', setTextColor) .text(function (d) { return keyFormatter(getKey(d)) }); //TODO: implement fixed-width and max-width options (max-width is especially useful with the align option) // NEW ALIGNING CODE, TODO: clean up var versPadding; switch(vers) { case 'furious' : versPadding = 23; break; case 'classic' : versPadding = 20; } if (align) { var seriesWidths = []; series.each(function(d,i) { var legendText; if (keyFormatter(getKey(d)) && keyFormatter(getKey(d)).length > maxKeyLength) { var trimmedKey = keyFormatter(getKey(d)).substring(0, maxKeyLength); legendText = d3.select(this).select('text').text(trimmedKey + "..."); d3.select(this).append("svg:title").text(keyFormatter(getKey(d))); } else { legendText = d3.select(this).select('text'); } var nodeTextLength; try { nodeTextLength = legendText.node().getComputedTextLength(); // If the legendText is display:none'd (nodeTextLength == 0), simulate an error so we approximate, instead if(nodeTextLength <= 0) throw Error(); } catch(e) { nodeTextLength = nv.utils.calcApproxTextWidth(legendText); } seriesWidths.push(nodeTextLength + padding); }); var seriesPerRow = 0; var legendWidth = 0; var columnWidths = []; while ( legendWidth < availableWidth && seriesPerRow < seriesWidths.length) { columnWidths[seriesPerRow] = seriesWidths[seriesPerRow]; legendWidth += seriesWidths[seriesPerRow++]; } if (seriesPerRow === 0) seriesPerRow = 1; //minimum of one series per row while ( legendWidth > availableWidth && seriesPerRow > 1 ) { columnWidths = []; seriesPerRow--; for (var k = 0; k < seriesWidths.length; k++) { if (seriesWidths[k] > (columnWidths[k % seriesPerRow] || 0) ) columnWidths[k % seriesPerRow] = seriesWidths[k]; } legendWidth = columnWidths.reduce(function(prev, cur, index, array) { return prev + cur; }); } var xPositions = []; for (var i = 0, curX = 0; i < seriesPerRow; i++) { xPositions[i] = curX; curX += columnWidths[i]; } series .attr('transform', function(d, i) { return 'translate(' + xPositions[i % seriesPerRow] + ',' + (5 + Math.floor(i / seriesPerRow) * versPadding) + ')'; }); //position legend as far right as possible within the total width if (rightAlign) { g.attr('transform', 'translate(' + (width - margin.right - legendWidth) + ',' + margin.top + ')'); } else { g.attr('transform', 'translate(0' + ',' + margin.top + ')'); } height = margin.top + margin.bottom + (Math.ceil(seriesWidths.length / seriesPerRow) * versPadding); } else { var ypos = 5, newxpos = 5, maxwidth = 0, xpos; series .attr('transform', function(d, i) { var length = d3.select(this).select('text').node().getComputedTextLength() + padding; xpos = newxpos; if (width < margin.left + margin.right + xpos + length) { newxpos = xpos = 5; ypos += versPadding; } newxpos += length; if (newxpos > maxwidth) maxwidth = newxpos; return 'translate(' + xpos + ',' + ypos + ')'; }); //position legend as far right as possible within the total width g.attr('transform', 'translate(' + (width - margin.right - maxwidth) + ',' + margin.top + ')'); height = margin.top + margin.bottom + ypos + 15; } if(vers == 'furious') { // Size rectangles after text is placed seriesShape .attr('width', function(d,i) { return seriesText[0][i].getComputedTextLength() + 27; }) .attr('height', 18) .attr('y', -9) .attr('x', -15) } seriesShape .style('fill', setBGColor) .style('stroke', function(d,i) { return d.color || color(d, i) }); }); function setTextColor(d,i) { if(vers != 'furious') return '#000'; if(expanded) { return d.disengaged ? color(d,i) : '#fff'; } else if (!expanded) { return !!d.disabled ? color(d,i) : '#fff'; } } function setBGColor(d,i) { if(expanded && vers == 'furious') { return d.disengaged ? '#fff' : color(d,i); } else { return !!d.disabled ? '#fff' : color(d,i); } } return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.dispatch = dispatch; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, key: {get: function(){return getKey;}, set: function(_){getKey=_;}}, keyFormatter: {get: function(){return keyFormatter;}, set: function(_){keyFormatter=_;}}, align: {get: function(){return align;}, set: function(_){align=_;}}, rightAlign: {get: function(){return rightAlign;}, set: function(_){rightAlign=_;}}, maxKeyLength: {get: function(){return maxKeyLength;}, set: function(_){maxKeyLength=_;}}, padding: {get: function(){return padding;}, set: function(_){padding=_;}}, updateState: {get: function(){return updateState;}, set: function(_){updateState=_;}}, radioButtonMode:{get: function(){return radioButtonMode;}, set: function(_){radioButtonMode=_;}}, expanded: {get: function(){return expanded;}, set: function(_){expanded=_;}}, vers: {get: function(){return vers;}, set: function(_){vers=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); }} }); nv.utils.initOptions(chart); return chart; }; ================================================ FILE: src/models/heatMap.js ================================================ /* Improvements: - consistenly apply no-hover classes to rect isntead of to containing g, see example CSS style for .no-hover rect, rect.no-hover - row/column order (user specified) or 'ascending' / 'descending' - I haven't tested for transitions between changing datasets */ nv.models.heatMap = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 0, right: 0, bottom: 0, left: 0} , width = 960 , height = 500 , id = Math.floor(Math.random() * 10000) //Create semi-unique ID in case user doesn't select one , container , xScale = d3.scale.ordinal() , yScale = d3.scale.ordinal() , colorScale = false , getX = function(d) { return d.x } , getY = function(d) { return d.y } , getCellValue = function(d) { return d.value } , showCellValues = true , cellValueFormat = function(d) { return typeof d === 'number' ? d.toFixed(0) : d } , cellAspectRatio = false // width / height of cell , cellRadius = 2 , cellBorderWidth = 4 // pixels between cells , normalize = false , highContrastText = true , xDomain , yDomain , xMetaColorScale = nv.utils.defaultColor() , yMetaColorScale = nv.utils.defaultColor() , missingDataColor = '#bcbcbc' , missingDataLabel = '' , metaOffset = 5 // spacing between meta rects and cells , xRange , yRange , xMeta , yMeta , colorRange , colorDomain , dispatch = d3.dispatch('chartClick', 'elementClick', 'elementDblClick', 'elementMouseover', 'elementMouseout', 'elementMousemove', 'renderEnd') , duration = 250 , xMetaHeight = function(d) { return cellHeight / 3 } , yMetaWidth = function(d) { return cellWidth / 3 } , showGrid = false ; //============================================================ // Aux helper function for heatmap //------------------------------------------------------------ // choose high contrast text color based on background // shameful steal: https://github.com/alexandersimoes/d3plus/blob/master/src/color/text.coffee function cellTextColor(bgColor) { if (highContrastText) { var rgbColor = d3.rgb(bgColor); var r = rgbColor.r; var g = rgbColor.g; var b = rgbColor.b; var yiq = (r * 299 + g * 587 + b * 114) / 1000; return yiq >= 128 ? "#404040" : "#EDEDED"; // dark text else light text } else { return 'black'; } } /* go through heatmap data and generate array of values * for each row/column or for entire dataset; for use in * calculating means/medians of data for normalizing * @param {str} axis - 'row', 'col' or null * * @returns {row/column index: [array of values for row/col]} * note that if axis is not specified, the return will be * {0: [all values in heatmap]} */ function getHeatmapValues(data, axis) { var vals = {}; data.forEach(function(cell, i) { if (axis == 'row') { if (!(getIY(cell) in vals)) vals[getIY(cell)] = []; vals[getIY(cell)].push(getCellValue(cell)); } else if (axis == 'col') { if (!(getIX(cell) in vals)) vals[getIX(cell)] = []; vals[getIX(cell)].push(getCellValue(cell)); } else if (axis == null) { // if calculating stat over entire dataset if (!(0 in vals)) vals[0] = []; vals[0].push(getCellValue(cell)); } }) return vals; } // calculate the median absolute deviation of the given array of data // https://en.wikipedia.org/wiki/Median_absolute_deviation // MAD = median(abs(Xi - median(X))) function mad(dat) { var med = d3.median(dat); var vals = dat.map(function(d) { return Math.abs(d - med); }) return d3.median(vals); } // set cell color based on cell value // depending on whether it should be normalized or not function cellColor(d) { var colorVal = normalize ? getNorm(d) : getCellValue(d); return (cellsAreNumeric() && !isNaN(colorVal) || typeof colorVal !== 'undefined') ? colorScale(colorVal) : missingDataColor; } // return the domain of the color data // if ordinal data is given for the cells, this will // return all possible cells values; otherwise it // returns the extent of the cell values // will take into account normalization if specified function getColorDomain() { if (cellsAreNumeric()) { // if cell values are numeric return normalize ? d3.extent(prepedData, function(d) { return getNorm(d); }) : d3.extent(uniqueColor); } else if (!cellsAreNumeric()) { // if cell values are ordinal return uniqueColor; } } // return true if cells are numeric // as opposed to categorical function cellsAreNumeric() { return typeof uniqueColor[0] === 'number'; } /* * Normalize input data * * normalize must be one of centerX, robustCenterX, centerScaleX, robustCenterScaleX, centerAll, * robustCenterAll, centerScaleAll, robustCenterScaleAll where X is either 'Row' or 'Column' * * - centerX: subtract row/column mean from cell * - centerAll: subtract mean of whole data set from cell * - centerScaleX: scale so that row/column has mean 0 and variance 1 (Z-score) * - centerScaleAll: scale by overall normalization factor so that the whole data set has mean 0 and variance 1 (Z-score) * - robustCenterX: subtract row/column median from cell * - robustCenterScaleX: subtract row/column median from cell and then scale row/column by median absolute deviation * - robustCenterAll: subtract median of whole data set from cell * - robustCenterScaleAll: subtract overall median from cell and scale by overall median absolute deviation */ function normalizeData(dat) { var normTypes = ['centerRow', 'robustCenterRow', 'centerScaleRow', 'robustCenterScaleRow', 'centerColumn', 'robustCenterColumn', 'centerScaleColumn', 'robustCenterScaleColumn', 'centerAll', 'robustCenterAll', 'centerScaleAll', 'robustCenterScaleAll']; if(normTypes.indexOf(normalize) != -1) { var xVals = Object.keys(uniqueX), yVals = Object.keys(uniqueY); // setup normalization options var scale = normalize.includes('Scale') ? true: false, agg = normalize.includes('robust') ? 'median': 'mean', axis = normalize.includes('Row') ? 'row' : normalize.includes('Column') ? 'col' : null, vals = getHeatmapValues(dat, axis); // calculate mean or median // calculate standard dev or median absolute deviation var stat = {}; var dev = {}; for (var key in vals) { stat[key] = agg == 'mean' ? d3.mean(vals[key]) : d3.median(vals[key]); if (scale) dev[key] = agg == 'mean' ? d3.deviation(vals[key]) : mad(vals[key]); } // do the normalizing dat.forEach(function(cell, i) { if (cellsAreNumeric()) { if (axis == 'row') { var key = getIY(cell); } else if (axis == 'col') { var key = getIX(cell); } else if (axis == null) { // if calculating stat over entire dataset var key = 0; } var normVal = getCellValue(cell) - stat[key]; if (scale) { cell._cellPos.norm = normVal / dev[key]; } else { cell._cellPos.norm = normVal; } } else { cell._cellPos.norm = getCellValue(cell); // if trying to normalize ordinal cells, just set norm to cell value } }) } else { normalize = false; // proper normalize option was not provided, disable it so heatmap still shows colors } return dat; } /* * Process incoming data for use with heatmap including: * - adding a unique key indexer to each data point (idx) * - getting a unique list of all x & y values * - generating a position index (x & y) for each data point * - sorting that data for correct traversal when generating rect * - generating placeholders for missing data * * In order to allow for the flexibility of the user providing either * categorical or quantitative data, we're going to position the cells * through indices that we increment based on previously seen data * this way we can use ordinal() axes even if the data is quantitative. * * When we generate the SVG elements, we assumes traversal occures from * top to bottom and from left to right. * * @param data {list} - input data organize as a list of objects * * @return - copy of input data with additional '_cellPos' key * formatted as {idx: XXX, ix, XXX, iy: XXX} * where idx is a global identifier; ix is an identifier * within each column, and iy is an identifier within * each row. */ function prepData(data) { // reinitialize uniqueX = {}, // {cell x value: ix index} uniqueY = {}, // {cell y value: iy index} uniqueColor = [], // [cell color value] uniqueXMeta = [], // [cell x metadata value] uniqueYMeta = [], // [cell y metadata value] uniqueCells = []; // [cell x,y values stored as array] var warnings = []; var sortedCells = {}; // {cell x values: {cell y value: cell data, ... }, ... } var ix = 0, iy = 0; // use these indices to position cell in x & y direction var combo, idx=0; data.forEach(function(cell) { var valX = getX(cell), valY = getY(cell), valColor = getCellValue(cell); // assemble list of unique values for each dimension if (!(valX in uniqueX)) { uniqueX[valX] = ix; ix++; sortedCells[valX] = {} if (typeof xMeta === 'function') uniqueXMeta.push(xMeta(cell)); } if (!(valY in uniqueY)) { uniqueY[valY] = iy; iy++; sortedCells[valX][valY] = {} if (typeof yMeta === 'function') uniqueYMeta.push(yMeta(cell)); } if (uniqueColor.indexOf(valColor) == -1) uniqueColor.push(valColor) // for each data point, we generate an object of data // needed to properly position each cell cell._cellPos = { idx: idx, ix: uniqueX[valX], iy: uniqueY[valY], } idx++; // keep track of row & column combinations we've already seen // this prevents the same cells from being generated when // the user hasn't provided proper data (one value for each // row & column). // if properly formatted data is not provided, only the first // row & column value is used (the rest are ignored) combo = [valX, valY]; if (!isArrayInArray(uniqueCells, combo)) { uniqueCells.push(combo) sortedCells[valX][valY] = cell; } else if (warnings.indexOf(valX + valY) == -1) { warnings.push(valX + valY); console.warn("The row/column position " + valX + "/" + valY + " has multiple values; ensure each cell has only a single value."); } }); uniqueColor = uniqueColor.sort() // check in sortedCells that each x has all the y's // if not, generate an empty placeholder // this will also sort all cells from left to right // and top to bottom var reformatData = []; Object.keys(uniqueY).forEach(function(j) { Object.keys(uniqueX).forEach(function(i) { var cellVal = sortedCells[i][j]; if (cellVal) { reformatData.push(cellVal); } else { var cellPos = { idx: idx, ix: uniqueX[i], iy: uniqueY[j], } idx++; reformatData.push({_cellPos: cellPos}); // empty cell placeholder } }) }) // normalize data is needed return normalize ? normalizeData(reformatData) : reformatData; } // https://stackoverflow.com/a/41661388/1153897 function isArrayInArray(arr, item){ var item_as_string = JSON.stringify(item); var contains = arr.some(function(ele){ return JSON.stringify(ele) === item_as_string; }); return contains; } function removeAllHoverClasses() { // remove all hover classes d3.selectAll('.cell-hover').classed('cell-hover', false); d3.selectAll('.no-hover').classed('no-hover', false); d3.selectAll('.row-hover').classed('row-hover', false); d3.selectAll('.column-hover').classed('column-hover', false); } // return the formatted cell value if it is // a number, otherwise return missingDataLabel var cellValueLabel = function(d) { var val = !normalize ? cellValueFormat(getCellValue(d)) : cellValueFormat(getNorm(d)); return (cellsAreNumeric() && !isNaN(val) || typeof val !== 'undefined') ? val : missingDataLabel; } // https://stackoverflow.com/a/16794116/1153897 // note this returns the obj keys function sortObjByVals(obj) { return Object.keys(obj).sort(function(a,b){return obj[a]-obj[b]}) } // https://stackoverflow.com/a/28191966/1153897 function getKeyByValue(object, value) { //return Object.keys(object).find(key => object[key] === value); return Object.keys(object).filter(function(key) {return object[key] === value})[0]; } //============================================================ // Private Variables //------------------------------------------------------------ var prepedData, cellHeight, cellWidth; var uniqueX = {}, uniqueY = {}, uniqueColor = []; var uniqueXMeta = [], uniqueYMeta = [], uniqueCells = [] var renderWatch = nv.utils.renderWatch(dispatch, duration); var RdYlBu = ["#a50026","#d73027","#f46d43","#fdae61","#fee090","#ffffbf","#e0f3f8","#abd9e9","#74add1","#4575b4","#313695"]; var getCellPos = function(d) { return d._cellPos; }; var getIX = function(d) { return getCellPos(d).ix; } // get the given cell's x index position var getIY = function(d) { return getCellPos(d).iy; } // get the given cell's y index position var getNorm = function(d) { return getCellPos(d).norm; } var getIdx = function(d) { return getCellPos(d).idx; } function chart(selection) { renderWatch.reset(); selection.each(function(data) { prepedData = prepData(data); var availableWidth = width - margin.left - margin.right, availableHeight = height - margin.top - margin.bottom; // available width/height set the cell dimenions unless // the aspect ratio is defined - in that case the cell // height is adjusted and availableHeight updated cellWidth = availableWidth / Object.keys(uniqueX).length; cellHeight = cellAspectRatio ? cellWidth / cellAspectRatio : availableHeight / Object.keys(uniqueY).length; if (cellAspectRatio) availableHeight = cellHeight * Object.keys(uniqueY).length - margin.top - margin.bottom; container = d3.select(this); nv.utils.initSVG(container); // Setup Scales xScale.domain(xDomain || sortObjByVals(uniqueX)) .rangeBands(xRange || [0, availableWidth-cellBorderWidth/2]); yScale.domain(yDomain || sortObjByVals(uniqueY)) .rangeBands(yRange || [0, availableHeight-cellBorderWidth/2]); colorScale = cellsAreNumeric() ? d3.scale.quantize() : d3.scale.ordinal(); colorScale.domain(colorDomain || getColorDomain()) .range(colorRange || RdYlBu); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-heatMapWrap').data([prepedData]); var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-heatMapWrap'); wrapEnter .append('g') .attr('class','cellWrap') wrap.watchTransition(renderWatch, 'nv-wrap: heatMapWrap') .attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); var gridWrap = wrapEnter .append('g') .attr('class','cellGrid') .style('opacity',1e-6) var gridLinesV = wrap.select('.cellGrid').selectAll('.gridLines.verticalGrid') .data(Object.values(uniqueX).concat([Object.values(uniqueX).length])) gridLinesV.enter() .append('line') .attr('class','gridLines verticalGrid') gridLinesV.exit() .remove() var gridLinesH = wrap.select('.cellGrid').selectAll('.gridLines.horizontalGrid') .data(Object.values(uniqueY).concat([Object.values(uniqueY).length])) gridLinesH.enter() .append('line') .attr('class','gridLines horizontalGrid') gridLinesH.exit() .remove() var cellWrap = wrap.select('.cellWrap') .selectAll(".nv-cell") .data(function(d) { return d; }, function(e) { return getIdx(e); }) var xMetaWrap = wrapEnter .append('g') .attr('class','xMetaWrap') .attr("transform", function() { return "translate(0," + (-xMetaHeight()-cellBorderWidth-metaOffset) + ")" }) var xMetas = wrap.select('.xMetaWrap').selectAll('.x-meta') .data(uniqueXMeta) var xMetaEnter = xMetas .enter() .append('rect') .attr('class','x-meta meta') .attr("width", cellWidth-cellBorderWidth) .attr("height", xMetaHeight()) .attr("transform", "translate(0,0)") .attr("fill", function(d) { return xMetaColorScale(d); }) var yMetaWrap = wrapEnter .append('g') .attr('class','yMetaWrap') .attr("transform", function(d,i) { return "translate(" + (-yMetaWidth()-cellBorderWidth-metaOffset) + ",0)" }) var yMetas = wrap.select('.yMetaWrap').selectAll('.y-meta') .data(uniqueYMeta) var yMetaEnter = yMetas .enter() .append('rect') .attr('class','y-meta meta') .attr("width", yMetaWidth()) .attr("height", cellHeight-cellBorderWidth) .attr("transform", function(d,i) { return "translate(0,0)" }) .attr("fill", function(d,i) { return yMetaColorScale(d); }) xMetas.exit().remove() yMetas.exit().remove() // CELLS var cellsEnter = cellWrap .enter() .append('g') .style('opacity', 1e-6) .attr("transform", function(d) { return "translate(0," + getIY(d) * cellHeight + ")" }) // enter all g's here for a sweep-right transition .attr('data-row', function(d) { return getIY(d) }) .attr('data-column', function(d) { return getIX(d) }); cellsEnter .append("rect") cellsEnter .append('text') .attr('text-anchor', 'middle') .attr("dy", 4) .attr("class","cell-text") // transition cell (rect) size cellWrap.selectAll('rect') .watchTransition(renderWatch, 'heatMap: rect') .attr("width", cellWidth-cellBorderWidth) .attr("height", cellHeight-cellBorderWidth) .attr('rx', cellRadius) .attr('ry', cellRadius) .style('stroke', function(d) { return cellColor(d) }) // transition cell (g) position, opacity and fill cellWrap .attr("class",function(d) { return isNaN(getCellValue(d)) ? 'nv-cell cell-missing' : 'nv-cell'}) .watchTransition(renderWatch, 'heatMap: cells') .style({ 'opacity': 1, 'fill': function(d) { return cellColor(d) }, }) .attr("transform", function(d) { return "translate(" + getIX(d) * cellWidth + "," + getIY(d) * cellHeight + ")" }) .attr("class",function(d) { return isNaN(getCellValue(d)) ? 'nv-cell cell-missing' : 'nv-cell'}) cellWrap.exit().remove(); // transition text position and fill cellWrap.selectAll('text') .watchTransition(renderWatch, 'heatMap: cells text') .text(function(d) { return cellValueLabel(d); }) .attr("x", function(d) { return (cellWidth-cellBorderWidth) / 2; }) .attr("y", function(d) { return (cellHeight-cellBorderWidth) / 2; }) .style("fill", function(d) { return cellTextColor(cellColor(d)) }) .style('opacity', function() { return showCellValues ? 1 : 0 }) // transition grid wrap.selectAll('.verticalGrid') .watchTransition(renderWatch, 'heatMap: gridLines') .attr('y1',0) .attr('y2',availableHeight-cellBorderWidth) .attr('x1',function(d) { return d*cellWidth-cellBorderWidth/2; }) .attr('x2',function(d) { return d*cellWidth-cellBorderWidth/2; }) var numHLines = Object.keys(uniqueY).length; wrap.selectAll('.horizontalGrid') .watchTransition(renderWatch, 'heatMap: gridLines') .attr('x1',function(d) { return (d == 0 || d == numHLines) ? -cellBorderWidth : 0 }) .attr('x2',function(d) { return (d == 0 || d == numHLines) ? availableWidth : availableWidth-cellBorderWidth}) .attr('y1',function(d) { return d*cellHeight-cellBorderWidth/2; }) .attr('y2',function(d) { return d*cellHeight-cellBorderWidth/2; }) wrap.select('.cellGrid') .watchTransition(renderWatch, 'heatMap: gridLines') .style({ 'stroke-width': cellBorderWidth, 'opacity': function() { return showGrid ? 1 : 1e-6 }, }) var xMetaRect = wrap.selectAll('.x-meta') var yMetaRect = wrap.selectAll('.y-meta') var allMetaRect = wrap.selectAll('.meta') // transition meta rect size xMetas .watchTransition(renderWatch, 'heatMap: xMetaRect') .attr("width", cellWidth-cellBorderWidth) .attr("height", xMetaHeight()) .attr("transform", function(d,i) { return "translate(" + (i * cellWidth) + ",0)" }) yMetas .watchTransition(renderWatch, 'heatMap: yMetaRect') .attr("width", yMetaWidth()) .attr("height", cellHeight-cellBorderWidth) .attr("transform", function(d,i) { return "translate(0," + (i * cellHeight) + ")" }) // transition position of meta wrap g & opacity wrap.select('.xMetaWrap') .watchTransition(renderWatch, 'heatMap: xMetaWrap') .attr("transform", function(d,i) { return "translate(0," + (-xMetaHeight()-cellBorderWidth-metaOffset) + ")" }) .style("opacity", function() { return xMeta !== false ? 1 : 0 }) wrap.select('.yMetaWrap') .watchTransition(renderWatch, 'heatMap: yMetaWrap') .attr("transform", function(d,i) { return "translate(" + (-yMetaWidth()-cellBorderWidth-metaOffset) + ",0)" }) .style("opacity", function() { return yMeta !== false ? 1 : 0 }) // TOOLTIPS cellWrap .on('mouseover', function(d,i) { var idx = getIdx(d); var ix = getIX(d); var iy = getIY(d); // set the proper classes for all cells // hover row gets class .row-hover // hover column gets class .column-hover // hover cell gets class .cell-hover // all remaining cells get class .no-hover d3.selectAll('.nv-cell').each(function(e) { if (idx == getIdx(e)) { d3.select(this).classed('cell-hover', true); d3.select(this).classed('no-hover', false); } else { d3.select(this).classed('no-hover', true); d3.select(this).classed('cell-hover', false); } if (ix == getIX(e)) { d3.select(this).classed('no-hover', false); d3.select(this).classed('column-hover', true); } if (iy == getIY(e)) { d3.select(this).classed('no-hover', false); d3.select(this).classed('row-hover', true); } }) // set hover classes for column metadata d3.selectAll('.x-meta').each(function(e, j) { if (j == ix) { d3.select(this).classed('cell-hover', true); d3.select(this).classed('no-hover', false); } else { d3.select(this).classed('no-hover', true); d3.select(this).classed('cell-hover', false); } }); // set hover class for row metadata d3.selectAll('.y-meta').each(function(e, j) { if (j == iy) { d3.select(this).classed('cell-hover', true); d3.select(this).classed('no-hover', false); } else { d3.select(this).classed('no-hover', true); d3.select(this).classed('cell-hover', false); } }); dispatch.elementMouseover({ value: getKeyByValue(uniqueX, ix) + ' & ' + getKeyByValue(uniqueY, iy), series: { value: cellValueLabel(d), color: d3.select(this).select('rect').style("fill") }, e: d3.event, }); }) .on('mouseout', function(d,i) { // allow tooltip to remain even when mouse is over the // space between the cell; // this prevents cells from "flashing" when transitioning // between cells var bBox = d3.select(this).select('rect').node().getBBox(); var coordinates = d3.mouse(d3.select('.nv-heatMap').node()); var x = coordinates[0]; var y = coordinates[1]; // we only trigger mouseout when mouse moves outside of // .nv-heatMap if (x + cellBorderWidth >= availableWidth || y + cellBorderWidth >= availableHeight || x < 0 || y < 0) { // remove all hover classes removeAllHoverClasses(); dispatch.elementMouseout({e: d3.event}); } }) .on('mousemove', function(d,i) { dispatch.elementMousemove({e: d3.event}); }) allMetaRect .on('mouseover', function(d,i) { // true if hovering over a row metadata rect var isColMeta = d3.select(this).attr('class').indexOf('x-meta') != -1 ? true : false; // apply proper .row-hover & .column-hover // classes to cells d3.selectAll('.nv-cell').each(function(e) { if (isColMeta && i == getIX(e)) { d3.select(this).classed('column-hover', true); d3.select(this).classed('no-hover', false); } else if (!isColMeta && i-uniqueXMeta.length == getIY(e)) { // since allMetaRect selects all the meta rects, the index for the y's will // be offset by the number of x rects. TODO - write seperate tooltip sections // for x meta rect & y meta rect d3.select(this).classed('row-hover', true); d3.select(this).classed('no-hover', false); } else { d3.select(this).classed('no-hover', true); d3.select(this).classed('column-hover', false); d3.select(this).classed('row-hover', false); } d3.select(this).classed('cell-hover', false); }) // apply proper .row-hover & .column-hover // classes to meta rects d3.selectAll('.meta').classed('no-hover', true); d3.select(this).classed('cell-hover', true); d3.select(this).classed('no-hover', false); dispatch.elementMouseover({ value: isColMeta ? 'Column meta' : 'Row meta', series: { value: d, color: d3.select(this).style('fill'), } }); }) .on('mouseout', function(d,i) { // true if hovering over a row metadata rect var isColMeta = d3.select(this).attr('class').indexOf('x-meta') != -1 ? true : false; // allow tooltip to remain even when mouse is over the // space between the cell; // this prevents cells from "flashing" when transitioning // between cells var bBox = d3.select(this).node().getBBox(); var coordinates = d3.mouse(d3.select(isColMeta ? '.xMetaWrap' : '.yMetaWrap').node()); var x = coordinates[0]; var y = coordinates[1]; if ( y < 0 || x < 0 || (isColMeta && x + cellBorderWidth >= availableWidth) || (!isColMeta && y + cellBorderWidth >= availableHeight) ) { // remove all hover classes removeAllHoverClasses(); dispatch.elementMouseout({e: d3.event}); } }) .on('mousemove', function(d,i) { dispatch.elementMousemove({e: d3.event}); }) }); renderWatch.renderEnd('heatMap immediate'); return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.dispatch = dispatch; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, showCellValues: {get: function(){return showCellValues;}, set: function(_){showCellValues=_;}}, x: {get: function(){return getX;}, set: function(_){getX=_;}}, // data attribute for horizontal axis y: {get: function(){return getY;}, set: function(_){getY=_;}}, // data attribute for vertical axis cellValue: {get: function(){return getCellValue;}, set: function(_){getCellValue=_;}}, // data attribute that sets cell value and color missingDataColor: {get: function(){return missingDataColor;}, set: function(_){missingDataColor=_;}}, missingDataLabel: {get: function(){return missingDataLabel;}, set: function(_){missingDataLabel=_;}}, xScale: {get: function(){return xScale;}, set: function(_){xScale=_;}}, yScale: {get: function(){return yScale;}, set: function(_){yScale=_;}}, colorScale: {get: function(){return colorScale;}, set: function(_){colorScale=_;}}, // scale to map cell values to colors xDomain: {get: function(){return xDomain;}, set: function(_){xDomain=_;}}, yDomain: {get: function(){return yDomain;}, set: function(_){yDomain=_;}}, xRange: {get: function(){return xRange;}, set: function(_){xRange=_;}}, yRange: {get: function(){return yRange;}, set: function(_){yRange=_;}}, colorRange: {get: function(){return colorRange;}, set: function(_){colorRange=_;}}, colorDomain: {get: function(){return colorDomain;}, set: function(_){colorDomain=_;}}, xMeta: {get: function(){return xMeta;}, set: function(_){xMeta=_;}}, yMeta: {get: function(){return yMeta;}, set: function(_){yMeta=_;}}, xMetaColorScale: {get: function(){return color;}, set: function(_){color = nv.utils.getColor(_);}}, yMetaColorScale: {get: function(){return color;}, set: function(_){color = nv.utils.getColor(_);}}, cellAspectRatio: {get: function(){return cellAspectRatio;}, set: function(_){cellAspectRatio=_;}}, // cell width / height cellRadius: {get: function(){return cellRadius;}, set: function(_){cellRadius=_;}}, // cell width / height cellHeight: {get: function(){return cellHeight;}}, // TODO - should not be exposed since we don't want user setting this cellWidth: {get: function(){return cellWidth;}}, // TODO - should not be exposed since we don't want user setting this normalize: {get: function(){return normalize;}, set: function(_){normalize=_;}}, cellBorderWidth: {get: function(){return cellBorderWidth;}, set: function(_){cellBorderWidth=_;}}, highContrastText: {get: function(){return highContrastText;}, set: function(_){highContrastText=_;}}, cellValueFormat: {get: function(){return cellValueFormat;}, set: function(_){cellValueFormat=_;}}, id: {get: function(){return id;}, set: function(_){id=_;}}, metaOffset: {get: function(){return metaOffset;}, set: function(_){metaOffset=_;}}, xMetaHeight: {get: function(){return xMetaHeight;}, set: function(_){xMetaHeight=_;}}, yMetaWidth: {get: function(){return yMetaWidth;}, set: function(_){yMetaWidth=_;}}, showGrid: {get: function(){return showGrid;}, set: function(_){showGrid=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; renderWatch.reset(duration); }} }); nv.utils.initOptions(chart); return chart; }; ================================================ FILE: src/models/heatMapChart.js ================================================ /* Heatmap Chart Type A heatmap is a graphical representation of data where the individual values contained in a matrix are represented as colors within cells. Furthermore, metadata can be associated with each of the matrix rows or columns. By grouping these rows/columns together by a given metadata value, data trends can be spotted. Format for input data should be: var data = [ {day: 'mo', hour: '1a', value: 16, timeperiod: 'early morning', weekperiod: 'week', category: 1}, {day: 'mo', hour: '2a', value: 20, timeperiod: 'early morning', weekperiod: 'week', category: 2}, {day: 'mo', hour: '3a', value: 0, timeperiod: 'early morning', weekperiod: 'week', category: 1}, ... ] where the keys 'day' and 'hour' specify the row/column of the heatmap, 'value' specifies the cell value and the keys 'timeperiod', 'weekperiod' and 'week' are extra metadata that can be associated with rows/columns. Options for chart: */ nv.models.heatMapChart = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var heatMap = nv.models.heatMap() , legend = nv.models.legend() , legendRowMeta = nv.models.legend() , legendColumnMeta = nv.models.legend() , tooltip = nv.models.tooltip() , xAxis = nv.models.axis() , yAxis = nv.models.axis() ; var margin = {top: 20, right: 10, bottom: 50, left: 60} , marginTop = null , width = null , height = null , color = nv.utils.getColor() , showLegend = true , staggerLabels = false , showXAxis = true , showYAxis = true , alignYAxis = 'left' , alignXAxis = 'top' , rotateLabels = 0 , title = false , x , y , noData = null , dispatch = d3.dispatch('beforeUpdate','renderEnd') , duration = 250 ; xAxis .orient(alignXAxis) .showMaxMin(false) .tickFormat(function(d) { return d }) ; yAxis .orient(alignYAxis) .showMaxMin(false) .tickFormat(function(d) { return d }) ; tooltip .duration(0) .headerEnabled(true) .keyFormatter(function(d, i) { return xAxis.tickFormat()(d, i); }) //============================================================ // Private Variables //------------------------------------------------------------ // https://bl.ocks.org/mbostock/4573883 // get max/min range for all the quantized cell values // returns an array where each element is [start,stop] // of color bin function quantizeLegendValues() { var e = heatMap.colorScale(), legendVals; if (typeof e.domain()[0] === 'string') { // if color scale is ordinal legendVals = e.domain(); } else { // if color scale is numeric legendVals = e.range().map(function(color) { var d = e.invertExtent(color); if (d[0] === null) d[0] = e.domain()[0]; if (d[1] === null) d[1] = e.domain()[1]; return d; }) } return legendVals } // return true if row metadata specified by user function hasRowMeta() { return typeof heatMap.yMeta() === 'function' } // return true if col metadata specified by user function hasColumnMeta() { return typeof heatMap.xMeta() === 'function' } var renderWatch = nv.utils.renderWatch(dispatch, duration); function chart(selection) { renderWatch.reset(); renderWatch.models(heatMap); renderWatch.models(xAxis); renderWatch.models(yAxis); selection.each(function(data) { var container = d3.select(this), that = this; nv.utils.initSVG(container); var availableWidth = nv.utils.availableWidth(width, container, margin), availableHeight = nv.utils.availableHeight(height, container, margin); chart.update = function() { dispatch.beforeUpdate(); container.transition().duration(duration).call(chart); }; chart.container = this; // Display No Data message if there's nothing to show. if (!data || !data.length) { nv.utils.noData(chart, container); return chart; } else { container.selectAll('.nv-noData').remove(); } // Setup Scales x = heatMap.xScale(); y = heatMap.yScale(); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap').data([data]); var gEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap').append('g'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-heatMap'); gEnter.append('g').attr('class', 'nv-legendWrap'); gEnter.append('g').attr('class', 'nv-x nv-axis'); gEnter.append('g').attr('class', 'nv-y nv-axis') g.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); heatMap .width(availableWidth) .height(availableHeight); var heatMapWrap = g.select('.nv-heatMap') .datum(data.filter(function(d) { return !d.disabled })); heatMapWrap.transition().call(heatMap); if (heatMap.cellAspectRatio()) { availableHeight = heatMap.cellHeight() * y.domain().length; heatMap.height(availableHeight); } // Setup Axes xAxis .scale(x) ._ticks( nv.utils.calcTicksX(availableWidth/100, data) ) .tickSize(-availableHeight, 0); var axisX = g.select('.nv-x.nv-axis') axisX.call(xAxis) .watchTransition(renderWatch, 'heatMap: axisX') .selectAll('.tick') .style('opacity', function() { return showXAxis ? 1 : 0 } ) var xTicks = axisX.selectAll('g'); xTicks .selectAll('.tick text') .attr('transform', function(d,i,j) { var rot = rotateLabels != 0 ? rotateLabels : '0'; var stagger = staggerLabels ? j % 2 == 0 ? '5' : '17' : '0'; return 'translate(0, ' + stagger + ') rotate(' + rot + ' 0,0)'; }) .style('text-anchor', rotateLabels > 0 ? 'start' : rotateLabels < 0 ? 'end' : 'middle'); // position text in center of meta rects var yPos = -5; if (hasColumnMeta()) { axisX.selectAll('text').style('text-anchor', 'middle') yPos = -heatMap.xMetaHeight()()/2 - heatMap.metaOffset() + 3; } // adjust position of axis based on presence of metadata group if (alignXAxis == 'bottom') { axisX .watchTransition(renderWatch, 'heatMap: axisX') .attr("transform", "translate(0," + (availableHeight - yPos) + ")"); if (heatMap.xMeta() !== false) { // if showing x metadata var pos = availableHeight+heatMap.metaOffset()+heatMap.cellBorderWidth() g.select('.xMetaWrap') .watchTransition(renderWatch, 'heatMap: xMetaWrap') .attr("transform", function(d,i) { return "translate(0," + pos + ")" }) } } else { axisX .watchTransition(renderWatch, 'heatMap: axisX') .attr("transform", "translate(0," + yPos + ")"); } yAxis .scale(y) ._ticks( nv.utils.calcTicksY(availableHeight/36, data) ) .tickSize( -availableWidth, 0); var axisY = g.select('.nv-y.nv-axis') axisY.call(yAxis) .watchTransition(renderWatch, 'heatMap: axisY') .selectAll('.tick') .style('opacity', function() { return showYAxis ? 1 : 0 } ) // position text in center of meta rects var xPos = -5; if (hasRowMeta()) { axisY.selectAll('text').style('text-anchor', 'middle') xPos = -heatMap.yMetaWidth()()/2 - heatMap.metaOffset(); } // adjust position of axis based on presence of metadata group if (alignYAxis == 'right') { axisY.attr("transform", "translate(" + (availableWidth - xPos) + ",0)"); if (heatMap.yMeta() !== false) { // if showing y meatdata var pos = availableWidth+heatMap.metaOffset()+heatMap.cellBorderWidth() g.select('.yMetaWrap') .watchTransition(renderWatch, 'heatMap: yMetaWrap') .attr("transform", function(d,i) { return "translate(" + pos + ",0)" }) } } else { axisY.attr("transform", "translate(" + xPos + ",0)"); } // Legend var legendWrap = g.select('.nv-legendWrap') legend .width(availableWidth) .color(heatMap.colorScale().range()) var legendVal = quantizeLegendValues().map(function(d) { if (Array.isArray(d)) { // if cell values are numeric return {key: d[0].toFixed(1) + " - " + d[1].toFixed(1)}; } else { // if cell values are ordinal return {key: d}; } }) legendWrap .datum(legendVal) .call(legend) .attr('transform', 'translate(0,' + (alignXAxis == 'top' ? availableHeight : -30) + ')'); // TODO: more intelligent offset (-30) when top aligning legend legendWrap .watchTransition(renderWatch, 'heatMap: nv-legendWrap') .style('opacity', function() { return showLegend ? 1 : 0 } ) }); // axis don't have a flag for disabling the zero line, so we do it manually d3.selectAll('.nv-axis').selectAll('line') .style('stroke-opacity', 0) d3.select('.nv-y').select('path.domain').remove() renderWatch.renderEnd('heatMap chart immediate'); return chart; } //============================================================ // Event Handling/Dispatching (out of chart's scope) //------------------------------------------------------------ heatMap.dispatch.on('elementMouseover.tooltip', function(evt) { tooltip.data(evt).hidden(false); }); heatMap.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true); }); heatMap.dispatch.on('elementMousemove.tooltip', function(evt) { tooltip(); }); //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.dispatch = dispatch; chart.heatMap = heatMap; chart.legend = legend; chart.xAxis = xAxis; chart.yAxis = yAxis; chart.tooltip = tooltip; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, showLegend: {get: function(){return showLegend;}, set: function(_){showLegend=_;}}, noData: {get: function(){return noData;}, set: function(_){noData=_;}}, showXAxis: {get: function(){return showXAxis;}, set: function(_){showXAxis=_;}}, showYAxis: {get: function(){return showYAxis;}, set: function(_){showYAxis=_;}}, staggerLabels: {get: function(){return staggerLabels;}, set: function(_){staggerLabels=_;}}, rotateLabels: {get: function(){return rotateLabels;}, set: function(_){rotateLabels=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ if (_.top !== undefined) { margin.top = _.top; marginTop = _.top; } margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; renderWatch.reset(duration); heatMap.duration(duration); xAxis.duration(duration); yAxis.duration(duration); }}, alignYAxis: {get: function(){return alignYAxis;}, set: function(_){ alignYAxis = _; yAxis.orient(_); }}, alignXAxis: {get: function(){return alignXAxis;}, set: function(_){ alignXAxis = _; xAxis.orient(_); }}, }); nv.utils.inheritOptions(chart, heatMap); nv.utils.initOptions(chart); return chart; } ================================================ FILE: src/models/historicalBar.js ================================================ //TODO: consider deprecating and using multibar with single series for this nv.models.historicalBar = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 0, right: 0, bottom: 0, left: 0} , width = null , height = null , id = Math.floor(Math.random() * 10000) //Create semi-unique ID in case user doesn't select one , container = null , x = d3.scale.linear() , y = d3.scale.linear() , getX = function(d) { return d.x } , getY = function(d) { return d.y } , forceX = [] , forceY = [0] , padData = false , clipEdge = true , color = nv.utils.defaultColor() , xDomain , yDomain , xRange , yRange , dispatch = d3.dispatch('chartClick', 'elementClick', 'elementDblClick', 'elementMouseover', 'elementMouseout', 'elementMousemove', 'renderEnd') , interactive = true ; var renderWatch = nv.utils.renderWatch(dispatch, 0); function chart(selection) { selection.each(function(data) { renderWatch.reset(); container = d3.select(this); var availableWidth = nv.utils.availableWidth(width, container, margin), availableHeight = nv.utils.availableHeight(height, container, margin); nv.utils.initSVG(container); // Setup Scales x.domain(xDomain || d3.extent(data[0].values.map(getX).concat(forceX) )); if (padData) x.range(xRange || [availableWidth * .5 / data[0].values.length, availableWidth * (data[0].values.length - .5) / data[0].values.length ]); else x.range(xRange || [0, availableWidth]); y.domain(yDomain || d3.extent(data[0].values.map(getY).concat(forceY) )) .range(yRange || [availableHeight, 0]); // If scale's domain don't have a range, slightly adjust to make one... so a chart can show a single data point if (x.domain()[0] === x.domain()[1]) x.domain()[0] ? x.domain([x.domain()[0] - x.domain()[0] * 0.01, x.domain()[1] + x.domain()[1] * 0.01]) : x.domain([-1,1]); if (y.domain()[0] === y.domain()[1]) y.domain()[0] ? y.domain([y.domain()[0] + y.domain()[0] * 0.01, y.domain()[1] - y.domain()[1] * 0.01]) : y.domain([-1,1]); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-historicalBar-' + id).data([data[0].values]); var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-historicalBar-' + id); var defsEnter = wrapEnter.append('defs'); var gEnter = wrapEnter.append('g'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-bars'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); container .on('click', function(d,i) { dispatch.chartClick({ data: d, index: i, pos: d3.event, id: id }); }); defsEnter.append('clipPath') .attr('id', 'nv-chart-clip-path-' + id) .append('rect'); wrap.select('#nv-chart-clip-path-' + id + ' rect') .attr('width', availableWidth) .attr('height', availableHeight); g.attr('clip-path', clipEdge ? 'url(#nv-chart-clip-path-' + id + ')' : ''); var bars = wrap.select('.nv-bars').selectAll('.nv-bar') .data(function(d) { return d }, function(d,i) {return getX(d,i)}); bars.exit().remove(); bars.enter().append('rect') .attr('x', 0 ) .attr('y', function(d,i) { return nv.utils.NaNtoZero(y(Math.max(0, getY(d,i)))) }) .attr('height', function(d,i) { return nv.utils.NaNtoZero(Math.abs(y(getY(d,i)) - y(0))) }) .attr('transform', function(d,i) { return 'translate(' + (x(getX(d,i)) - availableWidth / data[0].values.length * .45) + ',0)'; }) .on('mouseover', function(d,i) { if (!interactive) return; d3.select(this).classed('hover', true); dispatch.elementMouseover({ data: d, index: i, color: d3.select(this).style("fill") }); }) .on('mouseout', function(d,i) { if (!interactive) return; d3.select(this).classed('hover', false); dispatch.elementMouseout({ data: d, index: i, color: d3.select(this).style("fill") }); }) .on('mousemove', function(d,i) { if (!interactive) return; dispatch.elementMousemove({ data: d, index: i, color: d3.select(this).style("fill") }); }) .on('click', function(d,i) { if (!interactive) return; var element = this; dispatch.elementClick({ data: d, index: i, color: d3.select(this).style("fill"), event: d3.event, element: element }); d3.event.stopPropagation(); }) .on('dblclick', function(d,i) { if (!interactive) return; dispatch.elementDblClick({ data: d, index: i, color: d3.select(this).style("fill") }); d3.event.stopPropagation(); }); bars .attr('fill', function(d,i) { return color(d, i); }) .attr('class', function(d,i,j) { return (getY(d,i) < 0 ? 'nv-bar negative' : 'nv-bar positive') + ' nv-bar-' + j + '-' + i }) .watchTransition(renderWatch, 'bars') .attr('transform', function(d,i) { return 'translate(' + (x(getX(d,i)) - availableWidth / data[0].values.length * .45) + ',0)'; }) //TODO: better width calculations that don't assume always uniform data spacing;w .attr('width', (availableWidth / data[0].values.length) * .9 ); bars.watchTransition(renderWatch, 'bars') .attr('y', function(d,i) { var rval = getY(d,i) < 0 ? y(0) : y(0) - y(getY(d,i)) < 1 ? y(0) - 1 : y(getY(d,i)); return nv.utils.NaNtoZero(rval); }) .attr('height', function(d,i) { return nv.utils.NaNtoZero(Math.max(Math.abs(y(getY(d,i)) - y(0)),1)) }); }); renderWatch.renderEnd('historicalBar immediate'); return chart; } //Create methods to allow outside functions to highlight a specific bar. chart.highlightPoint = function(pointIndex, isHoverOver) { container .select(".nv-bars .nv-bar-0-" + pointIndex) .classed("hover", isHoverOver) ; }; chart.clearHighlights = function() { container .select(".nv-bars .nv-bar.hover") .classed("hover", false) ; }; //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.dispatch = dispatch; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, forceX: {get: function(){return forceX;}, set: function(_){forceX=_;}}, forceY: {get: function(){return forceY;}, set: function(_){forceY=_;}}, padData: {get: function(){return padData;}, set: function(_){padData=_;}}, x: {get: function(){return getX;}, set: function(_){getX=_;}}, y: {get: function(){return getY;}, set: function(_){getY=_;}}, xScale: {get: function(){return x;}, set: function(_){x=_;}}, yScale: {get: function(){return y;}, set: function(_){y=_;}}, xDomain: {get: function(){return xDomain;}, set: function(_){xDomain=_;}}, yDomain: {get: function(){return yDomain;}, set: function(_){yDomain=_;}}, xRange: {get: function(){return xRange;}, set: function(_){xRange=_;}}, yRange: {get: function(){return yRange;}, set: function(_){yRange=_;}}, clipEdge: {get: function(){return clipEdge;}, set: function(_){clipEdge=_;}}, id: {get: function(){return id;}, set: function(_){id=_;}}, interactive: {get: function(){return interactive;}, set: function(_){interactive=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); }} }); nv.utils.initOptions(chart); return chart; }; ================================================ FILE: src/models/historicalBarChart.js ================================================ nv.models.historicalBarChart = function(bar_model) { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var bars = bar_model || nv.models.historicalBar() , xAxis = nv.models.axis() , yAxis = nv.models.axis() , legend = nv.models.legend() , interactiveLayer = nv.interactiveGuideline() , tooltip = nv.models.tooltip() ; var margin = {top: 30, right: 90, bottom: 50, left: 90} , marginTop = null , color = nv.utils.defaultColor() , width = null , height = null , showLegend = false , showXAxis = true , showYAxis = true , rightAlignYAxis = false , useInteractiveGuideline = false , x , y , state = {} , defaultState = null , noData = null , dispatch = d3.dispatch('tooltipHide', 'stateChange', 'changeState', 'renderEnd') , transitionDuration = 250 ; xAxis.orient('bottom').tickPadding(7); yAxis.orient( (rightAlignYAxis) ? 'right' : 'left'); tooltip .duration(0) .headerEnabled(false) .valueFormatter(function(d, i) { return yAxis.tickFormat()(d, i); }) .headerFormatter(function(d, i) { return xAxis.tickFormat()(d, i); }); //============================================================ // Private Variables //------------------------------------------------------------ var renderWatch = nv.utils.renderWatch(dispatch, 0); function chart(selection) { selection.each(function(data) { renderWatch.reset(); renderWatch.models(bars); if (showXAxis) renderWatch.models(xAxis); if (showYAxis) renderWatch.models(yAxis); var container = d3.select(this), that = this; nv.utils.initSVG(container); var availableWidth = nv.utils.availableWidth(width, container, margin), availableHeight = nv.utils.availableHeight(height, container, margin); chart.update = function() { container.transition().duration(transitionDuration).call(chart) }; chart.container = this; //set state.disabled state.disabled = data.map(function(d) { return !!d.disabled }); if (!defaultState) { var key; defaultState = {}; for (key in state) { if (state[key] instanceof Array) defaultState[key] = state[key].slice(0); else defaultState[key] = state[key]; } } // Display noData message if there's nothing to show. if (!data || !data.length || !data.filter(function(d) { return d.values.length }).length) { nv.utils.noData(chart, container) return chart; } else { container.selectAll('.nv-noData').remove(); } // Setup Scales x = bars.xScale(); y = bars.yScale(); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-historicalBarChart').data([data]); var gEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-historicalBarChart').append('g'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-x nv-axis'); gEnter.append('g').attr('class', 'nv-y nv-axis'); gEnter.append('g').attr('class', 'nv-barsWrap'); gEnter.append('g').attr('class', 'nv-legendWrap'); gEnter.append('g').attr('class', 'nv-interactive'); // Legend if (!showLegend) { g.select('.nv-legendWrap').selectAll('*').remove(); } else { legend.width(availableWidth); g.select('.nv-legendWrap') .datum(data) .call(legend); if (!marginTop && legend.height() !== margin.top) { margin.top = legend.height(); availableHeight = nv.utils.availableHeight(height, container, margin); } wrap.select('.nv-legendWrap') .attr('transform', 'translate(0,' + (-margin.top) +')') } wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); if (rightAlignYAxis) { g.select(".nv-y.nv-axis") .attr("transform", "translate(" + availableWidth + ",0)"); } //Set up interactive layer if (useInteractiveGuideline) { interactiveLayer .width(availableWidth) .height(availableHeight) .margin({left:margin.left, top:margin.top}) .svgContainer(container) .xScale(x); wrap.select(".nv-interactive").call(interactiveLayer); } bars .width(availableWidth) .height(availableHeight) .color(data.map(function(d,i) { return d.color || color(d, i); }).filter(function(d,i) { return !data[i].disabled })); var barsWrap = g.select('.nv-barsWrap') .datum(data.filter(function(d) { return !d.disabled })); barsWrap.transition().call(bars); // Setup Axes if (showXAxis) { xAxis .scale(x) ._ticks( nv.utils.calcTicksX(availableWidth/100, data) ) .tickSize(-availableHeight, 0); g.select('.nv-x.nv-axis') .attr('transform', 'translate(0,' + y.range()[0] + ')'); g.select('.nv-x.nv-axis') .transition() .call(xAxis); } if (showYAxis) { yAxis .scale(y) ._ticks( nv.utils.calcTicksY(availableHeight/36, data) ) .tickSize( -availableWidth, 0); g.select('.nv-y.nv-axis') .transition() .call(yAxis); } //============================================================ // Event Handling/Dispatching (in chart's scope) //------------------------------------------------------------ interactiveLayer.dispatch.on('elementMousemove', function(e) { bars.clearHighlights(); var singlePoint, pointIndex, pointXLocation, allData = []; data .filter(function(series, i) { series.seriesIndex = i; return !series.disabled; }) .forEach(function(series,i) { pointIndex = nv.interactiveBisect(series.values, e.pointXValue, chart.x()); bars.highlightPoint(pointIndex,true); var point = series.values[pointIndex]; if (point === undefined) return; if (singlePoint === undefined) singlePoint = point; if (pointXLocation === undefined) pointXLocation = chart.xScale()(chart.x()(point,pointIndex)); allData.push({ key: series.key, value: chart.y()(point, pointIndex), color: color(series,series.seriesIndex), data: series.values[pointIndex] }); }); var xValue = xAxis.tickFormat()(chart.x()(singlePoint,pointIndex)); interactiveLayer.tooltip .valueFormatter(function(d,i) { return yAxis.tickFormat()(d); }) .data({ value: xValue, index: pointIndex, series: allData })(); interactiveLayer.renderGuideLine(pointXLocation); }); interactiveLayer.dispatch.on("elementMouseout",function(e) { dispatch.tooltipHide(); bars.clearHighlights(); }); legend.dispatch.on('legendClick', function(d,i) { d.disabled = !d.disabled; if (!data.filter(function(d) { return !d.disabled }).length) { data.map(function(d) { d.disabled = false; wrap.selectAll('.nv-series').classed('disabled', false); return d; }); } state.disabled = data.map(function(d) { return !!d.disabled }); dispatch.stateChange(state); selection.transition().call(chart); }); legend.dispatch.on('legendDblclick', function(d) { //Double clicking should always enable current series, and disabled all others. data.forEach(function(d) { d.disabled = true; }); d.disabled = false; state.disabled = data.map(function(d) { return !!d.disabled }); dispatch.stateChange(state); chart.update(); }); dispatch.on('changeState', function(e) { if (typeof e.disabled !== 'undefined') { data.forEach(function(series,i) { series.disabled = e.disabled[i]; }); state.disabled = e.disabled; } chart.update(); }); }); renderWatch.renderEnd('historicalBarChart immediate'); return chart; } //============================================================ // Event Handling/Dispatching (out of chart's scope) //------------------------------------------------------------ bars.dispatch.on('elementMouseover.tooltip', function(evt) { evt['series'] = { key: chart.x()(evt.data), value: chart.y()(evt.data), color: evt.color }; tooltip.data(evt).hidden(false); }); bars.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true); }); bars.dispatch.on('elementMousemove.tooltip', function(evt) { tooltip(); }); //============================================================ // Expose Public Variables //------------------------------------------------------------ // expose chart's sub-components chart.dispatch = dispatch; chart.bars = bars; chart.legend = legend; chart.xAxis = xAxis; chart.yAxis = yAxis; chart.interactiveLayer = interactiveLayer; chart.tooltip = tooltip; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, showLegend: {get: function(){return showLegend;}, set: function(_){showLegend=_;}}, showXAxis: {get: function(){return showXAxis;}, set: function(_){showXAxis=_;}}, showYAxis: {get: function(){return showYAxis;}, set: function(_){showYAxis=_;}}, defaultState: {get: function(){return defaultState;}, set: function(_){defaultState=_;}}, noData: {get: function(){return noData;}, set: function(_){noData=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ if (_.top !== undefined) { margin.top = _.top; marginTop = _.top; } margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); legend.color(color); bars.color(color); }}, duration: {get: function(){return transitionDuration;}, set: function(_){ transitionDuration=_; renderWatch.reset(transitionDuration); yAxis.duration(transitionDuration); xAxis.duration(transitionDuration); }}, rightAlignYAxis: {get: function(){return rightAlignYAxis;}, set: function(_){ rightAlignYAxis = _; yAxis.orient( (_) ? 'right' : 'left'); }}, useInteractiveGuideline: {get: function(){return useInteractiveGuideline;}, set: function(_){ useInteractiveGuideline = _; if (_ === true) { chart.interactive(false); } }} }); nv.utils.inheritOptions(chart, bars); nv.utils.initOptions(chart); return chart; }; // ohlcChart is just a historical chart with ohlc bars and some tweaks nv.models.ohlcBarChart = function() { var chart = nv.models.historicalBarChart(nv.models.ohlcBar()); // special default tooltip since we show multiple values per x chart.useInteractiveGuideline(true); chart.interactiveLayer.tooltip.contentGenerator(function(data) { // we assume only one series exists for this chart var d = data.series[0].data; // match line colors as defined in nv.d3.css var color = d.open < d.close ? "2ca02c" : "d62728"; return '' + '

' + data.value + '

' + '' + '' + '' + '' + '' + '
open:' + chart.yAxis.tickFormat()(d.open) + '
close:' + chart.yAxis.tickFormat()(d.close) + '
high' + chart.yAxis.tickFormat()(d.high) + '
low:' + chart.yAxis.tickFormat()(d.low) + '
'; }); return chart; }; // candlestickChart is just a historical chart with candlestick bars and some tweaks nv.models.candlestickBarChart = function() { var chart = nv.models.historicalBarChart(nv.models.candlestickBar()); // special default tooltip since we show multiple values per x chart.useInteractiveGuideline(true); chart.interactiveLayer.tooltip.contentGenerator(function(data) { // we assume only one series exists for this chart var d = data.series[0].data; // match line colors as defined in nv.d3.css var color = d.open < d.close ? "2ca02c" : "d62728"; return '' + '

' + data.value + '

' + '' + '' + '' + '' + '' + '
open:' + chart.yAxis.tickFormat()(d.open) + '
close:' + chart.yAxis.tickFormat()(d.close) + '
high' + chart.yAxis.tickFormat()(d.high) + '
low:' + chart.yAxis.tickFormat()(d.low) + '
'; }); return chart; }; ================================================ FILE: src/models/legend.js ================================================ nv.models.legend = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 5, right: 0, bottom: 5, left: 0} , width = 400 , height = 20 , getKey = function(d) { return d.key } , keyFormatter = function (d) { return d } , color = nv.utils.getColor() , maxKeyLength = 20 //default value for key lengths , align = true , padding = 32 //define how much space between legend items. - recommend 32 for furious version , rightAlign = true , updateState = true //If true, legend will update data.disabled and trigger a 'stateChange' dispatch. , enableDoubleClick = true //If true, legend will enable double click handling , radioButtonMode = false //If true, clicking legend items will cause it to behave like a radio button. (only one can be selected at a time) , expanded = false , dispatch = d3.dispatch('legendClick', 'legendDblclick', 'legendMouseover', 'legendMouseout', 'stateChange') , vers = 'classic' //Options are "classic" and "furious" ; function chart(selection) { selection.each(function(data) { var availableWidth = width - margin.left - margin.right, container = d3.select(this); nv.utils.initSVG(container); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-legend').data([data]); var gEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-legend').append('g'); var g = wrap.select('g'); if (rightAlign) wrap.attr('transform', 'translate(' + (- margin.right) + ',' + margin.top + ')'); else wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); var series = g.selectAll('.nv-series') .data(function(d) { if(vers != 'furious') return d; return d.filter(function(n) { return expanded ? true : !n.disengaged; }); }); var seriesEnter = series.enter().append('g').attr('class', 'nv-series'); var seriesShape; var versPadding; switch(vers) { case 'furious' : versPadding = 23; break; case 'classic' : versPadding = 20; } if(vers == 'classic') { seriesEnter.append('circle') .style('stroke-width', 2) .attr('class','nv-legend-symbol') .attr('r', 5); seriesShape = series.select('.nv-legend-symbol'); } else if (vers == 'furious') { seriesEnter.append('rect') .style('stroke-width', 2) .attr('class','nv-legend-symbol') .attr('rx', 3) .attr('ry', 3); seriesShape = series.select('.nv-legend-symbol'); seriesEnter.append('g') .attr('class', 'nv-check-box') .property('innerHTML','') .attr('transform', 'translate(-10,-8)scale(0.5)'); var seriesCheckbox = series.select('.nv-check-box'); seriesCheckbox.each(function(d,i) { d3.select(this).selectAll('path') .attr('stroke', setTextColor(d,i)); }); } seriesEnter.append('text') .attr('text-anchor', 'start') .attr('class','nv-legend-text') .attr('dy', '.32em') .attr('dx', '8'); var seriesText = series.select('text.nv-legend-text'); series .on('mouseover', function(d,i) { dispatch.legendMouseover(d,i); //TODO: Make consistent with other event objects }) .on('mouseout', function(d,i) { dispatch.legendMouseout(d,i); }) .on('click', function(d,i) { dispatch.legendClick(d,i); // make sure we re-get data in case it was modified var data = series.data(); if (updateState) { if(vers =='classic') { if (radioButtonMode) { //Radio button mode: set every series to disabled, // and enable the clicked series. data.forEach(function(series) { series.disabled = true}); d.disabled = false; } else { d.disabled = !d.disabled; if (data.every(function(series) { return series.disabled})) { //the default behavior of NVD3 legends is, if every single series // is disabled, turn all series' back on. data.forEach(function(series) { series.disabled = false}); } } } else if(vers == 'furious') { if(expanded) { d.disengaged = !d.disengaged; d.userDisabled = d.userDisabled == undefined ? !!d.disabled : d.userDisabled; d.disabled = d.disengaged || d.userDisabled; } else if (!expanded) { d.disabled = !d.disabled; d.userDisabled = d.disabled; var engaged = data.filter(function(d) { return !d.disengaged; }); if (engaged.every(function(series) { return series.userDisabled })) { //the default behavior of NVD3 legends is, if every single series // is disabled, turn all series' back on. data.forEach(function(series) { series.disabled = series.userDisabled = false; }); } } } dispatch.stateChange({ disabled: data.map(function(d) { return !!d.disabled }), disengaged: data.map(function(d) { return !!d.disengaged }) }); } }) .on('dblclick', function(d,i) { if (enableDoubleClick) { if (vers == 'furious' && expanded) return; dispatch.legendDblclick(d, i); if (updateState) { // make sure we re-get data in case it was modified var data = series.data(); //the default behavior of NVD3 legends, when double clicking one, // is to set all other series' to false, and make the double clicked series enabled. data.forEach(function (series) { series.disabled = true; if (vers == 'furious') series.userDisabled = series.disabled; }); d.disabled = false; if (vers == 'furious') d.userDisabled = d.disabled; dispatch.stateChange({ disabled: data.map(function (d) { return !!d.disabled }) }); } } }); series.classed('nv-disabled', function(d) { return d.userDisabled }); series.exit().remove(); seriesText .attr('fill', setTextColor) .text(function (d) { return keyFormatter(getKey(d)) }); //TODO: implement fixed-width and max-width options (max-width is especially useful with the align option) // NEW ALIGNING CODE, TODO: clean up var legendWidth = 0; if (align) { var seriesWidths = []; series.each(function(d,i) { var legendText; if (keyFormatter(getKey(d)) && keyFormatter(getKey(d)).length > maxKeyLength) { var trimmedKey = keyFormatter(getKey(d)).substring(0, maxKeyLength); legendText = d3.select(this).select('text').text(trimmedKey + "..."); d3.select(this).append("svg:title").text(keyFormatter(getKey(d))); } else { legendText = d3.select(this).select('text'); } var nodeTextLength; try { nodeTextLength = legendText.node().getComputedTextLength(); // If the legendText is display:none'd (nodeTextLength == 0), simulate an error so we approximate, instead if(nodeTextLength <= 0) throw Error(); } catch(e) { nodeTextLength = nv.utils.calcApproxTextWidth(legendText); } seriesWidths.push(nodeTextLength + padding); }); var seriesPerRow = 0; var columnWidths = []; legendWidth = 0; while ( legendWidth < availableWidth && seriesPerRow < seriesWidths.length) { columnWidths[seriesPerRow] = seriesWidths[seriesPerRow]; legendWidth += seriesWidths[seriesPerRow++]; } if (seriesPerRow === 0) seriesPerRow = 1; //minimum of one series per row while ( legendWidth > availableWidth && seriesPerRow > 1 ) { columnWidths = []; seriesPerRow--; for (var k = 0; k < seriesWidths.length; k++) { if (seriesWidths[k] > (columnWidths[k % seriesPerRow] || 0) ) columnWidths[k % seriesPerRow] = seriesWidths[k]; } legendWidth = columnWidths.reduce(function(prev, cur, index, array) { return prev + cur; }); } var xPositions = []; for (var i = 0, curX = 0; i < seriesPerRow; i++) { xPositions[i] = curX; curX += columnWidths[i]; } series .attr('transform', function(d, i) { return 'translate(' + xPositions[i % seriesPerRow] + ',' + (5 + Math.floor(i / seriesPerRow) * versPadding) + ')'; }); //position legend as far right as possible within the total width if (rightAlign) { g.attr('transform', 'translate(' + (width - margin.right - legendWidth) + ',' + margin.top + ')'); } else { g.attr('transform', 'translate(0' + ',' + margin.top + ')'); } height = margin.top + margin.bottom + (Math.ceil(seriesWidths.length / seriesPerRow) * versPadding); } else { var ypos = 5, newxpos = 5, maxwidth = 0, xpos; series .attr('transform', function(d, i) { var length = d3.select(this).select('text').node().getComputedTextLength() + padding; xpos = newxpos; if (width < margin.left + margin.right + xpos + length) { newxpos = xpos = 5; ypos += versPadding; } newxpos += length; if (newxpos > maxwidth) maxwidth = newxpos; if(legendWidth < xpos + maxwidth) { legendWidth = xpos + maxwidth; } return 'translate(' + xpos + ',' + ypos + ')'; }); //position legend as far right as possible within the total width g.attr('transform', 'translate(' + (width - margin.right - maxwidth) + ',' + margin.top + ')'); height = margin.top + margin.bottom + ypos + 15; } if(vers == 'furious') { // Size rectangles after text is placed seriesShape .attr('width', function(d,i) { return seriesText[0][i].getComputedTextLength() + 27; }) .attr('height', 18) .attr('y', -9) .attr('x', -15); // The background for the expanded legend (UI) gEnter.insert('rect',':first-child') .attr('class', 'nv-legend-bg') .attr('fill', '#eee') // .attr('stroke', '#444') .attr('opacity',0); var seriesBG = g.select('.nv-legend-bg'); seriesBG .transition().duration(300) .attr('x', -versPadding ) .attr('width', legendWidth + versPadding - 12) .attr('height', height + 10) .attr('y', -margin.top - 10) .attr('opacity', expanded ? 1 : 0); } seriesShape .style('fill', setBGColor) .style('fill-opacity', setBGOpacity) .style('stroke', setBGColor); }); function setTextColor(d,i) { if(vers != 'furious') return '#000'; if(expanded) { return d.disengaged ? '#000' : '#fff'; } else if (!expanded) { if(!d.color) d.color = color(d,i); return !!d.disabled ? d.color : '#fff'; } } function setBGColor(d,i) { if(expanded && vers == 'furious') { return d.disengaged ? '#eee' : d.color || color(d,i); } else { return d.color || color(d,i); } } function setBGOpacity(d,i) { if(expanded && vers == 'furious') { return 1; } else { return !!d.disabled ? 0 : 1; } } return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.dispatch = dispatch; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, key: {get: function(){return getKey;}, set: function(_){getKey=_;}}, keyFormatter: {get: function(){return keyFormatter;}, set: function(_){keyFormatter=_;}}, align: {get: function(){return align;}, set: function(_){align=_;}}, maxKeyLength: {get: function(){return maxKeyLength;}, set: function(_){maxKeyLength=_;}}, rightAlign: {get: function(){return rightAlign;}, set: function(_){rightAlign=_;}}, padding: {get: function(){return padding;}, set: function(_){padding=_;}}, updateState: {get: function(){return updateState;}, set: function(_){updateState=_;}}, enableDoubleClick: {get: function(){return enableDoubleClick;}, set: function(_){enableDoubleClick=_;}}, radioButtonMode:{get: function(){return radioButtonMode;}, set: function(_){radioButtonMode=_;}}, expanded: {get: function(){return expanded;}, set: function(_){expanded=_;}}, vers: {get: function(){return vers;}, set: function(_){vers=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); }} }); nv.utils.initOptions(chart); return chart; }; ================================================ FILE: src/models/line.js ================================================ nv.models.line = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var scatter = nv.models.scatter() ; var margin = {top: 0, right: 0, bottom: 0, left: 0} , width = 960 , height = 500 , container = null , strokeWidth = 1.5 , color = nv.utils.defaultColor() // a function that returns a color , getX = function(d) { return d.x } // accessor to get the x value from a data point , getY = function(d) { return d.y } // accessor to get the y value from a data point , defined = function(d,i) { return !isNaN(getY(d,i)) && getY(d,i) !== null } // allows a line to be not continuous when it is not defined , isArea = function(d) { return d.area } // decides if a line is an area or just a line , clipEdge = false // if true, masks lines within x and y scale , x //can be accessed via chart.xScale() , y //can be accessed via chart.yScale() , interpolate = "linear" // controls the line interpolation , duration = 250 , dispatch = d3.dispatch('elementClick', 'elementMouseover', 'elementMouseout', 'renderEnd') ; scatter .pointSize(16) // default size .pointDomain([16,256]) //set to speed up calculation, needs to be unset if there is a custom size accessor ; //============================================================ //============================================================ // Private Variables //------------------------------------------------------------ var x0, y0 //used to store previous scales , renderWatch = nv.utils.renderWatch(dispatch, duration) ; //============================================================ function chart(selection) { renderWatch.reset(); renderWatch.models(scatter); selection.each(function(data) { container = d3.select(this); var availableWidth = nv.utils.availableWidth(width, container, margin), availableHeight = nv.utils.availableHeight(height, container, margin); nv.utils.initSVG(container); // Setup Scales x = scatter.xScale(); y = scatter.yScale(); x0 = x0 || x; y0 = y0 || y; // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-line').data([data]); var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-line'); var defsEnter = wrapEnter.append('defs'); var gEnter = wrapEnter.append('g'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-groups'); gEnter.append('g').attr('class', 'nv-scatterWrap'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); scatter .width(availableWidth) .height(availableHeight); var scatterWrap = wrap.select('.nv-scatterWrap'); scatterWrap.call(scatter); defsEnter.append('clipPath') .attr('id', 'nv-edge-clip-' + scatter.id()) .append('rect'); wrap.select('#nv-edge-clip-' + scatter.id() + ' rect') .attr('width', availableWidth) .attr('height', (availableHeight > 0) ? availableHeight : 0); g .attr('clip-path', clipEdge ? 'url(#nv-edge-clip-' + scatter.id() + ')' : ''); scatterWrap .attr('clip-path', clipEdge ? 'url(#nv-edge-clip-' + scatter.id() + ')' : ''); var groups = wrap.select('.nv-groups').selectAll('.nv-group') .data(function(d) { return d }, function(d) { return d.key }); groups.enter().append('g') .style('stroke-opacity', 1e-6) .style('stroke-width', function(d) { return d.strokeWidth || strokeWidth }) .style('fill-opacity', 1e-6); groups.exit().remove(); groups .attr('class', function(d,i) { return (d.classed || '') + ' nv-group nv-series-' + i; }) .classed('hover', function(d) { return d.hover }) .style('fill', function(d,i){ return color(d, i) }) .style('stroke', function(d,i){ return color(d, i)}); groups.watchTransition(renderWatch, 'line: groups') .style('stroke-opacity', 1) .style('fill-opacity', function(d) { return d.fillOpacity || .5}); var areaPaths = groups.selectAll('path.nv-area') .data(function(d) { return isArea(d) ? [d] : [] }); // this is done differently than lines because I need to check if series is an area areaPaths.enter().append('path') .attr('class', 'nv-area') .attr('d', function(d) { return d3.svg.area() .interpolate(interpolate) .defined(defined) .x(function(d,i) { return nv.utils.NaNtoZero(x0(getX(d,i))) }) .y0(function(d,i) { return nv.utils.NaNtoZero(y0(getY(d,i))) }) .y1(function(d,i) { return y0( y.domain()[0] <= 0 ? y.domain()[1] >= 0 ? 0 : y.domain()[1] : y.domain()[0] ) }) //.y1(function(d,i) { return y0(0) }) //assuming 0 is within y domain.. may need to tweak this .apply(this, [d.values]) }); groups.exit().selectAll('path.nv-area') .remove(); areaPaths.watchTransition(renderWatch, 'line: areaPaths') .attr('d', function(d) { return d3.svg.area() .interpolate(interpolate) .defined(defined) .x(function(d,i) { return nv.utils.NaNtoZero(x(getX(d,i))) }) .y0(function(d,i) { return nv.utils.NaNtoZero(y(getY(d,i))) }) .y1(function(d,i) { return y( y.domain()[0] <= 0 ? y.domain()[1] >= 0 ? 0 : y.domain()[1] : y.domain()[0] ) }) //.y1(function(d,i) { return y0(0) }) //assuming 0 is within y domain.. may need to tweak this .apply(this, [d.values]) }); var linePaths = groups.selectAll('path.nv-line') .data(function(d) { return [d.values] }); linePaths.enter().append('path') .attr('class', 'nv-line') .attr('d', d3.svg.line() .interpolate(interpolate) .defined(defined) .x(function(d,i) { return nv.utils.NaNtoZero(x0(getX(d,i))) }) .y(function(d,i) { return nv.utils.NaNtoZero(y0(getY(d,i))) }) ); linePaths.watchTransition(renderWatch, 'line: linePaths') .attr('d', d3.svg.line() .interpolate(interpolate) .defined(defined) .x(function(d,i) { return nv.utils.NaNtoZero(x(getX(d,i))) }) .y(function(d,i) { return nv.utils.NaNtoZero(y(getY(d,i))) }) ); //store old scales for use in transitions on update x0 = x.copy(); y0 = y.copy(); }); renderWatch.renderEnd('line immediate'); return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.dispatch = dispatch; chart.scatter = scatter; // Pass through events scatter.dispatch.on('elementClick', function(){ dispatch.elementClick.apply(this, arguments); }); scatter.dispatch.on('elementMouseover', function(){ dispatch.elementMouseover.apply(this, arguments); }); scatter.dispatch.on('elementMouseout', function(){ dispatch.elementMouseout.apply(this, arguments); }); chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, defined: {get: function(){return defined;}, set: function(_){defined=_;}}, interpolate: {get: function(){return interpolate;}, set: function(_){interpolate=_;}}, clipEdge: {get: function(){return clipEdge;}, set: function(_){clipEdge=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; renderWatch.reset(duration); scatter.duration(duration); }}, isArea: {get: function(){return isArea;}, set: function(_){ isArea = d3.functor(_); }}, x: {get: function(){return getX;}, set: function(_){ getX = _; scatter.x(_); }}, y: {get: function(){return getY;}, set: function(_){ getY = _; scatter.y(_); }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); scatter.color(color); }} }); nv.utils.inheritOptions(chart, scatter); nv.utils.initOptions(chart); return chart; }; ================================================ FILE: src/models/lineChart.js ================================================ nv.models.lineChart = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var lines = nv.models.line() , xAxis = nv.models.axis() , yAxis = nv.models.axis() , legend = nv.models.legend() , interactiveLayer = nv.interactiveGuideline() , tooltip = nv.models.tooltip() , focus = nv.models.focus(nv.models.line()) ; var margin = {top: 30, right: 20, bottom: 50, left: 60} , marginTop = null , color = nv.utils.defaultColor() , width = null , height = null , showLegend = true , legendPosition = 'top' , showXAxis = true , showYAxis = true , rightAlignYAxis = false , useInteractiveGuideline = false , x , y , focusEnable = false , state = nv.utils.state() , defaultState = null , noData = null , dispatch = d3.dispatch('stateChange', 'changeState', 'renderEnd') , duration = 250 ; // set options on sub-objects for this chart xAxis.orient('bottom').tickPadding(7); yAxis.orient(rightAlignYAxis ? 'right' : 'left'); lines.clipEdge(true).duration(0); tooltip.valueFormatter(function(d, i) { return yAxis.tickFormat()(d, i); }).headerFormatter(function(d, i) { return xAxis.tickFormat()(d, i); }); interactiveLayer.tooltip.valueFormatter(function(d, i) { return yAxis.tickFormat()(d, i); }).headerFormatter(function(d, i) { return xAxis.tickFormat()(d, i); }); //============================================================ // Private Variables //------------------------------------------------------------ var renderWatch = nv.utils.renderWatch(dispatch, duration); var stateGetter = function(data) { return function(){ return { active: data.map(function(d) { return !d.disabled; }) }; }; }; var stateSetter = function(data) { return function(state) { if (state.active !== undefined) data.forEach(function(series,i) { series.disabled = !state.active[i]; }); }; }; function chart(selection) { renderWatch.reset(); renderWatch.models(lines); if (showXAxis) renderWatch.models(xAxis); if (showYAxis) renderWatch.models(yAxis); selection.each(function(data) { var container = d3.select(this); nv.utils.initSVG(container); var availableWidth = nv.utils.availableWidth(width, container, margin), availableHeight = nv.utils.availableHeight(height, container, margin) - (focusEnable ? focus.height() : 0); chart.update = function() { if( duration === 0 ) { container.call( chart ); } else { container.transition().duration(duration).call(chart); } }; chart.container = this; state .setter(stateSetter(data), chart.update) .getter(stateGetter(data)) .update(); // DEPRECATED set state.disabled state.disabled = data.map(function(d) { return !!d.disabled; }); if (!defaultState) { var key; defaultState = {}; for (key in state) { if (state[key] instanceof Array) defaultState[key] = state[key].slice(0); else defaultState[key] = state[key]; } } // Display noData message if there's nothing to show. if (!data || !data.length || !data.filter(function(d) { return d.values.length; }).length) { nv.utils.noData(chart, container); return chart; } else { container.selectAll('.nv-noData').remove(); } /* Update `main' graph on brush update. */ focus.dispatch.on("onBrush", function(extent) { onBrush(extent); }); // Setup Scales x = lines.xScale(); y = lines.yScale(); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-lineChart').data([data]); var gEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-lineChart').append('g'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-legendWrap'); var focusEnter = gEnter.append('g').attr('class', 'nv-focus'); focusEnter.append('g').attr('class', 'nv-background').append('rect'); focusEnter.append('g').attr('class', 'nv-x nv-axis'); focusEnter.append('g').attr('class', 'nv-y nv-axis'); focusEnter.append('g').attr('class', 'nv-linesWrap'); focusEnter.append('g').attr('class', 'nv-interactive'); var contextEnter = gEnter.append('g').attr('class', 'nv-focusWrap'); // Legend if (!showLegend) { g.select('.nv-legendWrap').selectAll('*').remove(); } else { legend.width(availableWidth); g.select('.nv-legendWrap') .datum(data) .call(legend); if (legendPosition === 'bottom') { margin.bottom = xAxis.height() + legend.height(); availableHeight = nv.utils.availableHeight(height, container, margin); g.select('.nv-legendWrap') .attr('transform', 'translate(0,' + (availableHeight + xAxis.height()) +')'); } else if (legendPosition === 'top') { if (!marginTop && legend.height() !== margin.top) { margin.top = legend.height(); availableHeight = nv.utils.availableHeight(height, container, margin) - (focusEnable ? focus.height() : 0); } wrap.select('.nv-legendWrap') .attr('transform', 'translate(0,' + (-margin.top) +')'); } } wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); if (rightAlignYAxis) { g.select(".nv-y.nv-axis") .attr("transform", "translate(" + availableWidth + ",0)"); } //Set up interactive layer if (useInteractiveGuideline) { interactiveLayer .width(availableWidth) .height(availableHeight) .margin({left:margin.left, top:margin.top}) .svgContainer(container) .xScale(x); wrap.select(".nv-interactive").call(interactiveLayer); } g.select('.nv-focus .nv-background rect') .attr('width', availableWidth) .attr('height', availableHeight); lines .width(availableWidth) .height(availableHeight) .color(data.map(function(d,i) { return d.color || color(d, i); }).filter(function(d,i) { return !data[i].disabled; })); var linesWrap = g.select('.nv-linesWrap') .datum(data.filter(function(d) { return !d.disabled; })); // Setup Main (Focus) Axes if (showXAxis) { xAxis .scale(x) ._ticks(nv.utils.calcTicksX(availableWidth/100, data) ) .tickSize(-availableHeight, 0); } if (showYAxis) { yAxis .scale(y) ._ticks( nv.utils.calcTicksY(availableHeight/36, data) ) .tickSize( -availableWidth, 0); } //============================================================ // Update Axes //============================================================ function updateXAxis() { if(showXAxis) { g.select('.nv-focus .nv-x.nv-axis') .transition() .duration(duration) .call(xAxis) ; } } function updateYAxis() { if(showYAxis) { g.select('.nv-focus .nv-y.nv-axis') .transition() .duration(duration) .call(yAxis) ; } } g.select('.nv-focus .nv-x.nv-axis') .attr('transform', 'translate(0,' + availableHeight + ')'); //============================================================ // Update Focus //============================================================ if (!focusEnable && focus.brush.extent() === null) { linesWrap.transition().call(lines); updateXAxis(); updateYAxis(); } else { focus.width(availableWidth); g.select('.nv-focusWrap') .style('display', focusEnable ? 'initial' : 'none') .attr('transform', 'translate(0,' + ( availableHeight + margin.bottom + focus.margin().top) + ')') .call(focus); var extent = focus.brush.empty() ? focus.xDomain() : focus.brush.extent(); if (extent !== null) { onBrush(extent); } } //============================================================ // Event Handling/Dispatching (in chart's scope) //------------------------------------------------------------ legend.dispatch.on('stateChange', function(newState) { for (var key in newState) state[key] = newState[key]; dispatch.stateChange(state); chart.update(); }); interactiveLayer.dispatch.on('elementMousemove', function(e) { lines.clearHighlights(); var singlePoint, pointIndex, pointXLocation, allData = []; data .filter(function(series, i) { series.seriesIndex = i; return !series.disabled && !series.disableTooltip; }) .forEach(function(series,i) { var extent = focus.brush.extent() !== null ? (focus.brush.empty() ? focus.xScale().domain() : focus.brush.extent()) : x.domain(); var currentValues = series.values.filter(function(d,i) { // Checks if the x point is between the extents, handling case where extent[0] is greater than extent[1] // (e.g. x domain is manually set to reverse the x-axis) if(extent[0] <= extent[1]) { return lines.x()(d,i) >= extent[0] && lines.x()(d,i) <= extent[1]; } else { return lines.x()(d,i) >= extent[1] && lines.x()(d,i) <= extent[0]; } }); if (currentValues.length > 0) { pointIndex = nv.interactiveBisect(currentValues, e.pointXValue, lines.x()); var point = currentValues[pointIndex]; var pointYValue = chart.y()(point, pointIndex); if (pointYValue !== null) { lines.highlightPoint(i, series.values.indexOf(point), true); } if (point === undefined) return; if (singlePoint === undefined) singlePoint = point; if (pointXLocation === undefined) pointXLocation = chart.xScale()(chart.x()(point,pointIndex)); allData.push({ key: series.key, value: pointYValue, color: color(series,series.seriesIndex), data: point }); } }); //Highlight the tooltip entry based on which point the mouse is closest to. if (allData.length > 2) { var yValue = chart.yScale().invert(e.mouseY); var domainExtent = Math.abs(chart.yScale().domain()[0] - chart.yScale().domain()[1]); var threshold = 0.03 * domainExtent; var indexToHighlight = nv.nearestValueIndex(allData.map(function(d){return d.value;}),yValue,threshold); if (indexToHighlight !== null) allData[indexToHighlight].highlight = true; } var defaultValueFormatter = function(d,i) { return d == null ? "N/A" : yAxis.tickFormat()(d); }; if (typeof pointIndex !== 'undefined') { interactiveLayer.tooltip .valueFormatter(interactiveLayer.tooltip.valueFormatter() || defaultValueFormatter) .data({ value: chart.x()( singlePoint,pointIndex ), index: pointIndex, series: allData })(); interactiveLayer.renderGuideLine(pointXLocation); } }); interactiveLayer.dispatch.on('elementClick', function(e) { var pointXLocation, allData = []; data.filter(function(series, i) { series.seriesIndex = i; return !series.disabled; }).forEach(function(series) { var pointIndex = nv.interactiveBisect(series.values, e.pointXValue, chart.x()); var point = series.values[pointIndex]; if (typeof point === 'undefined') return; if (typeof pointXLocation === 'undefined') pointXLocation = chart.xScale()(chart.x()(point,pointIndex)); var yPos = chart.yScale()(chart.y()(point,pointIndex)); allData.push({ point: point, pointIndex: pointIndex, pos: [pointXLocation, yPos], seriesIndex: series.seriesIndex, series: series }); }); lines.dispatch.elementClick(allData); }); interactiveLayer.dispatch.on("elementMouseout",function(e) { lines.clearHighlights(); }); dispatch.on('changeState', function(e) { if (typeof e.disabled !== 'undefined' && data.length === e.disabled.length) { data.forEach(function(series,i) { series.disabled = e.disabled[i]; }); state.disabled = e.disabled; } chart.update(); }); //============================================================ // Functions //------------------------------------------------------------ // Taken from crossfilter (http://square.github.com/crossfilter/) function resizePath(d) { var e = +(d == 'e'), x = e ? 1 : -1, y = availableHeight / 3; return 'M' + (0.5 * x) + ',' + y + 'A6,6 0 0 ' + e + ' ' + (6.5 * x) + ',' + (y + 6) + 'V' + (2 * y - 6) + 'A6,6 0 0 ' + e + ' ' + (0.5 * x) + ',' + (2 * y) + 'Z' + 'M' + (2.5 * x) + ',' + (y + 8) + 'V' + (2 * y - 8) + 'M' + (4.5 * x) + ',' + (y + 8) + 'V' + (2 * y - 8); } function onBrush(extent) { // Update Main (Focus) var focusLinesWrap = g.select('.nv-focus .nv-linesWrap') .datum( data.filter(function(d) { return !d.disabled; }) .map(function(d,i) { return { key: d.key, area: d.area, classed: d.classed, values: d.values.filter(function(d,i) { return lines.x()(d,i) >= extent[0] && lines.x()(d,i) <= extent[1]; }), disableTooltip: d.disableTooltip }; }) ); focusLinesWrap.transition().duration(duration).call(lines); // Update Main (Focus) Axes updateXAxis(); updateYAxis(); } }); renderWatch.renderEnd('lineChart immediate'); return chart; } //============================================================ // Event Handling/Dispatching (out of chart's scope) //------------------------------------------------------------ lines.dispatch.on('elementMouseover.tooltip', function(evt) { if(!evt.series.disableTooltip){ tooltip.data(evt).hidden(false); } }); lines.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true); }); //============================================================ // Expose Public Variables //------------------------------------------------------------ // expose chart's sub-components chart.dispatch = dispatch; chart.lines = lines; chart.legend = legend; chart.focus = focus; chart.xAxis = xAxis; chart.x2Axis = focus.xAxis chart.yAxis = yAxis; chart.y2Axis = focus.yAxis chart.interactiveLayer = interactiveLayer; chart.tooltip = tooltip; chart.state = state; chart.dispatch = dispatch; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, showLegend: {get: function(){return showLegend;}, set: function(_){showLegend=_;}}, legendPosition: {get: function(){return legendPosition;}, set: function(_){legendPosition=_;}}, showXAxis: {get: function(){return showXAxis;}, set: function(_){showXAxis=_;}}, showYAxis: {get: function(){return showYAxis;}, set: function(_){showYAxis=_;}}, defaultState: {get: function(){return defaultState;}, set: function(_){defaultState=_;}}, noData: {get: function(){return noData;}, set: function(_){noData=_;}}, // Focus options, mostly passed onto focus model. focusEnable: {get: function(){return focusEnable;}, set: function(_){focusEnable=_;}}, focusHeight: {get: function(){return focus.height();}, set: function(_){focus.height(_);}}, focusShowAxisX: {get: function(){return focus.showXAxis();}, set: function(_){focus.showXAxis(_);}}, focusShowAxisY: {get: function(){return focus.showYAxis();}, set: function(_){focus.showYAxis(_);}}, brushExtent: {get: function(){return focus.brushExtent();}, set: function(_){focus.brushExtent(_);}}, // options that require extra logic in the setter focusMargin: {get: function(){return focus.margin}, set: function(_){ if (_.top !== undefined) { margin.top = _.top; marginTop = _.top; } focus.margin.right = _.right !== undefined ? _.right : focus.margin.right; focus.margin.bottom = _.bottom !== undefined ? _.bottom : focus.margin.bottom; focus.margin.left = _.left !== undefined ? _.left : focus.margin.left; }}, margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; renderWatch.reset(duration); lines.duration(duration); focus.duration(duration); xAxis.duration(duration); yAxis.duration(duration); }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); legend.color(color); lines.color(color); focus.color(color); }}, interpolate: {get: function(){return lines.interpolate();}, set: function(_){ lines.interpolate(_); focus.interpolate(_); }}, xTickFormat: {get: function(){return xAxis.tickFormat();}, set: function(_){ xAxis.tickFormat(_); focus.xTickFormat(_); }}, yTickFormat: {get: function(){return yAxis.tickFormat();}, set: function(_){ yAxis.tickFormat(_); focus.yTickFormat(_); }}, x: {get: function(){return lines.x();}, set: function(_){ lines.x(_); focus.x(_); }}, y: {get: function(){return lines.y();}, set: function(_){ lines.y(_); focus.y(_); }}, rightAlignYAxis: {get: function(){return rightAlignYAxis;}, set: function(_){ rightAlignYAxis = _; yAxis.orient( rightAlignYAxis ? 'right' : 'left'); }}, useInteractiveGuideline: {get: function(){return useInteractiveGuideline;}, set: function(_){ useInteractiveGuideline = _; if (useInteractiveGuideline) { lines.interactive(false); lines.useVoronoi(false); } }} }); nv.utils.inheritOptions(chart, lines); nv.utils.initOptions(chart); return chart; }; nv.models.lineWithFocusChart = function() { return nv.models.lineChart() .margin({ bottom: 30 }) .focusEnable( true ); }; ================================================ FILE: src/models/linePlusBarChart.js ================================================ nv.models.linePlusBarChart = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var lines = nv.models.line() , lines2 = nv.models.line() , bars = nv.models.historicalBar() , bars2 = nv.models.historicalBar() , xAxis = nv.models.axis() , x2Axis = nv.models.axis() , y1Axis = nv.models.axis() , y2Axis = nv.models.axis() , y3Axis = nv.models.axis() , y4Axis = nv.models.axis() , legend = nv.models.legend() , brush = d3.svg.brush() , tooltip = nv.models.tooltip() ; var margin = {top: 30, right: 30, bottom: 30, left: 60} , marginTop = null , margin2 = {top: 0, right: 30, bottom: 20, left: 60} , width = null , height = null , getX = function(d) { return d.x } , getY = function(d) { return d.y } , color = nv.utils.defaultColor() , showLegend = true , focusEnable = true , focusShowAxisY = false , focusShowAxisX = true , focusHeight = 50 , extent , brushExtent = null , x , x2 , y1 , y2 , y3 , y4 , noData = null , dispatch = d3.dispatch('brush', 'stateChange', 'changeState') , transitionDuration = 0 , state = nv.utils.state() , defaultState = null , legendLeftAxisHint = ' (left axis)' , legendRightAxisHint = ' (right axis)' , switchYAxisOrder = false ; lines.clipEdge(true); lines2.interactive(false); // We don't want any points emitted for the focus chart's scatter graph. lines2.pointActive(function(d) { return false }); xAxis.orient('bottom').tickPadding(5); y1Axis.orient('left'); y2Axis.orient('right'); x2Axis.orient('bottom').tickPadding(5); y3Axis.orient('left'); y4Axis.orient('right'); tooltip.headerEnabled(true).headerFormatter(function(d, i) { return xAxis.tickFormat()(d, i); }); //============================================================ // Private Variables //------------------------------------------------------------ var getBarsAxis = function() { return switchYAxisOrder ? { main: y2Axis, focus: y4Axis } : { main: y1Axis, focus: y3Axis } } var getLinesAxis = function() { return switchYAxisOrder ? { main: y1Axis, focus: y3Axis } : { main: y2Axis, focus: y4Axis } } var stateGetter = function(data) { return function(){ return { active: data.map(function(d) { return !d.disabled }) }; } }; var stateSetter = function(data) { return function(state) { if (state.active !== undefined) data.forEach(function(series,i) { series.disabled = !state.active[i]; }); } }; var allDisabled = function(data) { return data.every(function(series) { return series.disabled; }); } function chart(selection) { selection.each(function(data) { var container = d3.select(this), that = this; nv.utils.initSVG(container); var availableWidth = nv.utils.availableWidth(width, container, margin), availableHeight1 = nv.utils.availableHeight(height, container, margin) - (focusEnable ? focusHeight : 0), availableHeight2 = focusHeight - margin2.top - margin2.bottom; chart.update = function() { container.transition().duration(transitionDuration).call(chart); }; chart.container = this; state .setter(stateSetter(data), chart.update) .getter(stateGetter(data)) .update(); // DEPRECATED set state.disableddisabled state.disabled = data.map(function(d) { return !!d.disabled }); if (!defaultState) { var key; defaultState = {}; for (key in state) { if (state[key] instanceof Array) defaultState[key] = state[key].slice(0); else defaultState[key] = state[key]; } } // Display No Data message if there's nothing to show. if (!data || !data.length || !data.filter(function(d) { return d.values.length }).length) { nv.utils.noData(chart, container) return chart; } else { container.selectAll('.nv-noData').remove(); } // Setup Scales var dataBars = data.filter(function(d) { return !d.disabled && d.bar }); var dataLines = data.filter(function(d) { return !d.bar }); // removed the !d.disabled clause here to fix Issue #240 if (dataBars.length && !switchYAxisOrder) { x = bars.xScale(); } else { x = lines.xScale(); } x2 = x2Axis.scale(); // select the scales and series based on the position of the yAxis y1 = switchYAxisOrder ? lines.yScale() : bars.yScale(); y2 = switchYAxisOrder ? bars.yScale() : lines.yScale(); y3 = switchYAxisOrder ? lines2.yScale() : bars2.yScale(); y4 = switchYAxisOrder ? bars2.yScale() : lines2.yScale(); var series1 = data .filter(function(d) { return !d.disabled && (switchYAxisOrder ? !d.bar : d.bar) }) .map(function(d) { return d.values.map(function(d,i) { return { x: getX(d,i), y: getY(d,i) } }) }); var series2 = data .filter(function(d) { return !d.disabled && (switchYAxisOrder ? d.bar : !d.bar) }) .map(function(d) { return d.values.map(function(d,i) { return { x: getX(d,i), y: getY(d,i) } }) }); x.range([0, availableWidth]); x2 .domain(d3.extent(d3.merge(series1.concat(series2)), function(d) { return d.x } )) .range([0, availableWidth]); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-linePlusBar').data([data]); var gEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-linePlusBar').append('g'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-legendWrap'); // this is the main chart var focusEnter = gEnter.append('g').attr('class', 'nv-focus'); focusEnter.append('g').attr('class', 'nv-x nv-axis'); focusEnter.append('g').attr('class', 'nv-y1 nv-axis'); focusEnter.append('g').attr('class', 'nv-y2 nv-axis'); focusEnter.append('g').attr('class', 'nv-barsWrap'); focusEnter.append('g').attr('class', 'nv-linesWrap'); // context chart is where you can focus in var contextEnter = gEnter.append('g').attr('class', 'nv-context'); contextEnter.append('g').attr('class', 'nv-x nv-axis'); contextEnter.append('g').attr('class', 'nv-y1 nv-axis'); contextEnter.append('g').attr('class', 'nv-y2 nv-axis'); contextEnter.append('g').attr('class', 'nv-barsWrap'); contextEnter.append('g').attr('class', 'nv-linesWrap'); contextEnter.append('g').attr('class', 'nv-brushBackground'); contextEnter.append('g').attr('class', 'nv-x nv-brush'); //============================================================ // Legend //------------------------------------------------------------ if (!showLegend) { g.select('.nv-legendWrap').selectAll('*').remove(); } else { var legendWidth = legend.align() ? availableWidth / 2 : availableWidth; var legendXPosition = legend.align() ? legendWidth : 0; legend.width(legendWidth); g.select('.nv-legendWrap') .datum(data.map(function(series) { series.originalKey = series.originalKey === undefined ? series.key : series.originalKey; if(switchYAxisOrder) { series.key = series.originalKey + (series.bar ? legendRightAxisHint : legendLeftAxisHint); } else { series.key = series.originalKey + (series.bar ? legendLeftAxisHint : legendRightAxisHint); } return series; })) .call(legend); if (!marginTop && legend.height() !== margin.top) { margin.top = legend.height(); // FIXME: shouldn't this be "- (focusEnabled ? focusHeight : 0)"? availableHeight1 = nv.utils.availableHeight(height, container, margin) - focusHeight; } g.select('.nv-legendWrap') .attr('transform', 'translate(' + legendXPosition + ',' + (-margin.top) +')'); } wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); //============================================================ // Context chart (focus chart) components //------------------------------------------------------------ // hide or show the focus context chart g.select('.nv-context').style('display', focusEnable ? 'initial' : 'none'); bars2 .width(availableWidth) .height(availableHeight2) .color(data.map(function (d, i) { return d.color || color(d, i); }).filter(function (d, i) { return !data[i].disabled && data[i].bar })); lines2 .width(availableWidth) .height(availableHeight2) .color(data.map(function (d, i) { return d.color || color(d, i); }).filter(function (d, i) { return !data[i].disabled && !data[i].bar })); var bars2Wrap = g.select('.nv-context .nv-barsWrap') .datum(dataBars.length ? dataBars : [ {values: []} ]); var lines2Wrap = g.select('.nv-context .nv-linesWrap') .datum(allDisabled(dataLines) ? [{values: []}] : dataLines.filter(function(dataLine) { return !dataLine.disabled; })); g.select('.nv-context') .attr('transform', 'translate(0,' + ( availableHeight1 + margin.bottom + margin2.top) + ')'); bars2Wrap.transition().call(bars2); lines2Wrap.transition().call(lines2); // context (focus chart) axis controls if (focusShowAxisX) { x2Axis ._ticks( nv.utils.calcTicksX(availableWidth / 100, data)) .tickSize(-availableHeight2, 0); g.select('.nv-context .nv-x.nv-axis') .attr('transform', 'translate(0,' + y3.range()[0] + ')'); g.select('.nv-context .nv-x.nv-axis').transition() .call(x2Axis); } if (focusShowAxisY) { y3Axis .scale(y3) ._ticks( availableHeight2 / 36 ) .tickSize( -availableWidth, 0); y4Axis .scale(y4) ._ticks( availableHeight2 / 36 ) .tickSize(dataBars.length ? 0 : -availableWidth, 0); // Show the y2 rules only if y1 has none g.select('.nv-context .nv-y3.nv-axis') .style('opacity', dataBars.length ? 1 : 0) .attr('transform', 'translate(0,' + x2.range()[0] + ')'); g.select('.nv-context .nv-y2.nv-axis') .style('opacity', dataLines.length ? 1 : 0) .attr('transform', 'translate(' + x2.range()[1] + ',0)'); g.select('.nv-context .nv-y1.nv-axis').transition() .call(y3Axis); g.select('.nv-context .nv-y2.nv-axis').transition() .call(y4Axis); } // Setup Brush brush.x(x2).on('brush', onBrush); if (brushExtent) brush.extent(brushExtent); var brushBG = g.select('.nv-brushBackground').selectAll('g') .data([brushExtent || brush.extent()]); var brushBGenter = brushBG.enter() .append('g'); brushBGenter.append('rect') .attr('class', 'left') .attr('x', 0) .attr('y', 0) .attr('height', availableHeight2); brushBGenter.append('rect') .attr('class', 'right') .attr('x', 0) .attr('y', 0) .attr('height', availableHeight2); var gBrush = g.select('.nv-x.nv-brush') .call(brush); gBrush.selectAll('rect') //.attr('y', -5) .attr('height', availableHeight2); gBrush.selectAll('.resize').append('path').attr('d', resizePath); //============================================================ // Event Handling/Dispatching (in chart's scope) //------------------------------------------------------------ legend.dispatch.on('stateChange', function(newState) { for (var key in newState) state[key] = newState[key]; dispatch.stateChange(state); chart.update(); }); // Update chart from a state object passed to event handler dispatch.on('changeState', function(e) { if (typeof e.disabled !== 'undefined') { data.forEach(function(series,i) { series.disabled = e.disabled[i]; }); state.disabled = e.disabled; } chart.update(); }); //============================================================ // Functions //------------------------------------------------------------ // Taken from crossfilter (http://square.github.com/crossfilter/) function resizePath(d) { var e = +(d == 'e'), x = e ? 1 : -1, y = availableHeight2 / 3; return 'M' + (.5 * x) + ',' + y + 'A6,6 0 0 ' + e + ' ' + (6.5 * x) + ',' + (y + 6) + 'V' + (2 * y - 6) + 'A6,6 0 0 ' + e + ' ' + (.5 * x) + ',' + (2 * y) + 'Z' + 'M' + (2.5 * x) + ',' + (y + 8) + 'V' + (2 * y - 8) + 'M' + (4.5 * x) + ',' + (y + 8) + 'V' + (2 * y - 8); } function updateBrushBG() { if (!brush.empty()) brush.extent(brushExtent); brushBG .data([brush.empty() ? x2.domain() : brushExtent]) .each(function(d,i) { var leftWidth = x2(d[0]) - x2.range()[0], rightWidth = x2.range()[1] - x2(d[1]); d3.select(this).select('.left') .attr('width', leftWidth < 0 ? 0 : leftWidth); d3.select(this).select('.right') .attr('x', x2(d[1])) .attr('width', rightWidth < 0 ? 0 : rightWidth); }); } function onBrush() { brushExtent = brush.empty() ? null : brush.extent(); extent = brush.empty() ? x2.domain() : brush.extent(); dispatch.brush({extent: extent, brush: brush}); updateBrushBG(); // Prepare Main (Focus) Bars and Lines bars .width(availableWidth) .height(availableHeight1) .color(data.map(function(d,i) { return d.color || color(d, i); }).filter(function(d,i) { return !data[i].disabled && data[i].bar })); lines .width(availableWidth) .height(availableHeight1) .color(data.map(function(d,i) { return d.color || color(d, i); }).filter(function(d,i) { return !data[i].disabled && !data[i].bar })); var focusBarsWrap = g.select('.nv-focus .nv-barsWrap') .datum(!dataBars.length ? [{values:[]}] : dataBars .map(function(d,i) { return { key: d.key, values: d.values.filter(function(d,i) { return bars.x()(d,i) >= extent[0] && bars.x()(d,i) <= extent[1]; }) } }) ); var focusLinesWrap = g.select('.nv-focus .nv-linesWrap') .datum(allDisabled(dataLines) ? [{values:[]}] : dataLines .filter(function(dataLine) { return !dataLine.disabled; }) .map(function(d,i) { return { area: d.area, fillOpacity: d.fillOpacity, strokeWidth: d.strokeWidth, key: d.key, values: d.values.filter(function(d,i) { return lines.x()(d,i) >= extent[0] && lines.x()(d,i) <= extent[1]; }) } }) ); // Update Main (Focus) X Axis if (dataBars.length && !switchYAxisOrder) { x = bars.xScale(); } else { x = lines.xScale(); } xAxis .scale(x) ._ticks( nv.utils.calcTicksX(availableWidth/100, data) ) .tickSize(-availableHeight1, 0); xAxis.domain([Math.ceil(extent[0]), Math.floor(extent[1])]); g.select('.nv-x.nv-axis').transition().duration(transitionDuration) .call(xAxis); // Update Main (Focus) Bars and Lines focusBarsWrap.transition().duration(transitionDuration).call(bars); focusLinesWrap.transition().duration(transitionDuration).call(lines); // Setup and Update Main (Focus) Y Axes g.select('.nv-focus .nv-x.nv-axis') .attr('transform', 'translate(0,' + y1.range()[0] + ')'); y1Axis .scale(y1) ._ticks( nv.utils.calcTicksY(availableHeight1/36, data) ) .tickSize(-availableWidth, 0); y2Axis .scale(y2) ._ticks( nv.utils.calcTicksY(availableHeight1/36, data) ); // Show the y2 rules only if y1 has none if(!switchYAxisOrder) { y2Axis.tickSize(dataBars.length ? 0 : -availableWidth, 0); } else { y2Axis.tickSize(dataLines.length ? 0 : -availableWidth, 0); } // Calculate opacity of the axis var barsOpacity = dataBars.length ? 1 : 0; var linesOpacity = dataLines.length && !allDisabled(dataLines) ? 1 : 0; var y1Opacity = switchYAxisOrder ? linesOpacity : barsOpacity; var y2Opacity = switchYAxisOrder ? barsOpacity : linesOpacity; g.select('.nv-focus .nv-y1.nv-axis') .style('opacity', y1Opacity); g.select('.nv-focus .nv-y2.nv-axis') .style('opacity', y2Opacity) .attr('transform', 'translate(' + x.range()[1] + ',0)'); g.select('.nv-focus .nv-y1.nv-axis').transition().duration(transitionDuration) .call(y1Axis); g.select('.nv-focus .nv-y2.nv-axis').transition().duration(transitionDuration) .call(y2Axis); } onBrush(); }); return chart; } //============================================================ // Event Handling/Dispatching (out of chart's scope) //------------------------------------------------------------ lines.dispatch.on('elementMouseover.tooltip', function(evt) { tooltip .duration(100) .valueFormatter(function(d, i) { return getLinesAxis().main.tickFormat()(d, i); }) .data(evt) .hidden(false); }); lines.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true) }); bars.dispatch.on('elementMouseover.tooltip', function(evt) { evt.value = chart.x()(evt.data); evt['series'] = { value: chart.y()(evt.data), color: evt.color }; tooltip .duration(0) .valueFormatter(function(d, i) { return getBarsAxis().main.tickFormat()(d, i); }) .data(evt) .hidden(false); }); bars.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true); }); bars.dispatch.on('elementMousemove.tooltip', function(evt) { tooltip(); }); //============================================================ //============================================================ // Expose Public Variables //------------------------------------------------------------ // expose chart's sub-components chart.dispatch = dispatch; chart.legend = legend; chart.lines = lines; chart.lines2 = lines2; chart.bars = bars; chart.bars2 = bars2; chart.xAxis = xAxis; chart.x2Axis = x2Axis; chart.y1Axis = y1Axis; chart.y2Axis = y2Axis; chart.y3Axis = y3Axis; chart.y4Axis = y4Axis; chart.tooltip = tooltip; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, showLegend: {get: function(){return showLegend;}, set: function(_){showLegend=_;}}, brushExtent: {get: function(){return brushExtent;}, set: function(_){brushExtent=_;}}, noData: {get: function(){return noData;}, set: function(_){noData=_;}}, focusEnable: {get: function(){return focusEnable;}, set: function(_){focusEnable=_;}}, focusHeight: {get: function(){return focusHeight;}, set: function(_){focusHeight=_;}}, focusShowAxisX: {get: function(){return focusShowAxisX;}, set: function(_){focusShowAxisX=_;}}, focusShowAxisY: {get: function(){return focusShowAxisY;}, set: function(_){focusShowAxisY=_;}}, legendLeftAxisHint: {get: function(){return legendLeftAxisHint;}, set: function(_){legendLeftAxisHint=_;}}, legendRightAxisHint: {get: function(){return legendRightAxisHint;}, set: function(_){legendRightAxisHint=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ if (_.top !== undefined) { margin.top = _.top; marginTop = _.top; } margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, focusMargin: {get: function(){return margin2;}, set: function(_){ margin2.top = _.top !== undefined ? _.top : margin2.top; margin2.right = _.right !== undefined ? _.right : margin2.right; margin2.bottom = _.bottom !== undefined ? _.bottom : margin2.bottom; margin2.left = _.left !== undefined ? _.left : margin2.left; }}, duration: {get: function(){return transitionDuration;}, set: function(_){ transitionDuration = _; }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); legend.color(color); }}, x: {get: function(){return getX;}, set: function(_){ getX = _; lines.x(_); lines2.x(_); bars.x(_); bars2.x(_); }}, y: {get: function(){return getY;}, set: function(_){ getY = _; lines.y(_); lines2.y(_); bars.y(_); bars2.y(_); }}, switchYAxisOrder: {get: function(){return switchYAxisOrder;}, set: function(_){ // Switch the tick format for the yAxis if(switchYAxisOrder !== _) { var y1 = y1Axis; y1Axis = y2Axis; y2Axis = y1; var y3 = y3Axis; y3Axis = y4Axis; y4Axis = y3; } switchYAxisOrder=_; y1Axis.orient('left'); y2Axis.orient('right'); y3Axis.orient('left'); y4Axis.orient('right'); }} }); nv.utils.inheritOptions(chart, lines); nv.utils.initOptions(chart); return chart; }; ================================================ FILE: src/models/multiBar.js ================================================ nv.models.multiBar = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 0, right: 0, bottom: 0, left: 0} , width = 960 , height = 500 , x = d3.scale.ordinal() , y = d3.scale.linear() , id = Math.floor(Math.random() * 10000) //Create semi-unique ID in case user doesn't select one , container = null , getX = function(d) { return d.x } , getY = function(d) { return d.y } , forceY = [0] // 0 is forced by default.. this makes sense for the majority of bar graphs... user can always do chart.forceY([]) to remove , clipEdge = true , stacked = false , stackOffset = 'zero' // options include 'silhouette', 'wiggle', 'expand', 'zero', or a custom function , color = nv.utils.defaultColor() , hideable = false , barColor = null // adding the ability to set the color for each rather than the whole group , disabled // used in conjunction with barColor to communicate from multiBarHorizontalChart what series are disabled , duration = 500 , xDomain , yDomain , xRange , yRange , groupSpacing = 0.1 , fillOpacity = 0.75 , dispatch = d3.dispatch('chartClick', 'elementClick', 'elementDblClick', 'elementMouseover', 'elementMouseout', 'elementMousemove', 'renderEnd') ; //============================================================ // Private Variables //------------------------------------------------------------ var x0, y0 //used to store previous scales , renderWatch = nv.utils.renderWatch(dispatch, duration) ; var last_datalength = 0; function chart(selection) { renderWatch.reset(); selection.each(function(data) { var availableWidth = width - margin.left - margin.right, availableHeight = height - margin.top - margin.bottom; container = d3.select(this); nv.utils.initSVG(container); var nonStackableCount = 0; // This function defines the requirements for render complete var endFn = function(d, i) { if (d.series === data.length - 1 && i === data[0].values.length - 1) return true; return false; }; if(hideable && data.length) hideable = [{ values: data[0].values.map(function(d) { return { x: d.x, y: 0, series: d.series, size: 0.01 };} )}]; if (stacked) { var parsed = d3.layout.stack() .offset(stackOffset) .values(function(d){ return d.values }) .y(getY) (!data.length && hideable ? hideable : data); parsed.forEach(function(series, i){ // if series is non-stackable, use un-parsed data if (series.nonStackable) { data[i].nonStackableSeries = nonStackableCount++; parsed[i] = data[i]; } else { // don't stack this seires on top of the nonStackable seriees if (i > 0 && parsed[i - 1].nonStackable){ parsed[i].values.map(function(d,j){ d.y0 -= parsed[i - 1].values[j].y; d.y1 = d.y0 + d.y; }); } } }); data = parsed; } //add series index and key to each data point for reference data.forEach(function(series, i) { series.values.forEach(function(point) { point.series = i; point.key = series.key; }); }); // HACK for negative value stacking if (stacked && data.length > 0) { data[0].values.map(function(d,i) { var posBase = 0, negBase = 0; data.map(function(d, idx) { if (!data[idx].nonStackable) { var f = d.values[i] f.size = Math.abs(f.y); if (f.y<0) { f.y1 = negBase; negBase = negBase - f.size; } else { f.y1 = f.size + posBase; posBase = posBase + f.size; } } }); }); } // Setup Scales // remap and flatten the data for use in calculating the scales' domains var seriesData = (xDomain && yDomain) ? [] : // if we know xDomain and yDomain, no need to calculate data.map(function(d, idx) { return d.values.map(function(d,i) { return { x: getX(d,i), y: getY(d,i), y0: d.y0, y1: d.y1, idx:idx } }) }); x.domain(xDomain || d3.merge(seriesData).map(function(d) { return d.x })) .rangeBands(xRange || [0, availableWidth], groupSpacing); y.domain(yDomain || d3.extent(d3.merge(seriesData).map(function(d) { var domain = d.y; // increase the domain range if this series is stackable if (stacked && !data[d.idx].nonStackable) { if (d.y > 0){ domain = d.y1 } else { domain = d.y1 + d.y } } return domain; }).concat(forceY))) .range(yRange || [availableHeight, 0]); // If scale's domain don't have a range, slightly adjust to make one... so a chart can show a single data point if (x.domain()[0] === x.domain()[1]) x.domain()[0] ? x.domain([x.domain()[0] - x.domain()[0] * 0.01, x.domain()[1] + x.domain()[1] * 0.01]) : x.domain([-1,1]); if (y.domain()[0] === y.domain()[1]) y.domain()[0] ? y.domain([y.domain()[0] + y.domain()[0] * 0.01, y.domain()[1] - y.domain()[1] * 0.01]) : y.domain([-1,1]); x0 = x0 || x; y0 = y0 || y; // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-multibar').data([data]); var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-multibar'); var defsEnter = wrapEnter.append('defs'); var gEnter = wrapEnter.append('g'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-groups'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); defsEnter.append('clipPath') .attr('id', 'nv-edge-clip-' + id) .append('rect'); wrap.select('#nv-edge-clip-' + id + ' rect') .attr('width', availableWidth) .attr('height', availableHeight); g.attr('clip-path', clipEdge ? 'url(#nv-edge-clip-' + id + ')' : ''); var groups = wrap.select('.nv-groups').selectAll('.nv-group') .data(function(d) { return d }, function(d,i) { return i }); groups.enter().append('g') .style('stroke-opacity', 1e-6) .style('fill-opacity', 1e-6); var exitTransition = renderWatch .transition(groups.exit().selectAll('rect.nv-bar'), 'multibarExit', Math.min(100, duration)) .attr('y', function(d, i, j) { var yVal = y0(0) || 0; if (stacked) { if (data[d.series] && !data[d.series].nonStackable) { yVal = y0(d.y0); } } return yVal; }) .attr('height', 0) .remove(); if (exitTransition.delay) exitTransition.delay(function(d,i) { var delay = i * (duration / (last_datalength + 1)) - i; return delay; }); groups .attr('class', function(d,i) { return 'nv-group nv-series-' + i }) .classed('hover', function(d) { return d.hover }) .style('fill', function(d,i){ return color(d, i) }) .style('stroke', function(d,i){ return color(d, i) }); groups .style('stroke-opacity', 1) .style('fill-opacity', fillOpacity); var bars = groups.selectAll('rect.nv-bar') .data(function(d) { return (hideable && !data.length) ? hideable.values : d.values }); bars.exit().remove(); var barsEnter = bars.enter().append('rect') .attr('class', function(d,i) { return getY(d,i) < 0 ? 'nv-bar negative' : 'nv-bar positive'}) .attr('x', function(d,i,j) { return stacked && !data[j].nonStackable ? 0 : (j * x.rangeBand() / data.length ) }) .attr('y', function(d,i,j) { return y0(stacked && !data[j].nonStackable ? d.y0 : 0) || 0 }) .attr('height', 0) .attr('width', function(d,i,j) { return x.rangeBand() / (stacked && !data[j].nonStackable ? 1 : data.length) }) .attr('transform', function(d,i) { return 'translate(' + x(getX(d,i)) + ',0)'; }) ; bars .style('fill', function(d,i,j){ return color(d, j, i); }) .style('stroke', function(d,i,j){ return color(d, j, i); }) .on('mouseover', function(d,i,j) { d3.select(this).classed('hover', true); dispatch.elementMouseover({ data: d, index: i, series: data[j], color: d3.select(this).style("fill") }); }) .on('mouseout', function(d,i,j) { d3.select(this).classed('hover', false); dispatch.elementMouseout({ data: d, index: i, series: data[j], color: d3.select(this).style("fill") }); }) .on('mousemove', function(d,i,j) { dispatch.elementMousemove({ data: d, index: i, series: data[j], color: d3.select(this).style("fill") }); }) .on('click', function(d,i,j) { var element = this; dispatch.elementClick({ data: d, index: i, series: data[j], color: d3.select(this).style("fill"), event: d3.event, element: element }); d3.event.stopPropagation(); }) .on('dblclick', function(d,i,j) { dispatch.elementDblClick({ data: d, index: i, series: data[j], color: d3.select(this).style("fill") }); d3.event.stopPropagation(); }); bars .attr('class', function(d,i) { return getY(d,i) < 0 ? 'nv-bar negative' : 'nv-bar positive'}) .attr('transform', function(d,i) { return 'translate(' + x(getX(d,i)) + ',0)'; }) if (barColor) { if (!disabled) disabled = data.map(function() { return true }); bars .style('fill', function(d,i,j) { return d3.rgb(barColor(d,i)).darker( disabled.map(function(d,i) { return i }).filter(function(d,i){ return !disabled[i] })[j] ).toString(); }) .style('stroke', function(d,i,j) { return d3.rgb(barColor(d,i)).darker( disabled.map(function(d,i) { return i }).filter(function(d,i){ return !disabled[i] })[j] ).toString(); }); } var barSelection = bars.watchTransition(renderWatch, 'multibar', Math.min(250, duration)) .delay(function(d,i) { return i * duration / data[0].values.length; }); if (stacked){ barSelection .attr('y', function(d,i,j) { var yVal = 0; // if stackable, stack it on top of the previous series if (!data[j].nonStackable) { yVal = y(d.y1); } else { if (getY(d,i) < 0){ yVal = y(0); } else { if (y(0) - y(getY(d,i)) < -1){ yVal = y(0) - 1; } else { yVal = y(getY(d, i)) || 0; } } } return yVal; }) .attr('height', function(d,i,j) { if (!data[j].nonStackable) { return Math.max(Math.abs(y(d.y+d.y0) - y(d.y0)), 0); } else { return Math.max(Math.abs(y(getY(d,i)) - y(0)), 0) || 0; } }) .attr('x', function(d,i,j) { var width = 0; if (data[j].nonStackable) { width = d.series * x.rangeBand() / data.length; if (data.length !== nonStackableCount){ width = data[j].nonStackableSeries * x.rangeBand()/(nonStackableCount*2); } } return width; }) .attr('width', function(d,i,j){ if (!data[j].nonStackable) { return x.rangeBand(); } else { // if all series are nonStacable, take the full width var width = (x.rangeBand() / nonStackableCount); // otherwise, nonStackable graph will be only taking the half-width // of the x rangeBand if (data.length !== nonStackableCount) { width = x.rangeBand()/(nonStackableCount*2); } return width; } }); } else { barSelection .attr('x', function(d,i) { return d.series * x.rangeBand() / data.length; }) .attr('width', x.rangeBand() / data.length) .attr('y', function(d,i) { return getY(d,i) < 0 ? y(0) : y(0) - y(getY(d,i)) < 1 ? y(0) - 1 : y(getY(d,i)) || 0; }) .attr('height', function(d,i) { return Math.max(Math.abs(y(getY(d,i)) - y(0)),1) || 0; }); } //store old scales for use in transitions on update x0 = x.copy(); y0 = y.copy(); // keep track of the last data value length for transition calculations if (data[0] && data[0].values) { last_datalength = data[0].values.length; } }); renderWatch.renderEnd('multibar immediate'); return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.dispatch = dispatch; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, x: {get: function(){return getX;}, set: function(_){getX=_;}}, y: {get: function(){return getY;}, set: function(_){getY=_;}}, xScale: {get: function(){return x;}, set: function(_){x=_;}}, yScale: {get: function(){return y;}, set: function(_){y=_;}}, xDomain: {get: function(){return xDomain;}, set: function(_){xDomain=_;}}, yDomain: {get: function(){return yDomain;}, set: function(_){yDomain=_;}}, xRange: {get: function(){return xRange;}, set: function(_){xRange=_;}}, yRange: {get: function(){return yRange;}, set: function(_){yRange=_;}}, forceY: {get: function(){return forceY;}, set: function(_){forceY=_;}}, stacked: {get: function(){return stacked;}, set: function(_){stacked=_;}}, stackOffset: {get: function(){return stackOffset;}, set: function(_){stackOffset=_;}}, clipEdge: {get: function(){return clipEdge;}, set: function(_){clipEdge=_;}}, disabled: {get: function(){return disabled;}, set: function(_){disabled=_;}}, id: {get: function(){return id;}, set: function(_){id=_;}}, hideable: {get: function(){return hideable;}, set: function(_){hideable=_;}}, groupSpacing:{get: function(){return groupSpacing;}, set: function(_){groupSpacing=_;}}, fillOpacity: {get: function(){return fillOpacity;}, set: function(_){fillOpacity=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; renderWatch.reset(duration); }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); }}, barColor: {get: function(){return barColor;}, set: function(_){ barColor = _ ? nv.utils.getColor(_) : null; }} }); nv.utils.initOptions(chart); return chart; }; ================================================ FILE: src/models/multiBarChart.js ================================================ nv.models.multiBarChart = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var multibar = nv.models.multiBar() , xAxis = nv.models.axis() , yAxis = nv.models.axis() , interactiveLayer = nv.interactiveGuideline() , legend = nv.models.legend() , controls = nv.models.legend() , tooltip = nv.models.tooltip() ; var margin = {top: 30, right: 20, bottom: 50, left: 60} , marginTop = null , width = null , height = null , color = nv.utils.defaultColor() , showControls = true , controlLabels = {} , showLegend = true , legendPosition = null , showXAxis = true , showYAxis = true , rightAlignYAxis = false , reduceXTicks = true // if false a tick will show for every data point , staggerLabels = false , wrapLabels = false , rotateLabels = 0 , x //can be accessed via chart.xScale() , y //can be accessed via chart.yScale() , state = nv.utils.state() , defaultState = null , noData = null , dispatch = d3.dispatch('stateChange', 'changeState', 'renderEnd') , controlWidth = function() { return showControls ? 180 : 0 } , duration = 250 , useInteractiveGuideline = false ; state.stacked = false // DEPRECATED Maintained for backward compatibility multibar.stacked(false); xAxis .orient('bottom') .tickPadding(7) .showMaxMin(false) .tickFormat(function(d) { return d }) ; yAxis .orient((rightAlignYAxis) ? 'right' : 'left') .tickFormat(d3.format(',.1f')) ; tooltip .duration(0) .valueFormatter(function(d, i) { return yAxis.tickFormat()(d, i); }) .headerFormatter(function(d, i) { return xAxis.tickFormat()(d, i); }); interactiveLayer.tooltip .valueFormatter(function(d, i) { return d == null ? "N/A" : yAxis.tickFormat()(d, i); }) .headerFormatter(function(d, i) { return xAxis.tickFormat()(d, i); }); interactiveLayer.tooltip .valueFormatter(function (d, i) { return d == null ? "N/A" : yAxis.tickFormat()(d, i); }) .headerFormatter(function (d, i) { return xAxis.tickFormat()(d, i); }); interactiveLayer.tooltip .duration(0) .valueFormatter(function(d, i) { return yAxis.tickFormat()(d, i); }) .headerFormatter(function(d, i) { return xAxis.tickFormat()(d, i); }); controls.updateState(false); //============================================================ // Private Variables //------------------------------------------------------------ var renderWatch = nv.utils.renderWatch(dispatch); var stacked = false; var stateGetter = function(data) { return function(){ return { active: data.map(function(d) { return !d.disabled }), stacked: stacked }; } }; var stateSetter = function(data) { return function(state) { if (state.stacked !== undefined) stacked = state.stacked; if (state.active !== undefined) data.forEach(function(series,i) { series.disabled = !state.active[i]; }); } }; function chart(selection) { renderWatch.reset(); renderWatch.models(multibar); if (showXAxis) renderWatch.models(xAxis); if (showYAxis) renderWatch.models(yAxis); selection.each(function(data) { var container = d3.select(this), that = this; nv.utils.initSVG(container); var availableWidth = nv.utils.availableWidth(width, container, margin), availableHeight = nv.utils.availableHeight(height, container, margin); chart.update = function() { if (duration === 0) container.call(chart); else container.transition() .duration(duration) .call(chart); }; chart.container = this; state .setter(stateSetter(data), chart.update) .getter(stateGetter(data)) .update(); // DEPRECATED set state.disableddisabled state.disabled = data.map(function(d) { return !!d.disabled }); if (!defaultState) { var key; defaultState = {}; for (key in state) { if (state[key] instanceof Array) defaultState[key] = state[key].slice(0); else defaultState[key] = state[key]; } } // Display noData message if there's nothing to show. if (!data || !data.length || !data.filter(function(d) { return d.values.length }).length) { nv.utils.noData(chart, container) return chart; } else { container.selectAll('.nv-noData').remove(); } // Setup Scales x = multibar.xScale(); y = multibar.yScale(); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-multiBarWithLegend').data([data]); var gEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-multiBarWithLegend').append('g'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-x nv-axis'); gEnter.append('g').attr('class', 'nv-y nv-axis'); gEnter.append('g').attr('class', 'nv-barsWrap'); gEnter.append('g').attr('class', 'nv-legendWrap'); gEnter.append('g').attr('class', 'nv-controlsWrap'); gEnter.append('g').attr('class', 'nv-interactive'); // Legend if (!showLegend) { g.select('.nv-legendWrap').selectAll('*').remove(); } else { if (legendPosition === 'bottom') { legend.width(availableWidth - margin.right); g.select('.nv-legendWrap') .datum(data) .call(legend); margin.bottom = xAxis.height() + legend.height(); availableHeight = nv.utils.availableHeight(height, container, margin); g.select('.nv-legendWrap') .attr('transform', 'translate(0,' + (availableHeight + xAxis.height()) +')'); } else { legend.width(availableWidth - controlWidth()); g.select('.nv-legendWrap') .datum(data) .call(legend); if (!marginTop && legend.height() !== margin.top) { margin.top = legend.height(); availableHeight = nv.utils.availableHeight(height, container, margin); } g.select('.nv-legendWrap') .attr('transform', 'translate(' + controlWidth() + ',' + (-margin.top) +')'); } } // Controls if (!showControls) { g.select('.nv-controlsWrap').selectAll('*').remove(); } else { var controlsData = [ { key: controlLabels.grouped || 'Grouped', disabled: multibar.stacked() }, { key: controlLabels.stacked || 'Stacked', disabled: !multibar.stacked() } ]; controls.width(controlWidth()).color(['#444', '#444', '#444']); g.select('.nv-controlsWrap') .datum(controlsData) .attr('transform', 'translate(0,' + (-margin.top) +')') .call(controls); } wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); if (rightAlignYAxis) { g.select(".nv-y.nv-axis") .attr("transform", "translate(" + availableWidth + ",0)"); } // Main Chart Component(s) multibar .disabled(data.map(function(series) { return series.disabled })) .width(availableWidth) .height(availableHeight) .color(data.map(function(d,i) { return d.color || color(d, i); }).filter(function(d,i) { return !data[i].disabled })); var barsWrap = g.select('.nv-barsWrap') .datum(data.filter(function(d) { return !d.disabled })); barsWrap.call(multibar); // Setup Axes if (showXAxis) { xAxis .scale(x) ._ticks( nv.utils.calcTicksX(availableWidth/100, data) ) .tickSize(-availableHeight, 0); g.select('.nv-x.nv-axis') .attr('transform', 'translate(0,' + y.range()[0] + ')'); g.select('.nv-x.nv-axis') .call(xAxis); var xTicks = g.select('.nv-x.nv-axis > g').selectAll('g'); xTicks .selectAll('line, text') .style('opacity', 1) if (staggerLabels) { var getTranslate = function(x,y) { return "translate(" + x + "," + y + ")"; }; var staggerUp = 5, staggerDown = 17; //pixels to stagger by // Issue #140 xTicks .selectAll("text") .attr('transform', function(d,i,j) { return getTranslate(0, (j % 2 == 0 ? staggerUp : staggerDown)); }); var totalInBetweenTicks = d3.selectAll(".nv-x.nv-axis .nv-wrap g g text")[0].length; g.selectAll(".nv-x.nv-axis .nv-axisMaxMin text") .attr("transform", function(d,i) { return getTranslate(0, (i === 0 || totalInBetweenTicks % 2 !== 0) ? staggerDown : staggerUp); }); } if (wrapLabels) { g.selectAll('.tick text') .call(nv.utils.wrapTicks, chart.xAxis.rangeBand()) } if (reduceXTicks) xTicks .filter(function(d,i) { return i % Math.ceil(data[0].values.length / (availableWidth / 100)) !== 0; }) .selectAll('text, line') .style('opacity', 0); if(rotateLabels) xTicks .selectAll('.tick text') .attr('transform', 'rotate(' + rotateLabels + ' 0,0)') .style('text-anchor', rotateLabels > 0 ? 'start' : 'end'); g.select('.nv-x.nv-axis').selectAll('g.nv-axisMaxMin text') .style('opacity', 1); } if (showYAxis) { yAxis .scale(y) ._ticks( nv.utils.calcTicksY(availableHeight/36, data) ) .tickSize( -availableWidth, 0); g.select('.nv-y.nv-axis') .call(yAxis); } //Set up interactive layer if (useInteractiveGuideline) { interactiveLayer .width(availableWidth) .height(availableHeight) .margin({left:margin.left, top:margin.top}) .svgContainer(container) .xScale(x); wrap.select(".nv-interactive").call(interactiveLayer); } //============================================================ // Event Handling/Dispatching (in chart's scope) //------------------------------------------------------------ legend.dispatch.on('stateChange', function(newState) { for (var key in newState) state[key] = newState[key]; dispatch.stateChange(state); chart.update(); }); controls.dispatch.on('legendClick', function(d,i) { if (!d.disabled) return; controlsData = controlsData.map(function(s) { s.disabled = true; return s; }); d.disabled = false; switch (d.key) { case 'Grouped': case controlLabels.grouped: multibar.stacked(false); break; case 'Stacked': case controlLabels.stacked: multibar.stacked(true); break; } state.stacked = multibar.stacked(); dispatch.stateChange(state); chart.update(); }); // Update chart from a state object passed to event handler dispatch.on('changeState', function(e) { if (typeof e.disabled !== 'undefined') { data.forEach(function(series,i) { series.disabled = e.disabled[i]; }); state.disabled = e.disabled; } if (typeof e.stacked !== 'undefined') { multibar.stacked(e.stacked); state.stacked = e.stacked; stacked = e.stacked; } chart.update(); }); if (useInteractiveGuideline) { interactiveLayer.dispatch.on('elementMousemove', function(e) { if (e.pointXValue == undefined) return; var singlePoint, pointIndex, pointXLocation, xValue, allData = []; data .filter(function(series, i) { series.seriesIndex = i; return !series.disabled; }) .forEach(function(series,i) { pointIndex = x.domain().indexOf(e.pointXValue) var point = series.values[pointIndex]; if (point === undefined) return; xValue = point.x; if (singlePoint === undefined) singlePoint = point; if (pointXLocation === undefined) pointXLocation = e.mouseX allData.push({ key: series.key, value: chart.y()(point, pointIndex), color: color(series,series.seriesIndex), data: series.values[pointIndex] }); }); interactiveLayer.tooltip .data({ value: xValue, index: pointIndex, series: allData })(); interactiveLayer.renderGuideLine(pointXLocation); }); interactiveLayer.dispatch.on("elementMouseout",function(e) { interactiveLayer.tooltip.hidden(true); }); } else { multibar.dispatch.on('elementMouseover.tooltip', function(evt) { evt.value = chart.x()(evt.data); evt['series'] = { key: evt.data.key, value: chart.y()(evt.data), color: evt.color }; tooltip.data(evt).hidden(false); }); multibar.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true); }); multibar.dispatch.on('elementMousemove.tooltip', function(evt) { tooltip(); }); } }); renderWatch.renderEnd('multibarchart immediate'); return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ // expose chart's sub-components chart.dispatch = dispatch; chart.multibar = multibar; chart.legend = legend; chart.controls = controls; chart.xAxis = xAxis; chart.yAxis = yAxis; chart.state = state; chart.tooltip = tooltip; chart.interactiveLayer = interactiveLayer; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, showLegend: {get: function(){return showLegend;}, set: function(_){showLegend=_;}}, legendPosition: {get: function(){return legendPosition;}, set: function(_){legendPosition=_;}}, showControls: {get: function(){return showControls;}, set: function(_){showControls=_;}}, controlLabels: {get: function(){return controlLabels;}, set: function(_){controlLabels=_;}}, showXAxis: {get: function(){return showXAxis;}, set: function(_){showXAxis=_;}}, showYAxis: {get: function(){return showYAxis;}, set: function(_){showYAxis=_;}}, defaultState: {get: function(){return defaultState;}, set: function(_){defaultState=_;}}, noData: {get: function(){return noData;}, set: function(_){noData=_;}}, reduceXTicks: {get: function(){return reduceXTicks;}, set: function(_){reduceXTicks=_;}}, rotateLabels: {get: function(){return rotateLabels;}, set: function(_){rotateLabels=_;}}, staggerLabels: {get: function(){return staggerLabels;}, set: function(_){staggerLabels=_;}}, wrapLabels: {get: function(){return wrapLabels;}, set: function(_){wrapLabels=!!_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ if (_.top !== undefined) { margin.top = _.top; marginTop = _.top; } margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; multibar.duration(duration); xAxis.duration(duration); yAxis.duration(duration); renderWatch.reset(duration); }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); legend.color(color); }}, rightAlignYAxis: {get: function(){return rightAlignYAxis;}, set: function(_){ rightAlignYAxis = _; yAxis.orient( rightAlignYAxis ? 'right' : 'left'); }}, useInteractiveGuideline: {get: function(){return useInteractiveGuideline;}, set: function(_){ useInteractiveGuideline = _; }}, barColor: {get: function(){return multibar.barColor;}, set: function(_){ multibar.barColor(_); legend.color(function(d,i) {return d3.rgb('#ccc').darker(i * 1.5).toString();}) }} }); nv.utils.inheritOptions(chart, multibar); nv.utils.initOptions(chart); return chart; }; ================================================ FILE: src/models/multiBarHorizontal.js ================================================ nv.models.multiBarHorizontal = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 0, right: 0, bottom: 0, left: 0} , width = 960 , height = 500 , id = Math.floor(Math.random() * 10000) //Create semi-unique ID in case user doesn't select one , container = null , x = d3.scale.ordinal() , y = d3.scale.linear() , getX = function(d) { return d.x } , getY = function(d) { return d.y } , getYerr = function(d) { return d.yErr } , forceY = [0] // 0 is forced by default.. this makes sense for the majority of bar graphs... user can always do chart.forceY([]) to remove , color = nv.utils.defaultColor() , barColor = null // adding the ability to set the color for each rather than the whole group , disabled // used in conjunction with barColor to communicate from multiBarHorizontalChart what series are disabled , stacked = false , showValues = false , showBarLabels = false , valuePadding = 60 , groupSpacing = 0.1 , fillOpacity = 0.75 , valueFormat = d3.format(',.2f') , delay = 1200 , xDomain , yDomain , xRange , yRange , duration = 250 , dispatch = d3.dispatch('chartClick', 'elementClick', 'elementDblClick', 'elementMouseover', 'elementMouseout', 'elementMousemove', 'renderEnd') ; //============================================================ // Private Variables //------------------------------------------------------------ var x0, y0; //used to store previous scales var renderWatch = nv.utils.renderWatch(dispatch, duration); function chart(selection) { renderWatch.reset(); selection.each(function(data) { var availableWidth = width - margin.left - margin.right, availableHeight = height - margin.top - margin.bottom; container = d3.select(this); nv.utils.initSVG(container); if (stacked) data = d3.layout.stack() .offset('zero') .values(function(d){ return d.values }) .y(getY) (data); //add series index and key to each data point for reference data.forEach(function(series, i) { series.values.forEach(function(point) { point.series = i; point.key = series.key; }); }); // HACK for negative value stacking if (stacked) data[0].values.map(function(d,i) { var posBase = 0, negBase = 0; data.map(function(d) { var f = d.values[i] f.size = Math.abs(f.y); if (f.y<0) { f.y1 = negBase - f.size; negBase = negBase - f.size; } else { f.y1 = posBase; posBase = posBase + f.size; } }); }); // Setup Scales // remap and flatten the data for use in calculating the scales' domains var seriesData = (xDomain && yDomain) ? [] : // if we know xDomain and yDomain, no need to calculate data.map(function(d) { return d.values.map(function(d,i) { return { x: getX(d,i), y: getY(d,i), y0: d.y0, y1: d.y1 } }) }); x.domain(xDomain || d3.merge(seriesData).map(function(d) { return d.x })) .rangeBands(xRange || [0, availableHeight], groupSpacing); y.domain(yDomain || d3.extent(d3.merge(seriesData).map(function(d) { return stacked ? (d.y > 0 ? d.y1 + d.y : d.y1 ) : d.y }).concat(forceY))) if (showValues && !stacked) y.range(yRange || [(y.domain()[0] < 0 ? valuePadding : 0), availableWidth - (y.domain()[1] > 0 ? valuePadding : 0) ]); else y.range(yRange || [0, availableWidth]); x0 = x0 || x; y0 = y0 || d3.scale.linear().domain(y.domain()).range([y(0),y(0)]); // Setup containers and skeleton of chart var wrap = d3.select(this).selectAll('g.nv-wrap.nv-multibarHorizontal').data([data]); var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-multibarHorizontal'); var defsEnter = wrapEnter.append('defs'); var gEnter = wrapEnter.append('g'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-groups'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); var groups = wrap.select('.nv-groups').selectAll('.nv-group') .data(function(d) { return d }, function(d,i) { return i }); groups.enter().append('g') .style('stroke-opacity', 1e-6) .style('fill-opacity', 1e-6); groups.exit().watchTransition(renderWatch, 'multibarhorizontal: exit groups') .style('stroke-opacity', 1e-6) .style('fill-opacity', 1e-6) .remove(); groups .attr('class', function(d,i) { return 'nv-group nv-series-' + i }) .classed('hover', function(d) { return d.hover }) .style('fill', function(d,i){ return color(d, i) }) .style('stroke', function(d,i){ return color(d, i) }); groups.watchTransition(renderWatch, 'multibarhorizontal: groups') .style('stroke-opacity', 1) .style('fill-opacity', fillOpacity); var bars = groups.selectAll('g.nv-bar') .data(function(d) { return d.values }); bars.exit().remove(); var barsEnter = bars.enter().append('g') .attr('transform', function(d,i,j) { return 'translate(' + y0(stacked ? d.y0 : 0) + ',' + (stacked ? 0 : (j * x.rangeBand() / data.length ) + x(getX(d,i))) + ')' }); barsEnter.append('rect') .attr('width', 0) .attr('height', x.rangeBand() / (stacked ? 1 : data.length) ) bars .on('mouseover', function(d,i) { //TODO: figure out why j works above, but not here d3.select(this).classed('hover', true); dispatch.elementMouseover({ data: d, index: i, color: d3.select(this).style("fill") }); }) .on('mouseout', function(d,i) { d3.select(this).classed('hover', false); dispatch.elementMouseout({ data: d, index: i, color: d3.select(this).style("fill") }); }) .on('mouseout', function(d,i) { dispatch.elementMouseout({ data: d, index: i, color: d3.select(this).style("fill") }); }) .on('mousemove', function(d,i) { dispatch.elementMousemove({ data: d, index: i, color: d3.select(this).style("fill") }); }) .on('click', function(d,i) { var element = this; dispatch.elementClick({ data: d, index: i, color: d3.select(this).style("fill"), event: d3.event, element: element }); d3.event.stopPropagation(); }) .on('dblclick', function(d,i) { dispatch.elementDblClick({ data: d, index: i, color: d3.select(this).style("fill") }); d3.event.stopPropagation(); }); if (getYerr(data[0],0)) { barsEnter.append('polyline'); bars.select('polyline') .attr('fill', 'none') .attr('points', function(d,i) { var xerr = getYerr(d,i) , mid = 0.8 * x.rangeBand() / ((stacked ? 1 : data.length) * 2); xerr = xerr.length ? xerr : [-Math.abs(xerr), Math.abs(xerr)]; xerr = xerr.map(function(e) { return y(e + ((getY(d,i) < 0) ? 0 : getY(d,i))) - y(0); }); var a = [[xerr[0],-mid], [xerr[0],mid], [xerr[0],0], [xerr[1],0], [xerr[1],-mid], [xerr[1],mid]]; return a.map(function (path) { return path.join(',') }).join(' '); }) .attr('transform', function(d,i) { var mid = x.rangeBand() / ((stacked ? 1 : data.length) * 2); return 'translate(0, ' + mid + ')'; }); } barsEnter.append('text'); if (showValues && !stacked) { bars.select('text') .attr('text-anchor', function(d,i) { return getY(d,i) < 0 ? 'end' : 'start' }) .attr('y', x.rangeBand() / (data.length * 2)) .attr('dy', '.32em') .text(function(d,i) { var t = valueFormat(getY(d,i)) , yerr = getYerr(d,i); if (yerr === undefined) return t; if (!yerr.length) return t + '±' + valueFormat(Math.abs(yerr)); return t + '+' + valueFormat(Math.abs(yerr[1])) + '-' + valueFormat(Math.abs(yerr[0])); }); bars.watchTransition(renderWatch, 'multibarhorizontal: bars') .select('text') .attr('x', function(d,i) { return getY(d,i) < 0 ? -4 : y(getY(d,i)) - y(0) + 4 }) } else { bars.selectAll('text').text(''); } if (showBarLabels && !stacked) { barsEnter.append('text').classed('nv-bar-label',true); bars.select('text.nv-bar-label') .attr('text-anchor', function(d,i) { return getY(d,i) < 0 ? 'start' : 'end' }) .attr('y', x.rangeBand() / (data.length * 2)) .attr('dy', '.32em') .text(function(d,i) { return getX(d,i) }); bars.watchTransition(renderWatch, 'multibarhorizontal: bars') .select('text.nv-bar-label') .attr('x', function(d,i) { return getY(d,i) < 0 ? y(0) - y(getY(d,i)) + 4 : -4 }); } else { bars.selectAll('text.nv-bar-label').text(''); } bars .attr('class', function(d,i) { return getY(d,i) < 0 ? 'nv-bar negative' : 'nv-bar positive'}) if (barColor) { if (!disabled) disabled = data.map(function() { return true }); bars .style('fill', function(d,i,j) { return d3.rgb(barColor(d,i)).darker( disabled.map(function(d,i) { return i }).filter(function(d,i){ return !disabled[i] })[j] ).toString(); }) .style('stroke', function(d,i,j) { return d3.rgb(barColor(d,i)).darker( disabled.map(function(d,i) { return i }).filter(function(d,i){ return !disabled[i] })[j] ).toString(); }); } if (stacked) bars.watchTransition(renderWatch, 'multibarhorizontal: bars') .attr('transform', function(d,i) { return 'translate(' + y(d.y1) + ',' + x(getX(d,i)) + ')' }) .select('rect') .attr('width', function(d,i) { return Math.abs(y(getY(d,i) + d.y0) - y(d.y0)) || 0 }) .attr('height', x.rangeBand() ); else bars.watchTransition(renderWatch, 'multibarhorizontal: bars') .attr('transform', function(d,i) { //TODO: stacked must be all positive or all negative, not both? return 'translate(' + (getY(d,i) < 0 ? y(getY(d,i)) : y(0)) + ',' + (d.series * x.rangeBand() / data.length + x(getX(d,i)) ) + ')' }) .select('rect') .attr('height', x.rangeBand() / data.length ) .attr('width', function(d,i) { return Math.max(Math.abs(y(getY(d,i)) - y(0)),1) || 0 }); //store old scales for use in transitions on update x0 = x.copy(); y0 = y.copy(); }); renderWatch.renderEnd('multibarHorizontal immediate'); return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.dispatch = dispatch; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, x: {get: function(){return getX;}, set: function(_){getX=_;}}, y: {get: function(){return getY;}, set: function(_){getY=_;}}, yErr: {get: function(){return getYerr;}, set: function(_){getYerr=_;}}, xScale: {get: function(){return x;}, set: function(_){x=_;}}, yScale: {get: function(){return y;}, set: function(_){y=_;}}, xDomain: {get: function(){return xDomain;}, set: function(_){xDomain=_;}}, yDomain: {get: function(){return yDomain;}, set: function(_){yDomain=_;}}, xRange: {get: function(){return xRange;}, set: function(_){xRange=_;}}, yRange: {get: function(){return yRange;}, set: function(_){yRange=_;}}, forceY: {get: function(){return forceY;}, set: function(_){forceY=_;}}, stacked: {get: function(){return stacked;}, set: function(_){stacked=_;}}, showValues: {get: function(){return showValues;}, set: function(_){showValues=_;}}, // this shows the group name, seems pointless? //showBarLabels: {get: function(){return showBarLabels;}, set: function(_){showBarLabels=_;}}, disabled: {get: function(){return disabled;}, set: function(_){disabled=_;}}, id: {get: function(){return id;}, set: function(_){id=_;}}, valueFormat: {get: function(){return valueFormat;}, set: function(_){valueFormat=_;}}, valuePadding: {get: function(){return valuePadding;}, set: function(_){valuePadding=_;}}, groupSpacing: {get: function(){return groupSpacing;}, set: function(_){groupSpacing=_;}}, fillOpacity: {get: function(){return fillOpacity;}, set: function(_){fillOpacity=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; renderWatch.reset(duration); }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); }}, barColor: {get: function(){return barColor;}, set: function(_){ barColor = _ ? nv.utils.getColor(_) : null; }} }); nv.utils.initOptions(chart); return chart; }; ================================================ FILE: src/models/multiBarHorizontalChart.js ================================================ nv.models.multiBarHorizontalChart = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var multibar = nv.models.multiBarHorizontal() , xAxis = nv.models.axis() , yAxis = nv.models.axis() , legend = nv.models.legend().height(30) , controls = nv.models.legend().height(30) , tooltip = nv.models.tooltip() ; var margin = {top: 30, right: 20, bottom: 50, left: 60} , marginTop = null , width = null , height = null , color = nv.utils.defaultColor() , showControls = true , controlsPosition = 'top' , controlLabels = {} , showLegend = true , legendPosition = 'top' , showXAxis = true , showYAxis = true , stacked = false , x //can be accessed via chart.xScale() , y //can be accessed via chart.yScale() , state = nv.utils.state() , defaultState = null , noData = null , dispatch = d3.dispatch('stateChange', 'changeState','renderEnd') , controlWidth = function() { return showControls ? 180 : 0 } , duration = 250 ; state.stacked = false; // DEPRECATED Maintained for backward compatibility multibar.stacked(stacked); xAxis .orient('left') .tickPadding(5) .showMaxMin(false) .tickFormat(function(d) { return d }) ; yAxis .orient('bottom') .tickFormat(d3.format(',.1f')) ; tooltip .duration(0) .valueFormatter(function(d, i) { return yAxis.tickFormat()(d, i); }) .headerFormatter(function(d, i) { return xAxis.tickFormat()(d, i); }); controls.updateState(false); //============================================================ // Private Variables //------------------------------------------------------------ var stateGetter = function(data) { return function(){ return { active: data.map(function(d) { return !d.disabled }), stacked: stacked }; } }; var stateSetter = function(data) { return function(state) { if (state.stacked !== undefined) stacked = state.stacked; if (state.active !== undefined) data.forEach(function(series,i) { series.disabled = !state.active[i]; }); } }; var renderWatch = nv.utils.renderWatch(dispatch, duration); function chart(selection) { renderWatch.reset(); renderWatch.models(multibar); if (showXAxis) renderWatch.models(xAxis); if (showYAxis) renderWatch.models(yAxis); selection.each(function(data) { var container = d3.select(this), that = this; nv.utils.initSVG(container); var availableWidth = nv.utils.availableWidth(width, container, margin), availableHeight = nv.utils.availableHeight(height, container, margin); chart.update = function() { container.transition().duration(duration).call(chart) }; chart.container = this; stacked = multibar.stacked(); state .setter(stateSetter(data), chart.update) .getter(stateGetter(data)) .update(); // DEPRECATED set state.disableddisabled state.disabled = data.map(function(d) { return !!d.disabled }); if (!defaultState) { var key; defaultState = {}; for (key in state) { if (state[key] instanceof Array) defaultState[key] = state[key].slice(0); else defaultState[key] = state[key]; } } // Display No Data message if there's nothing to show. if (!data || !data.length || !data.filter(function(d) { return d.values.length }).length) { nv.utils.noData(chart, container) return chart; } else { container.selectAll('.nv-noData').remove(); } // Setup Scales x = multibar.xScale(); y = multibar.yScale().clamp(true); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-multiBarHorizontalChart').data([data]); var gEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-multiBarHorizontalChart').append('g'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-x nv-axis'); gEnter.append('g').attr('class', 'nv-y nv-axis') .append('g').attr('class', 'nv-zeroLine') .append('line'); gEnter.append('g').attr('class', 'nv-barsWrap'); gEnter.append('g').attr('class', 'nv-legendWrap'); gEnter.append('g').attr('class', 'nv-controlsWrap'); // Legend if (!showLegend) { g.select('.nv-legendWrap').selectAll('*').remove(); } else { legend.width(availableWidth - controlWidth()); g.select('.nv-legendWrap') .datum(data) .call(legend); if (legendPosition === 'bottom') { margin.bottom = xAxis.height() + legend.height(); availableHeight = nv.utils.availableHeight(height, container, margin); g.select('.nv-legendWrap') .attr('transform', 'translate(' + controlWidth() + ',' + (availableHeight + xAxis.height()) +')'); } else if (legendPosition === 'top') { if (!marginTop && legend.height() !== margin.top) { margin.top = legend.height(); availableHeight = nv.utils.availableHeight(height, container, margin); } g.select('.nv-legendWrap') .attr('transform', 'translate(' + controlWidth() + ',' + (-margin.top) +')'); } } // Controls if (!showControls) { g.select('.nv-controlsWrap').selectAll('*').remove(); } else { var controlsData = [ { key: controlLabels.grouped || 'Grouped', disabled: multibar.stacked() }, { key: controlLabels.stacked || 'Stacked', disabled: !multibar.stacked() } ]; controls.width(controlWidth()).color(['#444', '#444', '#444']); if (controlsPosition === 'bottom') { margin.bottom = xAxis.height() + legend.height(); availableHeight = nv.utils.availableHeight(height, container, margin); g.select('.nv-controlsWrap') .datum(controlsData) .attr('transform', 'translate(0,' + (availableHeight + xAxis.height()) +')') .call(controls); } else if (controlsPosition === 'top') { g.select('.nv-controlsWrap') .datum(controlsData) .attr('transform', 'translate(0,' + (-margin.top) +')') .call(controls); } } wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); // Main Chart Component(s) multibar .disabled(data.map(function(series) { return series.disabled })) .width(availableWidth) .height(availableHeight) .color(data.map(function(d,i) { return d.color || color(d, i); }).filter(function(d,i) { return !data[i].disabled })); var barsWrap = g.select('.nv-barsWrap') .datum(data.filter(function(d) { return !d.disabled })); barsWrap.transition().call(multibar); // Setup Axes if (showXAxis) { xAxis .scale(x) ._ticks( nv.utils.calcTicksY(availableHeight/24, data) ) .tickSize(-availableWidth, 0); g.select('.nv-x.nv-axis').call(xAxis); var xTicks = g.select('.nv-x.nv-axis').selectAll('g'); xTicks .selectAll('line, text'); } if (showYAxis) { yAxis .scale(y) ._ticks( nv.utils.calcTicksX(availableWidth/100, data) ) .tickSize( -availableHeight, 0); g.select('.nv-y.nv-axis') .attr('transform', 'translate(0,' + availableHeight + ')'); g.select('.nv-y.nv-axis').call(yAxis); } // Zero line g.select(".nv-zeroLine line") .attr("x1", y(0)) .attr("x2", y(0)) .attr("y1", 0) .attr("y2", -availableHeight) ; //============================================================ // Event Handling/Dispatching (in chart's scope) //------------------------------------------------------------ legend.dispatch.on('stateChange', function(newState) { for (var key in newState) state[key] = newState[key]; dispatch.stateChange(state); chart.update(); }); controls.dispatch.on('legendClick', function(d,i) { if (!d.disabled) return; controlsData = controlsData.map(function(s) { s.disabled = true; return s; }); d.disabled = false; switch (d.key) { case 'Grouped': case controlLabels.grouped: multibar.stacked(false); break; case 'Stacked': case controlLabels.stacked: multibar.stacked(true); break; } state.stacked = multibar.stacked(); dispatch.stateChange(state); stacked = multibar.stacked(); chart.update(); }); // Update chart from a state object passed to event handler dispatch.on('changeState', function(e) { if (typeof e.disabled !== 'undefined') { data.forEach(function(series,i) { series.disabled = e.disabled[i]; }); state.disabled = e.disabled; } if (typeof e.stacked !== 'undefined') { multibar.stacked(e.stacked); state.stacked = e.stacked; stacked = e.stacked; } chart.update(); }); }); renderWatch.renderEnd('multibar horizontal chart immediate'); return chart; } //============================================================ // Event Handling/Dispatching (out of chart's scope) //------------------------------------------------------------ multibar.dispatch.on('elementMouseover.tooltip', function(evt) { evt.value = chart.x()(evt.data); evt['series'] = { key: evt.data.key, value: chart.y()(evt.data), color: evt.color }; tooltip.data(evt).hidden(false); }); multibar.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true); }); multibar.dispatch.on('elementMousemove.tooltip', function(evt) { tooltip(); }); //============================================================ // Expose Public Variables //------------------------------------------------------------ // expose chart's sub-components chart.dispatch = dispatch; chart.multibar = multibar; chart.legend = legend; chart.controls = controls; chart.xAxis = xAxis; chart.yAxis = yAxis; chart.state = state; chart.tooltip = tooltip; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, showLegend: {get: function(){return showLegend;}, set: function(_){showLegend=_;}}, legendPosition: {get: function(){return legendPosition;}, set: function(_){legendPosition=_;}}, controlsPosition: {get: function(){return controlsPosition;}, set: function(_){controlsPosition=_;}}, showControls: {get: function(){return showControls;}, set: function(_){showControls=_;}}, controlLabels: {get: function(){return controlLabels;}, set: function(_){controlLabels=_;}}, showXAxis: {get: function(){return showXAxis;}, set: function(_){showXAxis=_;}}, showYAxis: {get: function(){return showYAxis;}, set: function(_){showYAxis=_;}}, defaultState: {get: function(){return defaultState;}, set: function(_){defaultState=_;}}, noData: {get: function(){return noData;}, set: function(_){noData=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ if (_.top !== undefined) { margin.top = _.top; marginTop = _.top; } margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; renderWatch.reset(duration); multibar.duration(duration); xAxis.duration(duration); yAxis.duration(duration); }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); legend.color(color); }}, barColor: {get: function(){return multibar.barColor;}, set: function(_){ multibar.barColor(_); legend.color(function(d,i) {return d3.rgb('#ccc').darker(i * 1.5).toString();}) }} }); nv.utils.inheritOptions(chart, multibar); nv.utils.initOptions(chart); return chart; }; ================================================ FILE: src/models/multiChart.js ================================================ nv.models.multiChart = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 30, right: 20, bottom: 50, left: 60}, marginTop = null, color = nv.utils.defaultColor(), width = null, height = null, showLegend = true, noData = null, yDomain1, yDomain2, getX = function(d) { return d.x }, getY = function(d) { return d.y}, interpolate = 'linear', useVoronoi = true, interactiveLayer = nv.interactiveGuideline(), useInteractiveGuideline = false, legendRightAxisHint = ' (right axis)', duration = 250 ; //============================================================ // Private Variables //------------------------------------------------------------ var x = d3.scale.linear(), yScale1 = d3.scale.linear(), yScale2 = d3.scale.linear(), lines1 = nv.models.line().yScale(yScale1).duration(duration), lines2 = nv.models.line().yScale(yScale2).duration(duration), scatters1 = nv.models.scatter().yScale(yScale1).duration(duration), scatters2 = nv.models.scatter().yScale(yScale2).duration(duration), bars1 = nv.models.multiBar().stacked(false).yScale(yScale1).duration(duration), bars2 = nv.models.multiBar().stacked(false).yScale(yScale2).duration(duration), stack1 = nv.models.stackedArea().yScale(yScale1).duration(duration), stack2 = nv.models.stackedArea().yScale(yScale2).duration(duration), xAxis = nv.models.axis().scale(x).orient('bottom').tickPadding(5).duration(duration), yAxis1 = nv.models.axis().scale(yScale1).orient('left').duration(duration), yAxis2 = nv.models.axis().scale(yScale2).orient('right').duration(duration), legend = nv.models.legend().height(30), tooltip = nv.models.tooltip(), dispatch = d3.dispatch(); var charts = [lines1, lines2, scatters1, scatters2, bars1, bars2, stack1, stack2]; function chart(selection) { selection.each(function(data) { var container = d3.select(this), that = this; nv.utils.initSVG(container); chart.update = function() { container.transition().call(chart); }; chart.container = this; var availableWidth = nv.utils.availableWidth(width, container, margin), availableHeight = nv.utils.availableHeight(height, container, margin); var dataLines1 = data.filter(function(d) {return d.type == 'line' && d.yAxis == 1}); var dataLines2 = data.filter(function(d) {return d.type == 'line' && d.yAxis == 2}); var dataScatters1 = data.filter(function(d) {return d.type == 'scatter' && d.yAxis == 1}); var dataScatters2 = data.filter(function(d) {return d.type == 'scatter' && d.yAxis == 2}); var dataBars1 = data.filter(function(d) {return d.type == 'bar' && d.yAxis == 1}); var dataBars2 = data.filter(function(d) {return d.type == 'bar' && d.yAxis == 2}); var dataStack1 = data.filter(function(d) {return d.type == 'area' && d.yAxis == 1}); var dataStack2 = data.filter(function(d) {return d.type == 'area' && d.yAxis == 2}); // Display noData message if there's nothing to show. if (!data || !data.length || !data.filter(function(d) { return d.values.length }).length) { nv.utils.noData(chart, container); return chart; } else { container.selectAll('.nv-noData').remove(); } var series1 = data.filter(function(d) {return !d.disabled && d.yAxis == 1}) .map(function(d) { return d.values.map(function(d,i) { return { x: getX(d), y: getY(d) } }) }); var series2 = data.filter(function(d) {return !d.disabled && d.yAxis == 2}) .map(function(d) { return d.values.map(function(d,i) { return { x: getX(d), y: getY(d) } }) }); x .domain(d3.extent(d3.merge(series1.concat(series2)), function(d) { return d.x })) .range([0, availableWidth]); var wrap = container.selectAll('g.wrap.multiChart').data([data]); var gEnter = wrap.enter().append('g').attr('class', 'wrap nvd3 multiChart').append('g'); gEnter.append('g').attr('class', 'nv-x nv-axis'); gEnter.append('g').attr('class', 'nv-y1 nv-axis'); gEnter.append('g').attr('class', 'nv-y2 nv-axis'); gEnter.append('g').attr('class', 'stack1Wrap'); gEnter.append('g').attr('class', 'stack2Wrap'); gEnter.append('g').attr('class', 'bars1Wrap'); gEnter.append('g').attr('class', 'bars2Wrap'); gEnter.append('g').attr('class', 'scatters1Wrap'); gEnter.append('g').attr('class', 'scatters2Wrap'); gEnter.append('g').attr('class', 'lines1Wrap'); gEnter.append('g').attr('class', 'lines2Wrap'); gEnter.append('g').attr('class', 'legendWrap'); gEnter.append('g').attr('class', 'nv-interactive'); var g = wrap.select('g'); var color_array = data.map(function(d,i) { return data[i].color || color(d, i); }); // Legend if (!showLegend) { g.select('.legendWrap').selectAll('*').remove(); } else { var legendWidth = legend.align() ? availableWidth / 2 : availableWidth; var legendXPosition = legend.align() ? legendWidth : 0; legend.width(legendWidth); legend.color(color_array); g.select('.legendWrap') .datum(data.map(function(series) { series.originalKey = series.originalKey === undefined ? series.key : series.originalKey; series.key = series.originalKey + (series.yAxis == 1 ? '' : legendRightAxisHint); return series; })) .call(legend); if (!marginTop && legend.height() !== margin.top) { margin.top = legend.height(); availableHeight = nv.utils.availableHeight(height, container, margin); } g.select('.legendWrap') .attr('transform', 'translate(' + legendXPosition + ',' + (-margin.top) +')'); } lines1 .width(availableWidth) .height(availableHeight) .interpolate(interpolate) .color(color_array.filter(function(d,i) { return !data[i].disabled && data[i].yAxis == 1 && data[i].type == 'line'})); lines2 .width(availableWidth) .height(availableHeight) .interpolate(interpolate) .color(color_array.filter(function(d,i) { return !data[i].disabled && data[i].yAxis == 2 && data[i].type == 'line'})); scatters1 .width(availableWidth) .height(availableHeight) .color(color_array.filter(function(d,i) { return !data[i].disabled && data[i].yAxis == 1 && data[i].type == 'scatter'})); scatters2 .width(availableWidth) .height(availableHeight) .color(color_array.filter(function(d,i) { return !data[i].disabled && data[i].yAxis == 2 && data[i].type == 'scatter'})); bars1 .width(availableWidth) .height(availableHeight) .color(color_array.filter(function(d,i) { return !data[i].disabled && data[i].yAxis == 1 && data[i].type == 'bar'})); bars2 .width(availableWidth) .height(availableHeight) .color(color_array.filter(function(d,i) { return !data[i].disabled && data[i].yAxis == 2 && data[i].type == 'bar'})); stack1 .width(availableWidth) .height(availableHeight) .interpolate(interpolate) .color(color_array.filter(function(d,i) { return !data[i].disabled && data[i].yAxis == 1 && data[i].type == 'area'})); stack2 .width(availableWidth) .height(availableHeight) .interpolate(interpolate) .color(color_array.filter(function(d,i) { return !data[i].disabled && data[i].yAxis == 2 && data[i].type == 'area'})); g.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); var lines1Wrap = g.select('.lines1Wrap') .datum(dataLines1.filter(function(d){return !d.disabled})); var scatters1Wrap = g.select('.scatters1Wrap') .datum(dataScatters1.filter(function(d){return !d.disabled})); var bars1Wrap = g.select('.bars1Wrap') .datum(dataBars1.filter(function(d){return !d.disabled})); var stack1Wrap = g.select('.stack1Wrap') .datum(dataStack1.filter(function(d){return !d.disabled})); var lines2Wrap = g.select('.lines2Wrap') .datum(dataLines2.filter(function(d){return !d.disabled})); var scatters2Wrap = g.select('.scatters2Wrap') .datum(dataScatters2.filter(function(d){return !d.disabled})); var bars2Wrap = g.select('.bars2Wrap') .datum(dataBars2.filter(function(d){return !d.disabled})); var stack2Wrap = g.select('.stack2Wrap') .datum(dataStack2.filter(function(d){return !d.disabled})); var extraValue1BarStacked = []; if (bars1.stacked() && dataBars1.length) { var extraValue1BarStacked = dataBars1.filter(function(d){return !d.disabled}).map(function(a){return a.values}); if (extraValue1BarStacked.length > 0) extraValue1BarStacked = extraValue1BarStacked.reduce(function(a,b){ return a.map(function(aVal,i){return {x: aVal.x, y: aVal.y + b[i].y}}) }); } if (dataBars1.length) { extraValue1BarStacked.push({x:0, y:0}); } var extraValue2BarStacked = []; if (bars2.stacked() && dataBars2.length) { var extraValue2BarStacked = dataBars2.filter(function(d){return !d.disabled}).map(function(a){return a.values}); if (extraValue2BarStacked.length > 0) extraValue2BarStacked = extraValue2BarStacked.reduce(function(a,b){ return a.map(function(aVal,i){return {x: aVal.x, y: aVal.y + b[i].y}}) }); } if (dataBars2.length) { extraValue2BarStacked.push({x:0, y:0}); } function getStackedAreaYs(series) { return d3.transpose(series).map(function(x) { return x.map(function(g) { return g.y; }); }).map(function(x) {return d3.sum(x);}) } yScale1 .domain(yDomain1 || d3.extent(d3.merge(series1).concat(extraValue1BarStacked), function(d) { return d.y } )) .range([0, availableHeight]); yScale2 .domain(yDomain2 || d3.extent(d3.merge(series2).concat(extraValue2BarStacked), function(d) { return d.y } )) .range([0, availableHeight]); lines1.yDomain(yScale1.domain()); scatters1.yDomain(yScale1.domain()); if(bars1.stacked()) { var yStackScale1 = yScale1.domain([0, d3.max(getStackedAreaYs(series1))]).range([0, availableHeight]); bars1.yDomain(yStackScale1.domain()) } else { bars1.yDomain(yScale1.domain()); } stack1.yDomain(yScale1.domain()); lines2.yDomain(yScale2.domain()); scatters2.yDomain(yScale2.domain()); if(bars2.stacked()) { var yStackScale2 = yScale2.domain([0, d3.max(getStackedAreaYs(series2))]).range([0, availableHeight]); bars2.yDomain(yStackScale2.domain()) } else { bars2.yDomain(yScale2.domain()); } stack2.yDomain(yScale2.domain()); if(dataStack1.length){d3.transition(stack1Wrap).call(stack1);} if(dataStack2.length){d3.transition(stack2Wrap).call(stack2);} if(dataBars1.length){d3.transition(bars1Wrap).call(bars1);} if(dataBars2.length){d3.transition(bars2Wrap).call(bars2);} if(dataLines1.length){d3.transition(lines1Wrap).call(lines1);} if(dataLines2.length){d3.transition(lines2Wrap).call(lines2);} if(dataScatters1.length){d3.transition(scatters1Wrap).call(scatters1);} if(dataScatters2.length){d3.transition(scatters2Wrap).call(scatters2);} xAxis ._ticks( nv.utils.calcTicksX(availableWidth/100, data) ) .tickSize(-availableHeight, 0); g.select('.nv-x.nv-axis') .attr('transform', 'translate(0,' + availableHeight + ')'); d3.transition(g.select('.nv-x.nv-axis')) .call(xAxis); yAxis1 ._ticks( nv.utils.calcTicksY(availableHeight/36, data) ) .tickSize( -availableWidth, 0); d3.transition(g.select('.nv-y1.nv-axis')) .call(yAxis1); yAxis2 ._ticks( nv.utils.calcTicksY(availableHeight/36, data) ) .tickSize( -availableWidth, 0); d3.transition(g.select('.nv-y2.nv-axis')) .call(yAxis2); g.select('.nv-y1.nv-axis') .classed('nv-disabled', series1.length ? false : true) .attr('transform', 'translate(' + x.range()[0] + ',0)'); g.select('.nv-y2.nv-axis') .classed('nv-disabled', series2.length ? false : true) .attr('transform', 'translate(' + x.range()[1] + ',0)'); legend.dispatch.on('stateChange', function(newState) { chart.update(); }); if(useInteractiveGuideline){ interactiveLayer .width(availableWidth) .height(availableHeight) .margin({left:margin.left, top:margin.top}) .svgContainer(container) .xScale(x); wrap.select(".nv-interactive").call(interactiveLayer); } //============================================================ // Event Handling/Dispatching //------------------------------------------------------------ function mouseover_line(evt) { var yaxis = evt.series.yAxis === 2 ? yAxis2 : yAxis1; evt.value = evt.point.x; evt.series = { value: evt.point.y, color: evt.point.color, key: evt.series.key }; tooltip .duration(0) .headerFormatter(function(d, i) { return xAxis.tickFormat()(d, i); }) .valueFormatter(function(d, i) { return yaxis.tickFormat()(d, i); }) .data(evt) .hidden(false); } function mouseover_scatter(evt) { var yaxis = evt.series.yAxis === 2 ? yAxis2 : yAxis1; evt.value = evt.point.x; evt.series = { value: evt.point.y, color: evt.point.color, key: evt.series.key }; tooltip .duration(100) .headerFormatter(function(d, i) { return xAxis.tickFormat()(d, i); }) .valueFormatter(function(d, i) { return yaxis.tickFormat()(d, i); }) .data(evt) .hidden(false); } function mouseover_stack(evt) { var yaxis = evt.series.yAxis === 2 ? yAxis2 : yAxis1; evt.point['x'] = stack1.x()(evt.point); evt.point['y'] = stack1.y()(evt.point); tooltip .duration(0) .headerFormatter(function(d, i) { return xAxis.tickFormat()(d, i); }) .valueFormatter(function(d, i) { return yaxis.tickFormat()(d, i); }) .data(evt) .hidden(false); } function mouseover_bar(evt) { var yaxis = evt.series.yAxis === 2 ? yAxis2 : yAxis1; evt.value = bars1.x()(evt.data); evt['series'] = { value: bars1.y()(evt.data), color: evt.color, key: evt.data.key }; tooltip .duration(0) .headerFormatter(function(d, i) { return xAxis.tickFormat()(d, i); }) .valueFormatter(function(d, i) { return yaxis.tickFormat()(d, i); }) .data(evt) .hidden(false); } function clearHighlights() { for(var i=0, il=charts.length; i < il; i++){ var chart = charts[i]; try { chart.clearHighlights(); } catch(e){} } } function highlightPoint(series, pointIndex, b, pointYValue) { var chartMap = { 'line': { 'yAxis1': { chart: lines1, data: dataLines1 }, 'yAxis2': { chart: lines2, data: dataLines2 } }, 'scatter': { 'yAxis1': { chart: scatters1, data: dataScatters1 }, 'yAxis2': { chart: scatters2, data: dataScatters2 } }, 'bar': { 'yAxis1': { chart: bars1, data: dataBars1 }, 'yAxis2': { chart: bars2, data: dataBars2 } }, 'area': { 'yAxis1': { chart: stack1, data: dataStack1 }, 'yAxis2': { chart: stack2, data: dataStack2 } } }; var relevantChart = chartMap[series.type]['yAxis' + series.yAxis].chart; var relevantDatasets = chartMap[series.type]['yAxis' + series.yAxis].data; var seriesIndex = relevantDatasets.reduce(function (seriesIndex, dataSet, i) { return dataSet.key === series.key ? i : seriesIndex; }, 0); try { relevantChart.highlightPoint(seriesIndex, pointIndex, b, pointYValue); } catch(e){} } if(useInteractiveGuideline){ interactiveLayer.dispatch.on('elementMousemove', function(e) { clearHighlights(); var singlePoint, pointIndex, pointXLocation, allData = []; data .filter(function(series, i) { series.seriesIndex = i; return !series.disabled; }) .forEach(function(series, i) { var extent = x.domain(); var currentValues = series.values.filter(function(d,i) { return chart.x()(d,i) >= extent[0] && chart.x()(d,i) <= extent[1]; }); pointIndex = nv.interactiveBisect(currentValues, e.pointXValue, chart.x()); var point = currentValues[pointIndex]; var pointYValue = chart.y()(point, pointIndex); if (pointYValue !== null && !isNaN(pointYValue) && !series.noHighlightSeries) { highlightPoint(series, pointIndex, true); } if (point === undefined) return; if (singlePoint === undefined) singlePoint = point; if (pointXLocation === undefined) pointXLocation = x(chart.x()(point,pointIndex)); allData.push({ key: series.key, value: pointYValue, color: color(series,series.seriesIndex), data: point, yAxis: series.yAxis == 2 ? yAxis2 : yAxis1 }); }); var defaultValueFormatter = function(d,i) { var yAxis = allData[i].yAxis; return d == null ? "N/A" : yAxis.tickFormat()(d); }; interactiveLayer.tooltip .headerFormatter(function(d, i) { return xAxis.tickFormat()(d, i); }) .valueFormatter(interactiveLayer.tooltip.valueFormatter() || defaultValueFormatter) .data({ value: chart.x()( singlePoint,pointIndex ), index: pointIndex, series: allData })(); interactiveLayer.renderGuideLine(pointXLocation); }); interactiveLayer.dispatch.on("elementMouseout",function(e) { clearHighlights(); }); } else { lines1.dispatch.on('elementMouseover.tooltip', mouseover_line); lines2.dispatch.on('elementMouseover.tooltip', mouseover_line); lines1.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true) }); lines2.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true) }); scatters1.dispatch.on('elementMouseover.tooltip', mouseover_scatter); scatters2.dispatch.on('elementMouseover.tooltip', mouseover_scatter); scatters1.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true) }); scatters2.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true) }); stack1.dispatch.on('elementMouseover.tooltip', mouseover_stack); stack2.dispatch.on('elementMouseover.tooltip', mouseover_stack); stack1.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true) }); stack2.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true) }); bars1.dispatch.on('elementMouseover.tooltip', mouseover_bar); bars2.dispatch.on('elementMouseover.tooltip', mouseover_bar); bars1.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true); }); bars2.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true); }); bars1.dispatch.on('elementMousemove.tooltip', function(evt) { tooltip(); }); bars2.dispatch.on('elementMousemove.tooltip', function(evt) { tooltip(); }); } }); return chart; } //============================================================ // Global getters and setters //------------------------------------------------------------ chart.dispatch = dispatch; chart.legend = legend; chart.lines1 = lines1; chart.lines2 = lines2; chart.scatters1 = scatters1; chart.scatters2 = scatters2; chart.bars1 = bars1; chart.bars2 = bars2; chart.stack1 = stack1; chart.stack2 = stack2; chart.xAxis = xAxis; chart.yAxis1 = yAxis1; chart.yAxis2 = yAxis2; chart.tooltip = tooltip; chart.interactiveLayer = interactiveLayer; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, showLegend: {get: function(){return showLegend;}, set: function(_){showLegend=_;}}, xScale: {get: function(){return x;}, set: function(_){ x = _; xAxis.scale(x); }}, yDomain1: {get: function(){return yDomain1;}, set: function(_){yDomain1=_;}}, yDomain2: {get: function(){return yDomain2;}, set: function(_){yDomain2=_;}}, noData: {get: function(){return noData;}, set: function(_){noData=_;}}, interpolate: {get: function(){return interpolate;}, set: function(_){interpolate=_;}}, legendRightAxisHint: {get: function(){return legendRightAxisHint;}, set: function(_){legendRightAxisHint=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ if (_.top !== undefined) { margin.top = _.top; marginTop = _.top; } margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); }}, x: {get: function(){return getX;}, set: function(_){ getX = _; lines1.x(_); lines2.x(_); scatters1.x(_); scatters2.x(_); bars1.x(_); bars2.x(_); stack1.x(_); stack2.x(_); }}, y: {get: function(){return getY;}, set: function(_){ getY = _; lines1.y(_); lines2.y(_); scatters1.y(_); scatters2.y(_); stack1.y(_); stack2.y(_); bars1.y(_); bars2.y(_); }}, useVoronoi: {get: function(){return useVoronoi;}, set: function(_){ useVoronoi=_; lines1.useVoronoi(_); lines2.useVoronoi(_); stack1.useVoronoi(_); stack2.useVoronoi(_); }}, useInteractiveGuideline: {get: function(){return useInteractiveGuideline;}, set: function(_){ useInteractiveGuideline = _; if (useInteractiveGuideline) { lines1.interactive(false); lines1.useVoronoi(false); lines2.interactive(false); lines2.useVoronoi(false); stack1.interactive(false); stack1.useVoronoi(false); stack2.interactive(false); stack2.useVoronoi(false); scatters1.interactive(false); scatters2.interactive(false); } }}, duration: {get: function(){return duration;}, set: function(_) { duration = _; [lines1, lines2, stack1, stack2, scatters1, scatters2, xAxis, yAxis1, yAxis2].forEach(function(model){ model.duration(duration); }); }} }); nv.utils.initOptions(chart); return chart; }; ================================================ FILE: src/models/ohlcBar.js ================================================ nv.models.ohlcBar = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 0, right: 0, bottom: 0, left: 0} , width = null , height = null , id = Math.floor(Math.random() * 10000) //Create semi-unique ID in case user doesn't select one , container = null , x = d3.scale.linear() , y = d3.scale.linear() , getX = function(d) { return d.x } , getY = function(d) { return d.y } , getOpen = function(d) { return d.open } , getClose = function(d) { return d.close } , getHigh = function(d) { return d.high } , getLow = function(d) { return d.low } , forceX = [] , forceY = [] , padData = false // If true, adds half a data points width to front and back, for lining up a line chart with a bar chart , clipEdge = true , color = nv.utils.defaultColor() , interactive = false , xDomain , yDomain , xRange , yRange , dispatch = d3.dispatch('stateChange', 'changeState', 'renderEnd', 'chartClick', 'elementClick', 'elementDblClick', 'elementMouseover', 'elementMouseout', 'elementMousemove') ; //============================================================ // Private Variables //------------------------------------------------------------ function chart(selection) { selection.each(function(data) { container = d3.select(this); var availableWidth = nv.utils.availableWidth(width, container, margin), availableHeight = nv.utils.availableHeight(height, container, margin); nv.utils.initSVG(container); // ohlc bar width. var w = (availableWidth / data[0].values.length) * .9; // Setup Scales x.domain(xDomain || d3.extent(data[0].values.map(getX).concat(forceX) )); if (padData) x.range(xRange || [availableWidth * .5 / data[0].values.length, availableWidth * (data[0].values.length - .5) / data[0].values.length ]); else x.range(xRange || [5 + w/2, availableWidth - w/2 - 5]); y.domain(yDomain || [ d3.min(data[0].values.map(getLow).concat(forceY)), d3.max(data[0].values.map(getHigh).concat(forceY)) ] ).range(yRange || [availableHeight, 0]); // If scale's domain don't have a range, slightly adjust to make one... so a chart can show a single data point if (x.domain()[0] === x.domain()[1]) x.domain()[0] ? x.domain([x.domain()[0] - x.domain()[0] * 0.01, x.domain()[1] + x.domain()[1] * 0.01]) : x.domain([-1,1]); if (y.domain()[0] === y.domain()[1]) y.domain()[0] ? y.domain([y.domain()[0] + y.domain()[0] * 0.01, y.domain()[1] - y.domain()[1] * 0.01]) : y.domain([-1,1]); // Setup containers and skeleton of chart var wrap = d3.select(this).selectAll('g.nv-wrap.nv-ohlcBar').data([data[0].values]); var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-ohlcBar'); var defsEnter = wrapEnter.append('defs'); var gEnter = wrapEnter.append('g'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-ticks'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); container .on('click', function(d,i) { dispatch.chartClick({ data: d, index: i, pos: d3.event, id: id }); }); defsEnter.append('clipPath') .attr('id', 'nv-chart-clip-path-' + id) .append('rect'); wrap.select('#nv-chart-clip-path-' + id + ' rect') .attr('width', availableWidth) .attr('height', availableHeight); g .attr('clip-path', clipEdge ? 'url(#nv-chart-clip-path-' + id + ')' : ''); var ticks = wrap.select('.nv-ticks').selectAll('.nv-tick') .data(function(d) { return d }); ticks.exit().remove(); ticks.enter().append('path') .attr('class', function(d,i,j) { return (getOpen(d,i) > getClose(d,i) ? 'nv-tick negative' : 'nv-tick positive') + ' nv-tick-' + j + '-' + i }) .attr('d', function(d,i) { return 'm0,0l0,' + (y(getOpen(d,i)) - y(getHigh(d,i))) + 'l' + (-w/2) + ',0l' + (w/2) + ',0l0,' + (y(getLow(d,i)) - y(getOpen(d,i))) + 'l0,' + (y(getClose(d,i)) - y(getLow(d,i))) + 'l' + (w/2) + ',0l' + (-w/2) + ',0z'; }) .attr('transform', function(d,i) { return 'translate(' + x(getX(d,i)) + ',' + y(getHigh(d,i)) + ')'; }) .attr('fill', function(d,i) { return color[0]; }) .attr('stroke', function(d,i) { return color[0]; }) .attr('x', 0 ) .attr('y', function(d,i) { return y(Math.max(0, getY(d,i))) }) .attr('height', function(d,i) { return Math.abs(y(getY(d,i)) - y(0)) }); // the bar colors are controlled by CSS currently ticks.attr('class', function(d,i,j) { return (getOpen(d,i) > getClose(d,i) ? 'nv-tick negative' : 'nv-tick positive') + ' nv-tick-' + j + '-' + i; }); d3.transition(ticks) .attr('transform', function(d,i) { return 'translate(' + x(getX(d,i)) + ',' + y(getHigh(d,i)) + ')'; }) .attr('d', function(d,i) { var w = (availableWidth / data[0].values.length) * .9; return 'm0,0l0,' + (y(getOpen(d,i)) - y(getHigh(d,i))) + 'l' + (-w/2) + ',0l' + (w/2) + ',0l0,' + (y(getLow(d,i)) - y(getOpen(d,i))) + 'l0,' + (y(getClose(d,i)) - y(getLow(d,i))) + 'l' + (w/2) + ',0l' + (-w/2) + ',0z'; }); }); return chart; } //Create methods to allow outside functions to highlight a specific bar. chart.highlightPoint = function(pointIndex, isHoverOver) { chart.clearHighlights(); container.select(".nv-ohlcBar .nv-tick-0-" + pointIndex) .classed("hover", isHoverOver) ; }; chart.clearHighlights = function() { container.select(".nv-ohlcBar .nv-tick.hover") .classed("hover", false) ; }; //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.dispatch = dispatch; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, xScale: {get: function(){return x;}, set: function(_){x=_;}}, yScale: {get: function(){return y;}, set: function(_){y=_;}}, xDomain: {get: function(){return xDomain;}, set: function(_){xDomain=_;}}, yDomain: {get: function(){return yDomain;}, set: function(_){yDomain=_;}}, xRange: {get: function(){return xRange;}, set: function(_){xRange=_;}}, yRange: {get: function(){return yRange;}, set: function(_){yRange=_;}}, forceX: {get: function(){return forceX;}, set: function(_){forceX=_;}}, forceY: {get: function(){return forceY;}, set: function(_){forceY=_;}}, padData: {get: function(){return padData;}, set: function(_){padData=_;}}, clipEdge: {get: function(){return clipEdge;}, set: function(_){clipEdge=_;}}, id: {get: function(){return id;}, set: function(_){id=_;}}, interactive: {get: function(){return interactive;}, set: function(_){interactive=_;}}, x: {get: function(){return getX;}, set: function(_){getX=_;}}, y: {get: function(){return getY;}, set: function(_){getY=_;}}, open: {get: function(){return getOpen();}, set: function(_){getOpen=_;}}, close: {get: function(){return getClose();}, set: function(_){getClose=_;}}, high: {get: function(){return getHigh;}, set: function(_){getHigh=_;}}, low: {get: function(){return getLow;}, set: function(_){getLow=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top != undefined ? _.top : margin.top; margin.right = _.right != undefined ? _.right : margin.right; margin.bottom = _.bottom != undefined ? _.bottom : margin.bottom; margin.left = _.left != undefined ? _.left : margin.left; }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); }} }); nv.utils.initOptions(chart); return chart; }; ================================================ FILE: src/models/parallelCoordinates.js ================================================ // Code adapted from Jason Davies' "Parallel Coordinates" // http://bl.ocks.org/jasondavies/1341281 nv.models.parallelCoordinates = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 30, right: 0, bottom: 10, left: 0} , width = null , height = null , availableWidth = null , availableHeight = null , x = d3.scale.ordinal() , y = {} , undefinedValuesLabel = "undefined values" , dimensionData = [] , enabledDimensions = [] , dimensionNames = [] , displayBrush = true , color = nv.utils.defaultColor() , filters = [] , active = [] , dragging = [] , axisWithUndefinedValues = [] , lineTension = 1 , foreground , background , dimensions , line = d3.svg.line() , axis = d3.svg.axis() , dispatch = d3.dispatch('brushstart', 'brush', 'brushEnd', 'dimensionsOrder', "stateChange", 'elementClick', 'elementMouseover', 'elementMouseout', 'elementMousemove', 'renderEnd', 'activeChanged') ; //============================================================ // Private Variables //------------------------------------------------------------ var renderWatch = nv.utils.renderWatch(dispatch); function chart(selection) { renderWatch.reset(); selection.each(function(data) { var container = d3.select(this); availableWidth = nv.utils.availableWidth(width, container, margin); availableHeight = nv.utils.availableHeight(height, container, margin); nv.utils.initSVG(container); //Convert old data to new format (name, values) if (data[0].values === undefined) { var newData = []; data.forEach(function (d) { var val = {}; var key = Object.keys(d); key.forEach(function (k) { if (k !== "name") val[k] = d[k] }); newData.push({ key: d.name, values: val }); }); data = newData; } var dataValues = data.map(function (d) {return d.values}); if (active.length === 0) { active = data; }; //set all active before first brush call dimensionNames = dimensionData.sort(function (a, b) { return a.currentPosition - b.currentPosition; }).map(function (d) { return d.key }); enabledDimensions = dimensionData.filter(function (d) { return !d.disabled; }); // Setup Scales x.rangePoints([0, availableWidth], 1).domain(enabledDimensions.map(function (d) { return d.key; })); //Set as true if all values on an axis are missing. // Extract the list of dimensions and create a scale for each. var oldDomainMaxValue = {}; var displayMissingValuesline = false; var currentTicks = []; dimensionNames.forEach(function(d) { var extent = d3.extent(dataValues, function (p) { return +p[d]; }); var min = extent[0]; var max = extent[1]; var onlyUndefinedValues = false; //If there is no values to display on an axis, set the extent to 0 if (isNaN(min) || isNaN(max)) { onlyUndefinedValues = true; min = 0; max = 0; } //Scale axis if there is only one value if (min === max) { min = min - 1; max = max + 1; } var f = filters.filter(function (k) { return k.dimension == d; }); if (f.length !== 0) { //If there is only NaN values, keep the existing domain. if (onlyUndefinedValues) { min = y[d].domain()[0]; max = y[d].domain()[1]; } //If the brush extent is > max (< min), keep the extent value. else if (!f[0].hasOnlyNaN && displayBrush) { min = min > f[0].extent[0] ? f[0].extent[0] : min; max = max < f[0].extent[1] ? f[0].extent[1] : max; } //If there is NaN values brushed be sure the brush extent is on the domain. else if (f[0].hasNaN) { max = max < f[0].extent[1] ? f[0].extent[1] : max; oldDomainMaxValue[d] = y[d].domain()[1]; displayMissingValuesline = true; } } //Use 90% of (availableHeight - 12) for the axis range, 12 reprensenting the space necessary to display "undefined values" text. //The remaining 10% are used to display the missingValue line. y[d] = d3.scale.linear() .domain([min, max]) .range([(availableHeight - 12) * 0.9, 0]); axisWithUndefinedValues = []; y[d].brush = d3.svg.brush().y(y[d]).on('brushstart', brushstart).on('brush', brush).on('brushend', brushend); }); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-parallelCoordinates').data([data]); var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-parallelCoordinates'); var gEnter = wrapEnter.append('g'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-parallelCoordinates background'); gEnter.append('g').attr('class', 'nv-parallelCoordinates foreground'); gEnter.append('g').attr('class', 'nv-parallelCoordinates missingValuesline'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); line.interpolate('cardinal').tension(lineTension); axis.orient('left'); var axisDrag = d3.behavior.drag() .on('dragstart', dragStart) .on('drag', dragMove) .on('dragend', dragEnd); //Add missing value line at the bottom of the chart var missingValuesline, missingValueslineText; var step = x.range()[1] - x.range()[0]; step = isNaN(step) ? x.range()[0] : step; if (!isNaN(step)) { var lineData = [0 + step / 2, availableHeight - 12, availableWidth - step / 2, availableHeight - 12]; missingValuesline = wrap.select('.missingValuesline').selectAll('line').data([lineData]); missingValuesline.enter().append('line'); missingValuesline.exit().remove(); missingValuesline.attr("x1", function(d) { return d[0]; }) .attr("y1", function(d) { return d[1]; }) .attr("x2", function(d) { return d[2]; }) .attr("y2", function(d) { return d[3]; }); //Add the text "undefined values" under the missing value line missingValueslineText = wrap.select('.missingValuesline').selectAll('text').data([undefinedValuesLabel]); missingValueslineText.append('text').data([undefinedValuesLabel]); missingValueslineText.enter().append('text'); missingValueslineText.exit().remove(); missingValueslineText.attr("y", availableHeight) //To have the text right align with the missingValues line, substract 92 representing the text size. .attr("x", availableWidth - 92 - step / 2) .text(function(d) { return d; }); } // Add grey background lines for context. background = wrap.select('.background').selectAll('path').data(data); background.enter().append('path'); background.exit().remove(); background.attr('d', path); // Add blue foreground lines for focus. foreground = wrap.select('.foreground').selectAll('path').data(data); foreground.enter().append('path') foreground.exit().remove(); foreground.attr('d', path) .style("stroke-width", function (d, i) { if (isNaN(d.strokeWidth)) { d.strokeWidth = 1;} return d.strokeWidth;}) .attr('stroke', function (d, i) { return d.color || color(d, i); }); foreground.on("mouseover", function (d, i) { d3.select(this).classed('hover', true).style("stroke-width", d.strokeWidth + 2 + "px").style("stroke-opacity", 1); dispatch.elementMouseover({ label: d.name, color: d.color || color(d, i), values: d.values, dimensions: enabledDimensions }); }); foreground.on("mouseout", function (d, i) { d3.select(this).classed('hover', false).style("stroke-width", d.strokeWidth + "px").style("stroke-opacity", 0.7); dispatch.elementMouseout({ label: d.name, index: i }); }); foreground.on('mousemove', function (d, i) { dispatch.elementMousemove(); }); foreground.on('click', function (d) { dispatch.elementClick({ id: d.id }); }); // Add a group element for each dimension. dimensions = g.selectAll('.dimension').data(enabledDimensions); var dimensionsEnter = dimensions.enter().append('g').attr('class', 'nv-parallelCoordinates dimension'); dimensions.attr('transform', function(d) { return 'translate(' + x(d.key) + ',0)'; }); dimensionsEnter.append('g').attr('class', 'nv-axis'); // Add an axis and title. dimensionsEnter.append('text') .attr('class', 'nv-label') .style("cursor", "move") .attr('dy', '-1em') .attr('text-anchor', 'middle') .on("mouseover", function(d, i) { dispatch.elementMouseover({ label: d.tooltip || d.key, color: d.color }); }) .on("mouseout", function(d, i) { dispatch.elementMouseout({ label: d.tooltip }); }) .on('mousemove', function (d, i) { dispatch.elementMousemove(); }) .call(axisDrag); dimensionsEnter.append('g').attr('class', 'nv-brushBackground'); dimensions.exit().remove(); dimensions.select('.nv-label').text(function (d) { return d.key }); // Add and store a brush for each axis. restoreBrush(displayBrush); var actives = dimensionNames.filter(function (p) { return !y[p].brush.empty(); }), extents = actives.map(function (p) { return y[p].brush.extent(); }); var formerActive = active.slice(0); //Restore active values active = []; foreground.style("display", function (d) { var isActive = actives.every(function (p, i) { if ((isNaN(d.values[p]) || isNaN(parseFloat(d.values[p]))) && extents[i][0] == y[p].brush.y().domain()[0]) { return true; } return (extents[i][0] <= d.values[p] && d.values[p] <= extents[i][1]) && !isNaN(parseFloat(d.values[p])); }); if (isActive) active.push(d); return !isActive ? "none" : null; }); if (filters.length > 0 || !nv.utils.arrayEquals(active, formerActive)) { dispatch.activeChanged(active); } // Returns the path for a given data point. function path(d) { return line(enabledDimensions.map(function (p) { //If value if missing, put the value on the missing value line if (isNaN(d.values[p.key]) || isNaN(parseFloat(d.values[p.key])) || displayMissingValuesline) { var domain = y[p.key].domain(); var range = y[p.key].range(); var min = domain[0] - (domain[1] - domain[0]) / 9; //If it's not already the case, allow brush to select undefined values if (axisWithUndefinedValues.indexOf(p.key) < 0) { var newscale = d3.scale.linear().domain([min, domain[1]]).range([availableHeight - 12, range[1]]); y[p.key].brush.y(newscale); axisWithUndefinedValues.push(p.key); } if (isNaN(d.values[p.key]) || isNaN(parseFloat(d.values[p.key]))) { return [x(p.key), y[p.key](min)]; } } //If parallelCoordinate contain missing values show the missing values line otherwise, hide it. if (missingValuesline !== undefined) { if (axisWithUndefinedValues.length > 0 || displayMissingValuesline) { missingValuesline.style("display", "inline"); missingValueslineText.style("display", "inline"); } else { missingValuesline.style("display", "none"); missingValueslineText.style("display", "none"); } } return [x(p.key), y[p.key](d.values[p.key])]; })); } function restoreBrush(visible) { filters.forEach(function (f) { //If filter brushed NaN values, keep the brush on the bottom of the axis. var brushDomain = y[f.dimension].brush.y().domain(); if (f.hasOnlyNaN) { f.extent[1] = (y[f.dimension].domain()[1] - brushDomain[0]) * (f.extent[1] - f.extent[0]) / (oldDomainMaxValue[f.dimension] - f.extent[0]) + brushDomain[0]; } if (f.hasNaN) { f.extent[0] = brushDomain[0]; } if (visible) y[f.dimension].brush.extent(f.extent); }); dimensions.select('.nv-brushBackground') .each(function (d) { d3.select(this).call(y[d.key].brush); }) .selectAll('rect') .attr('x', -8) .attr('width', 16); updateTicks(); } // Handles a brush event, toggling the display of foreground lines. function brushstart() { //If brush aren't visible, show it before brushing again. if (displayBrush === false) { displayBrush = true; restoreBrush(true); } } // Handles a brush event, toggling the display of foreground lines. function brush() { actives = dimensionNames.filter(function (p) { return !y[p].brush.empty(); }); extents = actives.map(function(p) { return y[p].brush.extent(); }); filters = []; //erase current filters actives.forEach(function(d,i) { filters[i] = { dimension: d, extent: extents[i], hasNaN: false, hasOnlyNaN: false } }); active = []; //erase current active list foreground.style('display', function(d) { var isActive = actives.every(function(p, i) { if ((isNaN(d.values[p]) || isNaN(parseFloat(d.values[p]))) && extents[i][0] == y[p].brush.y().domain()[0]) return true; return (extents[i][0] <= d.values[p] && d.values[p] <= extents[i][1]) && !isNaN(parseFloat(d.values[p])); }); if (isActive) active.push(d); return isActive ? null : 'none'; }); updateTicks(); dispatch.brush({ filters: filters, active: active }); } function brushend() { var hasActiveBrush = actives.length > 0 ? true : false; filters.forEach(function (f) { if (f.extent[0] === y[f.dimension].brush.y().domain()[0] && axisWithUndefinedValues.indexOf(f.dimension) >= 0) f.hasNaN = true; if (f.extent[1] < y[f.dimension].domain()[0]) f.hasOnlyNaN = true; }); dispatch.brushEnd(active, hasActiveBrush); } function updateTicks() { dimensions.select('.nv-axis') .each(function (d, i) { var f = filters.filter(function (k) { return k.dimension == d.key; }); currentTicks[d.key] = y[d.key].domain(); //If brush are available, display brush extent if (f.length != 0 && displayBrush) { currentTicks[d.key] = []; if (f[0].extent[1] > y[d.key].domain()[0]) currentTicks[d.key] = [f[0].extent[1]]; if (f[0].extent[0] >= y[d.key].domain()[0]) currentTicks[d.key].push(f[0].extent[0]); } d3.select(this).call(axis.scale(y[d.key]).tickFormat(d.format).tickValues(currentTicks[d.key])); }); } function dragStart(d) { dragging[d.key] = this.parentNode.__origin__ = x(d.key); background.attr("visibility", "hidden"); } function dragMove(d) { dragging[d.key] = Math.min(availableWidth, Math.max(0, this.parentNode.__origin__ += d3.event.x)); foreground.attr("d", path); enabledDimensions.sort(function (a, b) { return dimensionPosition(a.key) - dimensionPosition(b.key); }); enabledDimensions.forEach(function (d, i) { return d.currentPosition = i; }); x.domain(enabledDimensions.map(function (d) { return d.key; })); dimensions.attr("transform", function(d) { return "translate(" + dimensionPosition(d.key) + ")"; }); } function dragEnd(d, i) { delete this.parentNode.__origin__; delete dragging[d.key]; d3.select(this.parentNode).attr("transform", "translate(" + x(d.key) + ")"); foreground .attr("d", path); background .attr("d", path) .attr("visibility", null); dispatch.dimensionsOrder(enabledDimensions); } function dimensionPosition(d) { var v = dragging[d]; return v == null ? x(d) : v; } }); return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.dispatch = dispatch; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width= _;}}, height: {get: function(){return height;}, set: function(_){height= _;}}, dimensionData: { get: function () { return dimensionData; }, set: function (_) { dimensionData = _; } }, displayBrush: { get: function () { return displayBrush; }, set: function (_) { displayBrush = _; } }, filters: { get: function () { return filters; }, set: function (_) { filters = _; } }, active: { get: function () { return active; }, set: function (_) { active = _; } }, lineTension: {get: function(){return lineTension;}, set: function(_){lineTension = _;}}, undefinedValuesLabel : {get: function(){return undefinedValuesLabel;}, set: function(_){undefinedValuesLabel=_;}}, // deprecated options dimensions: {get: function () { return dimensionData.map(function (d){return d.key}); }, set: function (_) { // deprecated after 1.8.1 nv.deprecated('dimensions', 'use dimensionData instead'); if (dimensionData.length === 0) { _.forEach(function (k) { dimensionData.push({ key: k }) }) } else { _.forEach(function (k, i) { dimensionData[i].key= k }) } }}, dimensionNames: {get: function () { return dimensionData.map(function (d){return d.key}); }, set: function (_) { // deprecated after 1.8.1 nv.deprecated('dimensionNames', 'use dimensionData instead'); dimensionNames = []; if (dimensionData.length === 0) { _.forEach(function (k) { dimensionData.push({ key: k }) }) } else { _.forEach(function (k, i) { dimensionData[i].key = k }) } }}, dimensionFormats: {get: function () { return dimensionData.map(function (d) { return d.format }); }, set: function (_) { // deprecated after 1.8.1 nv.deprecated('dimensionFormats', 'use dimensionData instead'); if (dimensionData.length === 0) { _.forEach(function (f) { dimensionData.push({ format: f }) }) } else { _.forEach(function (f, i) { dimensionData[i].format = f }) } }}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); }} }); nv.utils.initOptions(chart); return chart; }; ================================================ FILE: src/models/parallelCoordinatesChart.js ================================================ nv.models.parallelCoordinatesChart = function () { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var parallelCoordinates = nv.models.parallelCoordinates() var legend = nv.models.legend() var tooltip = nv.models.tooltip(); var dimensionTooltip = nv.models.tooltip(); var margin = { top: 0, right: 0, bottom: 0, left: 0 } , marginTop = null , width = null , height = null , showLegend = true , color = nv.utils.defaultColor() , state = nv.utils.state() , dimensionData = [] , displayBrush = true , defaultState = null , noData = null , nanValue = "undefined" , dispatch = d3.dispatch('dimensionsOrder', 'brushEnd', 'stateChange', 'changeState', 'renderEnd') , controlWidth = function () { return showControls ? 180 : 0 } ; //============================================================ //============================================================ // Private Variables //------------------------------------------------------------ var renderWatch = nv.utils.renderWatch(dispatch); var stateGetter = function(data) { return function() { return { active: data.map(function(d) { return !d.disabled }) }; } }; var stateSetter = function(data) { return function(state) { if(state.active !== undefined) { data.forEach(function(series, i) { series.disabled = !state.active[i]; }); } } }; tooltip.contentGenerator(function(data) { var str = ''; if(data.series.length !== 0) { str = str + ''; data.series.forEach(function(d){ str = str + ''; }); str = str + ''; } str = str + '
' + data.key + '
' + d.key + '' + d.value + '
'; return str; }); //============================================================ // Chart function //------------------------------------------------------------ function chart(selection) { renderWatch.reset(); renderWatch.models(parallelCoordinates); selection.each(function(data) { var container = d3.select(this); nv.utils.initSVG(container); var that = this; var availableWidth = nv.utils.availableWidth(width, container, margin), availableHeight = nv.utils.availableHeight(height, container, margin); chart.update = function() { container.call(chart); }; chart.container = this; state.setter(stateSetter(dimensionData), chart.update) .getter(stateGetter(dimensionData)) .update(); //set state.disabled state.disabled = dimensionData.map(function (d) { return !!d.disabled }); //Keep dimensions position in memory dimensionData = dimensionData.map(function (d) {d.disabled = !!d.disabled; return d}); dimensionData.forEach(function (d, i) { d.originalPosition = isNaN(d.originalPosition) ? i : d.originalPosition; d.currentPosition = isNaN(d.currentPosition) ? i : d.currentPosition; }); if (!defaultState) { var key; defaultState = {}; for(key in state) { if(state[key] instanceof Array) defaultState[key] = state[key].slice(0); else defaultState[key] = state[key]; } } // Display No Data message if there's nothing to show. if(!data || !data.length) { nv.utils.noData(chart, container); return chart; } else { container.selectAll('.nv-noData').remove(); } //------------------------------------------------------------ // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-parallelCoordinatesChart').data([data]); var gEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-parallelCoordinatesChart').append('g'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-parallelCoordinatesWrap'); gEnter.append('g').attr('class', 'nv-legendWrap'); g.select("rect") .attr("width", availableWidth) .attr("height", (availableHeight > 0) ? availableHeight : 0); // Legend if (!showLegend) { g.select('.nv-legendWrap').selectAll('*').remove(); } else { legend.width(availableWidth) .color(function (d) { return "rgb(188,190,192)"; }); g.select('.nv-legendWrap') .datum(dimensionData.sort(function (a, b) { return a.originalPosition - b.originalPosition; })) .call(legend); if (!marginTop && legend.height() !== margin.top) { margin.top = legend.height(); availableHeight = nv.utils.availableHeight(height, container, margin); } wrap.select('.nv-legendWrap') .attr('transform', 'translate( 0 ,' + (-margin.top) + ')'); } wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); // Main Chart Component(s) parallelCoordinates .width(availableWidth) .height(availableHeight) .dimensionData(dimensionData) .displayBrush(displayBrush); var parallelCoordinatesWrap = g.select('.nv-parallelCoordinatesWrap ') .datum(data); parallelCoordinatesWrap.transition().call(parallelCoordinates); //============================================================ // Event Handling/Dispatching (in chart's scope) //------------------------------------------------------------ //Display reset brush button parallelCoordinates.dispatch.on('brushEnd', function (active, hasActiveBrush) { if (hasActiveBrush) { displayBrush = true; dispatch.brushEnd(active); } else { displayBrush = false; } }); legend.dispatch.on('stateChange', function(newState) { for(var key in newState) { state[key] = newState[key]; } dispatch.stateChange(state); chart.update(); }); //Update dimensions order and display reset sorting button parallelCoordinates.dispatch.on('dimensionsOrder', function (e) { dimensionData.sort(function (a, b) { return a.currentPosition - b.currentPosition; }); var isSorted = false; dimensionData.forEach(function (d, i) { d.currentPosition = i; if (d.currentPosition !== d.originalPosition) isSorted = true; }); dispatch.dimensionsOrder(dimensionData, isSorted); }); // Update chart from a state object passed to event handler dispatch.on('changeState', function (e) { if (typeof e.disabled !== 'undefined') { dimensionData.forEach(function (series, i) { series.disabled = e.disabled[i]; }); state.disabled = e.disabled; } chart.update(); }); }); renderWatch.renderEnd('parraleleCoordinateChart immediate'); return chart; } //============================================================ // Event Handling/Dispatching (out of chart's scope) //------------------------------------------------------------ parallelCoordinates.dispatch.on('elementMouseover.tooltip', function (evt) { var tp = { key: evt.label, color: evt.color, series: [] } if(evt.values){ Object.keys(evt.values).forEach(function (d) { var dim = evt.dimensions.filter(function (dd) {return dd.key === d;})[0]; if(dim){ var v; if (isNaN(evt.values[d]) || isNaN(parseFloat(evt.values[d]))) { v = nanValue; } else { v = dim.format(evt.values[d]); } tp.series.push({ idx: dim.currentPosition, key: d, value: v, color: dim.color }); } }); tp.series.sort(function(a,b) {return a.idx - b.idx}); } tooltip.data(tp).hidden(false); }); parallelCoordinates.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true) }); parallelCoordinates.dispatch.on('elementMousemove.tooltip', function () { tooltip(); }); //============================================================ // Expose Public Variables //------------------------------------------------------------ // expose chart's sub-components chart.dispatch = dispatch; chart.parallelCoordinates = parallelCoordinates; chart.legend = legend; chart.tooltip = tooltip; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: { get: function () { return width; }, set: function (_) { width = _; } }, height: { get: function () { return height; }, set: function (_) { height = _; } }, showLegend: { get: function () { return showLegend; }, set: function (_) { showLegend = _; } }, defaultState: { get: function () { return defaultState; }, set: function (_) { defaultState = _; } }, dimensionData: { get: function () { return dimensionData; }, set: function (_) { dimensionData = _; } }, displayBrush: { get: function () { return displayBrush; }, set: function (_) { displayBrush = _; } }, noData: { get: function () { return noData; }, set: function (_) { noData = _; } }, nanValue: { get: function () { return nanValue; }, set: function (_) { nanValue = _; } }, // options that require extra logic in the setter margin: { get: function () { return margin; }, set: function (_) { if (_.top !== undefined) { margin.top = _.top; marginTop = _.top; } margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; } }, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); legend.color(color); parallelCoordinates.color(color); }} }); nv.utils.inheritOptions(chart, parallelCoordinates); nv.utils.initOptions(chart); return chart; }; ================================================ FILE: src/models/pie.js ================================================ nv.models.pie = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 0, right: 0, bottom: 0, left: 0} , width = 500 , height = 500 , getX = function(d) { return d.x } , getY = function(d) { return d.y } , id = Math.floor(Math.random() * 10000) //Create semi-unique ID in case user doesn't select one , container = null , color = nv.utils.defaultColor() , valueFormat = d3.format(',.2f') , showLabels = true , labelsOutside = false , labelType = "key" , labelThreshold = .02 //if slice percentage is under this, don't show label , hideOverlapLabels = false //Hide labels that don't fit in slice , donut = false , title = false , growOnHover = true , titleOffset = 0 , labelSunbeamLayout = false , startAngle = false , padAngle = false , endAngle = false , cornerRadius = 0 , donutRatio = 0.5 , duration = 250 , arcsRadius = [] , dispatch = d3.dispatch('chartClick', 'elementClick', 'elementDblClick', 'elementMouseover', 'elementMouseout', 'elementMousemove', 'renderEnd') ; var arcs = []; var arcsOver = []; //============================================================ // chart function //------------------------------------------------------------ var renderWatch = nv.utils.renderWatch(dispatch); function chart(selection) { renderWatch.reset(); selection.each(function(data) { var availableWidth = width - margin.left - margin.right , availableHeight = height - margin.top - margin.bottom , radius = Math.min(availableWidth, availableHeight) / 2 , arcsRadiusOuter = [] , arcsRadiusInner = [] ; container = d3.select(this) if (arcsRadius.length === 0) { var outer = radius - radius / 10; var inner = donutRatio * radius; for (var i = 0; i < data[0].length; i++) { arcsRadiusOuter.push(outer); arcsRadiusInner.push(inner); } } else { if(growOnHover){ arcsRadiusOuter = arcsRadius.map(function (d) { return (d.outer - d.outer / 10) * radius; }); arcsRadiusInner = arcsRadius.map(function (d) { return (d.inner - d.inner / 10) * radius; }); donutRatio = d3.min(arcsRadius.map(function (d) { return (d.inner - d.inner / 10); })); } else { arcsRadiusOuter = arcsRadius.map(function (d) { return d.outer * radius; }); arcsRadiusInner = arcsRadius.map(function (d) { return d.inner * radius; }); donutRatio = d3.min(arcsRadius.map(function (d) { return d.inner; })); } } nv.utils.initSVG(container); // Setup containers and skeleton of chart var wrap = container.selectAll('.nv-wrap.nv-pie').data(data); var wrapEnter = wrap.enter().append('g').attr('class','nvd3 nv-wrap nv-pie nv-chart-' + id); var gEnter = wrapEnter.append('g'); var g = wrap.select('g'); var g_pie = gEnter.append('g').attr('class', 'nv-pie'); gEnter.append('g').attr('class', 'nv-pieLabels'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); g.select('.nv-pie').attr('transform', 'translate(' + availableWidth / 2 + ',' + availableHeight / 2 + ')'); g.select('.nv-pieLabels').attr('transform', 'translate(' + availableWidth / 2 + ',' + availableHeight / 2 + ')'); // container.on('click', function(d,i) { dispatch.chartClick({ data: d, index: i, pos: d3.event, id: id }); }); arcs = []; arcsOver = []; for (var i = 0; i < data[0].length; i++) { var arc = d3.svg.arc().outerRadius(arcsRadiusOuter[i]); var arcOver = d3.svg.arc().outerRadius(arcsRadiusOuter[i] + 5); if (startAngle !== false) { arc.startAngle(startAngle); arcOver.startAngle(startAngle); } if (endAngle !== false) { arc.endAngle(endAngle); arcOver.endAngle(endAngle); } if (donut) { arc.innerRadius(arcsRadiusInner[i]); arcOver.innerRadius(arcsRadiusInner[i]); } if (arc.cornerRadius && cornerRadius) { arc.cornerRadius(cornerRadius); arcOver.cornerRadius(cornerRadius); } arcs.push(arc); arcsOver.push(arcOver); } // Setup the Pie chart and choose the data element var pie = d3.layout.pie() .sort(null) .value(function(d) { return d.disabled ? 0 : getY(d) }); // padAngle added in d3 3.5 if (pie.padAngle && padAngle) { pie.padAngle(padAngle); } // if title is specified and donut, put it in the middle if (donut && title) { g_pie.append("text").attr('class', 'nv-pie-title'); wrap.select('.nv-pie-title') .style("text-anchor", "middle") .text(function (d) { return title; }) .style("font-size", (Math.min(availableWidth, availableHeight)) * donutRatio * 2 / (title.length + 2) + "px") .attr("dy", "0.35em") // trick to vertically center text .attr('transform', function(d, i) { return 'translate(0, '+ titleOffset + ')'; }); } var slices = wrap.select('.nv-pie').selectAll('.nv-slice').data(pie); var pieLabels = wrap.select('.nv-pieLabels').selectAll('.nv-label').data(pie); slices.exit().remove(); pieLabels.exit().remove(); var ae = slices.enter().append('g'); ae.attr('class', 'nv-slice'); ae.on('mouseover', function(d, i) { d3.select(this).classed('hover', true); if (growOnHover) { d3.select(this).select("path").transition() .duration(70) .attr("d", arcsOver[i]); } dispatch.elementMouseover({ data: d.data, index: i, color: d3.select(this).style("fill"), percent: (d.endAngle - d.startAngle) / (2 * Math.PI) }); }); ae.on('mouseout', function(d, i) { d3.select(this).classed('hover', false); if (growOnHover) { d3.select(this).select("path").transition() .duration(50) .attr("d", arcs[i]); } dispatch.elementMouseout({data: d.data, index: i}); }); ae.on('mousemove', function(d, i) { dispatch.elementMousemove({data: d.data, index: i}); }); ae.on('click', function(d, i) { var element = this; dispatch.elementClick({ data: d.data, index: i, color: d3.select(this).style("fill"), event: d3.event, element: element }); }); ae.on('dblclick', function(d, i) { dispatch.elementDblClick({ data: d.data, index: i, color: d3.select(this).style("fill") }); }); slices.attr('fill', function(d,i) { return color(d.data, i); }); slices.attr('stroke', function(d,i) { return color(d.data, i); }); var paths = ae.append('path').each(function(d) { this._current = d; }); slices.select('path') .transition() .duration(duration) .attr('d', function (d, i) { return arcs[i](d); }) .attrTween('d', arcTween); if (showLabels) { // This does the normal label var labelsArc = []; for (var i = 0; i < data[0].length; i++) { labelsArc.push(arcs[i]); if (labelsOutside) { if (donut) { labelsArc[i] = d3.svg.arc().outerRadius(arcs[i].outerRadius()); if (startAngle !== false) labelsArc[i].startAngle(startAngle); if (endAngle !== false) labelsArc[i].endAngle(endAngle); } } else if (!donut) { labelsArc[i].innerRadius(0); } } pieLabels.enter().append("g").classed("nv-label",true).each(function(d,i) { var group = d3.select(this); group.attr('transform', function (d, i) { if (labelSunbeamLayout) { d.outerRadius = arcsRadiusOuter[i] + 10; // Set Outer Coordinate d.innerRadius = arcsRadiusOuter[i] + 15; // Set Inner Coordinate var rotateAngle = (d.startAngle + d.endAngle) / 2 * (180 / Math.PI); if ((d.startAngle + d.endAngle) / 2 < Math.PI) { rotateAngle -= 90; } else { rotateAngle += 90; } return 'translate(' + labelsArc[i].centroid(d) + ') rotate(' + rotateAngle + ')'; } else { d.outerRadius = radius + 10; // Set Outer Coordinate d.innerRadius = radius + 15; // Set Inner Coordinate return 'translate(' + labelsArc[i].centroid(d) + ')' } }); group.append('rect') .style('stroke', '#fff') .style('fill', '#fff') .attr("rx", 3) .attr("ry", 3); group.append('text') .style('text-anchor', labelSunbeamLayout ? ((d.startAngle + d.endAngle) / 2 < Math.PI ? 'start' : 'end') : 'middle') //center the text on it's origin or begin/end if orthogonal aligned .style('fill', '#000') }); var labelLocationHash = {}; var avgHeight = 14; var avgWidth = 140; var createHashKey = function(coordinates) { return Math.floor(coordinates[0]/avgWidth) * avgWidth + ',' + Math.floor(coordinates[1]/avgHeight) * avgHeight; }; var getSlicePercentage = function(d) { return (d.endAngle - d.startAngle) / (2 * Math.PI); }; pieLabels.watchTransition(renderWatch, 'pie labels').attr('transform', function (d, i) { if (labelSunbeamLayout) { d.outerRadius = arcsRadiusOuter[i] + 10; // Set Outer Coordinate d.innerRadius = arcsRadiusOuter[i] + 15; // Set Inner Coordinate var rotateAngle = (d.startAngle + d.endAngle) / 2 * (180 / Math.PI); if ((d.startAngle + d.endAngle) / 2 < Math.PI) { rotateAngle -= 90; } else { rotateAngle += 90; } return 'translate(' + labelsArc[i].centroid(d) + ') rotate(' + rotateAngle + ')'; } else { d.outerRadius = radius + 10; // Set Outer Coordinate d.innerRadius = radius + 15; // Set Inner Coordinate /* Overlapping pie labels are not good. What this attempts to do is, prevent overlapping. Each label location is hashed, and if a hash collision occurs, we assume an overlap. Adjust the label's y-position to remove the overlap. */ var center = labelsArc[i].centroid(d); var percent = getSlicePercentage(d); if (d.value && percent >= labelThreshold) { var hashKey = createHashKey(center); if (labelLocationHash[hashKey]) { center[1] -= avgHeight; } labelLocationHash[createHashKey(center)] = true; } return 'translate(' + center + ')' } }); pieLabels.select(".nv-label text") .style('text-anchor', function(d,i) { //center the text on it's origin or begin/end if orthogonal aligned return labelSunbeamLayout ? ((d.startAngle + d.endAngle) / 2 < Math.PI ? 'start' : 'end') : 'middle'; }) .text(function(d, i) { var percent = getSlicePercentage(d); var label = ''; if (!d.value || percent < labelThreshold) return ''; if(typeof labelType === 'function') { label = labelType(d, i, { 'key': getX(d.data), 'value': getY(d.data), 'percent': valueFormat(percent) }); } else { switch (labelType) { case 'key': label = getX(d.data); break; case 'value': label = valueFormat(getY(d.data)); break; case 'percent': label = d3.format('%')(percent); break; } } return label; }) ; if (hideOverlapLabels) { pieLabels .each(function (d, i) { if (!this.getBBox) return; var bb = this.getBBox(), center = labelsArc[i].centroid(d); var topLeft = { x : center[0] + bb.x, y : center[1] + bb.y }; var topRight = { x : topLeft.x + bb.width, y : topLeft.y }; var bottomLeft = { x : topLeft.x, y : topLeft.y + bb.height }; var bottomRight = { x : topLeft.x + bb.width, y : topLeft.y + bb.height }; d.visible = nv.utils.pointIsInArc(topLeft, d, arc) && nv.utils.pointIsInArc(topRight, d, arc) && nv.utils.pointIsInArc(bottomLeft, d, arc) && nv.utils.pointIsInArc(bottomRight, d, arc); }) .style('display', function (d) { return d.visible ? null : 'none'; }) ; } } // Computes the angle of an arc, converting from radians to degrees. function angle(d) { var a = (d.startAngle + d.endAngle) * 90 / Math.PI - 90; return a > 90 ? a - 180 : a; } function arcTween(a, idx) { a.endAngle = isNaN(a.endAngle) ? 0 : a.endAngle; a.startAngle = isNaN(a.startAngle) ? 0 : a.startAngle; if (!donut) a.innerRadius = 0; var i = d3.interpolate(this._current, a); this._current = i(0); return function (t) { return arcs[idx](i(t)); }; } }); renderWatch.renderEnd('pie immediate'); return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.dispatch = dispatch; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values arcsRadius: { get: function () { return arcsRadius; }, set: function (_) { arcsRadius = _; } }, width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, showLabels: {get: function(){return showLabels;}, set: function(_){showLabels=_;}}, title: {get: function(){return title;}, set: function(_){title=_;}}, titleOffset: {get: function(){return titleOffset;}, set: function(_){titleOffset=_;}}, labelThreshold: {get: function(){return labelThreshold;}, set: function(_){labelThreshold=_;}}, hideOverlapLabels: {get: function(){return hideOverlapLabels;}, set: function(_){hideOverlapLabels=_;}}, valueFormat: {get: function(){return valueFormat;}, set: function(_){valueFormat=_;}}, x: {get: function(){return getX;}, set: function(_){getX=_;}}, id: {get: function(){return id;}, set: function(_){id=_;}}, endAngle: {get: function(){return endAngle;}, set: function(_){endAngle=_;}}, startAngle: {get: function(){return startAngle;}, set: function(_){startAngle=_;}}, padAngle: {get: function(){return padAngle;}, set: function(_){padAngle=_;}}, cornerRadius: {get: function(){return cornerRadius;}, set: function(_){cornerRadius=_;}}, donutRatio: {get: function(){return donutRatio;}, set: function(_){donutRatio=_;}}, labelsOutside: {get: function(){return labelsOutside;}, set: function(_){labelsOutside=_;}}, labelSunbeamLayout: {get: function(){return labelSunbeamLayout;}, set: function(_){labelSunbeamLayout=_;}}, donut: {get: function(){return donut;}, set: function(_){donut=_;}}, growOnHover: {get: function(){return growOnHover;}, set: function(_){growOnHover=_;}}, // depreciated after 1.7.1 pieLabelsOutside: {get: function(){return labelsOutside;}, set: function(_){ labelsOutside=_; nv.deprecated('pieLabelsOutside', 'use labelsOutside instead'); }}, // depreciated after 1.7.1 donutLabelsOutside: {get: function(){return labelsOutside;}, set: function(_){ labelsOutside=_; nv.deprecated('donutLabelsOutside', 'use labelsOutside instead'); }}, // deprecated after 1.7.1 labelFormat: {get: function(){ return valueFormat;}, set: function(_) { valueFormat=_; nv.deprecated('labelFormat','use valueFormat instead'); }}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = typeof _.top != 'undefined' ? _.top : margin.top; margin.right = typeof _.right != 'undefined' ? _.right : margin.right; margin.bottom = typeof _.bottom != 'undefined' ? _.bottom : margin.bottom; margin.left = typeof _.left != 'undefined' ? _.left : margin.left; }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; renderWatch.reset(duration); }}, y: {get: function(){return getY;}, set: function(_){ getY=d3.functor(_); }}, color: {get: function(){return color;}, set: function(_){ color=nv.utils.getColor(_); }}, labelType: {get: function(){return labelType;}, set: function(_){ labelType= _ || 'key'; }} }); nv.utils.initOptions(chart); return chart; }; ================================================ FILE: src/models/pieChart.js ================================================ nv.models.pieChart = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var pie = nv.models.pie(); var legend = nv.models.legend(); var tooltip = nv.models.tooltip(); var margin = {top: 30, right: 20, bottom: 20, left: 20} , marginTop = null , width = null , height = null , showTooltipPercent = false , showLegend = true , legendPosition = "top" , color = nv.utils.defaultColor() , state = nv.utils.state() , defaultState = null , noData = null , duration = 250 , dispatch = d3.dispatch('stateChange', 'changeState','renderEnd') ; tooltip .duration(0) .headerEnabled(false) .valueFormatter(function(d, i) { return pie.valueFormat()(d, i); }); //============================================================ // Private Variables //------------------------------------------------------------ var renderWatch = nv.utils.renderWatch(dispatch); var stateGetter = function(data) { return function(){ return { active: data.map(function(d) { return !d.disabled }) }; } }; var stateSetter = function(data) { return function(state) { if (state.active !== undefined) { data.forEach(function (series, i) { series.disabled = !state.active[i]; }); } } }; //============================================================ // Chart function //------------------------------------------------------------ function chart(selection) { renderWatch.reset(); renderWatch.models(pie); selection.each(function(data) { var container = d3.select(this); nv.utils.initSVG(container); var that = this; var availableWidth = nv.utils.availableWidth(width, container, margin), availableHeight = nv.utils.availableHeight(height, container, margin); chart.update = function() { container.transition().call(chart); }; chart.container = this; state.setter(stateSetter(data), chart.update) .getter(stateGetter(data)) .update(); //set state.disabled state.disabled = data.map(function(d) { return !!d.disabled }); if (!defaultState) { var key; defaultState = {}; for (key in state) { if (state[key] instanceof Array) defaultState[key] = state[key].slice(0); else defaultState[key] = state[key]; } } // Display No Data message if there's nothing to show. if (!data || !data.length) { nv.utils.noData(chart, container); return chart; } else { container.selectAll('.nv-noData').remove(); } // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-pieChart').data([data]); var gEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-pieChart').append('g'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-pieWrap'); gEnter.append('g').attr('class', 'nv-legendWrap'); // Legend if (!showLegend) { g.select('.nv-legendWrap').selectAll('*').remove(); } else { if (legendPosition === "top") { legend.width( availableWidth ).key(pie.x()); wrap.select('.nv-legendWrap') .datum(data) .call(legend); if (!marginTop && legend.height() !== margin.top) { margin.top = legend.height(); availableHeight = nv.utils.availableHeight(height, container, margin); } wrap.select('.nv-legendWrap') .attr('transform', 'translate(0,' + (-margin.top) +')'); } else if (legendPosition === "right") { var legendWidth = nv.models.legend().width(); if (availableWidth / 2 < legendWidth) { legendWidth = (availableWidth / 2) } legend.height(availableHeight).key(pie.x()); legend.width(legendWidth); availableWidth -= legend.width(); wrap.select('.nv-legendWrap') .datum(data) .call(legend) .attr('transform', 'translate(' + (availableWidth) +',0)'); } else if (legendPosition === "bottom") { legend.width( availableWidth ).key(pie.x()); wrap.select('.nv-legendWrap') .datum(data) .call(legend); margin.bottom = legend.height(); availableHeight = nv.utils.availableHeight(height, container, margin); wrap.select('.nv-legendWrap') .attr('transform', 'translate(0,' + availableHeight +')'); } } wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); // Main Chart Component(s) pie.width(availableWidth).height(availableHeight); var pieWrap = g.select('.nv-pieWrap').datum([data]); d3.transition(pieWrap).call(pie); //============================================================ // Event Handling/Dispatching (in chart's scope) //------------------------------------------------------------ legend.dispatch.on('stateChange', function(newState) { for (var key in newState) { state[key] = newState[key]; } dispatch.stateChange(state); chart.update(); }); // Update chart from a state object passed to event handler dispatch.on('changeState', function(e) { if (typeof e.disabled !== 'undefined') { data.forEach(function(series,i) { series.disabled = e.disabled[i]; }); state.disabled = e.disabled; } chart.update(); }); }); renderWatch.renderEnd('pieChart immediate'); return chart; } //============================================================ // Event Handling/Dispatching (out of chart's scope) //------------------------------------------------------------ pie.dispatch.on('elementMouseover.tooltip', function(evt) { evt['series'] = { key: chart.x()(evt.data), value: chart.y()(evt.data), color: evt.color, percent: evt.percent }; if (!showTooltipPercent) { delete evt.percent; delete evt.series.percent; } tooltip.data(evt).hidden(false); }); pie.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true); }); pie.dispatch.on('elementMousemove.tooltip', function(evt) { tooltip(); }); //============================================================ // Expose Public Variables //------------------------------------------------------------ // expose chart's sub-components chart.legend = legend; chart.dispatch = dispatch; chart.pie = pie; chart.tooltip = tooltip; chart.options = nv.utils.optionsFunc.bind(chart); // use Object get/set functionality to map between vars and chart functions chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, noData: {get: function(){return noData;}, set: function(_){noData=_;}}, showTooltipPercent: {get: function(){return showTooltipPercent;}, set: function(_){showTooltipPercent=_;}}, showLegend: {get: function(){return showLegend;}, set: function(_){showLegend=_;}}, legendPosition: {get: function(){return legendPosition;}, set: function(_){legendPosition=_;}}, defaultState: {get: function(){return defaultState;}, set: function(_){defaultState=_;}}, // options that require extra logic in the setter color: {get: function(){return color;}, set: function(_){ color = _; legend.color(color); pie.color(color); }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; renderWatch.reset(duration); pie.duration(duration); }}, margin: {get: function(){return margin;}, set: function(_){ if (_.top !== undefined) { margin.top = _.top; marginTop = _.top; } margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }} }); nv.utils.inheritOptions(chart, pie); nv.utils.initOptions(chart); return chart; }; ================================================ FILE: src/models/sankey.js ================================================ nv.models.sankey = function() { 'use strict'; // Sources: // - https://bost.ocks.org/mike/sankey/ // - https://github.com/soxofaan/d3-plugin-captain-sankey //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var sankey = {}, nodeWidth = 24, nodePadding = 8, size = [1, 1], nodes = [], links = [], sinksRight = true; var layout = function(iterations) { computeNodeLinks(); computeNodeValues(); computeNodeBreadths(); computeNodeDepths(iterations); }; var relayout = function() { computeLinkDepths(); }; // SVG path data generator, to be used as 'd' attribute on 'path' element selection. var link = function() { var curvature = .5; function link(d) { var x0 = d.source.x + d.source.dx, x1 = d.target.x, xi = d3.interpolateNumber(x0, x1), x2 = xi(curvature), x3 = xi(1 - curvature), y0 = d.source.y + d.sy + d.dy / 2, y1 = d.target.y + d.ty + d.dy / 2; var linkPath = 'M' + x0 + ',' + y0 + 'C' + x2 + ',' + y0 + ' ' + x3 + ',' + y1 + ' ' + x1 + ',' + y1; return linkPath; } link.curvature = function(_) { if (!arguments.length) return curvature; curvature = +_; return link; }; return link; }; // Y-position of the middle of a node. var center = function(node) { return node.y + node.dy / 2; }; //============================================================ // Private Variables //------------------------------------------------------------ // Populate the sourceLinks and targetLinks for each node. // Also, if the source and target are not objects, assume they are indices. function computeNodeLinks() { nodes.forEach(function(node) { // Links that have this node as source. node.sourceLinks = []; // Links that have this node as target. node.targetLinks = []; }); links.forEach(function(link) { var source = link.source, target = link.target; if (typeof source === 'number') source = link.source = nodes[link.source]; if (typeof target === 'number') target = link.target = nodes[link.target]; source.sourceLinks.push(link); target.targetLinks.push(link); }); } // Compute the value (size) of each node by summing the associated links. function computeNodeValues() { nodes.forEach(function(node) { node.value = Math.max( d3.sum(node.sourceLinks, value), d3.sum(node.targetLinks, value) ); }); } // Iteratively assign the breadth (x-position) for each node. // Nodes are assigned the maximum breadth of incoming neighbors plus one; // nodes with no incoming links are assigned breadth zero, while // nodes with no outgoing links are assigned the maximum breadth. function computeNodeBreadths() { // var remainingNodes = nodes, nextNodes, x = 0; // Work from left to right. // Keep updating the breath (x-position) of nodes that are target of recently updated nodes. // while (remainingNodes.length && x < nodes.length) { nextNodes = []; remainingNodes.forEach(function(node) { node.x = x; node.dx = nodeWidth; node.sourceLinks.forEach(function(link) { if (nextNodes.indexOf(link.target) < 0) { nextNodes.push(link.target); } }); }); remainingNodes = nextNodes; ++x; // } // Optionally move pure sinks always to the right. if (sinksRight) { moveSinksRight(x); } scaleNodeBreadths((size[0] - nodeWidth) / (x - 1)); } function moveSourcesRight() { nodes.forEach(function(node) { if (!node.targetLinks.length) { node.x = d3.min(node.sourceLinks, function(d) { return d.target.x; }) - 1; } }); } function moveSinksRight(x) { nodes.forEach(function(node) { if (!node.sourceLinks.length) { node.x = x - 1; } }); } function scaleNodeBreadths(kx) { nodes.forEach(function(node) { node.x *= kx; }); } // Compute the depth (y-position) for each node. function computeNodeDepths(iterations) { // Group nodes by breath. var nodesByBreadth = d3.nest() .key(function(d) { return d.x; }) .sortKeys(d3.ascending) .entries(nodes) .map(function(d) { return d.values; }); // initializeNodeDepth(); resolveCollisions(); computeLinkDepths(); for (var alpha = 1; iterations > 0; --iterations) { relaxRightToLeft(alpha *= .99); resolveCollisions(); computeLinkDepths(); relaxLeftToRight(alpha); resolveCollisions(); computeLinkDepths(); } function initializeNodeDepth() { // Calculate vertical scaling factor. var ky = d3.min(nodesByBreadth, function(nodes) { return (size[1] - (nodes.length - 1) * nodePadding) / d3.sum(nodes, value); }); nodesByBreadth.forEach(function(nodes) { nodes.forEach(function(node, i) { node.y = i; node.dy = node.value * ky; }); }); links.forEach(function(link) { link.dy = link.value * ky; }); } function relaxLeftToRight(alpha) { nodesByBreadth.forEach(function(nodes, breadth) { nodes.forEach(function(node) { if (node.targetLinks.length) { // Value-weighted average of the y-position of source node centers linked to this node. var y = d3.sum(node.targetLinks, weightedSource) / d3.sum(node.targetLinks, value); node.y += (y - center(node)) * alpha; } }); }); function weightedSource(link) { return (link.source.y + link.sy + link.dy / 2) * link.value; } } function relaxRightToLeft(alpha) { nodesByBreadth.slice().reverse().forEach(function(nodes) { nodes.forEach(function(node) { if (node.sourceLinks.length) { // Value-weighted average of the y-positions of target nodes linked to this node. var y = d3.sum(node.sourceLinks, weightedTarget) / d3.sum(node.sourceLinks, value); node.y += (y - center(node)) * alpha; } }); }); function weightedTarget(link) { return (link.target.y + link.ty + link.dy / 2) * link.value; } } function resolveCollisions() { nodesByBreadth.forEach(function(nodes) { var node, dy, y0 = 0, n = nodes.length, i; // Push any overlapping nodes down. nodes.sort(ascendingDepth); for (i = 0; i < n; ++i) { node = nodes[i]; dy = y0 - node.y; if (dy > 0) node.y += dy; y0 = node.y + node.dy + nodePadding; } // If the bottommost node goes outside the bounds, push it back up. dy = y0 - nodePadding - size[1]; if (dy > 0) { y0 = node.y -= dy; // Push any overlapping nodes back up. for (i = n - 2; i >= 0; --i) { node = nodes[i]; dy = node.y + node.dy + nodePadding - y0; if (dy > 0) node.y -= dy; y0 = node.y; } } }); } function ascendingDepth(a, b) { return a.y - b.y; } } // Compute y-offset of the source endpoint (sy) and target endpoints (ty) of links, // relative to the source/target node's y-position. function computeLinkDepths() { nodes.forEach(function(node) { node.sourceLinks.sort(ascendingTargetDepth); node.targetLinks.sort(ascendingSourceDepth); }); nodes.forEach(function(node) { var sy = 0, ty = 0; node.sourceLinks.forEach(function(link) { link.sy = sy; sy += link.dy; }); node.targetLinks.forEach(function(link) { link.ty = ty; ty += link.dy; }); }); function ascendingSourceDepth(a, b) { return a.source.y - b.source.y; } function ascendingTargetDepth(a, b) { return a.target.y - b.target.y; } } // Value property accessor. function value(x) { return x.value; } sankey.options = nv.utils.optionsFunc.bind(sankey); sankey._options = Object.create({}, { nodeWidth: {get: function(){return nodeWidth;}, set: function(_){nodeWidth=+_;}}, nodePadding: {get: function(){return nodePadding;}, set: function(_){nodePadding=_;}}, nodes: {get: function(){return nodes;}, set: function(_){nodes=_;}}, links: {get: function(){return links ;}, set: function(_){links=_;}}, size: {get: function(){return size;}, set: function(_){size=_;}}, sinksRight: {get: function(){return sinksRight;}, set: function(_){sinksRight=_;}}, layout: {get: function(){layout(32);}, set: function(_){layout(_);}}, relayout: {get: function(){relayout();}, set: function(_){}}, center: {get: function(){return center();}, set: function(_){ if(typeof _ === 'function'){ center=_; } }}, link: {get: function(){return link();}, set: function(_){ if(typeof _ === 'function'){ link=_; } return link(); }} }); nv.utils.initOptions(sankey); return sankey; }; ================================================ FILE: src/models/sankeyChart.js ================================================ nv.models.sankeyChart = function() { "use strict"; // Sources: // - https://bost.ocks.org/mike/sankey/ // - https://github.com/soxofaan/d3-plugin-captain-sankey //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 5, right: 0, bottom: 5, left: 0} , sankey = nv.models.sankey() , width = 600 , height = 400 , nodeWidth = 36 , nodePadding = 40 , units = 'units' , center = undefined ; //============================================================ // Private Variables //------------------------------------------------------------ var formatNumber = d3.format(',.0f'); // zero decimal places var format = function(d) { return formatNumber(d) + ' ' + units; }; var color = d3.scale.category20(); var linkTitle = function(d){ return d.source.name + ' → ' + d.target.name + '\n' + format(d.value); }; var nodeFillColor = function(d){ return d.color = color(d.name.replace(/ .*/, '')); }; var nodeStrokeColor = function(d){ return d3.rgb(d.color).darker(2); }; var nodeTitle = function(d){ return d.name + '\n' + format(d.value); }; var showError = function(element, message) { element.append('text') .attr('x', 0) .attr('y', 0) .attr('class', 'nvd3-sankey-chart-error') .attr('text-anchor', 'middle') .text(message); }; function chart(selection) { selection.each(function(data) { var testData = { nodes: [ {'node': 1, 'name': 'Test 1'}, {'node': 2, 'name': 'Test 2'}, {'node': 3, 'name': 'Test 3'}, {'node': 4, 'name': 'Test 4'}, {'node': 5, 'name': 'Test 5'}, {'node': 6, 'name': 'Test 6'} ], links: [ {'source': 0, 'target': 1, 'value': 2295}, {'source': 0, 'target': 5, 'value': 1199}, {'source': 1, 'target': 2, 'value': 1119}, {'source': 1, 'target': 5, 'value': 1176}, {'source': 2, 'target': 3, 'value': 487}, {'source': 2, 'target': 5, 'value': 632}, {'source': 3, 'target': 4, 'value': 301}, {'source': 3, 'target': 5, 'value': 186} ] }; // Error handling var isDataValid = false; var dataAvailable = false; // check if data is valid if( (typeof data['nodes'] === 'object' && data['nodes'].length) >= 0 && (typeof data['links'] === 'object' && data['links'].length) >= 0 ){ isDataValid = true; } // check if data is available if( data['nodes'] && data['nodes'].length > 0 && data['links'] && data['links'].length > 0 ) { dataAvailable = true; } // show error if(!isDataValid) { console.error('NVD3 Sankey chart error:', 'invalid data format for', data); console.info('Valid data format is: ', testData, JSON.stringify(testData)); showError(selection, 'Error loading chart, data is invalid'); return false; } // TODO use nv.utils.noData if(!dataAvailable) { showError(selection, 'No data available'); return false; } // No errors, continue // append the svg canvas to the page var svg = selection.append('svg') .attr('width', width) .attr('height', height) .append('g') .attr('class', 'nvd3 nv-wrap nv-sankeyChart'); // Set the sankey diagram properties sankey .nodeWidth(nodeWidth) .nodePadding(nodePadding) .size([width, height]); var path = sankey.link(); sankey .nodes(data.nodes) .links(data.links) .layout(32) .center(center); // add in the links var link = svg.append('g').selectAll('.link') .data(data.links) .enter().append('path') .attr('class', 'link') .attr('d', path) .style('stroke-width', function(d) { return Math.max(1, d.dy); }) .sort(function(a,b) { return b.dy - a.dy; }); // add the link titles link.append('title') .text(linkTitle); // add in the nodes var node = svg.append('g').selectAll('.node') .data(data.nodes) .enter().append('g') .attr('class', 'node') .attr('transform', function(d) { return 'translate(' + d.x + ',' + d.y + ')'; }) .call( d3.behavior .drag() .origin(function(d) { return d; }) .on('dragstart', function() { this.parentNode.appendChild(this); }) .on('drag', dragmove) ); // add the rectangles for the nodes node.append('rect') .attr('height', function(d) { return d.dy; }) .attr('width', sankey.nodeWidth()) .style('fill', nodeFillColor) .style('stroke', nodeStrokeColor) .append('title') .text(nodeTitle); // add in the title for the nodes node.append('text') .attr('x', -6) .attr('y', function(d) { return d.dy / 2; }) .attr('dy', '.35em') .attr('text-anchor', 'end') .attr('transform', null) .text(function(d) { return d.name; }) .filter(function(d) { return d.x < width / 2; }) .attr('x', 6 + sankey.nodeWidth()) .attr('text-anchor', 'start'); // the function for moving the nodes function dragmove(d) { d3.select(this).attr('transform', 'translate(' + d.x + ',' + ( d.y = Math.max(0, Math.min(height - d.dy, d3.event.y)) ) + ')'); sankey.relayout(); link.attr('d', path); } }); return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values units: {get: function(){return units;}, set: function(_){units=_;}}, width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, format: {get: function(){return format;}, set: function(_){format=_;}}, linkTitle: {get: function(){return linkTitle;}, set: function(_){linkTitle=_;}}, nodeWidth: {get: function(){return nodeWidth;}, set: function(_){nodeWidth=_;}}, nodePadding: {get: function(){return nodePadding;}, set: function(_){nodePadding=_;}}, center: {get: function(){return center}, set: function(_){center=_}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, nodeStyle: {get: function(){return {};}, set: function(_){ nodeFillColor = _.fillColor !== undefined ? _.fillColor : nodeFillColor; nodeStrokeColor = _.strokeColor !== undefined ? _.strokeColor : nodeStrokeColor; nodeTitle = _.title !== undefined ? _.title : nodeTitle; }} }); nv.utils.initOptions(chart); return chart; }; ================================================ FILE: src/models/scatter.js ================================================ nv.models.scatter = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 0, right: 0, bottom: 0, left: 0} , width = null , height = null , color = nv.utils.defaultColor() // chooses color , pointBorderColor = null , id = Math.floor(Math.random() * 100000) //Create semi-unique ID incase user doesn't select one , container = null , x = d3.scale.linear() , y = d3.scale.linear() , z = d3.scale.linear() //linear because d3.svg.shape.size is treated as area , getX = function(d) { return d.x } // accessor to get the x value , getY = function(d) { return d.y } // accessor to get the y value , getSize = function(d) { return d.size || 1} // accessor to get the point size , getShape = function(d) { return d.shape || 'circle' } // accessor to get point shape , forceX = [] // List of numbers to Force into the X scale (ie. 0, or a max / min, etc.) , forceY = [] // List of numbers to Force into the Y scale , forceSize = [] // List of numbers to Force into the Size scale , interactive = true // If true, plots a voronoi overlay for advanced point intersection , pointActive = function(d) { return !d.notActive } // any points that return false will be filtered out , padData = false // If true, adds half a data points width to front and back, for lining up a line chart with a bar chart , padDataOuter = .1 //outerPadding to imitate ordinal scale outer padding , clipEdge = false // if true, masks points within x and y scale , clipVoronoi = true // if true, masks each point with a circle... can turn off to slightly increase performance , showVoronoi = false // display the voronoi areas , clipRadius = function() { return 25 } // function to get the radius for voronoi point clips , xDomain = null // Override x domain (skips the calculation from data) , yDomain = null // Override y domain , xRange = null // Override x range , yRange = null // Override y range , sizeDomain = null // Override point size domain , sizeRange = null , singlePoint = false , dispatch = d3.dispatch('elementClick', 'elementDblClick', 'elementMouseover', 'elementMouseout', 'renderEnd') , useVoronoi = true , duration = 250 , interactiveUpdateDelay = 300 , showLabels = false ; //============================================================ // Private Variables //------------------------------------------------------------ var x0, y0, z0 // used to store previous scales , xDom, yDom // used to store previous domains , width0 , height0 , timeoutID , needsUpdate = false // Flag for when the points are visually updating, but the interactive layer is behind, to disable tooltips , renderWatch = nv.utils.renderWatch(dispatch, duration) , _sizeRange_def = [16, 256] , _cache = {} ; //============================================================ // Diff and Cache Utilities //------------------------------------------------------------ // getDiffs is used to filter unchanged points from the update // selection. It implicitly updates it's cache when called and // therefor the diff is based upon the previous invocation NOT // the previous update. // // getDiffs takes a point as its first argument followed by n // key getter pairs (d, [key, get... key, get]) this approach // was chosen for efficiency. (The filter will call it a LOT). // // It is important to call delCache on point exit to prevent a // memory leak. It is also needed to prevent invalid caches if // a new point uses the same series and point id key. // // Argument Performance Concerns: // - Object property lists for key getter pairs would be very // expensive (points * objects for the GC every update). // - ES6 function names for implicit keys would be nice but // they are not guaranteed to be unique. // - function.toString to obtain implicit keys is possible // but long object keys are not free (internal hash). // - Explicit key without objects are the most efficient. function getCache(d) { var key, val; key = d[0].series + ':' + d[1]; val = _cache[key] = _cache[key] || {}; return val; } function delCache(d) { var key, val; key = d[0].series + ':' + d[1]; delete _cache[key]; } function getDiffs(d) { var i, key, val, cache = getCache(d), diffs = false; for (i = 1; i < arguments.length; i += 2) { key = arguments[i]; val = arguments[i + 1](d[0], d[1]); if (cache[key] !== val || !cache.hasOwnProperty(key)) { cache[key] = val; diffs = true; } } return diffs; } function chart(selection) { renderWatch.reset(); selection.each(function(data) { container = d3.select(this); var availableWidth = nv.utils.availableWidth(width, container, margin), availableHeight = nv.utils.availableHeight(height, container, margin); nv.utils.initSVG(container); //add series index to each data point for reference data.forEach(function(series, i) { series.values.forEach(function(point) { point.series = i; }); }); // Setup Scales var logScale = (typeof(chart.yScale().base) === "function"); // Only log scale has a method "base()" // remap and flatten the data for use in calculating the scales' domains var seriesData = (xDomain && yDomain && sizeDomain) ? [] : // if we know xDomain and yDomain and sizeDomain, no need to calculate.... if Size is constant remember to set sizeDomain to speed up performance d3.merge( data.map(function(d) { return d.values.map(function(d,i) { return { x: getX(d,i), y: getY(d,i), size: getSize(d,i) } }) }) ); x .domain(xDomain || d3.extent(seriesData.map(function(d) { return d.x; }).concat(forceX))) if (padData && data[0]) x.range(xRange || [(availableWidth * padDataOuter + availableWidth) / (2 *data[0].values.length), availableWidth - availableWidth * (1 + padDataOuter) / (2 * data[0].values.length) ]); //x.range([availableWidth * .5 / data[0].values.length, availableWidth * (data[0].values.length - .5) / data[0].values.length ]); else x.range(xRange || [0, availableWidth]); if (logScale) { var min = d3.min(seriesData.map(function(d) { if (d.y !== 0) return d.y; })); y.clamp(true) .domain(yDomain || d3.extent(seriesData.map(function(d) { if (d.y !== 0) return d.y; else return min * 0.1; }).concat(forceY))) .range(yRange || [availableHeight, 0]); } else { y.domain(yDomain || d3.extent(seriesData.map(function (d) { return d.y;}).concat(forceY))) .range(yRange || [availableHeight, 0]); } z .domain(sizeDomain || d3.extent(seriesData.map(function(d) { return d.size }).concat(forceSize))) .range(sizeRange || _sizeRange_def); // If scale's domain don't have a range, slightly adjust to make one... so a chart can show a single data point singlePoint = x.domain()[0] === x.domain()[1] || y.domain()[0] === y.domain()[1]; if (x.domain()[0] === x.domain()[1]) x.domain()[0] ? x.domain([x.domain()[0] - x.domain()[0] * 0.01, x.domain()[1] + x.domain()[1] * 0.01]) : x.domain([-1,1]); if (y.domain()[0] === y.domain()[1]) y.domain()[0] ? y.domain([y.domain()[0] - y.domain()[0] * 0.01, y.domain()[1] + y.domain()[1] * 0.01]) : y.domain([-1,1]); if ( isNaN(x.domain()[0])) { x.domain([-1,1]); } if ( isNaN(y.domain()[0])) { y.domain([-1,1]); } x0 = x0 || x; y0 = y0 || y; z0 = z0 || z; var scaleDiff = x(1) !== x0(1) || y(1) !== y0(1) || z(1) !== z0(1); width0 = width0 || width; height0 = height0 || height; var sizeDiff = width0 !== width || height0 !== height; // Domain Diffs xDom = xDom || []; var domainDiff = xDom[0] !== x.domain()[0] || xDom[1] !== x.domain()[1]; xDom = x.domain(); yDom = yDom || []; domainDiff = domainDiff || yDom[0] !== y.domain()[0] || yDom[1] !== y.domain()[1]; yDom = y.domain(); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-scatter').data([data]); var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-scatter nv-chart-' + id); var defsEnter = wrapEnter.append('defs'); var gEnter = wrapEnter.append('g'); var g = wrap.select('g'); wrap.classed('nv-single-point', singlePoint); gEnter.append('g').attr('class', 'nv-groups'); gEnter.append('g').attr('class', 'nv-point-paths'); wrapEnter.append('g').attr('class', 'nv-point-clips'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); defsEnter.append('clipPath') .attr('id', 'nv-edge-clip-' + id) .append('rect') .attr('transform', 'translate( -10, -10)'); wrap.select('#nv-edge-clip-' + id + ' rect') .attr('width', availableWidth + 20) .attr('height', (availableHeight > 0) ? availableHeight + 20 : 0); g.attr('clip-path', clipEdge ? 'url(#nv-edge-clip-' + id + ')' : ''); function updateInteractiveLayer() { // Always clear needs-update flag regardless of whether or not // we will actually do anything (avoids needless invocations). needsUpdate = false; if (!interactive) return false; container.selectAll(".nv-point.hover").classed("hover", false); // nuke all voronoi paths wrap.select('.nv-point-paths').selectAll('path').remove(); // inject series and point index for reference into voronoi if (useVoronoi === true) { var vertices = d3.merge(data.map(function(group, groupIndex) { return group.values .map(function(point, pointIndex) { // *Adding noise to make duplicates very unlikely // *Injecting series and point index for reference // *Adding a 'jitter' to the points, because there's an issue in d3.geom.voronoi. var pX = getX(point,pointIndex); var pY = getY(point,pointIndex); return [nv.utils.NaNtoZero(x(pX)) + Math.random() * 1e-4, nv.utils.NaNtoZero(y(pY)) + Math.random() * 1e-4, groupIndex, pointIndex, point]; }) .filter(function(pointArray, pointIndex) { return pointActive(pointArray[4], pointIndex); // Issue #237.. move filter to after map, so pointIndex is correct! }) }) ); if (vertices.length == 0) return false; // No active points, we're done if (vertices.length < 3) { // Issue #283 - Adding 2 dummy points to the voronoi b/c voronoi requires min 3 points to work vertices.push([x.range()[0] - 20, y.range()[0] - 20, null, null]); vertices.push([x.range()[1] + 20, y.range()[1] + 20, null, null]); vertices.push([x.range()[0] - 20, y.range()[0] + 20, null, null]); vertices.push([x.range()[1] + 20, y.range()[1] - 20, null, null]); } // keep voronoi sections from going more than 10 outside of graph // to avoid overlap with other things like legend etc var bounds = d3.geom.polygon([ [-10,-10], [-10,height + 10], [width + 10,height + 10], [width + 10,-10] ]); // delete duplicates from vertices - essential assumption for d3.geom.voronoi var epsilon = 1e-4; // Uses 1e-4 to determine equivalence. vertices = vertices.sort(function(a,b){return ((a[0] - b[0]) || (a[1] - b[1]))}); for (var i = 0; i < vertices.length - 1; ) { if ((Math.abs(vertices[i][0] - vertices[i+1][0]) < epsilon) && (Math.abs(vertices[i][1] - vertices[i+1][1]) < epsilon)) { vertices.splice(i+1, 1); } else { i++; } } var voronoi = d3.geom.voronoi(vertices).map(function(d, i) { if (d.length === 0) { return null; } return { 'data': bounds.clip(d), 'series': vertices[i][2], 'point': vertices[i][3] } }); var pointPaths = wrap.select('.nv-point-paths').selectAll('path').data(voronoi); var vPointPaths = pointPaths .enter().append("svg:path") .attr("d", function(d) { if (!d || !d.data || d.data.length === 0) return 'M 0 0'; else return "M" + d.data.join(",") + "Z"; }) .attr("id", function(d,i) { return "nv-path-"+i; }) .attr("clip-path", function(d,i) { return "url(#nv-clip-"+id+"-"+i+")"; }) ; // good for debugging point hover issues if (showVoronoi) { vPointPaths.style("fill", d3.rgb(230, 230, 230)) .style('fill-opacity', 0.4) .style('stroke-opacity', 1) .style("stroke", d3.rgb(200,200,200)); } if (clipVoronoi) { // voronoi sections are already set to clip, // just create the circles with the IDs they expect wrap.select('.nv-point-clips').selectAll('*').remove(); // must do * since it has sub-dom var pointClips = wrap.select('.nv-point-clips').selectAll('clipPath').data(vertices); var vPointClips = pointClips .enter().append("svg:clipPath") .attr("id", function(d, i) { return "nv-clip-"+id+"-"+i;}) .append("svg:circle") .attr('cx', function(d) { return d[0]; }) .attr('cy', function(d) { return d[1]; }) .attr('r', clipRadius); } var mouseEventCallback = function(el, d, mDispatch) { if (needsUpdate) return 0; var series = data[d.series]; if (series === undefined) return; var point = series.values[d.point]; point['color'] = color(series, d.series); // standardize attributes for tooltip. point['x'] = getX(point); point['y'] = getY(point); // can't just get box of event node since it's actually a voronoi polygon var box = container.node().getBoundingClientRect(); var scrollTop = window.pageYOffset || document.documentElement.scrollTop; var scrollLeft = window.pageXOffset || document.documentElement.scrollLeft; var pos = { left: x(getX(point, d.point)) + box.left + scrollLeft + margin.left + 10, top: y(getY(point, d.point)) + box.top + scrollTop + margin.top + 10 }; mDispatch({ point: point, series: series, pos: pos, relativePos: [x(getX(point, d.point)) + margin.left, y(getY(point, d.point)) + margin.top], seriesIndex: d.series, pointIndex: d.point, event: d3.event, element: el }); }; pointPaths .on('click', function(d) { mouseEventCallback(this, d, dispatch.elementClick); }) .on('dblclick', function(d) { mouseEventCallback(this, d, dispatch.elementDblClick); }) .on('mouseover', function(d) { mouseEventCallback(this, d, dispatch.elementMouseover); }) .on('mouseout', function(d, i) { mouseEventCallback(this, d, dispatch.elementMouseout); }); } else { // add event handlers to points instead voronoi paths wrap.select('.nv-groups').selectAll('.nv-group') .selectAll('.nv-point') //.data(dataWithPoints) //.style('pointer-events', 'auto') // recativate events, disabled by css .on('click', function(d,i) { //nv.log('test', d, i); if (needsUpdate || !data[d[0].series]) return 0; //check if this is a dummy point var series = data[d[0].series], point = series.values[i]; var element = this; dispatch.elementClick({ point: point, series: series, pos: [x(getX(point, i)) + margin.left, y(getY(point, i)) + margin.top], //TODO: make this pos base on the page relativePos: [x(getX(point, i)) + margin.left, y(getY(point, i)) + margin.top], seriesIndex: d[0].series, pointIndex: i, event: d3.event, element: element }); }) .on('dblclick', function(d,i) { if (needsUpdate || !data[d[0].series]) return 0; //check if this is a dummy point var series = data[d[0].series], point = series.values[i]; dispatch.elementDblClick({ point: point, series: series, pos: [x(getX(point, i)) + margin.left, y(getY(point, i)) + margin.top],//TODO: make this pos base on the page relativePos: [x(getX(point, i)) + margin.left, y(getY(point, i)) + margin.top], seriesIndex: d[0].series, pointIndex: i }); }) .on('mouseover', function(d,i) { if (needsUpdate || !data[d[0].series]) return 0; //check if this is a dummy point var series = data[d[0].series], point = series.values[i]; dispatch.elementMouseover({ point: point, series: series, pos: [x(getX(point, i)) + margin.left, y(getY(point, i)) + margin.top],//TODO: make this pos base on the page relativePos: [x(getX(point, i)) + margin.left, y(getY(point, i)) + margin.top], seriesIndex: d[0].series, pointIndex: i, color: color(d[0], i) }); }) .on('mouseout', function(d,i) { if (needsUpdate || !data[d[0].series]) return 0; //check if this is a dummy point var series = data[d[0].series], point = series.values[i]; dispatch.elementMouseout({ point: point, series: series, pos: [x(getX(point, i)) + margin.left, y(getY(point, i)) + margin.top],//TODO: make this pos base on the page relativePos: [x(getX(point, i)) + margin.left, y(getY(point, i)) + margin.top], seriesIndex: d[0].series, pointIndex: i, color: color(d[0], i) }); }); } } needsUpdate = true; var groups = wrap.select('.nv-groups').selectAll('.nv-group') .data(function(d) { return d }, function(d) { return d.key }); groups.enter().append('g') .style('stroke-opacity', 1e-6) .style('fill-opacity', 1e-6); groups.exit() .remove(); groups .attr('class', function(d,i) { return (d.classed || '') + ' nv-group nv-series-' + i; }) .classed('nv-noninteractive', !interactive) .classed('hover', function(d) { return d.hover }); groups.watchTransition(renderWatch, 'scatter: groups') .style('fill', function(d,i) { return color(d, i) }) .style('stroke', function(d,i) { return d.pointBorderColor || pointBorderColor || color(d, i) }) .style('stroke-opacity', 1) .style('fill-opacity', .5); // create the points, maintaining their IDs from the original data set var points = groups.selectAll('path.nv-point') .data(function(d) { return d.values.map( function (point, pointIndex) { return [point, pointIndex] }).filter( function(pointArray, pointIndex) { return pointActive(pointArray[0], pointIndex) }) }); points.enter().append('path') .attr('class', function (d) { return 'nv-point nv-point-' + d[1]; }) .style('fill', function (d) { return d.color }) .style('stroke', function (d) { return d.color }) .attr('transform', function(d) { return 'translate(' + nv.utils.NaNtoZero(x0(getX(d[0],d[1]))) + ',' + nv.utils.NaNtoZero(y0(getY(d[0],d[1]))) + ')' }) .attr('d', nv.utils.symbol() .type(function(d) { return getShape(d[0]); }) .size(function(d) { return z(getSize(d[0],d[1])) }) ); points.exit().each(delCache).remove(); groups.exit().selectAll('path.nv-point') .watchTransition(renderWatch, 'scatter exit') .attr('transform', function(d) { return 'translate(' + nv.utils.NaNtoZero(x(getX(d[0],d[1]))) + ',' + nv.utils.NaNtoZero(y(getY(d[0],d[1]))) + ')' }) .remove(); //============================================================ // Point Update Optimisation Notes //------------------------------------------------------------ // The following update selections are filtered with getDiffs // (defined at the top of this file) this brings a performance // benefit for charts with large data sets that accumulate a // subset of changes or additions over time. // // Uneccesary and expensive DOM calls are avoided by culling // unchanged points from the selection in exchange for the // cheaper overhead of caching and diffing each point first. // // Due to the way D3 and NVD3 work, other global changes need // to be considered in addition to local point properties. // This is a potential source of bugs (if any of the global // changes that possibly affect points are missed). // Update Point Positions [x, y] points.filter(function (d) { // getDiffs must always be called to update cache return getDiffs(d, 'x', getX, 'y', getY) || scaleDiff || sizeDiff || domainDiff; }) .watchTransition(renderWatch, 'scatter points') .attr('transform', function (d) { return 'translate(' + nv.utils.NaNtoZero(x(getX(d[0], d[1]))) + ',' + nv.utils.NaNtoZero(y(getY(d[0], d[1]))) + ')' }); // Update Point Appearance [shape, size] points.filter(function (d) { // getDiffs must always be called to update cache return getDiffs(d, 'shape', getShape, 'size', getSize) || scaleDiff || sizeDiff || domainDiff; }) .watchTransition(renderWatch, 'scatter points') .attr('d', nv.utils.symbol() .type(function (d) { return getShape(d[0]) }) .size(function (d) { return z(getSize(d[0], d[1])) }) ); // add label a label to scatter chart if(showLabels) { var titles = groups.selectAll('.nv-label') .data(function(d) { return d.values.map( function (point, pointIndex) { return [point, pointIndex] }).filter( function(pointArray, pointIndex) { return pointActive(pointArray[0], pointIndex) }) }); titles.enter().append('text') .style('fill', function (d,i) { return d.color }) .style('stroke-opacity', 0) .style('fill-opacity', 1) .attr('transform', function(d) { var dx = nv.utils.NaNtoZero(x0(getX(d[0],d[1]))) + Math.sqrt(z(getSize(d[0],d[1]))/Math.PI) + 2; return 'translate(' + dx + ',' + nv.utils.NaNtoZero(y0(getY(d[0],d[1]))) + ')'; }) .text(function(d,i){ return d[0].label;}); titles.exit().remove(); groups.exit().selectAll('path.nv-label') .watchTransition(renderWatch, 'scatter exit') .attr('transform', function(d) { var dx = nv.utils.NaNtoZero(x(getX(d[0],d[1])))+ Math.sqrt(z(getSize(d[0],d[1]))/Math.PI)+2; return 'translate(' + dx + ',' + nv.utils.NaNtoZero(y(getY(d[0],d[1]))) + ')'; }) .remove(); titles.each(function(d) { d3.select(this) .classed('nv-label', true) .classed('nv-label-' + d[1], false) .classed('hover',false); }); titles.watchTransition(renderWatch, 'scatter labels') .text(function(d,i){ return d[0].label;}) .attr('transform', function(d) { var dx = nv.utils.NaNtoZero(x(getX(d[0],d[1])))+ Math.sqrt(z(getSize(d[0],d[1]))/Math.PI)+2; return 'translate(' + dx + ',' + nv.utils.NaNtoZero(y(getY(d[0],d[1]))) + ')' }); } // Delay updating the invisible interactive layer for smoother animation if( interactiveUpdateDelay ) { clearTimeout(timeoutID); // stop repeat calls to updateInteractiveLayer timeoutID = setTimeout(updateInteractiveLayer, interactiveUpdateDelay ); } else { updateInteractiveLayer(); } //store old scales for use in transitions on update x0 = x.copy(); y0 = y.copy(); z0 = z.copy(); width0 = width; height0 = height; }); renderWatch.renderEnd('scatter immediate'); return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.dispatch = dispatch; chart.options = nv.utils.optionsFunc.bind(chart); // utility function calls provided by this chart chart._calls = new function() { this.clearHighlights = function () { nv.dom.write(function() { container.selectAll(".nv-point.hover").classed("hover", false); }); return null; }; this.highlightPoint = function (seriesIndex, pointIndex, isHoverOver) { nv.dom.write(function() { container.select('.nv-groups') .selectAll(".nv-series-" + seriesIndex) .selectAll(".nv-point-" + pointIndex) .classed("hover", isHoverOver); }); }; }; // trigger calls from events too dispatch.on('elementMouseover.point', function(d) { if (interactive) chart._calls.highlightPoint(d.seriesIndex,d.pointIndex,true); }); dispatch.on('elementMouseout.point', function(d) { if (interactive) chart._calls.highlightPoint(d.seriesIndex,d.pointIndex,false); }); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, xScale: {get: function(){return x;}, set: function(_){x=_;}}, yScale: {get: function(){return y;}, set: function(_){y=_;}}, pointScale: {get: function(){return z;}, set: function(_){z=_;}}, xDomain: {get: function(){return xDomain;}, set: function(_){xDomain=_;}}, yDomain: {get: function(){return yDomain;}, set: function(_){yDomain=_;}}, pointDomain: {get: function(){return sizeDomain;}, set: function(_){sizeDomain=_;}}, xRange: {get: function(){return xRange;}, set: function(_){xRange=_;}}, yRange: {get: function(){return yRange;}, set: function(_){yRange=_;}}, pointRange: {get: function(){return sizeRange;}, set: function(_){sizeRange=_;}}, forceX: {get: function(){return forceX;}, set: function(_){forceX=_;}}, forceY: {get: function(){return forceY;}, set: function(_){forceY=_;}}, forcePoint: {get: function(){return forceSize;}, set: function(_){forceSize=_;}}, interactive: {get: function(){return interactive;}, set: function(_){interactive=_;}}, pointActive: {get: function(){return pointActive;}, set: function(_){pointActive=_;}}, padDataOuter: {get: function(){return padDataOuter;}, set: function(_){padDataOuter=_;}}, padData: {get: function(){return padData;}, set: function(_){padData=_;}}, clipEdge: {get: function(){return clipEdge;}, set: function(_){clipEdge=_;}}, clipVoronoi: {get: function(){return clipVoronoi;}, set: function(_){clipVoronoi=_;}}, clipRadius: {get: function(){return clipRadius;}, set: function(_){clipRadius=_;}}, showVoronoi: {get: function(){return showVoronoi;}, set: function(_){showVoronoi=_;}}, id: {get: function(){return id;}, set: function(_){id=_;}}, interactiveUpdateDelay: {get:function(){return interactiveUpdateDelay;}, set: function(_){interactiveUpdateDelay=_;}}, showLabels: {get: function(){return showLabels;}, set: function(_){ showLabels = _;}}, pointBorderColor: {get: function(){return pointBorderColor;}, set: function(_){pointBorderColor=_;}}, // simple functor options x: {get: function(){return getX;}, set: function(_){getX = d3.functor(_);}}, y: {get: function(){return getY;}, set: function(_){getY = d3.functor(_);}}, pointSize: {get: function(){return getSize;}, set: function(_){getSize = d3.functor(_);}}, pointShape: {get: function(){return getShape;}, set: function(_){getShape = d3.functor(_);}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; renderWatch.reset(duration); }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); }}, useVoronoi: {get: function(){return useVoronoi;}, set: function(_){ useVoronoi = _; if (useVoronoi === false) { clipVoronoi = false; } }} }); nv.utils.initOptions(chart); return chart; }; ================================================ FILE: src/models/scatterChart.js ================================================ nv.models.scatterChart = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var scatter = nv.models.scatter() , xAxis = nv.models.axis() , yAxis = nv.models.axis() , legend = nv.models.legend() , distX = nv.models.distribution() , distY = nv.models.distribution() , tooltip = nv.models.tooltip() ; var margin = {top: 30, right: 20, bottom: 50, left: 75} , marginTop = null , width = null , height = null , container = null , color = nv.utils.defaultColor() , x = scatter.xScale() , y = scatter.yScale() , showDistX = false , showDistY = false , showLegend = true , showXAxis = true , showYAxis = true , rightAlignYAxis = false , state = nv.utils.state() , defaultState = null , dispatch = d3.dispatch('stateChange', 'changeState', 'renderEnd') , noData = null , duration = 250 , showLabels = false ; scatter.xScale(x).yScale(y); xAxis.orient('bottom').tickPadding(10); yAxis .orient((rightAlignYAxis) ? 'right' : 'left') .tickPadding(10) ; distX.axis('x'); distY.axis('y'); tooltip .headerFormatter(function(d, i) { return xAxis.tickFormat()(d, i); }) .valueFormatter(function(d, i) { return yAxis.tickFormat()(d, i); }); //============================================================ // Private Variables //------------------------------------------------------------ var x0, y0 , renderWatch = nv.utils.renderWatch(dispatch, duration); var stateGetter = function(data) { return function(){ return { active: data.map(function(d) { return !d.disabled }) }; } }; var stateSetter = function(data) { return function(state) { if (state.active !== undefined) data.forEach(function(series,i) { series.disabled = !state.active[i]; }); } }; function chart(selection) { renderWatch.reset(); renderWatch.models(scatter); if (showXAxis) renderWatch.models(xAxis); if (showYAxis) renderWatch.models(yAxis); if (showDistX) renderWatch.models(distX); if (showDistY) renderWatch.models(distY); selection.each(function(data) { var that = this; container = d3.select(this); nv.utils.initSVG(container); var availableWidth = nv.utils.availableWidth(width, container, margin), availableHeight = nv.utils.availableHeight(height, container, margin); chart.update = function() { if (duration === 0) container.call(chart); else container.transition().duration(duration).call(chart); }; chart.container = this; state .setter(stateSetter(data), chart.update) .getter(stateGetter(data)) .update(); // DEPRECATED set state.disableddisabled state.disabled = data.map(function(d) { return !!d.disabled }); if (!defaultState) { var key; defaultState = {}; for (key in state) { if (state[key] instanceof Array) defaultState[key] = state[key].slice(0); else defaultState[key] = state[key]; } } // Display noData message if there's nothing to show. if (!data || !data.length || !data.filter(function(d) { return d.values.length }).length) { nv.utils.noData(chart, container); renderWatch.renderEnd('scatter immediate'); return chart; } else { container.selectAll('.nv-noData').remove(); } // Setup Scales x = scatter.xScale(); y = scatter.yScale(); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-scatterChart').data([data]); var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-scatterChart nv-chart-' + scatter.id()); var gEnter = wrapEnter.append('g'); var g = wrap.select('g'); // background for pointer events gEnter.append('rect').attr('class', 'nvd3 nv-background').style("pointer-events","none"); gEnter.append('g').attr('class', 'nv-x nv-axis'); gEnter.append('g').attr('class', 'nv-y nv-axis'); gEnter.append('g').attr('class', 'nv-scatterWrap'); gEnter.append('g').attr('class', 'nv-regressionLinesWrap'); gEnter.append('g').attr('class', 'nv-distWrap'); gEnter.append('g').attr('class', 'nv-legendWrap'); if (rightAlignYAxis) { g.select(".nv-y.nv-axis") .attr("transform", "translate(" + availableWidth + ",0)"); } // Legend if (!showLegend) { g.select('.nv-legendWrap').selectAll('*').remove(); } else { var legendWidth = availableWidth; legend.width(legendWidth); wrap.select('.nv-legendWrap') .datum(data) .call(legend); if (!marginTop && legend.height() !== margin.top) { margin.top = legend.height(); availableHeight = nv.utils.availableHeight(height, container, margin); } wrap.select('.nv-legendWrap') .attr('transform', 'translate(0' + ',' + (-margin.top) +')'); } wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); // Main Chart Component(s) scatter .width(availableWidth) .height(availableHeight) .color(data.map(function(d,i) { d.color = d.color || color(d, i); return d.color; }).filter(function(d,i) { return !data[i].disabled })) .showLabels(showLabels); wrap.select('.nv-scatterWrap') .datum(data.filter(function(d) { return !d.disabled })) .call(scatter); wrap.select('.nv-regressionLinesWrap') .attr('clip-path', 'url(#nv-edge-clip-' + scatter.id() + ')'); var regWrap = wrap.select('.nv-regressionLinesWrap').selectAll('.nv-regLines') .data(function (d) { return d; }); regWrap.enter().append('g').attr('class', 'nv-regLines'); var regLine = regWrap.selectAll('.nv-regLine') .data(function (d) { return [d] }); regLine.enter() .append('line').attr('class', 'nv-regLine') .style('stroke-opacity', 0); // don't add lines unless we have slope and intercept to use regLine.filter(function(d) { return d.intercept && d.slope; }) .watchTransition(renderWatch, 'scatterPlusLineChart: regline') .attr('x1', x.range()[0]) .attr('x2', x.range()[1]) .attr('y1', function (d, i) { return y(x.domain()[0] * d.slope + d.intercept) }) .attr('y2', function (d, i) { return y(x.domain()[1] * d.slope + d.intercept) }) .style('stroke', function (d, i, j) { return color(d, j) }) .style('stroke-opacity', function (d, i) { return (d.disabled || typeof d.slope === 'undefined' || typeof d.intercept === 'undefined') ? 0 : 1 }); // Setup Axes if (showXAxis) { xAxis .scale(x) ._ticks( nv.utils.calcTicksX(availableWidth/100, data) ) .tickSize( -availableHeight , 0); g.select('.nv-x.nv-axis') .attr('transform', 'translate(0,' + y.range()[0] + ')') .call(xAxis); } if (showYAxis) { yAxis .scale(y) ._ticks( nv.utils.calcTicksY(availableHeight/36, data) ) .tickSize( -availableWidth, 0); g.select('.nv-y.nv-axis') .call(yAxis); } // Setup Distribution distX .getData(scatter.x()) .scale(x) .width(availableWidth) .color(data.map(function(d,i) { return d.color || color(d, i); }).filter(function(d,i) { return !data[i].disabled })); gEnter.select('.nv-distWrap').append('g') .attr('class', 'nv-distributionX'); g.select('.nv-distributionX') .attr('transform', 'translate(0,' + y.range()[0] + ')') .datum(data.filter(function(d) { return !d.disabled })) .call(distX) .style('opacity', function() { return showDistX ? '1' : '1e-6'; }) .watchTransition(renderWatch, 'scatterPlusLineChart') .style('opacity', function() { return showDistX ? '1' : '1e-6'; }) distY .getData(scatter.y()) .scale(y) .width(availableHeight) .color(data.map(function(d,i) { return d.color || color(d, i); }).filter(function(d,i) { return !data[i].disabled })); gEnter.select('.nv-distWrap').append('g') .attr('class', 'nv-distributionY'); g.select('.nv-distributionY') .attr('transform', 'translate(' + (rightAlignYAxis ? availableWidth : -distY.size() ) + ',0)') .datum(data.filter(function(d) { return !d.disabled })) .call(distY) .style('opacity', function() { return showDistY ? '1' : '1e-6'; }) .watchTransition(renderWatch, 'scatterPlusLineChart') .style('opacity', function() { return showDistY ? '1' : '1e-6'; }) //============================================================ // Event Handling/Dispatching (in chart's scope) //------------------------------------------------------------ legend.dispatch.on('stateChange', function(newState) { for (var key in newState) state[key] = newState[key]; dispatch.stateChange(state); chart.update(); }); // Update chart from a state object passed to event handler dispatch.on('changeState', function(e) { if (typeof e.disabled !== 'undefined') { data.forEach(function(series,i) { series.disabled = e.disabled[i]; }); state.disabled = e.disabled; } chart.update(); }); // mouseover needs availableHeight so we just keep scatter mouse events inside the chart block scatter.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true); container.select('.nv-chart-' + scatter.id() + ' .nv-series-' + evt.seriesIndex + ' .nv-distx-' + evt.pointIndex) .attr('y1', 0); container.select('.nv-chart-' + scatter.id() + ' .nv-series-' + evt.seriesIndex + ' .nv-disty-' + evt.pointIndex) .attr('x2', distY.size()); }); scatter.dispatch.on('elementMouseover.tooltip', function(evt) { container.select('.nv-series-' + evt.seriesIndex + ' .nv-distx-' + evt.pointIndex) .attr('y1', evt.relativePos[1] - availableHeight); container.select('.nv-series-' + evt.seriesIndex + ' .nv-disty-' + evt.pointIndex) .attr('x2', evt.relativePos[0] + distX.size()); tooltip.data(evt).hidden(false); }); //store old scales for use in transitions on update x0 = x.copy(); y0 = y.copy(); }); renderWatch.renderEnd('scatter with line immediate'); return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ // expose chart's sub-components chart.dispatch = dispatch; chart.scatter = scatter; chart.legend = legend; chart.xAxis = xAxis; chart.yAxis = yAxis; chart.distX = distX; chart.distY = distY; chart.tooltip = tooltip; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, container: {get: function(){return container;}, set: function(_){container=_;}}, showDistX: {get: function(){return showDistX;}, set: function(_){showDistX=_;}}, showDistY: {get: function(){return showDistY;}, set: function(_){showDistY=_;}}, showLegend: {get: function(){return showLegend;}, set: function(_){showLegend=_;}}, showXAxis: {get: function(){return showXAxis;}, set: function(_){showXAxis=_;}}, showYAxis: {get: function(){return showYAxis;}, set: function(_){showYAxis=_;}}, defaultState: {get: function(){return defaultState;}, set: function(_){defaultState=_;}}, noData: {get: function(){return noData;}, set: function(_){noData=_;}}, duration: {get: function(){return duration;}, set: function(_){duration=_;}}, showLabels: {get: function(){return showLabels;}, set: function(_){showLabels=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ if (_.top !== undefined) { margin.top = _.top; marginTop = _.top; } margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, rightAlignYAxis: {get: function(){return rightAlignYAxis;}, set: function(_){ rightAlignYAxis = _; yAxis.orient( (_) ? 'right' : 'left'); }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); legend.color(color); distX.color(color); distY.color(color); }} }); nv.utils.inheritOptions(chart, scatter); nv.utils.initOptions(chart); return chart; }; ================================================ FILE: src/models/sparkline.js ================================================ nv.models.sparkline = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 2, right: 0, bottom: 2, left: 0} , width = 400 , height = 32 , container = null , animate = true , x = d3.scale.linear() , y = d3.scale.linear() , getX = function(d) { return d.x } , getY = function(d) { return d.y } , color = nv.utils.getColor(['#000']) , xDomain , yDomain , xRange , yRange , showMinMaxPoints = true , showCurrentPoint = true , dispatch = d3.dispatch('renderEnd') ; //============================================================ // Private Variables //------------------------------------------------------------ var renderWatch = nv.utils.renderWatch(dispatch); function chart(selection) { renderWatch.reset(); selection.each(function(data) { var availableWidth = width - margin.left - margin.right, availableHeight = height - margin.top - margin.bottom; container = d3.select(this); nv.utils.initSVG(container); // Setup Scales x .domain(xDomain || d3.extent(data, getX )) .range(xRange || [0, availableWidth]); y .domain(yDomain || d3.extent(data, getY )) .range(yRange || [availableHeight, 0]); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-sparkline').data([data]); var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-sparkline'); var gEnter = wrapEnter.append('g'); var g = wrap.select('g'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')') var paths = wrap.selectAll('path') .data(function(d) { return [d] }); paths.enter().append('path'); paths.exit().remove(); paths .style('stroke', function(d,i) { return d.color || color(d, i) }) .attr('d', d3.svg.line() .x(function(d,i) { return x(getX(d,i)) }) .y(function(d,i) { return y(getY(d,i)) }) ); // TODO: Add CURRENT data point (Need Min, Mac, Current / Most recent) var points = wrap.selectAll('circle.nv-point') .data(function(data) { var yValues = data.map(function(d, i) { return getY(d,i); }); function pointIndex(index) { if (index != -1) { var result = data[index]; result.pointIndex = index; return result; } else { return null; } } var maxPoint = pointIndex(yValues.lastIndexOf(y.domain()[1])), minPoint = pointIndex(yValues.indexOf(y.domain()[0])), currentPoint = pointIndex(yValues.length - 1); return [(showMinMaxPoints ? minPoint : null), (showMinMaxPoints ? maxPoint : null), (showCurrentPoint ? currentPoint : null)].filter(function (d) {return d != null;}); }); points.enter().append('circle'); points.exit().remove(); points .attr('cx', function(d,i) { return x(getX(d,d.pointIndex)) }) .attr('cy', function(d,i) { return y(getY(d,d.pointIndex)) }) .attr('r', 2) .attr('class', function(d,i) { return getX(d, d.pointIndex) == x.domain()[1] ? 'nv-point nv-currentValue' : getY(d, d.pointIndex) == y.domain()[0] ? 'nv-point nv-minValue' : 'nv-point nv-maxValue' }); }); renderWatch.renderEnd('sparkline immediate'); return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, xDomain: {get: function(){return xDomain;}, set: function(_){xDomain=_;}}, yDomain: {get: function(){return yDomain;}, set: function(_){yDomain=_;}}, xRange: {get: function(){return xRange;}, set: function(_){xRange=_;}}, yRange: {get: function(){return yRange;}, set: function(_){yRange=_;}}, xScale: {get: function(){return x;}, set: function(_){x=_;}}, yScale: {get: function(){return y;}, set: function(_){y=_;}}, animate: {get: function(){return animate;}, set: function(_){animate=_;}}, showMinMaxPoints: {get: function(){return showMinMaxPoints;}, set: function(_){showMinMaxPoints=_;}}, showCurrentPoint: {get: function(){return showCurrentPoint;}, set: function(_){showCurrentPoint=_;}}, //functor options x: {get: function(){return getX;}, set: function(_){getX=d3.functor(_);}}, y: {get: function(){return getY;}, set: function(_){getY=d3.functor(_);}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); }} }); chart.dispatch = dispatch; nv.utils.initOptions(chart); return chart; }; ================================================ FILE: src/models/sparklinePlus.js ================================================ nv.models.sparklinePlus = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var sparkline = nv.models.sparkline(); var margin = {top: 15, right: 100, bottom: 10, left: 50} , width = null , height = null , x , y , index = [] , paused = false , xTickFormat = d3.format(',r') , yTickFormat = d3.format(',.2f') , showLastValue = true , alignValue = true , rightAlignValue = false , noData = null , dispatch = d3.dispatch('renderEnd') ; //============================================================ // Private Variables //------------------------------------------------------------ var renderWatch = nv.utils.renderWatch(dispatch); function chart(selection) { renderWatch.reset(); renderWatch.models(sparkline); selection.each(function(data) { var container = d3.select(this); nv.utils.initSVG(container); var availableWidth = nv.utils.availableWidth(width, container, margin), availableHeight = nv.utils.availableHeight(height, container, margin); chart.update = function() { container.call(chart); }; chart.container = this; // Display No Data message if there's nothing to show. if (!data || !data.length) { nv.utils.noData(chart, container) return chart; } else { container.selectAll('.nv-noData').remove(); } var currentValue = sparkline.y()(data[data.length-1], data.length-1); // Setup Scales x = sparkline.xScale(); y = sparkline.yScale(); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-sparklineplus').data([data]); var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-sparklineplus'); var gEnter = wrapEnter.append('g'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-sparklineWrap'); gEnter.append('g').attr('class', 'nv-valueWrap'); gEnter.append('g').attr('class', 'nv-hoverArea'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); // Main Chart Component(s) var sparklineWrap = g.select('.nv-sparklineWrap'); sparkline.width(availableWidth).height(availableHeight); sparklineWrap.call(sparkline); if (showLastValue) { var valueWrap = g.select('.nv-valueWrap'); var value = valueWrap.selectAll('.nv-currentValue') .data([currentValue]); value.enter().append('text').attr('class', 'nv-currentValue') .attr('dx', rightAlignValue ? -8 : 8) .attr('dy', '.9em') .style('text-anchor', rightAlignValue ? 'end' : 'start'); value .attr('x', availableWidth + (rightAlignValue ? margin.right : 0)) .attr('y', alignValue ? function (d) { return y(d) } : 0) .style('fill', sparkline.color()(data[data.length - 1], data.length - 1)) .text(yTickFormat(currentValue)); } gEnter.select('.nv-hoverArea').append('rect') .on('mousemove', sparklineHover) .on('click', function() { paused = !paused }) .on('mouseout', function() { index = []; updateValueLine(); }); g.select('.nv-hoverArea rect') .attr('transform', function(d) { return 'translate(' + -margin.left + ',' + -margin.top + ')' }) .attr('width', availableWidth + margin.left + margin.right) .attr('height', availableHeight + margin.top); //index is currently global (within the chart), may or may not keep it that way function updateValueLine() { if (paused) return; var hoverValue = g.selectAll('.nv-hoverValue').data(index); var hoverEnter = hoverValue.enter() .append('g').attr('class', 'nv-hoverValue') .style('stroke-opacity', 0) .style('fill-opacity', 0); hoverValue.exit() .transition().duration(250) .style('stroke-opacity', 0) .style('fill-opacity', 0) .remove(); hoverValue .attr('transform', function(d) { return 'translate(' + x(sparkline.x()(data[d],d)) + ',0)' }) .transition().duration(250) .style('stroke-opacity', 1) .style('fill-opacity', 1); if (!index.length) return; hoverEnter.append('line') .attr('x1', 0) .attr('y1', -margin.top) .attr('x2', 0) .attr('y2', availableHeight); hoverEnter.append('text').attr('class', 'nv-xValue') .attr('x', -6) .attr('y', -margin.top) .attr('text-anchor', 'end') .attr('dy', '.9em'); g.select('.nv-hoverValue .nv-xValue') .text(xTickFormat(sparkline.x()(data[index[0]], index[0]))); hoverEnter.append('text').attr('class', 'nv-yValue') .attr('x', 6) .attr('y', -margin.top) .attr('text-anchor', 'start') .attr('dy', '.9em'); g.select('.nv-hoverValue .nv-yValue') .text(yTickFormat(sparkline.y()(data[index[0]], index[0]))); } function sparklineHover() { if (paused) return; var pos = d3.mouse(this)[0] - margin.left; function getClosestIndex(data, x) { var distance = Math.abs(sparkline.x()(data[0], 0) - x); var closestIndex = 0; for (var i = 0; i < data.length; i++){ if (Math.abs(sparkline.x()(data[i], i) - x) < distance) { distance = Math.abs(sparkline.x()(data[i], i) - x); closestIndex = i; } } return closestIndex; } index = [getClosestIndex(data, Math.round(x.invert(pos)))]; updateValueLine(); } }); renderWatch.renderEnd('sparklinePlus immediate'); return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ // expose chart's sub-components chart.dispatch = dispatch; chart.sparkline = sparkline; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, xTickFormat: {get: function(){return xTickFormat;}, set: function(_){xTickFormat=_;}}, yTickFormat: {get: function(){return yTickFormat;}, set: function(_){yTickFormat=_;}}, showLastValue: {get: function(){return showLastValue;}, set: function(_){showLastValue=_;}}, alignValue: {get: function(){return alignValue;}, set: function(_){alignValue=_;}}, rightAlignValue: {get: function(){return rightAlignValue;}, set: function(_){rightAlignValue=_;}}, noData: {get: function(){return noData;}, set: function(_){noData=_;}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }} }); nv.utils.inheritOptions(chart, sparkline); nv.utils.initOptions(chart); return chart; }; ================================================ FILE: src/models/stackedArea.js ================================================ nv.models.stackedArea = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 0, right: 0, bottom: 0, left: 0} , width = 960 , height = 500 , color = nv.utils.defaultColor() // a function that computes the color , id = Math.floor(Math.random() * 100000) //Create semi-unique ID incase user doesn't selet one , container = null , getX = function(d) { return d.x } // accessor to get the x value from a data point , getY = function(d) { return d.y } // accessor to get the y value from a data point , defined = function(d,i) { return !isNaN(getY(d,i)) && getY(d,i) !== null } // allows a line to be not continuous when it is not defined , style = 'stack' , offset = 'zero' , order = 'default' , interpolate = 'linear' // controls the line interpolation , clipEdge = false // if true, masks lines within x and y scale , x //can be accessed via chart.xScale() , y //can be accessed via chart.yScale() , scatter = nv.models.scatter() , duration = 250 , transformData = function(d, y0, y) { d.display = { y: y, y0: y0 }; } , areaY1 = function(d) { return y(d.display.y + d.display.y0) } , dispatch = d3.dispatch('areaClick', 'areaMouseover', 'areaMouseout','renderEnd', 'elementClick', 'elementMouseover', 'elementMouseout') ; scatter .pointSize(2.2) // default size .pointDomain([2.2, 2.2]) // all the same size by default ; /************************************ * offset: * 'wiggle' (stream) * 'zero' (stacked) * 'expand' (normalize to 100%) * 'silhouette' (simple centered) * * order: * 'inside-out' (stream) * 'default' (input order) ************************************/ var renderWatch = nv.utils.renderWatch(dispatch, duration); function chart(selection) { renderWatch.reset(); renderWatch.models(scatter); selection.each(function(data) { var availableWidth = width - margin.left - margin.right, availableHeight = height - margin.top - margin.bottom; container = d3.select(this); nv.utils.initSVG(container); // Setup Scales x = scatter.xScale(); y = scatter.yScale(); var dataRaw = data; // Injecting point index into each point because d3.layout.stack().out does not give index data.forEach(function(aseries, i) { aseries.seriesIndex = i; aseries.values = aseries.values.map(function(d, j) { d.index = j; d.seriesIndex = i; return d; }); }); var dataFiltered = data.filter(function(series) { return !series.disabled; }); data = d3.layout.stack() .order(order) .offset(offset) .values(function(d) { return d.values }) //TODO: make values customizeable in EVERY model in this fashion .x(getX) .y(getY) .out(transformData) (dataFiltered); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-stackedarea').data([data]); var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-stackedarea'); var defsEnter = wrapEnter.append('defs'); var gEnter = wrapEnter.append('g'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-areaWrap'); gEnter.append('g').attr('class', 'nv-scatterWrap'); wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); // If the user has not specified forceY, make sure 0 is included in the domain // Otherwise, use user-specified values for forceY if (scatter.forceY().length == 0) { scatter.forceY().push(0); } scatter .width(availableWidth) .height(availableHeight) .x(getX) .y(function(d) { if (d.display !== undefined) { return d.display.y + d.display.y0; } }) .color(data.map(function(d,i) { d.color = d.color || color(d, d.seriesIndex); return d.color; })); var scatterWrap = g.select('.nv-scatterWrap') .datum(data); scatterWrap.call(scatter); defsEnter.append('clipPath') .attr('id', 'nv-edge-clip-' + id) .append('rect'); wrap.select('#nv-edge-clip-' + id + ' rect') .attr('width', availableWidth) .attr('height', availableHeight); g.attr('clip-path', clipEdge ? 'url(#nv-edge-clip-' + id + ')' : ''); var area = d3.svg.area() .defined(defined) .x(function(d,i) { return x(getX(d,i)) }) .y0(function(d) { return y(d.display.y0) }) .y1(areaY1) .interpolate(interpolate); var zeroArea = d3.svg.area() .defined(defined) .x(function(d,i) { return x(getX(d,i)) }) .y0(function(d) { return y(d.display.y0) }) .y1(function(d) { return y(d.display.y0) }); var path = g.select('.nv-areaWrap').selectAll('path.nv-area') .data(function(d) { return d }); path.enter().append('path').attr('class', function(d,i) { return 'nv-area nv-area-' + i }) .attr('d', function(d,i){ return zeroArea(d.values, d.seriesIndex); }) .on('mouseover', function(d,i) { d3.select(this).classed('hover', true); dispatch.areaMouseover({ point: d, series: d.key, pos: [d3.event.pageX, d3.event.pageY], seriesIndex: d.seriesIndex }); }) .on('mouseout', function(d,i) { d3.select(this).classed('hover', false); dispatch.areaMouseout({ point: d, series: d.key, pos: [d3.event.pageX, d3.event.pageY], seriesIndex: d.seriesIndex }); }) .on('click', function(d,i) { d3.select(this).classed('hover', false); dispatch.areaClick({ point: d, series: d.key, pos: [d3.event.pageX, d3.event.pageY], seriesIndex: d.seriesIndex }); }); path.exit().remove(); path.style('fill', function(d,i){ return d.color || color(d, d.seriesIndex) }) .style('stroke', function(d,i){ return d.color || color(d, d.seriesIndex) }); path.watchTransition(renderWatch,'stackedArea path') .attr('d', function(d,i) { return area(d.values,i) }); //============================================================ // Event Handling/Dispatching (in chart's scope) //------------------------------------------------------------ scatter.dispatch.on('elementMouseover.area', function(e) { g.select('.nv-chart-' + id + ' .nv-area-' + e.seriesIndex).classed('hover', true); }); scatter.dispatch.on('elementMouseout.area', function(e) { g.select('.nv-chart-' + id + ' .nv-area-' + e.seriesIndex).classed('hover', false); }); //Special offset functions chart.d3_stackedOffset_stackPercent = function(stackData) { var n = stackData.length, //How many series m = stackData[0].length, //how many points per series i, j, o, y0 = []; for (j = 0; j < m; ++j) { //Looping through all points for (i = 0, o = 0; i < dataRaw.length; i++) { //looping through all series o += getY(dataRaw[i].values[j]); //total y value of all series at a certian point in time. } if (o) for (i = 0; i < n; i++) { //(total y value of all series at point in time i) != 0 stackData[i][j][1] /= o; } else { //(total y value of all series at point in time i) == 0 for (i = 0; i < n; i++) { stackData[i][j][1] = 0; } } } for (j = 0; j < m; ++j) y0[j] = 0; return y0; }; }); renderWatch.renderEnd('stackedArea immediate'); return chart; } //============================================================ // Global getters and setters //------------------------------------------------------------ chart.dispatch = dispatch; chart.scatter = scatter; scatter.dispatch.on('elementClick', function(){ dispatch.elementClick.apply(this, arguments); }); scatter.dispatch.on('elementMouseover', function(){ dispatch.elementMouseover.apply(this, arguments); }); scatter.dispatch.on('elementMouseout', function(){ dispatch.elementMouseout.apply(this, arguments); }); chart.interpolate = function(_) { if (!arguments.length) return interpolate; interpolate = _; return chart; }; chart.duration = function(_) { if (!arguments.length) return duration; duration = _; renderWatch.reset(duration); scatter.duration(duration); return chart; }; chart.dispatch = dispatch; chart.scatter = scatter; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, defined: {get: function(){return defined;}, set: function(_){defined=_;}}, clipEdge: {get: function(){return clipEdge;}, set: function(_){clipEdge=_;}}, offset: {get: function(){return offset;}, set: function(_){offset=_;}}, order: {get: function(){return order;}, set: function(_){order=_;}}, interpolate: {get: function(){return interpolate;}, set: function(_){interpolate=_;}}, // simple functor options x: {get: function(){return getX;}, set: function(_){getX = d3.functor(_);}}, y: {get: function(){return getY;}, set: function(_){getY = d3.functor(_);}}, areaY1: {get: function(){return areaY1;}, set: function(_){ areaY1 = d3.functor(_);}}, transformData: {get: function(){return transformData;}, set: function(_){ transformData = d3.functor(_);}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); }}, style: {get: function(){return style;}, set: function(_){ style = _; switch (style) { case 'stack': chart.offset('zero'); chart.order('default'); break; case 'stream': chart.offset('wiggle'); chart.order('inside-out'); break; case 'stream-center': chart.offset('silhouette'); chart.order('inside-out'); break; case 'expand': chart.offset('expand'); chart.order('default'); break; case 'stack_percent': chart.offset(chart.d3_stackedOffset_stackPercent); chart.order('default'); break; } }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; renderWatch.reset(duration); scatter.duration(duration); }} }); nv.utils.inheritOptions(chart, scatter); nv.utils.initOptions(chart); return chart; }; ================================================ FILE: src/models/stackedAreaChart.js ================================================ nv.models.stackedAreaChart = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var stacked = nv.models.stackedArea() , xAxis = nv.models.axis() , yAxis = nv.models.axis() , legend = nv.models.legend() , controls = nv.models.legend() , interactiveLayer = nv.interactiveGuideline() , tooltip = nv.models.tooltip() , focus = nv.models.focus(nv.models.stackedArea()) ; var margin = {top: 10, right: 25, bottom: 50, left: 60} , marginTop = null , width = null , height = null , color = nv.utils.defaultColor() , showControls = true , showLegend = true , legendPosition = 'top' , showXAxis = true , showYAxis = true , rightAlignYAxis = false , focusEnable = false , useInteractiveGuideline = false , showTotalInTooltip = true , totalLabel = 'TOTAL' , x //can be accessed via chart.xScale() , y //can be accessed via chart.yScale() , state = nv.utils.state() , defaultState = null , noData = null , dispatch = d3.dispatch('stateChange', 'changeState','renderEnd') , controlWidth = 250 , controlOptions = ['Stacked','Stream','Expanded'] , controlLabels = {} , duration = 250 ; state.style = stacked.style(); xAxis.orient('bottom').tickPadding(7); yAxis.orient((rightAlignYAxis) ? 'right' : 'left'); tooltip .headerFormatter(function(d, i) { return xAxis.tickFormat()(d, i); }) .valueFormatter(function(d, i) { return yAxis.tickFormat()(d, i); }); interactiveLayer.tooltip .headerFormatter(function(d, i) { return xAxis.tickFormat()(d, i); }) .valueFormatter(function(d, i) { return d == null ? "N/A" : yAxis.tickFormat()(d, i); }); var oldYTickFormat = null, oldValueFormatter = null; controls.updateState(false); //============================================================ // Private Variables //------------------------------------------------------------ var renderWatch = nv.utils.renderWatch(dispatch); var style = stacked.style(); var stateGetter = function(data) { return function(){ return { active: data.map(function(d) { return !d.disabled }), style: stacked.style() }; } }; var stateSetter = function(data) { return function(state) { if (state.style !== undefined) style = state.style; if (state.active !== undefined) data.forEach(function(series,i) { series.disabled = !state.active[i]; }); } }; var percentFormatter = d3.format('%'); function chart(selection) { renderWatch.reset(); renderWatch.models(stacked); if (showXAxis) renderWatch.models(xAxis); if (showYAxis) renderWatch.models(yAxis); selection.each(function(data) { var container = d3.select(this), that = this; nv.utils.initSVG(container); var availableWidth = nv.utils.availableWidth(width, container, margin), availableHeight = nv.utils.availableHeight(height, container, margin) - (focusEnable ? focus.height() : 0); chart.update = function() { container.transition().duration(duration).call(chart); }; chart.container = this; state .setter(stateSetter(data), chart.update) .getter(stateGetter(data)) .update(); // DEPRECATED set state.disabled state.disabled = data.map(function(d) { return !!d.disabled }); if (!defaultState) { var key; defaultState = {}; for (key in state) { if (state[key] instanceof Array) defaultState[key] = state[key].slice(0); else defaultState[key] = state[key]; } } // Display No Data message if there's nothing to show. if (!data || !data.length || !data.filter(function(d) { return d.values.length }).length) { nv.utils.noData(chart, container) return chart; } else { container.selectAll('.nv-noData').remove(); } // Setup Scales x = stacked.xScale(); y = stacked.yScale(); // Setup containers and skeleton of chart var wrap = container.selectAll('g.nv-wrap.nv-stackedAreaChart').data([data]); var gEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-stackedAreaChart').append('g'); var g = wrap.select('g'); gEnter.append('g').attr('class', 'nv-legendWrap'); gEnter.append('g').attr('class', 'nv-controlsWrap'); var focusEnter = gEnter.append('g').attr('class', 'nv-focus'); focusEnter.append('g').attr('class', 'nv-background').append('rect'); focusEnter.append('g').attr('class', 'nv-x nv-axis'); focusEnter.append('g').attr('class', 'nv-y nv-axis'); focusEnter.append('g').attr('class', 'nv-stackedWrap'); focusEnter.append('g').attr('class', 'nv-interactive'); // g.select("rect").attr("width",availableWidth).attr("height",availableHeight); var contextEnter = gEnter.append('g').attr('class', 'nv-focusWrap'); // Legend if (!showLegend) { g.select('.nv-legendWrap').selectAll('*').remove(); } else { var legendWidth = (showControls && legendPosition === 'top') ? availableWidth - controlWidth : availableWidth; legend.width(legendWidth); g.select('.nv-legendWrap').datum(data).call(legend); if (legendPosition === 'bottom') { var xAxisHeight = xAxis.height(); margin.bottom = Math.max(legend.height() + xAxisHeight, margin.bottom); availableHeight = nv.utils.availableHeight(height, container, margin) - (focusEnable ? focus.height() : 0); var legendTop = availableHeight + xAxisHeight; g.select('.nv-legendWrap') .attr('transform', 'translate(0,' + legendTop +')'); } else if (legendPosition === 'top') { if (!marginTop && margin.top != legend.height()) { margin.top = legend.height(); availableHeight = nv.utils.availableHeight(height, container, margin) - (focusEnable ? focus.height() : 0); } g.select('.nv-legendWrap') .attr('transform', 'translate(' + (availableWidth-legendWidth) + ',' + (-margin.top) +')'); } } // Controls if (!showControls) { g.select('.nv-controlsWrap').selectAll('*').remove(); } else { var controlsData = [ { key: controlLabels.stacked || 'Stacked', metaKey: 'Stacked', disabled: stacked.style() != 'stack', style: 'stack' }, { key: controlLabels.stream || 'Stream', metaKey: 'Stream', disabled: stacked.style() != 'stream', style: 'stream' }, { key: controlLabels.stream_center || 'Stream Center', metaKey: 'Stream_Center', disabled: stacked.style() != 'stream_center', style: 'stream-center' }, { key: controlLabels.expanded || 'Expanded', metaKey: 'Expanded', disabled: stacked.style() != 'expand', style: 'expand' }, { key: controlLabels.stack_percent || 'Stack %', metaKey: 'Stack_Percent', disabled: stacked.style() != 'stack_percent', style: 'stack_percent' } ]; controlWidth = (controlOptions.length/3) * 260; controlsData = controlsData.filter(function(d) { return controlOptions.indexOf(d.metaKey) !== -1; }); controls .width( controlWidth ) .color(['#444', '#444', '#444']); g.select('.nv-controlsWrap') .datum(controlsData) .call(controls); var requiredTop = Math.max(controls.height(), showLegend && (legendPosition === 'top') ? legend.height() : 0); if ( margin.top != requiredTop ) { margin.top = requiredTop; availableHeight = nv.utils.availableHeight(height, container, margin) - (focusEnable ? focus.height() : 0); } g.select('.nv-controlsWrap') .attr('transform', 'translate(0,' + (-margin.top) +')'); } wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); if (rightAlignYAxis) { g.select(".nv-y.nv-axis") .attr("transform", "translate(" + availableWidth + ",0)"); } //Set up interactive layer if (useInteractiveGuideline) { interactiveLayer .width(availableWidth) .height(availableHeight) .margin({left: margin.left, top: margin.top}) .svgContainer(container) .xScale(x); wrap.select(".nv-interactive").call(interactiveLayer); } g.select('.nv-focus .nv-background rect') .attr('width', availableWidth) .attr('height', availableHeight); stacked .width(availableWidth) .height(availableHeight) .color(data.map(function(d,i) { return d.color || color(d, i); }).filter(function(d,i) { return !data[i].disabled; })); var stackedWrap = g.select('.nv-focus .nv-stackedWrap') .datum(data.filter(function(d) { return !d.disabled; })); // Setup Axes if (showXAxis) { xAxis.scale(x) ._ticks( nv.utils.calcTicksX(availableWidth/100, data) ) .tickSize( -availableHeight, 0); } if (showYAxis) { var ticks; if (stacked.offset() === 'wiggle') { ticks = 0; } else { ticks = nv.utils.calcTicksY(availableHeight/36, data); } yAxis.scale(y) ._ticks(ticks) .tickSize(-availableWidth, 0); } //============================================================ // Update Axes //============================================================ function updateXAxis() { if(showXAxis) { g.select('.nv-focus .nv-x.nv-axis') .attr('transform', 'translate(0,' + availableHeight + ')') .transition() .duration(duration) .call(xAxis) ; } } function updateYAxis() { if(showYAxis) { if (stacked.style() === 'expand' || stacked.style() === 'stack_percent') { var currentFormat = yAxis.tickFormat(); if ( !oldYTickFormat || currentFormat !== percentFormatter ) oldYTickFormat = currentFormat; //Forces the yAxis to use percentage in 'expand' mode. yAxis.tickFormat(percentFormatter); } else { if (oldYTickFormat) { yAxis.tickFormat(oldYTickFormat); oldYTickFormat = null; } } g.select('.nv-focus .nv-y.nv-axis') .transition().duration(0) .call(yAxis); } } //============================================================ // Update Focus //============================================================ if(!focusEnable) { stackedWrap.transition().call(stacked); updateXAxis(); updateYAxis(); } else { focus.width(availableWidth); g.select('.nv-focusWrap') .attr('transform', 'translate(0,' + ( availableHeight + margin.bottom + focus.margin().top) + ')') .datum(data.filter(function(d) { return !d.disabled; })) .call(focus); var extent = focus.brush.empty() ? focus.xDomain() : focus.brush.extent(); if(extent !== null){ onBrush(extent); } } //============================================================ // Event Handling/Dispatching (in chart's scope) //------------------------------------------------------------ stacked.dispatch.on('areaClick.toggle', function(e) { if (data.filter(function(d) { return !d.disabled }).length === 1) data.forEach(function(d) { d.disabled = false; }); else data.forEach(function(d,i) { d.disabled = (i != e.seriesIndex); }); state.disabled = data.map(function(d) { return !!d.disabled }); dispatch.stateChange(state); chart.update(); }); legend.dispatch.on('stateChange', function(newState) { for (var key in newState) state[key] = newState[key]; dispatch.stateChange(state); chart.update(); }); controls.dispatch.on('legendClick', function(d,i) { if (!d.disabled) return; controlsData = controlsData.map(function(s) { s.disabled = true; return s; }); d.disabled = false; stacked.style(d.style); state.style = stacked.style(); dispatch.stateChange(state); chart.update(); }); interactiveLayer.dispatch.on('elementMousemove', function(e) { stacked.clearHighlights(); var singlePoint, pointIndex, pointXLocation, allData = [], valueSum = 0, allNullValues = true, atleastOnePoint = false; data .filter(function(series, i) { series.seriesIndex = i; return !series.disabled; }) .forEach(function(series,i) { pointIndex = nv.interactiveBisect(series.values, e.pointXValue, chart.x()); var point = series.values[pointIndex]; var pointYValue = chart.y()(point, pointIndex); if (pointYValue != null && pointYValue > 0) { stacked.highlightPoint(i, pointIndex, true); atleastOnePoint = true; } // Draw at least one point if all values are zero. if (i === (data.length - 1) && !atleastOnePoint) { stacked.highlightPoint(i, pointIndex, true); } if (typeof point === 'undefined') return; if (typeof singlePoint === 'undefined') singlePoint = point; if (typeof pointXLocation === 'undefined') pointXLocation = chart.xScale()(chart.x()(point,pointIndex)); //If we are in 'expand' mode, use the stacked percent value instead of raw value. var tooltipValue = (stacked.style() == 'expand') ? point.display.y : chart.y()(point,pointIndex); allData.push({ key: series.key, value: tooltipValue, color: color(series,series.seriesIndex), point: point }); if (showTotalInTooltip && stacked.style() != 'expand' && tooltipValue != null) { valueSum += tooltipValue; allNullValues = false; }; }); allData.reverse(); //Highlight the tooltip entry based on which stack the mouse is closest to. if (allData.length > 2) { var yValue = chart.yScale().invert(e.mouseY); var yDistMax = Infinity, indexToHighlight = null; allData.forEach(function(series,i) { //To handle situation where the stacked area chart is negative, we need to use absolute values //when checking if the mouse Y value is within the stack area. yValue = Math.abs(yValue); var stackedY0 = Math.abs(series.point.display.y0); var stackedY = Math.abs(series.point.display.y); if ( yValue >= stackedY0 && yValue <= (stackedY + stackedY0)) { indexToHighlight = i; return; } }); if (indexToHighlight != null) allData[indexToHighlight].highlight = true; } //If we are not in 'expand' mode, add a 'Total' row to the tooltip. if (showTotalInTooltip && stacked.style() != 'expand' && allData.length >= 2 && !allNullValues) { allData.push({ key: totalLabel, value: valueSum, total: true }); } var xValue = chart.x()(singlePoint,pointIndex); var valueFormatter = interactiveLayer.tooltip.valueFormatter(); // Keeps track of the tooltip valueFormatter if the chart changes to expanded view if (stacked.style() === 'expand' || stacked.style() === 'stack_percent') { if ( !oldValueFormatter ) { oldValueFormatter = valueFormatter; } //Forces the tooltip to use percentage in 'expand' mode. valueFormatter = d3.format(".1%"); } else { if (oldValueFormatter) { valueFormatter = oldValueFormatter; oldValueFormatter = null; } } interactiveLayer.tooltip .valueFormatter(valueFormatter) .data( { value: xValue, series: allData } )(); interactiveLayer.renderGuideLine(pointXLocation); }); interactiveLayer.dispatch.on("elementMouseout",function(e) { stacked.clearHighlights(); }); /* Update `main' graph on brush update. */ focus.dispatch.on("onBrush", function(extent) { onBrush(extent); }); // Update chart from a state object passed to event handler dispatch.on('changeState', function(e) { if (typeof e.disabled !== 'undefined' && data.length === e.disabled.length) { data.forEach(function(series,i) { series.disabled = e.disabled[i]; }); state.disabled = e.disabled; } if (typeof e.style !== 'undefined') { stacked.style(e.style); style = e.style; } chart.update(); }); //============================================================ // Functions //------------------------------------------------------------ function onBrush(extent) { // Update Main (Focus) var stackedWrap = g.select('.nv-focus .nv-stackedWrap') .datum( data.filter(function(d) { return !d.disabled; }) .map(function(d,i) { return { key: d.key, area: d.area, classed: d.classed, values: d.values.filter(function(d,i) { return stacked.x()(d,i) >= extent[0] && stacked.x()(d,i) <= extent[1]; }), disableTooltip: d.disableTooltip }; }) ); stackedWrap.transition().duration(duration).call(stacked); // Update Main (Focus) Axes updateXAxis(); updateYAxis(); } }); renderWatch.renderEnd('stacked Area chart immediate'); return chart; } //============================================================ // Event Handling/Dispatching (out of chart's scope) //------------------------------------------------------------ stacked.dispatch.on('elementMouseover.tooltip', function(evt) { evt.point['x'] = stacked.x()(evt.point); evt.point['y'] = stacked.y()(evt.point); tooltip.data(evt).hidden(false); }); stacked.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true) }); //============================================================ // Expose Public Variables //------------------------------------------------------------ // expose chart's sub-components chart.dispatch = dispatch; chart.stacked = stacked; chart.legend = legend; chart.controls = controls; chart.xAxis = xAxis; chart.x2Axis = focus.xAxis; chart.yAxis = yAxis; chart.y2Axis = focus.yAxis; chart.interactiveLayer = interactiveLayer; chart.tooltip = tooltip; chart.focus = focus; chart.dispatch = dispatch; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, showLegend: {get: function(){return showLegend;}, set: function(_){showLegend=_;}}, legendPosition: {get: function(){return legendPosition;}, set: function(_){legendPosition=_;}}, showXAxis: {get: function(){return showXAxis;}, set: function(_){showXAxis=_;}}, showYAxis: {get: function(){return showYAxis;}, set: function(_){showYAxis=_;}}, defaultState: {get: function(){return defaultState;}, set: function(_){defaultState=_;}}, noData: {get: function(){return noData;}, set: function(_){noData=_;}}, showControls: {get: function(){return showControls;}, set: function(_){showControls=_;}}, controlLabels: {get: function(){return controlLabels;}, set: function(_){controlLabels=_;}}, controlOptions: {get: function(){return controlOptions;}, set: function(_){controlOptions=_;}}, showTotalInTooltip: {get: function(){return showTotalInTooltip;}, set: function(_){showTotalInTooltip=_;}}, totalLabel: {get: function(){return totalLabel;}, set: function(_){totalLabel=_;}}, focusEnable: {get: function(){return focusEnable;}, set: function(_){focusEnable=_;}}, focusHeight: {get: function(){return focus.height();}, set: function(_){focus.height(_);}}, brushExtent: {get: function(){return focus.brushExtent();}, set: function(_){focus.brushExtent(_);}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ if (_.top !== undefined) { margin.top = _.top; marginTop = _.top; } margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; }}, focusMargin: {get: function(){return focus.margin}, set: function(_){ focus.margin.top = _.top !== undefined ? _.top : focus.margin.top; focus.margin.right = _.right !== undefined ? _.right : focus.margin.right; focus.margin.bottom = _.bottom !== undefined ? _.bottom : focus.margin.bottom; focus.margin.left = _.left !== undefined ? _.left : focus.margin.left; }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; renderWatch.reset(duration); stacked.duration(duration); xAxis.duration(duration); yAxis.duration(duration); }}, color: {get: function(){return color;}, set: function(_){ color = nv.utils.getColor(_); legend.color(color); stacked.color(color); focus.color(color); }}, x: {get: function(){return stacked.x();}, set: function(_){ stacked.x(_); focus.x(_); }}, y: {get: function(){return stacked.y();}, set: function(_){ stacked.y(_); focus.y(_); }}, rightAlignYAxis: {get: function(){return rightAlignYAxis;}, set: function(_){ rightAlignYAxis = _; yAxis.orient( rightAlignYAxis ? 'right' : 'left'); }}, useInteractiveGuideline: {get: function(){return useInteractiveGuideline;}, set: function(_){ useInteractiveGuideline = !!_; chart.interactive(!_); chart.useVoronoi(!_); stacked.scatter.interactive(!_); }} }); nv.utils.inheritOptions(chart, stacked); nv.utils.initOptions(chart); return chart; }; nv.models.stackedAreaWithFocusChart = function() { return nv.models.stackedAreaChart() .margin({ bottom: 30 }) .focusEnable( true ); }; ================================================ FILE: src/models/sunburst.js ================================================ // based on http://bl.ocks.org/kerryrodden/477c1bfb081b783f80ad nv.models.sunburst = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var margin = {top: 0, right: 0, bottom: 0, left: 0} , width = 600 , height = 600 , mode = "count" , modes = {count: function(d) { return 1; }, value: function(d) { return d.value || d.size }, size: function(d) { return d.value || d.size }} , id = Math.floor(Math.random() * 10000) //Create semi-unique ID in case user doesn't select one , container = null , color = nv.utils.defaultColor() , showLabels = false , labelFormat = function(d){if(mode === 'count'){return d.name + ' #' + d.value}else{return d.name + ' ' + (d.value || d.size)}} , labelThreshold = 0.02 , sort = function(d1, d2){return d1.name > d2.name;} , key = function(d,i){ if (d.parent !== undefined) { return d.name + '-' + d.parent.name + '-' + i; } else { return d.name; } } , groupColorByParent = true , duration = 500 , dispatch = d3.dispatch('chartClick', 'elementClick', 'elementDblClick', 'elementMousemove', 'elementMouseover', 'elementMouseout', 'renderEnd'); //============================================================ // aux functions and setup //------------------------------------------------------------ var x = d3.scale.linear().range([0, 2 * Math.PI]); var y = d3.scale.sqrt(); var partition = d3.layout.partition().sort(sort); var node, availableWidth, availableHeight, radius; var prevPositions = {}; var arc = d3.svg.arc() .startAngle(function(d) {return Math.max(0, Math.min(2 * Math.PI, x(d.x))) }) .endAngle(function(d) {return Math.max(0, Math.min(2 * Math.PI, x(d.x + d.dx))) }) .innerRadius(function(d) {return Math.max(0, y(d.y)) }) .outerRadius(function(d) {return Math.max(0, y(d.y + d.dy)) }); function rotationToAvoidUpsideDown(d) { var centerAngle = computeCenterAngle(d); if(centerAngle > 90){ return 180; } else { return 0; } } function computeCenterAngle(d) { var startAngle = Math.max(0, Math.min(2 * Math.PI, x(d.x))); var endAngle = Math.max(0, Math.min(2 * Math.PI, x(d.x + d.dx))); var centerAngle = (((startAngle + endAngle) / 2) * (180 / Math.PI)) - 90; return centerAngle; } function computeNodePercentage(d) { var startAngle = Math.max(0, Math.min(2 * Math.PI, x(d.x))); var endAngle = Math.max(0, Math.min(2 * Math.PI, x(d.x + d.dx))); return (endAngle - startAngle) / (2 * Math.PI); } function labelThresholdMatched(d) { var startAngle = Math.max(0, Math.min(2 * Math.PI, x(d.x))); var endAngle = Math.max(0, Math.min(2 * Math.PI, x(d.x + d.dx))); var size = endAngle - startAngle; return size > labelThreshold; } // When zooming: interpolate the scales. function arcTweenZoom(e,i) { var xd = d3.interpolate(x.domain(), [node.x, node.x + node.dx]), yd = d3.interpolate(y.domain(), [node.y, 1]), yr = d3.interpolate(y.range(), [node.y ? 20 : 0, radius]); if (i === 0) { return function() {return arc(e);} } else { return function (t) { x.domain(xd(t)); y.domain(yd(t)).range(yr(t)); return arc(e); } }; } function arcTweenUpdate(d) { var ipo = d3.interpolate({x: d.x0, dx: d.dx0, y: d.y0, dy: d.dy0}, d); return function (t) { var b = ipo(t); d.x0 = b.x; d.dx0 = b.dx; d.y0 = b.y; d.dy0 = b.dy; return arc(b); }; } function updatePrevPosition(node) { var k = key(node); if(! prevPositions[k]) prevPositions[k] = {}; var pP = prevPositions[k]; pP.dx = node.dx; pP.x = node.x; pP.dy = node.dy; pP.y = node.y; } function storeRetrievePrevPositions(nodes) { nodes.forEach(function(n){ var k = key(n); var pP = prevPositions[k]; //console.log(k,n,pP); if( pP ){ n.dx0 = pP.dx; n.x0 = pP.x; n.dy0 = pP.dy; n.y0 = pP.y; } else { n.dx0 = n.dx; n.x0 = n.x; n.dy0 = n.dy; n.y0 = n.y; } updatePrevPosition(n); }); } function zoomClick(d) { var labels = container.selectAll('text') var path = container.selectAll('path') // fade out all text elements labels.transition().attr("opacity",0); // to allow reference to the new center node node = d; path.transition() .duration(duration) .attrTween("d", arcTweenZoom) .each('end', function(e) { // partially taken from here: http://bl.ocks.org/metmajer/5480307 // check if the animated element's data e lies within the visible angle span given in d if(e.x >= d.x && e.x < (d.x + d.dx) ){ if(e.depth >= d.depth){ // get a selection of the associated text element var parentNode = d3.select(this.parentNode); var arcText = parentNode.select('text'); // fade in the text element and recalculate positions arcText.transition().duration(duration) .text( function(e){return labelFormat(e) }) .attr("opacity", function(d){ if(labelThresholdMatched(d)) { return 1; } else { return 0; } }) .attr("transform", function() { var width = this.getBBox().width; if(e.depth === 0) return "translate(" + (width / 2 * - 1) + ",0)"; else if(e.depth === d.depth){ return "translate(" + (y(e.y) + 5) + ",0)"; } else { var centerAngle = computeCenterAngle(e); var rotation = rotationToAvoidUpsideDown(e); if (rotation === 0) { return 'rotate('+ centerAngle +')translate(' + (y(e.y) + 5) + ',0)'; } else { return 'rotate('+ centerAngle +')translate(' + (y(e.y) + width + 5) + ',0)rotate(' + rotation + ')'; } } }); } } }) } //============================================================ // chart function //------------------------------------------------------------ var renderWatch = nv.utils.renderWatch(dispatch); function chart(selection) { renderWatch.reset(); selection.each(function(data) { container = d3.select(this); availableWidth = nv.utils.availableWidth(width, container, margin); availableHeight = nv.utils.availableHeight(height, container, margin); radius = Math.min(availableWidth, availableHeight) / 2; y.range([0, radius]); // Setup containers and skeleton of chart var wrap = container.select('g.nvd3.nv-wrap.nv-sunburst'); if( !wrap[0][0] ) { wrap = container.append('g') .attr('class', 'nvd3 nv-wrap nv-sunburst nv-chart-' + id) .attr('transform', 'translate(' + ((availableWidth / 2) + margin.left + margin.right) + ',' + ((availableHeight / 2) + margin.top + margin.bottom) + ')'); } else { wrap.attr('transform', 'translate(' + ((availableWidth / 2) + margin.left + margin.right) + ',' + ((availableHeight / 2) + margin.top + margin.bottom) + ')'); } container.on('click', function (d, i) { dispatch.chartClick({ data: d, index: i, pos: d3.event, id: id }); }); partition.value(modes[mode] || modes["count"]); //reverse the drawing order so that the labels of inner //arcs are drawn on top of the outer arcs. var nodes = partition.nodes(data[0]).reverse() storeRetrievePrevPositions(nodes); var cG = wrap.selectAll('.arc-container').data(nodes, key) //handle new datapoints var cGE = cG.enter() .append("g") .attr("class",'arc-container') cGE.append("path") .attr("d", arc) .style("fill", function (d) { if (d.color) { return d.color; } else if (groupColorByParent) { return color((d.children ? d : d.parent).name); } else { return color(d.name); } }) .style("stroke", "#FFF") .on("click", function(d,i){ zoomClick(d); dispatch.elementClick({ data: d, index: i }) }) .on('mouseover', function(d,i){ d3.select(this).classed('hover', true).style('opacity', 0.8); dispatch.elementMouseover({ data: d, color: d3.select(this).style("fill"), percent: computeNodePercentage(d) }); }) .on('mouseout', function(d,i){ d3.select(this).classed('hover', false).style('opacity', 1); dispatch.elementMouseout({ data: d }); }) .on('mousemove', function(d,i){ dispatch.elementMousemove({ data: d }); }); ///Iterating via each and selecting based on the this ///makes it work ... a cG.selectAll('path') doesn't. ///Without iteration the data (in the element) didn't update. cG.each(function(d){ d3.select(this).select('path') .transition() .duration(duration) .attrTween('d', arcTweenUpdate); }); if(showLabels){ //remove labels first and add them back cG.selectAll('text').remove(); //this way labels are on top of newly added arcs cG.append('text') .text( function(e){ return labelFormat(e)}) .transition() .duration(duration) .attr("opacity", function(d){ if(labelThresholdMatched(d)) { return 1; } else { return 0; } }) .attr("transform", function(d) { var width = this.getBBox().width; if(d.depth === 0){ return "rotate(0)translate(" + (width / 2 * -1) + ",0)"; } else { var centerAngle = computeCenterAngle(d); var rotation = rotationToAvoidUpsideDown(d); if (rotation === 0) { return 'rotate('+ centerAngle +')translate(' + (y(d.y) + 5) + ',0)'; } else { return 'rotate('+ centerAngle +')translate(' + (y(d.y) + width + 5) + ',0)rotate(' + rotation + ')'; } } }); } //zoom out to the center when the data is updated. zoomClick(nodes[nodes.length - 1]) //remove unmatched elements ... cG.exit() .transition() .duration(duration) .attr('opacity',0) .each('end',function(d){ var k = key(d); prevPositions[k] = undefined; }) .remove(); }); renderWatch.renderEnd('sunburst immediate'); return chart; } //============================================================ // Expose Public Variables //------------------------------------------------------------ chart.dispatch = dispatch; chart.options = nv.utils.optionsFunc.bind(chart); chart._options = Object.create({}, { // simple options, just get/set the necessary values width: {get: function(){return width;}, set: function(_){width=_;}}, height: {get: function(){return height;}, set: function(_){height=_;}}, mode: {get: function(){return mode;}, set: function(_){mode=_;}}, id: {get: function(){return id;}, set: function(_){id=_;}}, duration: {get: function(){return duration;}, set: function(_){duration=_;}}, groupColorByParent: {get: function(){return groupColorByParent;}, set: function(_){groupColorByParent=!!_;}}, showLabels: {get: function(){return showLabels;}, set: function(_){showLabels=!!_}}, labelFormat: {get: function(){return labelFormat;}, set: function(_){labelFormat=_}}, labelThreshold: {get: function(){return labelThreshold;}, set: function(_){labelThreshold=_}}, sort: {get: function(){return sort;}, set: function(_){sort=_}}, key: {get: function(){return key;}, set: function(_){key=_}}, // options that require extra logic in the setter margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top != undefined ? _.top : margin.top; margin.right = _.right != undefined ? _.right : margin.right; margin.bottom = _.bottom != undefined ? _.bottom : margin.bottom; margin.left = _.left != undefined ? _.left : margin.left; }}, color: {get: function(){return color;}, set: function(_){ color=nv.utils.getColor(_); }} }); nv.utils.initOptions(chart); return chart; }; ================================================ FILE: src/models/sunburstChart.js ================================================ nv.models.sunburstChart = function() { "use strict"; //============================================================ // Public Variables with Default Settings //------------------------------------------------------------ var sunburst = nv.models.sunburst(); var tooltip = nv.models.tooltip(); var margin = {top: 30, right: 20, bottom: 20, left: 20} , width = null , height = null , color = nv.utils.defaultColor() , showTooltipPercent = false , id = Math.round(Math.random() * 100000) , defaultState = null , noData = null , duration = 250 , dispatch = d3.dispatch('stateChange', 'changeState','renderEnd'); //============================================================ // Private Variables //------------------------------------------------------------ var renderWatch = nv.utils.renderWatch(dispatch); tooltip .duration(0) .headerEnabled(false) .valueFormatter(function(d){return d;}); //============================================================ // Chart function //------------------------------------------------------------ function chart(selection) { renderWatch.reset(); renderWatch.models(sunburst); selection.each(function(data) { var container = d3.select(this); nv.utils.initSVG(container); var availableWidth = nv.utils.availableWidth(width, container, margin); var availableHeight = nv.utils.availableHeight(height, container, margin); chart.update = function() { if (duration === 0) { container.call(chart); } else { container.transition().duration(duration).call(chart); } }; chart.container = container; // Display No Data message if there's nothing to show. if (!data || !data.length) { nv.utils.noData(chart, container); return chart; } else { container.selectAll('.nv-noData').remove(); } sunburst.width(availableWidth).height(availableHeight).margin(margin); container.call(sunburst); }); renderWatch.renderEnd('sunburstChart immediate'); return chart; } //============================================================ // Event Handling/Dispatching (out of chart's scope) //------------------------------------------------------------ sunburst.dispatch.on('elementMouseover.tooltip', function(evt) { evt.series = { key: evt.data.name, value: (evt.data.value || evt.data.size), color: evt.color, percent: evt.percent }; if (!showTooltipPercent) { delete evt.percent; delete evt.series.percent; } tooltip.data(evt).hidden(false); }); sunburst.dispatch.on('elementMouseout.tooltip', function(evt) { tooltip.hidden(true); }); sunburst.dispatch.on('elementMousemove.tooltip', function(evt) { tooltip(); }); //============================================================ // Expose Public Variables //------------------------------------------------------------ // expose chart's sub-components chart.dispatch = dispatch; chart.sunburst = sunburst; chart.tooltip = tooltip; chart.options = nv.utils.optionsFunc.bind(chart); // use Object get/set functionality to map between vars and chart functions chart._options = Object.create({}, { // simple options, just get/set the necessary values noData: {get: function(){return noData;}, set: function(_){noData=_;}}, defaultState: {get: function(){return defaultState;}, set: function(_){defaultState=_;}}, showTooltipPercent: {get: function(){return showTooltipPercent;}, set: function(_){showTooltipPercent=_;}}, // options that require extra logic in the setter color: {get: function(){return color;}, set: function(_){ color = _; sunburst.color(color); }}, duration: {get: function(){return duration;}, set: function(_){ duration = _; renderWatch.reset(duration); sunburst.duration(duration); }}, margin: {get: function(){return margin;}, set: function(_){ margin.top = _.top !== undefined ? _.top : margin.top; margin.right = _.right !== undefined ? _.right : margin.right; margin.bottom = _.bottom !== undefined ? _.bottom : margin.bottom; margin.left = _.left !== undefined ? _.left : margin.left; sunburst.margin(margin); }} }); nv.utils.inheritOptions(chart, sunburst); nv.utils.initOptions(chart); return chart; }; ================================================ FILE: src/tooltip.js ================================================ /* Model which can be instantiated to handle tooltip rendering. Example usage: var tip = nv.models.tooltip().gravity('w').distance(23) .data(myDataObject); tip(); //just invoke the returned function to render tooltip. */ nv.models.tooltip = function() { "use strict"; /* Tooltip data. If data is given in the proper format, a consistent tooltip is generated. Example Format of data: { key: "Date", value: "August 2009", series: [ {key: "Series 1", value: "Value 1", color: "#000"}, {key: "Series 2", value: "Value 2", color: "#00f"} ] } */ var id = "nvtooltip-" + Math.floor(Math.random() * 100000) // Generates a unique id when you create a new tooltip() object. , data = null , gravity = 'w' // Can be 'n','s','e','w'. Determines how tooltip is positioned. , distance = 25 // Distance to offset tooltip from the mouse location. , snapDistance = 0 // Tolerance allowed before tooltip is moved from its current position (creates 'snapping' effect) , classes = null // Attaches additional CSS classes to the tooltip DIV that is created. , hidden = true // Start off hidden, toggle with hide/show functions below. , hideDelay = 200 // Delay (in ms) before the tooltip hides after calling hide(). , tooltip = null // d3 select of the tooltip div. , lastPosition = { left: null, top: null } // Last position the tooltip was in. , enabled = true // True -> tooltips are rendered. False -> don't render tooltips. , duration = 100 // Tooltip movement duration, in ms. , headerEnabled = true // If is to show the tooltip header. , nvPointerEventsClass = "nv-pointer-events-none" // CSS class to specify whether element should not have mouse events. ; // Format function for the tooltip values column. // d is value, // i is series index // p is point containing the value var valueFormatter = function(d, i, p) { return d; }; // Format function for the tooltip header value. var headerFormatter = function(d) { return d; }; var keyFormatter = function(d, i) { return d; }; // By default, the tooltip model renders a beautiful table inside a DIV, returned as HTML // You can override this function if a custom tooltip is desired. For instance, you could directly manipulate // the DOM by accessing elem and returning false. var contentGenerator = function(d, elem) { if (d === null) { return ''; } var table = d3.select(document.createElement("table")); if (headerEnabled) { var theadEnter = table.selectAll("thead") .data([d]) .enter().append("thead"); theadEnter.append("tr") .append("td") .attr("colspan", 3) .append("strong") .classed("x-value", true) .html(headerFormatter(d.value)); } var tbodyEnter = table.selectAll("tbody") .data([d]) .enter().append("tbody"); var trowEnter = tbodyEnter.selectAll("tr") .data(function(p) { return p.series}) .enter() .append("tr") .classed("highlight", function(p) { return p.highlight}); trowEnter.append("td") .classed("legend-color-guide",true) .append("div") .style("background-color", function(p) { return p.color}); trowEnter.append("td") .classed("key",true) .classed("total",function(p) { return !!p.total}) .html(function(p, i) { return keyFormatter(p.key, i)}); trowEnter.append("td") .classed("value",true) .html(function(p, i) { return valueFormatter(p.value, i, p) }); trowEnter.filter(function (p,i) { return p.percent !== undefined }).append("td") .classed("percent", true) .html(function(p, i) { return "(" + d3.format('%')(p.percent) + ")" }); trowEnter.selectAll("td").each(function(p) { if (p.highlight) { var opacityScale = d3.scale.linear().domain([0,1]).range(["#fff",p.color]); var opacity = 0.6; d3.select(this) .style("border-bottom-color", opacityScale(opacity)) .style("border-top-color", opacityScale(opacity)) ; } }); var html = table.node().outerHTML; if (d.footer !== undefined) html += ""; return html; }; /* Function that returns the position (relative to the viewport/document.body) the tooltip should be placed in. Should return: { left: , top: } */ var position = function() { var pos = { left: d3.event !== null ? d3.event.clientX : 0, top: d3.event !== null ? d3.event.clientY : 0 }; if(getComputedStyle(document.body).transform != 'none') { // Take the offset into account, as now the tooltip is relative // to document.body. var client = document.body.getBoundingClientRect(); pos.left -= client.left; pos.top -= client.top; } return pos; }; var dataSeriesExists = function(d) { if (d && d.series) { if (nv.utils.isArray(d.series)) { return true; } // if object, it's okay just convert to array of the object if (nv.utils.isObject(d.series)) { d.series = [d.series]; return true; } } return false; }; // Calculates the gravity offset of the tooltip. Parameter is position of tooltip // relative to the viewport. var calcGravityOffset = function(pos) { var height = tooltip.node().offsetHeight, width = tooltip.node().offsetWidth, clientWidth = document.documentElement.clientWidth, // Don't want scrollbars. clientHeight = document.documentElement.clientHeight, // Don't want scrollbars. left, top, tmp; // calculate position based on gravity switch (gravity) { case 'e': left = - width - distance; top = - (height / 2); if(pos.left + left < 0) left = distance; if((tmp = pos.top + top) < 0) top -= tmp; if((tmp = pos.top + top + height) > clientHeight) top -= tmp - clientHeight; break; case 'w': left = distance; top = - (height / 2); if (pos.left + left + width > clientWidth) left = - width - distance; if ((tmp = pos.top + top) < 0) top -= tmp; if ((tmp = pos.top + top + height) > clientHeight) top -= tmp - clientHeight; break; case 'n': left = - (width / 2) - 5; // - 5 is an approximation of the mouse's height. top = distance; if (pos.top + top + height > clientHeight) top = - height - distance; if ((tmp = pos.left + left) < 0) left -= tmp; if ((tmp = pos.left + left + width) > clientWidth) left -= tmp - clientWidth; break; case 's': left = - (width / 2); top = - height - distance; if (pos.top + top < 0) top = distance; if ((tmp = pos.left + left) < 0) left -= tmp; if ((tmp = pos.left + left + width) > clientWidth) left -= tmp - clientWidth; break; case 'center': left = - (width / 2); top = - (height / 2); break; default: left = 0; top = 0; break; } return { 'left': left, 'top': top }; }; /* Positions the tooltip in the correct place, as given by the position() function. */ var positionTooltip = function() { nv.dom.read(function() { var pos = position(), gravityOffset = calcGravityOffset(pos), left = pos.left + gravityOffset.left, top = pos.top + gravityOffset.top; // delay hiding a bit to avoid flickering if (hidden) { tooltip .interrupt() .transition() .delay(hideDelay) .duration(0) .style('opacity', 0); } else { // using tooltip.style('transform') returns values un-usable for tween var old_translate = 'translate(' + lastPosition.left + 'px, ' + lastPosition.top + 'px)'; var new_translate = 'translate(' + Math.round(left) + 'px, ' + Math.round(top) + 'px)'; var translateInterpolator = d3.interpolateString(old_translate, new_translate); var is_hidden = tooltip.style('opacity') < 0.1; tooltip .interrupt() // cancel running transitions .transition() .duration(is_hidden ? 0 : duration) // using tween since some versions of d3 can't auto-tween a translate on a div .styleTween('transform', function (d) { return translateInterpolator; }, 'important') // Safari has its own `-webkit-transform` and does not support `transform` .styleTween('-webkit-transform', function (d) { return translateInterpolator; }) .style('-ms-transform', new_translate) .style('opacity', 1); } lastPosition.left = left; lastPosition.top = top; }); }; // Creates new tooltip container, or uses existing one on DOM. function initTooltip() { if (!tooltip || !tooltip.node()) { // Create new tooltip div if it doesn't exist on DOM. var data = [1]; tooltip = d3.select(document.body).selectAll('#'+id).data(data); tooltip.enter().append('div') .attr("class", "nvtooltip " + (classes ? classes : "xy-tooltip")) .attr("id", id) .style("top", 0).style("left", 0) .style('opacity', 0) .style('position', 'absolute') .selectAll("div, table, td, tr").classed(nvPointerEventsClass, true) .classed(nvPointerEventsClass, true); tooltip.exit().remove() } } // Draw the tooltip onto the DOM. function nvtooltip() { if (!enabled) return; if (!dataSeriesExists(data)) return; nv.dom.write(function () { initTooltip(); // Generate data and set it into tooltip. // Bonus - If you override contentGenerator and return false, you can use something like // Angular, React or Knockout to bind the data for your tooltip directly to the DOM. var newContent = contentGenerator(data, tooltip.node()); if (newContent) { tooltip.node().innerHTML = newContent; } positionTooltip(); }); return nvtooltip; } nvtooltip.nvPointerEventsClass = nvPointerEventsClass; nvtooltip.options = nv.utils.optionsFunc.bind(nvtooltip); nvtooltip._options = Object.create({}, { // simple read/write options duration: {get: function(){return duration;}, set: function(_){duration=_;}}, gravity: {get: function(){return gravity;}, set: function(_){gravity=_;}}, distance: {get: function(){return distance;}, set: function(_){distance=_;}}, snapDistance: {get: function(){return snapDistance;}, set: function(_){snapDistance=_;}}, classes: {get: function(){return classes;}, set: function(_){classes=_;}}, enabled: {get: function(){return enabled;}, set: function(_){enabled=_;}}, hideDelay: {get: function(){return hideDelay;}, set: function(_){hideDelay=_;}}, contentGenerator: {get: function(){return contentGenerator;}, set: function(_){contentGenerator=_;}}, valueFormatter: {get: function(){return valueFormatter;}, set: function(_){valueFormatter=_;}}, headerFormatter: {get: function(){return headerFormatter;}, set: function(_){headerFormatter=_;}}, keyFormatter: {get: function(){return keyFormatter;}, set: function(_){keyFormatter=_;}}, headerEnabled: {get: function(){return headerEnabled;}, set: function(_){headerEnabled=_;}}, position: {get: function(){return position;}, set: function(_){position=_;}}, // Deprecated options chartContainer: {get: function(){return document.body;}, set: function(_){ // deprecated after 1.8.3 nv.deprecated('chartContainer', 'feature removed after 1.8.3'); }}, fixedTop: {get: function(){return null;}, set: function(_){ // deprecated after 1.8.1 nv.deprecated('fixedTop', 'feature removed after 1.8.1'); }}, offset: {get: function(){return {left: 0, top: 0};}, set: function(_){ // deprecated after 1.8.1 nv.deprecated('offset', 'use chart.tooltip.distance() instead'); }}, // options with extra logic hidden: {get: function(){return hidden;}, set: function(_){ if (hidden != _) { hidden = !!_; nvtooltip(); } }}, data: {get: function(){return data;}, set: function(_){ // if showing a single data point, adjust data format with that if (_.point) { _.value = _.point.x; _.series = _.series || {}; _.series.value = _.point.y; _.series.color = _.point.color || _.series.color; } data = _; }}, // read only properties node: {get: function(){return tooltip.node();}, set: function(_){}}, id: {get: function(){return id;}, set: function(_){}} }); nv.utils.initOptions(nvtooltip); return nvtooltip; }; ================================================ FILE: src/utils.js ================================================ /* Gets the browser window size Returns object with height and width properties */ nv.utils.windowSize = function() { // Sane defaults var size = {width: 640, height: 480}; // Most recent browsers use if (window.innerWidth && window.innerHeight) { size.width = window.innerWidth; size.height = window.innerHeight; return (size); } // IE can use depending on mode it is in if (document.compatMode=='CSS1Compat' && document.documentElement && document.documentElement.offsetWidth ) { size.width = document.documentElement.offsetWidth; size.height = document.documentElement.offsetHeight; return (size); } // Earlier IE uses Doc.body if (document.body && document.body.offsetWidth) { size.width = document.body.offsetWidth; size.height = document.body.offsetHeight; return (size); } return (size); }; /* handle dumb browser quirks... isinstance breaks if you use frames typeof returns 'object' for null, NaN is a number, etc. */ nv.utils.isArray = Array.isArray; nv.utils.isObject = function(a) { return a !== null && typeof a === 'object'; }; nv.utils.isFunction = function(a) { return typeof a === 'function'; }; nv.utils.isDate = function(a) { return toString.call(a) === '[object Date]'; }; nv.utils.isNumber = function(a) { return !isNaN(a) && typeof a === 'number'; }; /* Binds callback function to run when window is resized */ nv.utils.windowResize = function(handler) { if (window.addEventListener) { window.addEventListener('resize', handler); } else { nv.log("ERROR: Failed to bind to window.resize with: ", handler); } // return object with clear function to remove the single added callback. return { callback: handler, clear: function() { window.removeEventListener('resize', handler); } } }; /* Backwards compatible way to implement more d3-like coloring of graphs. Can take in nothing, an array, or a function/scale To use a normal scale, get the range and pass that because we must be able to take two arguments and use the index to keep backward compatibility */ nv.utils.getColor = function(color) { //if you pass in nothing, get default colors back if (color === undefined) { return nv.utils.defaultColor(); //if passed an array, turn it into a color scale } else if(nv.utils.isArray(color)) { var color_scale = d3.scale.ordinal().range(color); return function(d, i) { var key = i === undefined ? d : i; return d.color || color_scale(key); }; //if passed a function or scale, return it, or whatever it may be //external libs, such as angularjs-nvd3-directives use this } else { //can't really help it if someone passes rubbish as color return color; } }; /* Default color chooser uses a color scale of 20 colors from D3 https://github.com/mbostock/d3/wiki/Ordinal-Scales#categorical-colors */ nv.utils.defaultColor = function() { // get range of the scale so we'll turn it into our own function. return nv.utils.getColor(d3.scale.category20().range()); }; /* Returns a color function that takes the result of 'getKey' for each series and looks for a corresponding color from the dictionary */ nv.utils.customTheme = function(dictionary, getKey, defaultColors) { // use default series.key if getKey is undefined getKey = getKey || function(series) { return series.key }; defaultColors = defaultColors || d3.scale.category20().range(); // start at end of default color list and walk back to index 0 var defIndex = defaultColors.length; return function(series, index) { var key = getKey(series); if (nv.utils.isFunction(dictionary[key])) { return dictionary[key](); } else if (dictionary[key] !== undefined) { return dictionary[key]; } else { // no match in dictionary, use a default color if (!defIndex) { // used all the default colors, start over defIndex = defaultColors.length; } defIndex = defIndex - 1; return defaultColors[defIndex]; } }; }; /* From the PJAX example on d3js.org, while this is not really directly needed it's a very cool method for doing pjax, I may expand upon it a little bit, open to suggestions on anything that may be useful */ nv.utils.pjax = function(links, content) { var load = function(href) { d3.html(href, function(fragment) { var target = d3.select(content).node(); target.parentNode.replaceChild( d3.select(fragment).select(content).node(), target); nv.utils.pjax(links, content); }); }; d3.selectAll(links).on("click", function() { history.pushState(this.href, this.textContent, this.href); load(this.href); d3.event.preventDefault(); }); d3.select(window).on("popstate", function() { if (d3.event.state) { load(d3.event.state); } }); }; /* For when we want to approximate the width in pixels for an SVG:text element. Most common instance is when the element is in a display:none; container. Forumla is : text.length * font-size * constant_factor */ nv.utils.calcApproxTextWidth = function (svgTextElem) { if (nv.utils.isFunction(svgTextElem.style) && nv.utils.isFunction(svgTextElem.text)) { var fontSize = parseInt(svgTextElem.style("font-size").replace("px",""), 10); var textLength = svgTextElem.text().length; return nv.utils.NaNtoZero(textLength * fontSize * 0.5); } return 0; }; /* Numbers that are undefined, null or NaN, convert them to zeros. */ nv.utils.NaNtoZero = function(n) { if (!nv.utils.isNumber(n) || isNaN(n) || n === null || n === Infinity || n === -Infinity) { return 0; } return n; }; /* Add a way to watch for d3 transition ends to d3 */ d3.selection.prototype.watchTransition = function(renderWatch){ var args = [this].concat([].slice.call(arguments, 1)); return renderWatch.transition.apply(renderWatch, args); }; /* Helper object to watch when d3 has rendered something */ nv.utils.renderWatch = function(dispatch, duration) { if (!(this instanceof nv.utils.renderWatch)) { return new nv.utils.renderWatch(dispatch, duration); } var _duration = duration !== undefined ? duration : 250; var renderStack = []; var self = this; this.models = function(models) { models = [].slice.call(arguments, 0); models.forEach(function(model){ model.__rendered = false; (function(m){ m.dispatch.on('renderEnd', function(arg){ m.__rendered = true; self.renderEnd('model'); }); })(model); if (renderStack.indexOf(model) < 0) { renderStack.push(model); } }); return this; }; this.reset = function(duration) { if (duration !== undefined) { _duration = duration; } renderStack = []; }; this.transition = function(selection, args, duration) { args = arguments.length > 1 ? [].slice.call(arguments, 1) : []; if (args.length > 1) { duration = args.pop(); } else { duration = _duration !== undefined ? _duration : 250; } selection.__rendered = false; if (renderStack.indexOf(selection) < 0) { renderStack.push(selection); } if (duration === 0) { selection.__rendered = true; selection.delay = function() { return this; }; selection.duration = function() { return this; }; return selection; } else { if (selection.length === 0) { selection.__rendered = true; } else if (selection.every( function(d){ return !d.length; } )) { selection.__rendered = true; } else { selection.__rendered = false; } var n = 0; return selection .transition() .duration(duration) .each(function(){ ++n; }) .each('end', function(d, i) { if (--n === 0) { selection.__rendered = true; self.renderEnd.apply(this, args); } }); } }; this.renderEnd = function() { if (renderStack.every( function(d){ return d.__rendered; } )) { renderStack.forEach( function(d){ d.__rendered = false; }); dispatch.renderEnd.apply(this, arguments); } } }; /* Takes multiple objects and combines them into the first one (dst) example: nv.utils.deepExtend({a: 1}, {a: 2, b: 3}, {c: 4}); gives: {a: 2, b: 3, c: 4} */ nv.utils.deepExtend = function(dst){ var sources = arguments.length > 1 ? [].slice.call(arguments, 1) : []; sources.forEach(function(source) { for (var key in source) { var isArray = nv.utils.isArray(dst[key]); var isObject = nv.utils.isObject(dst[key]); var srcObj = nv.utils.isObject(source[key]); if (isObject && !isArray && srcObj) { nv.utils.deepExtend(dst[key], source[key]); } else { dst[key] = source[key]; } } }); }; /* state utility object, used to track d3 states in the models */ nv.utils.state = function(){ if (!(this instanceof nv.utils.state)) { return new nv.utils.state(); } var state = {}; var _self = this; var _setState = function(){}; var _getState = function(){ return {}; }; var init = null; var changed = null; this.dispatch = d3.dispatch('change', 'set'); this.dispatch.on('set', function(state){ _setState(state, true); }); this.getter = function(fn){ _getState = fn; return this; }; this.setter = function(fn, callback) { if (!callback) { callback = function(){}; } _setState = function(state, update){ fn(state); if (update) { callback(); } }; return this; }; this.init = function(state){ init = init || {}; nv.utils.deepExtend(init, state); }; var _set = function(){ var settings = _getState(); if (JSON.stringify(settings) === JSON.stringify(state)) { return false; } for (var key in settings) { if (state[key] === undefined) { state[key] = {}; } state[key] = settings[key]; changed = true; } return true; }; this.update = function(){ if (init) { _setState(init, false); init = null; } if (_set.call(this)) { this.dispatch.change(state); } }; }; /* Snippet of code you can insert into each nv.models.* to give you the ability to do things like: chart.options({ showXAxis: true, tooltips: true }); To enable in the chart: chart.options = nv.utils.optionsFunc.bind(chart); */ nv.utils.optionsFunc = function(args) { if (args) { d3.map(args).forEach((function(key,value) { if (nv.utils.isFunction(this[key])) { this[key](value); } }).bind(this)); } return this; }; /* numTicks: requested number of ticks data: the chart data returns the number of ticks to actually use on X axis, based on chart data to avoid duplicate ticks with the same value */ nv.utils.calcTicksX = function(numTicks, data) { // find max number of values from all data streams var numValues = 1; var i = 0; for (i; i < data.length; i += 1) { var stream_len = data[i] && data[i].values ? data[i].values.length : 0; numValues = stream_len > numValues ? stream_len : numValues; } nv.log("Requested number of ticks: ", numTicks); nv.log("Calculated max values to be: ", numValues); // make sure we don't have more ticks than values to avoid duplicates numTicks = numTicks > numValues ? numTicks = numValues - 1 : numTicks; // make sure we have at least one tick numTicks = numTicks < 1 ? 1 : numTicks; // make sure it's an integer numTicks = Math.floor(numTicks); nv.log("Calculating tick count as: ", numTicks); return numTicks; }; /* returns number of ticks to actually use on Y axis, based on chart data */ nv.utils.calcTicksY = function(numTicks, data, getY) { if (getY) { var numValues = 1; for (var i=0; i < data.length; i += 1) { var values = data[i] && data[i].values ? data[i].values : []; var maxValue; for (var j=0; j < values.length; j += 1) { maxValue = values[j] && getY(values[j]) ? getY(values[j]): 0; numValues = maxValue > numValues ? maxValue : numValues; } } nv.log("Requested number of ticks: ", numTicks); nv.log("Calculated max values to be: ", numValues); // make sure we don't have more ticks than values to avoid duplicates numTicks = numTicks > numValues ? numValues - 1 : numTicks; // make sure we have at least one tick numTicks = numTicks < 1 ? 1 : numTicks; // make sure it's an integer numTicks = Math.floor(numTicks); nv.log("Calculating tick count as: ", numTicks); return numTicks; } else { return nv.utils.calcTicksX(numTicks, data); } }; /* Add a particular option from an options object onto chart Options exposed on a chart are a getter/setter function that returns chart on set to mimic typical d3 option chaining, e.g. svg.option1('a').option2('b'); option objects should be generated via Object.create() to provide the option of manipulating data via get/set functions. */ nv.utils.initOption = function(chart, name) { // if it's a call option, just call it directly, otherwise do get/set if (chart._calls && chart._calls[name]) { chart[name] = chart._calls[name]; } else { chart[name] = function (_) { if (!arguments.length) return chart._options[name]; chart._overrides[name] = true; chart._options[name] = _; return chart; }; // calling the option as _option will ignore if set by option already // so nvd3 can set options internally but the stop if set manually chart['_' + name] = function(_) { if (!arguments.length) return chart._options[name]; if (!chart._overrides[name]) { chart._options[name] = _; } return chart; } } }; /* Add all options in an options object to the chart */ nv.utils.initOptions = function(chart) { chart._overrides = chart._overrides || {}; var ops = Object.getOwnPropertyNames(chart._options || {}); var calls = Object.getOwnPropertyNames(chart._calls || {}); ops = ops.concat(calls); for (var i in ops) { nv.utils.initOption(chart, ops[i]); } }; /* Inherit options from a D3 object d3.rebind makes calling the function on target actually call it on source Also use _d3options so we can track what we inherit for documentation and chained inheritance */ nv.utils.inheritOptionsD3 = function(target, d3_source, oplist) { target._d3options = oplist.concat(target._d3options || []); // Find unique d3 options (string) and update d3options target._d3options = (target._d3options || []).filter(function(item, i, ar){ return ar.indexOf(item) === i; }); oplist.unshift(d3_source); oplist.unshift(target); d3.rebind.apply(this, oplist); }; /* Remove duplicates from an array */ nv.utils.arrayUnique = function(a) { return a.sort().filter(function(item, pos) { return !pos || item != a[pos - 1]; }); }; /* Keeps a list of custom symbols to draw from in addition to d3.svg.symbol Necessary since d3 doesn't let you extend its list -_- Add new symbols by doing nv.utils.symbols.set('name', function(size){...}); */ nv.utils.symbolMap = d3.map(); /* Replaces d3.svg.symbol so that we can look both there and our own map */ nv.utils.symbol = function() { var type, size = 64; function symbol(d,i) { var t = type.call(this,d,i); var s = size.call(this,d,i); if (d3.svg.symbolTypes.indexOf(t) !== -1) { return d3.svg.symbol().type(t).size(s)(); } else { return nv.utils.symbolMap.get(t)(s); } } symbol.type = function(_) { if (!arguments.length) return type; type = d3.functor(_); return symbol; }; symbol.size = function(_) { if (!arguments.length) return size; size = d3.functor(_); return symbol; }; return symbol; }; /* Inherit option getter/setter functions from source to target d3.rebind makes calling the function on target actually call it on source Also track via _inherited and _d3options so we can track what we inherit for documentation generation purposes and chained inheritance */ nv.utils.inheritOptions = function(target, source) { // inherit all the things var ops = Object.getOwnPropertyNames(source._options || {}); var calls = Object.getOwnPropertyNames(source._calls || {}); var inherited = source._inherited || []; var d3ops = source._d3options || []; var args = ops.concat(calls).concat(inherited).concat(d3ops); args.unshift(source); args.unshift(target); d3.rebind.apply(this, args); // pass along the lists to keep track of them, don't allow duplicates target._inherited = nv.utils.arrayUnique(ops.concat(calls).concat(inherited).concat(ops).concat(target._inherited || [])); target._d3options = nv.utils.arrayUnique(d3ops.concat(target._d3options || [])); }; /* Runs common initialize code on the svg before the chart builds */ nv.utils.initSVG = function(svg) { svg.classed({'nvd3-svg':true}); }; /* Sanitize and provide default for the container height. */ nv.utils.sanitizeHeight = function(height, container) { return (height || parseInt(container.style('height'), 10) || 400); }; /* Sanitize and provide default for the container width. */ nv.utils.sanitizeWidth = function(width, container) { return (width || parseInt(container.style('width'), 10) || 960); }; /* Calculate the available height for a chart. */ nv.utils.availableHeight = function(height, container, margin) { return Math.max(0,nv.utils.sanitizeHeight(height, container) - margin.top - margin.bottom); }; /* Calculate the available width for a chart. */ nv.utils.availableWidth = function(width, container, margin) { return Math.max(0,nv.utils.sanitizeWidth(width, container) - margin.left - margin.right); }; /* Clear any rendered chart components and display a chart's 'noData' message */ nv.utils.noData = function(chart, container) { var opt = chart.options(), margin = opt.margin(), noData = opt.noData(), data = (noData == null) ? ["No Data Available."] : [noData], height = nv.utils.availableHeight(null, container, margin), width = nv.utils.availableWidth(null, container, margin), x = margin.left + width/2, y = margin.top + height/2; //Remove any previously created chart components container.selectAll('g').remove(); var noDataText = container.selectAll('.nv-noData').data(data); noDataText.enter().append('text') .attr('class', 'nvd3 nv-noData') .attr('dy', '-.7em') .style('text-anchor', 'middle'); noDataText .attr('x', x) .attr('y', y) .text(function(t){ return t; }); }; /* Wrap long labels. */ nv.utils.wrapTicks = function (text, width) { text.each(function() { var text = d3.select(this), words = text.text().split(/\s+/).reverse(), word, line = [], lineNumber = 0, lineHeight = 1.1, y = text.attr("y"), dy = parseFloat(text.attr("dy")), tspan = text.text(null).append("tspan").attr("x", 0).attr("y", y).attr("dy", dy + "em"); while (word = words.pop()) { line.push(word); tspan.text(line.join(" ")); if (tspan.node().getComputedTextLength() > width) { line.pop(); tspan.text(line.join(" ")); line = [word]; tspan = text.append("tspan").attr("x", 0).attr("y", y).attr("dy", ++lineNumber * lineHeight + dy + "em").text(word); } } }); }; /* Check equality of 2 array */ nv.utils.arrayEquals = function (array1, array2) { if (array1 === array2) return true; if (!array1 || !array2) return false; // compare lengths - can save a lot of time if (array1.length != array2.length) return false; for (var i = 0, l = array1.length; i < l; i++) { // Check if we have nested arrays if (array1[i] instanceof Array && array2[i] instanceof Array) { // recurse into the nested arrays if (!nv.arrayEquals(array1[i], array2[i])) return false; } else if (array1[i] != array2[i]) { // Warning - two different object instances will never be equal: {x:20} != {x:20} return false; } } return true; }; /* Check if a point within an arc */ nv.utils.pointIsInArc = function(pt, ptData, d3Arc) { // Center of the arc is assumed to be 0,0 // (pt.x, pt.y) are assumed to be relative to the center var r1 = d3Arc.innerRadius()(ptData), // Note: Using the innerRadius r2 = d3Arc.outerRadius()(ptData), theta1 = d3Arc.startAngle()(ptData), theta2 = d3Arc.endAngle()(ptData); var dist = pt.x * pt.x + pt.y * pt.y, angle = Math.atan2(pt.x, -pt.y); // Note: different coordinate system. angle = (angle < 0) ? (angle + Math.PI * 2) : angle; return (r1 * r1 <= dist) && (dist <= r2 * r2) && (theta1 <= angle) && (angle <= theta2); }; ================================================ FILE: test/ScatterChartTest.html ================================================

Scatter chart tests

Normal - four series', all random (40 points)
Normal - one series', all random (5 points), zero left margin
Zero right margin, 200 points
Bigger margins
Zero data points
One point.
Two points
Three series', one point each
Three series', first one has zero points
Lots of series
Scatter plus line: y=2x + 0
Scatter plus line: y=2x + 10;
Scatter plus line: y=-0.5x + 1.0;
Scatter chart: duplicate y values
Scatter chart: duplicate x values
Scatter chart: extremely small data points (1e-10)
================================================ FILE: test/bootstrapModalTest.html ================================================

Noraml Example

Modal Example

================================================ FILE: test/boxPlotTest.html ================================================

Box Plot test cases

Normal data with outlier objects (partial overrides: value/label/color)
Custom data model overrides
Empty chart
Normal data (maxBoxWidth and staggerLabel options)
Normal data (forceY)
Single box
Twelve boxes (repeating)
Bad whiskers
Bad outliers
Zero whiskers
================================================ FILE: test/cumulativeLineChart.html ================================================
Chart with new tooltips and guide line (with-transitions)
Chart with old tooltips (with-transitions)
================================================ FILE: test/lineChartTest.html ================================================

Line chart test cases - feel free to add more tests

Example of chart with many series', and new interactive guideline plus tooltip. A chunk of data was purposely removed to show how the chart handles it.
Chart with old tooltip style (with-transitions).
Chart with three data points.
Chart where two series have different number of points.
Chart with one point.
Chart with 1000 points.
Chart with no data.
All points random. No order.
Points do not increase linearly.
Chart with 15 series'
Data points go backwards
Duplicate X coordinate points.
Duplicate Y coordinate points.
Chart in a overflow div with scrolls (new tooltips)
Chart in a overflow div with scrolls (old tooltips)
What if there are null, Infinity and NaN values in points?
Chart with very small, 1e-10, points (old tooltips)
Chart with missing data (discontinuous lines). Check that all highlighted points have the same x, matching the guideline. Check that "N/A" appears in tooltip for points with undefined y.
================================================ FILE: test/linePlusBarChart.html ================================================
================================================ FILE: test/linePlusBarWithFocusChart.html ================================================
================================================ FILE: test/lineWithFisheyeChart.html ================================================
================================================ FILE: test/lineWithFocusChart.html ================================================
================================================ FILE: test/lineWithFocusChartMissingData.html ================================================
================================================ FILE: test/mocha/axis.coffee ================================================ describe 'NVD3', -> describe 'Axis', -> sampleData1 = [ key: 'Series 1' values: [ [-1,-1] [0,0] [1,1] [2,2] ] ] options = x: (d)-> d[0] y: (d)-> d[1] axisOptions = margin: top: 0 right: 0 bottom: 0 left: 0 width: 75 height: 60 axisLabel: 'Date' showMaxMin: true scale: d3.scale.linear() rotateYLabel: true rotateLabels: 0 staggerLabels: false axisLabelDistance: 12 duration: 0 builder = null beforeEach -> builder = new ChartBuilder nv.models.lineChart() builder.build options, sampleData1 axis = builder.model.xAxis for opt, val of axisOptions axis[opt](val) builder.model.update() afterEach -> builder.teardown() it 'api check', -> axis = builder.model.xAxis for opt, val of axisOptions should.exist axis[opt](), "#{opt} can be called" it 'x axis structure', -> axis = builder.$ '.nv-x.nv-axis' should.exist axis[0], '.nv-axis exists' maxMin = builder.$ '.nv-x.nv-axis .nv-axisMaxMin' maxMin.should.have.length 2 maxMin[0].textContent.should.equal '-1' maxMin[1].textContent.should.equal '2' ticks = builder.$ '.nv-x.nv-axis .tick' ticks.should.have.length 2 expected = [ '0' '1' ] for tick,i in ticks tick.textContent.should.equal expected[i] axisLabel = builder.$ '.nv-x.nv-axis .nv-axislabel' should.exist axisLabel[0], 'axis label exists' axisLabel[0].textContent.should.equal 'Date' it 'y axis structure', -> axis = builder.$ '.nv-y.nv-axis' should.exist axis[0], '.nv-axis exists' maxMin = builder.$ '.nv-y.nv-axis .nv-axisMaxMin' maxMin.should.have.length 2 maxMin[0].textContent.should.equal '-1' maxMin[1].textContent.should.equal '2' ticks = builder.$ '.nv-y.nv-axis .tick' ticks.should.have.length 4 expected = [ '-1' '0' '1' '2' ] for tick,i in ticks tick.textContent.should.equal expected[i] it 'axis rotate labels', -> axis = builder.model.xAxis axis.rotateLabels 30 builder.model.update() ticks = builder.$ '.nv-x.nv-axis .tick text' for tick in ticks transform = tick.getAttribute 'transform' transform.should.match /rotate\(30 0,\d+?.*?\)/ maxMin = builder.$ '.nv-x.nv-axis .nv-axisMaxMin text' for tick in maxMin transform = tick.getAttribute 'transform' transform.should.match /rotate\(30 0,\d+?.*?\)/ it 'axis stagger labels', -> axis = builder.model.xAxis axis.staggerLabels true builder.model.update() ticks = builder.$ '.nv-x.nv-axis .tick text' prevTransform = '' for tick, i in ticks transform = tick.getAttribute 'transform' transform.should.not.equal prevTransform transform.should.match /translate\(0,(12|0)\)/ prevTransform = transform it 'axis orientation', (done)-> axis = builder.model.xAxis axis.orient 'top' builder.model.update() axis.orient 'right' builder.model.update() done() it 'has CSS class "zero" to mark zero tick', -> tick = builder.$ '.nv-x.nv-axis .tick.zero' tick.length.should.equal 1, 'x axis zero' tick = builder.$ '.nv-y.nv-axis .tick.zero' tick.length.should.equal 1, 'y axis zero' it 'default tick format for max/min should be integer based', -> axis = builder.model.xAxis builder.model.update() minAxisText = builder.$('.nv-axisMaxMin.nv-axisMaxMin-x.nv-axisMin-x text')[0].textContent minAxisText.should.equal('-1') it 'tickFormatMaxMin should change tick format of max/min', -> axis = builder.model.xAxis axis.tickFormatMaxMin(d3.format(',.2f')) builder.model.update() minAxisText = builder.$('.nv-axisMaxMin.nv-axisMaxMin-x.nv-axisMin-x text')[0].textContent minAxisText.should.equal('-1.00') ================================================ FILE: test/mocha/boxplot.coffee ================================================ describe 'NVD3', -> describe 'Box Plot', -> sampleData1 = [ label: 'Sample A', values: Q1: 120, Q2: 150, Q3: 200, whisker_low: 115, whisker_high: 210, outliers: [50, 100, 225] ] sampleData2 = [ label: 'Sample A', values: Q1: 120, Q2: 150, Q3: 200, whisker_low: 115, whisker_high: 210, outliers: [] ] sampleData3 = [ { label: 'Sample A', values: { Q1: 120, Q2: 150, Q3: 200, whisker_low: 115, whisker_high: 210, outliers: [50, 100, 225] } }, { label: 'Sample B', values: { Q1: 300, Q2: 350, Q3: 400, whisker_low: 2255, whisker_high: 400, outliers: [175] } } ] sampleData4 = [ label: 'Sample A', values: Q1: -3, Q2: -2, Q3: -1, whisker_low: -5, whisker_high: 0, outliers: [-10, 10] ] options = x: (d)-> d.label y: (d)-> d.values.Q3 margin: top: 30 right: 20 bottom: 50 left: 75 color: nv.utils.defaultColor() height: 400 width: 800 showXAxis: true showYAxis: true noData: 'No Data Available' duration: 0 maxBoxWidth: 75 builder = null beforeEach -> builder = new ChartBuilder nv.models.boxPlotChart() builder.build options, sampleData1 afterEach -> builder.teardown() it 'api check', -> should.exist builder.model.options, 'options exposed' for opt of options should.exist builder.model[opt](), "#{opt} can be called" builder.model.update() it 'renders', -> wrap = builder.$ 'g.nvd3.nv-boxPlotWithAxes' should.exist wrap[0] it 'no data text', -> builder = new ChartBuilder nv.models.boxPlotChart() builder.build options, [] noData = builder.$ '.nv-noData' noData[0].textContent.should.equal 'No Data Available' it 'has correct structure', -> cssClasses = [ '.nv-x.nv-axis' '.nv-y.nv-axis' '.nv-barsWrap' '.nv-wrap' '.nv-boxplot' '.nv-boxplot-median' '.nv-boxplot-tick.nv-boxplot-low' '.nv-boxplot-whisker.nv-boxplot-low' '.nv-boxplot-tick.nv-boxplot-high' '.nv-boxplot-whisker.nv-boxplot-high' ] for cssClass in cssClasses do (cssClass) -> should.exist builder.$("g.nvd3.nv-boxPlotWithAxes #{cssClass}")[0] it 'Has boxplots', -> builder = new ChartBuilder nv.models.boxPlotChart() builder.buildover options, sampleData3, [] boxes = builder.$ '.nv-boxplot-box' boxes.length.should.equal 2, 'boxplots exist' it 'Has outliers', -> builder = new ChartBuilder nv.models.boxPlotChart() builder.buildover options, sampleData1, [] outliers = builder.$ '.nv-boxplot .nv-boxplot-outlier' outliers.length.should.equal 3, 'outliers exist' it 'Has no outliers', -> builder = new ChartBuilder nv.models.boxPlotChart() builder.buildover options, sampleData2, [] outliers = builder.$ '.nv-boxplot-outlier' outliers.length.should.equal 0, 'empty outliers' it 'Displays whiskers whose value are <= 0', -> builder = new ChartBuilder nv.models.boxPlotChart() builder.buildover options, sampleData4, [] whiskers = builder.$ '.nv-boxplot-whisker' whiskers.length.should.equal 2, 'zero whiskers' ================================================ FILE: test/mocha/bullet.coffee ================================================ describe 'NVD3', -> describe 'Bullet Chart', -> sampleData1 = title: 'Revenue' subtitle: 'US$ in thousands' ranges: [10,20,30] measures: [40] markers: [50, 100] options = orient: 'left' margin: top: 60 right: 70 bottom: 80 left: 90 color: nv.utils.defaultColor() ranges: (d)-> d.ranges markers: (d)-> d.markers measures: (d)-> d.measures width: 100 height: 110 tickFormat: (d)-> d.toFixed 2 noData: 'No Data Available' builder1 = null beforeEach -> builder1 = new ChartBuilder nv.models.bulletChart() builder1.build options, sampleData1 afterEach -> builder1.teardown() it 'api check', -> should.exist builder1.model.options, 'options exposed' for opt of options should.exist builder1.model[opt](), "#{opt} can be called" it 'renders', -> wrap = builder1.$ 'g.nvd3.nv-bulletChart' should.exist wrap[0] it 'displays multiple markers', -> markers = document.querySelectorAll '.nv-markerTriangle' markers.length.should.equal 2 it 'has correct g.nvd3.nv-bulletChart position', -> chart = builder1.$ 'g.nvd3.nv-bulletChart' chart[0].getAttribute('transform').should.be.equal 'translate(90,60)' it "has correct structure", -> cssClasses = [ '.nv-bulletWrap' '.nv-bullet' '.nv-rangeMax' '.nv-rangeAvg' '.nv-rangeMin' '.nv-measure' '.nv-markerTriangle' '.nv-titles' '.nv-title' '.nv-subtitle' ] for cssClass in cssClasses do (cssClass) -> should.exist builder1.$("g.nvd3 #{cssClass}")[0] describe "no markers", -> builder = null sampleData = null beforeEach -> builder = new ChartBuilder nv.models.bulletChart() noMarkerOptions = margin: top: 0 right: 0 bottom: 0 left: 0 width: 300 sampleData = title: 'Revenue' subtitle: 'US$ in thousands' ranges: [10,20,30] measures: [40] markers: [] builder.build noMarkerOptions, sampleData afterEach -> builder.teardown() it "does not show marker if no marker provided", -> markers = builder.$ '.nv-markerTriangle' markers.length.should.equal 0 it "renders xAxis if empty markers", -> ticks = builder.$ '.nv-tick' ticks.length.should.equal 5 describe "applies correctly option", -> builder = null sampleData = null beforeEach -> builder = new ChartBuilder nv.models.bulletChart() sampleData = title: 'Revenue' subtitle: 'US$ in thousands' ranges: [10,20,30] measures: [40] markers: [50] afterEach -> builder.teardown() describe "orient", -> it 'left', -> options = orient: 'left' builder.build options, sampleData ticks = builder.$(".nv-tick") offsetPrevious = 0 offsetCurrent = 0 pattern = /// translate\((.*),0\) /// for tick, i in ticks offsetPrevious = offsetCurrent offsetCurrent = parseInt ticks[i].getAttribute('transform').match(pattern)[1] window.setTimeout -> expect(offsetPrevious).to.be.below(offsetCurrent) if i > 0 , 1500 it 'right', -> options = orient: 'right' builder.build options, sampleData ticks = builder.$(".nv-tick") offsetPrevious = 0 offsetCurrent = 0 pattern = /// translate\((.*),0\) /// for tick, i in ticks offsetPrevious = offsetCurrent offsetCurrent = parseInt ticks[i].getAttribute('transform').match(pattern)[1] window.setTimeout -> expect(offsetPrevious).to.be.above(offsetCurrent) if i > 0 , 1500 it "noData", -> options = noData: 'No Data Available' builder.build options, {} builder.svg.textContent.should.be.equal 'No Data Available' it 'clears chart objects for no data', -> builder = new ChartBuilder nv.models.bulletChart() builder.buildover options, sampleData, [] groups = builder.$ 'g' groups.length.should.equal 0, 'removes chart components' it 'margin', -> options = margin: top: 10 right: 20 bottom: 30 left: 40 builder.build options, sampleData builder.$(".nv-bulletChart")[0].getAttribute('transform').should.be.equal "translate(40,10)" it "color", -> options = color: -> "#000000" builder.build options, sampleData expect(builder.$(".nv-measure")[0].getAttribute("style")).to.contain "fill: rgb(0, 0, 0)" it 'width', -> options = margin: top: 0 right: 0 bottom: 0 left: 0 width: 300 builder.build options, sampleData parseInt( builder.$(".nv-rangeMax")[0].getAttribute('width') ).should.be.equal 300 it 'height', -> options = margin: top: 0 right: 0 bottom: 0 left: 0 height: 300 builder.build options, sampleData parseInt( builder.$(".nv-rangeMax")[0].getAttribute('height') ).should.be.equal 300 ================================================ FILE: test/mocha/core.coffee ================================================ describe 'NVD3', -> describe 'Core', -> objects = [ 'window.nv' 'd3_time_range' 'nv.utils' 'nv.models' 'nv.charts' 'nv.graphs' 'nv.logs' 'nv.dispatch' 'nv.log' 'nv.deprecated' 'nv.render' 'nv.addGraph' ] describe 'has', -> for obj in objects it " #{obj} object", -> should.exist eval obj describe 'has nv.dispatch with default', -> dispatchDefaults = ['render_start', 'render_end'] for event in dispatchDefaults do (event) -> it "#{event} event", -> assert.isFunction nv.dispatch[event] ================================================ FILE: test/mocha/cumulative-line.coffee ================================================ describe 'NVD3', -> describe 'Cumulative Line Chart', -> sampleData1 = [ key: 'Series 1' values: [ [0.000001, 0.000001] [0,0] [1,1] [2,2] ] average: 1.3 ] sampleData2 = [ key: 'Series 1' values: [ [-1,-3] [0,6] [1,12] [2,18] ] average: 12.3 , key: 'Series 2' values: [ [-1,-4] [0,7] [1,13] [2,14] ] ] eventTooltipData = {mouseX: 1250, mouseY: 363, pointXValue: 1271774227712.8547} options = x: (d)-> d[0] y: (d)-> d[1] margin: right: 20 bottom: 30 left: 40 color: nv.utils.defaultColor() showLegend: true showXAxis: true showYAxis: true rightAlignYAxis: false useInteractiveGuideline: true noData: 'No Data Available' average: (d)-> d.average duration: 0 noErrorCheck: false builder1 = null beforeEach -> builder1 = new ChartBuilder nv.models.cumulativeLineChart() builder1.build options, sampleData1 # remove all tooltips elements = document.getElementsByClassName('nvtooltip') while(elements[0]) elements[0].parentNode.removeChild(elements[0]) afterEach -> builder1.teardown() it 'api check', -> should.exist builder1.model.options, 'options exposed' for opt of options should.exist builder1.model[opt](), "#{opt} can be called" it 'renders', -> wrap = builder1.$ 'g.nvd3.nv-cumulativeLine' should.exist wrap[0] it 'has the element with .nv-cumulativeLine class right positioned', -> cumulativeLine = builder1.$ 'g.nvd3.nv-cumulativeLine' cumulativeLine[0].getAttribute('transform').should.be.equal "translate(40,30)" it 'clears chart objects for no data', -> builder = new ChartBuilder nv.models.cumulativeLineChart() builder.buildover options, sampleData1, [] groups = builder.$ 'g' groups.length.should.equal 0, 'removes chart components' it 'has correct structure', -> cssClasses = [ '.nv-interactive' '.nv-interactiveLineLayer' '.nv-interactiveGuideLine' '.nv-y.nv-axis' '.nv-x.nv-axis' '.nv-background' '.nv-linesWrap' '.nv-line' '.nv-scatterWrap' '.nv-scatter' '.nv-indexLine' '.nv-avgLinesWrap' '.nv-legendWrap' '.nv-controlsWrap' '.tempDisabled' ] for cssClass in cssClasses do (cssClass) -> should.exist builder1.$("g.nvd3 #{cssClass}")[0] describe "applies correctly option", -> builder = null sampleData = sampleData1 beforeEach -> builder = new ChartBuilder nv.models.cumulativeLineChart() afterEach -> builder.teardown() # todo: ideally it should work, but... xit 'margin', -> options = margin: top: 10 right: 20 bottom: 30 left: 40 builder.build options, sampleData builder.$(".nv-cumulativeLine")[0].getAttribute('transform').should.be.equal "translate(40,10)" it "color", -> options.color = -> "#000000" builder.build options, sampleData legendSymbol = builder.$(".nv-cumulativeLine .nv-legend-symbol") expect(legendSymbol[0].getAttribute("style")).to.contain "fill: rgb(0, 0, 0)" expect(legendSymbol[0].getAttribute("style")).to.contain "stroke: rgb(0, 0, 0)" describe "showLegend", -> it 'true', -> options.showLegend = true builder.build options, sampleData builder.$(".nv-cumulativeLine .nv-legendWrap *").length.should.not.be.equal 0 it 'false', -> options = showLegend : false builder.build options, sampleData builder.$(".nv-cumulativeLine .nv-legendWrap *").length.should.be.equal 0 describe 'showXAxis', -> it 'true', -> options.showXAxis = true builder.build options, sampleData builder.$(".nv-cumulativeLine .nv-axis.nv-x *").length.should.not.be.equal 0 it 'false', -> options.showXAxis = false builder.build options, sampleData builder.$(".nv-cumulativeLine .nv-axis.nv-x *").length.should.be.equal 0 it 'can override axis ticks', -> builder.build options, sampleData builder.model.xAxis.ticks(34) builder.model.yAxis.ticks(56) builder.model.update() builder.model.xAxis.ticks().should.equal 34 builder.model.yAxis.ticks().should.equal 56 describe 'showYAxis', -> it 'true', -> options.showYAxis = true builder.build options, sampleData builder.$(".nv-cumulativeLine .nv-axis.nv-y *").length.should.not.be.equal 0 it 'false', -> options.showYAxis = false builder.build options, sampleData builder.$(".nv-cumulativeLine .nv-axis.nv-y *").length.should.be.equal 0 describe 'rightAlignYAxis', -> it 'true', -> options.rightAlignYAxis = true builder.build options, sampleData builder.$(".nv-cumulativeLine .nv-axis.nv-y")[0].getAttribute('transform').should.be.equal "translate(870,0)" it 'false', -> options.rightAlignYAxis = false builder.build options, sampleData assert.isNull builder.$(".nv-cumulativeLine .nv-axis.nv-y")[0].getAttribute('transform') describe "useInteractiveGuideline", -> it "true", -> options.useInteractiveGuideline = true builder.build options, sampleData builder.$(".nv-cumulativeLine .nv-interactiveLineLayer").should.have.length 1 it "false", -> options.useInteractiveGuideline = false builder.build options, sampleData builder.$(".nv-cumulativeLine .nv-interactiveLineLayer").should.have.length 0 # todo: pass this describe "noErrorCheck", -> xit "true", -> options.noErrorCheck = true builder.build options, sampleData xit "false", -> options.noErrorCheck = false builder.build options, sampleData it "noData", -> options.noData = "error error" builder.build options, [] builder.svg.textContent.should.be.equal 'error error' it "x", -> options.x = (d) -> d[1] builder.build options, sampleData builder.model.x()([1,2]).should.be.equal 2 it "y", -> options.y = (d) -> d[0] builder.build options, sampleData builder.model.y()({display: {y: 1}}).should.be.equal 1 it "average", -> options.average = (d)-> d.avg builder.build options, sampleData builder.model.average()({avg: 1}).should.be.equal 1 it "duration", -> options.duration = 100 builder.build options, sampleData builder.model.duration().should.be.equal 100 ================================================ FILE: test/mocha/differenceChart.js ================================================ (function () { 'use strict'; var clean = void 0, benv = void 0, _sinon = void 0, ChartFactory = void 0, snapshot = void 0, _should = void 0, moment = void 0; if (typeof require !== 'undefined') { clean = require('clean-html').clean; benv = require('benv'); _sinon = require('sinon'); _should = require('chai').should(); require('coffee-script/register'); ChartFactory = require('./test-utils.coffee'); snapshot = require('snap-shot'); moment = require('moment'); } else { ChartFactory = window.ChartBuilder; _sinon = window.sinon; _should = window.should; moment = window.moment; } describe('NVD3', function () { return describe('Difference Chart', function () { var options = { x: function x(d) { return d.x; }, y: function y(d) { return d.y; }, focusMargin: { top: 0, right: 60, bottom: 0, left: 20 }, margin: { top: 30, right: 20, bottom: 50, left: 75 }, noData: 'No Data Available', duration: 0 }; // Predicted > Actual var testData = [{ key: 'Actual Data', type: 'actual', values: [{ x: 123, y: 10 }, { x: 124, y: 20 }] }, { key: 'Predicted Data', type: 'expected', values: [{ x: 123, y: 15 }, { x: 124, y: 25 }] }]; var sampleDataWithDates = [{ key: 'Actual Data', type: 'actual', values: [{ x: new Date('2016-01-01T02:00:00+1100'), y: 10 }, { x: new Date('2016-01-01T02:15:00+1100'), y: 30 }, { x: new Date('2016-01-01T02:20:00+1100'), y: 40 }, { x: new Date('2016-01-01T02:30:00+1100'), y: 20 }, { x: new Date('2016-01-01T02:45:00+1100'), y: 50 }, { x: new Date('2016-01-01T03:00:00+1100'), y: 60 }] }, { key: 'Predicted Data', type: 'expected', values: [{ x: new Date('2016-01-01T02:00:00+1100'), y: 15 }, { x: new Date('2016-01-01T02:15:00+1100'), y: 35 }, { x: new Date('2016-01-01T02:20:00+1100'), y: 45 }, { x: new Date('2016-01-01T02:30:00+1100'), y: 25 }, { x: new Date('2016-01-01T02:45:00+1100'), y: 75 }, { x: new Date('2016-01-01T03:00:00+1100'), y: 65 }] }]; var builder = null; var sandbox = void 0; function setupBenv(done) { if (typeof require === 'undefined') { done(); return; } benv.setup(function () { benv.expose({ $: benv.require('zepto'), d3: benv.require('d3'), nv: benv.require('../../src/core.js') }); benv.require('../../src/dom.js'); benv.require('../../src/utils.js'); benv.require('../../src/interactiveLayer.js'); benv.require('../../src/tooltip.js'); benv.require('../../src/models/differenceChart.js'); benv.require('../../src/models/line.js'); benv.require('../../src/models/scatter.js'); benv.require('../../src/models/axis.js'); benv.require('../../src/models/legend.js'); benv.require('../../src/models/focus.js'); benv.require('../../src/models/historicalBar.js'); benv.require('../../src/models/multiChart.js'); benv.require('../../src/models/multiBar.js'); benv.require('../../src/models/stackedArea.js'); done(); }); } before(function (done) { sandbox = _sinon.sandbox.create(); setupBenv(done); }); beforeEach(function () { options.color = nv.utils.defaultColor(); builder = new ChartFactory(nv.models.differenceChart()); builder.build(options, testData); }); afterEach(function () { builder.teardown(); sandbox.restore(); }); after(function () { if (typeof benv === 'undefined') { return; } benv.teardown(true); }); it('y-domain should be the maximum and minimum y values on the graph', function () { var someData = [{ key: 'Predicted Data minus Actual Data (Predicted > Actual)', type: 'area', values: [{ x: 123, y0: 10, y1: 15 }, { x: 124, y0: 20, y1: 25 }], yAxis: 1, color: 'rgba(44,160,44,.9)', processed: true }, { key: 'Predicted Data minus Actual Data (Predicted < Actual)', type: 'area', values: [{ x: 123, y0: 10, y1: 10 }, { x: 124, y0: 20, y1: 20 }], yAxis: 1, color: 'rgba(234,39,40,.9)', processed: true }, { key: 'Actual Data', type: 'line', values: [{ x: 123, y: 10 }, { x: 124, y: 20 }], yAxis: 1, color: '#666666', processed: true, strokeWidth: 1 }, { key: 'Predicted Data', type: 'line', values: [{ x: 123, y: 15 }, { x: 124, y: 25 }], yAxis: 1, color: '#aec7e8', processed: true, strokeWidth: 1 }]; builder.model.processData(someData); builder.model.multiChart.yDomain1().should.deep.equal([10, 25]); }); describe('should be able to handle empty date', function () { it('clears chart objects for empty data', function () { builder.updateData([]); var groups = builder.$('g'); groups.length.should.equal(0, 'removes chart components'); builder.$('.nv-noData').length.should.equal(1); }); it('clears chart objects if all of the datasets are disabled', function () { var disabledData = testData.map(function (dataset) { var processedData = Object.assign({}, dataset); processedData.disabled = true; return processedData; }); builder.updateData(disabledData); var groups = builder.$('g'); groups.length.should.equal(0, 'removes chart components'); builder.$('.nv-noData').length.should.equal(1); }); it('clears chart objects for undefined data', function () { builder.updateData(null); var groups = builder.$('g'); groups.length.should.equal(0, 'removes chart components'); builder.$('.nv-noData').length.should.equal(1); }); it('clears chart components if chart has no values', function () { var dataWithNoValues = testData.map(function (dataset) { var modifiedDataset = Object.assign({}, dataset); modifiedDataset.values = []; return modifiedDataset; }); builder.updateData(dataWithNoValues); var groups = builder.$('g'); groups.length.should.equal(0, 'removes chart components'); builder.$('.nv-noData').length.should.equal(1); }); it('should clear no data artefacts if data is supplied', function () { // set up no data builder.updateData([]); builder.updateData(testData); builder.$('.nv-noData').length.should.equal(0); }); }); it('api check', function () { _should.exist(builder.model.options, 'options exposed'); return function () { var result = []; for (var opt in options) { result.push(_should.exist(builder.model[opt](), opt + ' can be called')); } return result; }(); }); describe('Processing Data', function () { it('should does not process data if series toggled off', function () { builder.model.showPredictedLine(false); <<<<<<< HEAD var expectedData = [{ key: 'Predicted Data minus Actual Data (Predicted > Actual)', type: 'area', values: [{ x: 123, y0: 10, y1: 15 }, { x: 124, y0: 20, y1: 25 }], yAxis: 1, color: 'rgba(44,160,44,.9)', processed: true, noHighlightSeries: true }, { key: 'Predicted Data minus Actual Data (Predicted < Actual)', type: 'area', values: [{ x: 123, y0: 10, y1: 10 }, { x: 124, y0: 20, y1: 20 }], yAxis: 1, color: 'rgba(234,39,40,.9)', processed: true, noHighlightSeries: true }, { key: 'Actual Data', type: 'line', values: [{ x: 123, y: 10 }, { x: 124, y: 20 }], yAxis: 1, color: '#666666', processed: true, strokeWidth: 1 }]; ======= var expectedData = [ { key: 'Predicted Data minus Actual Data (Predicted > Actual)', type: 'area', values: [{ x: '123', y0: 10, y1: 15 }, { x: '124', y0: 20, y1: 25 }], yAxis: 1, color: 'rgba(44,160,44,.9)', processed: true, noHighlightSeries: true }, { key: 'Predicted Data minus Actual Data (Predicted < Actual)', type: 'area', values: [{ x: '123', y0: 10, y1: 10 }, { x: '124', y0: 20, y1: 20 }], yAxis: 1, color: 'rgba(234,39,40,.9)', processed: true, noHighlightSeries: true }, { key: 'Actual Data', type: 'line', values: [{ x: '123', y: 10 }, { x: '124', y: 20 }], yAxis: 1, color: '#666666', processed: true, strokeWidth: 1 } ]; var actualData = builder.model.processData(testData); JSON.stringify(actualData).should.equal(JSON.stringify(expectedData)); }); it('correctly processes data when Predicted > Actual', () => { var expectedData = [ { key: 'Predicted Data minus Actual Data (Predicted > Actual)', type: 'area', values: [{ x: '123', y0: 10, y1: 15 }, { x: '124', y0: 20, y1: 25 }], yAxis: 1, color: 'rgba(44,160,44,.9)', processed: true, noHighlightSeries: true }, { key: 'Predicted Data minus Actual Data (Predicted < Actual)', type: 'area', values: [{ x: '123', y0: 10, y1: 10 }, { x: '124', y0: 20, y1: 20 }], yAxis: 1, color: 'rgba(234,39,40,.9)', processed: true, noHighlightSeries: true }, { key: 'Actual Data', type: 'line', values: [{ x: '123', y: 10 }, { x: '124', y: 20 }], yAxis: 1, color: '#666666', processed: true, strokeWidth: 1 }, { key: 'Predicted Data', type: 'line', values: [{ x: '123', y: 15 }, { x: '124', y: 25 }], yAxis: 1, color: '#aec7e8', processed: true, strokeWidth: 1 } ]; var actualData = builder.model.processData(testData); JSON.stringify(actualData).should.equal(JSON.stringify(expectedData)); }); it('correctly processes data when Predicted < Actual', function () { //Predicted < Actual var testData2 = [ { key: 'Actual Data', type: 'actual', values: [{ x: '123', y: 15 }, { x: '124', y: 25 }] }, { key: 'Predicted Data', type: 'expected', values: [{ x: '123', y: 10 }, { x: '124', y: 20 }] } ]; var expectedData = [ { key: 'Predicted Data minus Actual Data (Predicted > Actual)', type: 'area', values: [{ x: '123', y0: 15, y1: 15 }, { x: '124', y0: 25, y1: 25 }], yAxis: 1, color: 'rgba(44,160,44,.9)', processed: true, noHighlightSeries: true }, { key: 'Predicted Data minus Actual Data (Predicted < Actual)', type: 'area', values: [{ x: '123', y0: 15, y1: 10 }, { x: '124', y0: 25, y1: 20 }], yAxis: 1, color: 'rgba(234,39,40,.9)', processed: true, noHighlightSeries: true }, { key: 'Actual Data', type: 'line', values: [{ x: '123', y: 15 }, { x: '124', y: 25 }], yAxis: 1, color: '#666666', processed: true, strokeWidth: 1 }, { key: 'Predicted Data', type: 'line', values: [{ x: '123', y: 10 }, { x: '124', y: 20 }], yAxis: 1, color: '#aec7e8', processed: true, strokeWidth: 1 } ]; var actualData = builder.model.processData(testData2); JSON.stringify(actualData).should.equal(JSON.stringify(expectedData)); }); it('correctly processes data when Predicted = Actual', () => { var equalTestData = [ { key: 'Actual Data', type: 'actual', values: [{ x: '123', y: 15 }, { x: '124', y: 25 }] }, { key: 'Predicted Data', type: 'expected', values: [{ x: '123', y: 15 }, { x: '124', y: 25 }] } ]; var expectedData = [ { key: 'Predicted Data minus Actual Data (Predicted > Actual)', type: 'area', values: [{ x: '123', y0: 15, y1: 15 }, { x: '124', y0: 25, y1: 25 }], yAxis: 1, color: 'rgba(44,160,44,.9)', processed: true, noHighlightSeries: true }, { key: 'Predicted Data minus Actual Data (Predicted < Actual)', type: 'area', values: [{ x: '123', y0: 15, y1: 15 }, { x: '124', y0: 25, y1: 25 }], yAxis: 1, color: 'rgba(234,39,40,.9)', processed: true, noHighlightSeries: true }, { key: 'Actual Data', type: 'line', values: [{ x: '123', y: 15 }, { x: '124', y: 25 }], yAxis: 1, color: '#666666', processed: true, strokeWidth: 1 }, { key: 'Predicted Data', type: 'line', values: [{ x: '123', y: 15 }, { x: '124', y: 25 }], yAxis: 1, color: '#aec7e8', processed: true, strokeWidth: 1 } ]; var actualData = builder.model.processData(equalTestData); JSON.stringify(actualData).should.equal(JSON.stringify(expectedData)); }); it('removes any predicted data points that are not found in predicted data', () => { const unevenTestData = [ { key: 'Actual Data', type: 'actual', values: [{ x: '123', y: 15 }, { x: '124', y: 25 }] }, { key: 'Predicted Data', type: 'expected', values: [{ x: '123', y: 15 }, { x: 125, y: 25 }] } ]; const expectedData = [ { key: 'Predicted Data minus Actual Data (Predicted > Actual)', type: 'area', values: [{ x: '123', y0: 15, y1: 15 }, { x: '124', y0: 25, y1: 25 }], yAxis: 1, color: 'rgba(44,160,44,.9)', processed: true, noHighlightSeries: true }, { key: 'Predicted Data minus Actual Data (Predicted < Actual)', type: 'area', values: [{ x: '123', y0: 15, y1: 15 }, { x: '124', y0: 25, y1: 25 }], yAxis: 1, color: 'rgba(234,39,40,.9)', processed: true, noHighlightSeries: true }, { key: 'Actual Data', type: 'line', values: [{ x: '123', y: 15 }, { x: '124', y: 25 }], yAxis: 1, color: '#666666', processed: true, strokeWidth: 1 }, { key: 'Predicted Data', type: 'line', values: [{ x: '123', y: 15 }, { x: '124' }], yAxis: 1, color: '#aec7e8', processed: true, strokeWidth: 1 } ]; const actualData = builder.model.processData(unevenTestData); JSON.stringify(actualData).should.equal(JSON.stringify(expectedData)); }); it('respects any processing done in x accessor', () => { const unevenTestData = [ { key: 'Actual Data', type: 'actual', values: [{ x: '123', y: 15 }, { x: '124', y: 25 }] }, { key: 'Predicted Data', type: 'expected', values: [{ x: '123', y: 15 }, { x: 125, y: 25 }] } ]; builder.model.x((d) => parseInt(d.x)); const expectedData = [ { key: 'Predicted Data minus Actual Data (Predicted > Actual)', type: 'area', values: [{ x: 123, y0: 15, y1: 15 }, { x: 124, y0: 25, y1: 25 }], yAxis: 1, color: 'rgba(44,160,44,.9)', processed: true, noHighlightSeries: true }, { key: 'Predicted Data minus Actual Data (Predicted < Actual)', type: 'area', values: [{ x: 123, y0: 15, y1: 15 }, { x: 124, y0: 25, y1: 25 }], yAxis: 1, color: 'rgba(234,39,40,.9)', processed: true, noHighlightSeries: true }, { key: 'Actual Data', type: 'line', values: [{ x: 123, y: 15 }, { x: 124, y: 25 }], yAxis: 1, color: '#666666', processed: true, strokeWidth: 1 }, { key: 'Predicted Data', type: 'line', values: [{ x: 123, y: 15 }, { x: 124 }], yAxis: 1, color: '#aec7e8', processed: true, strokeWidth: 1 } ]; const actualData = builder.model.processData(unevenTestData); JSON.stringify(actualData).should.equal(JSON.stringify(expectedData)); }); }); it('should render the chart', function () { var wrap = builder.$('.multiChart'); return _should.exist(wrap[0]); }); it('should clear chart objects for no data', function () { builder = new ChartFactory(nv.models.differenceChart()); builder.buildover(options, testData, []); var groups = builder.$('g'); groups.length.should.equal(0, 'removes chart components'); }); it('has correct structure', function () { var cssClasses = ['.multiChart', '.multiChart .nv-interactive', '.multiChart .nv-x.nv-axis', '.nv-focus']; cssClasses.forEach(function (cssClass) { _should.exist(builder.$('' + cssClass)[0]); }); }); describe('default values', function () { it('default chart width should be null', function () { var defaultWidth = builder.model.width(); _should.equal(defaultWidth, null); }); it('default chart height should be null', function () { var defaultHeight = builder.model.height(); _should.equal(defaultHeight, null); }); it('default value for showPredictedLine should be true', function () { var defaultValue = builder.model.showPredictedLine(); defaultValue.should.be.true; }); }); describe('setters', function () { it('can override chart focusMargin', function () { builder.model.focusMargin({ right: 75 }); builder.model.focusMargin().right.should.equal(75); builder.model.focusMargin({ bottom: 7 }); builder.model.focusMargin().bottom.should.equal(7); }); it('can override chart Margin', function () { builder.model.margin({ right: 75 }); builder.model.margin().right.should.equal(75); builder.model.margin({ bottom: 7 }); builder.model.margin().bottom.should.equal(7); }); it('can override chart interpolation', function () { builder.model.interpolate('basis'); return builder.model.interpolate().should.equal('basis'); }); it('can override chart strokeWidth', function () { builder.model.strokeWidth(3); return builder.model.strokeWidth().should.equal(3); }); it('can override chart keyForActualLessThanPredicted', function () { builder.model.keyForActualLessThanPredicted('blah'); return builder.model.keyForActualLessThanPredicted().should.equal('blah'); }); it('can override chart keyForActualGreaterThanPredicted', function () { builder.model.keyForActualGreaterThanPredicted('yoo'); return builder.model.keyForActualGreaterThanPredicted().should.equal('yoo'); }); it('can override axis ticks', function () { builder.model.xAxis.ticks(34); builder.model.yAxis.ticks(56); builder.model.xAxis.ticks().should.equal(34); return builder.model.yAxis.ticks().should.equal(56); }); it('can override chart height', function () { builder.model.height(340); builder.model.update(); var xAxis = builder.$('.multiChart .nv-x.nv-axis'); xAxis[0].getAttribute('transform').should.equal('translate(0,110)'); }); it('can override chart width', function () { builder.model.width(340); builder.model.update(); var legendWrap = builder.$('.legendWrap'); legendWrap[0].getAttribute('transform').should.equal('translate(122.5,-30)'); }); it('can override xAccessor', function () { builder.model.x(888); builder.model.x().should.equal(888); }); it('can override yAccessor', function () { builder.model.y(999); builder.model.y().should.equal(999); }); describe('xScale', function () { it('defaults to d3.time.scale()', function () { var defaultXScale = builder.model.multiChart.xAxis.scale(); defaultXScale.domain.toString().indexOf('Date').should.not.equal(-1); }); it('can override xScale', function () { builder.model.xScale(999); builder.model.xScale().should.equal(999); }); }); describe('tickFormat', function () { it('can override tickFormat', function () { builder.model.tickFormat(999); builder.model.tickFormat().should.equal(999); }); }); }); describe('tooltip - ', function () { var testCases = [{ name: 'If no point data supplied, should use value (first param) ', payloadForPointData: { key: 'blah' }, expectedResult: '10' }, { name: 'If equal point data supplied, should use value (first param) ', payloadForPointData: { key: 'keyForActualLessThanPredicted', data: { y0: '5', y1: '5' } }, expectedResult: '-' }, { name: 'If different point data supplied, should use value (first param) ', payloadForPointData: { key: 'keyForActualLessThanPredicted', data: { y0: '25', y1: '20' } }, expectedResult: 5 }]; testCases.forEach(function (testCase) { it(testCase.name, function () { builder.model.keyForActualLessThanPredicted('keyForActualLessThanPredicted'); var valueFormatter = builder.model.multiChart.interactiveLayer.tooltip.valueFormatter(); valueFormatter('10', '3', testCase.payloadForPointData).should.deep.equal(testCase.expectedResult); }); }); }); describe('yAxis', function () { var yForMultiChartFunc = void 0; beforeEach(function () { var yForMultiChartSpy = sandbox.spy(builder.model.multiChart, 'y'); builder.model.update(); yForMultiChartFunc = yForMultiChartSpy.args[0][0]; }); it('yAxis for multi chart should return y0 if y0 is defined', function () { yForMultiChartFunc({ y0: 'blah' }).should.equal('blah'); }); it('yAxis for multi chart should return y if y0 is not defined', function () { yForMultiChartFunc({ y: 'boo' }).should.equal('boo'); }); }); describe('areaY1', function () { it('should use the scatter yScale to calculate the value using d.display.y', function () { var fakeYScale = sandbox.spy(d3.scale.linear()); builder.model.multiChart.stack1.scatter.yScale(fakeYScale); builder.model.update(); builder.model.multiChart.stack1.areaY1()({ display: { y: 'jabbathehutt' } }); fakeYScale.args[fakeYScale.args.length - 1][0].should.equal('jabbathehutt'); }); }); describe('x axis', function () { it('should use a multi time formatter to format x axis ticks by default', function () { var testDataForXAxis = [{ testDatum: new Date('2017-01-03T09:15:00'), expectedValue: '09:15' }, { testDatum: new Date('2017-01-03T09:00:00'), expectedValue: '09 AM' }, { testDatum: new Date('2017-01-03T00:00:00'), expectedValue: 'Tue 03' }, { testDatum: new Date('2017-04-02T00:00:00'), expectedValue: 'Apr 02' }, { testDatum: new Date('2000-05-01T00:00:00'), expectedValue: 'May' }, { testDatum: new Date('2000-01-01T00:00:00'), expectedValue: '2000' }]; testDataForXAxis.forEach(function (testDataset) { builder.model.multiChart.xAxis.tickFormat()(testDataset.testDatum).should.equal(testDataset.expectedValue); }); }); it('has default range value', function () { builder.model.multiChart.xAxis.range()[1].should.be.above(0); }); it('sets up x domain based on the extent of the dataset x values', function () { var processedData = [{ key: 'Predicted Data minus Actual Data (Predicted > Actual)', type: 'area', values: [{ x: new Date('2016-01-03T09:00'), y0: 10, y1: 15 }, { x: new Date('2016-01-03T09:30'), y0: 20, y1: 25 }], yAxis: 1, color: 'rgba(44,160,44,.9)', processed: true }, { key: 'Predicted Data minus Actual Data (Predicted < Actual)', type: 'area', values: [{ x: new Date('2016-01-03T09:00'), y0: 10, y1: 10 }, { x: new Date('2016-01-03T09:30'), y0: 20, y1: 20 }], yAxis: 1, color: 'rgba(234,39,40,.9)', processed: true }, { key: 'Actual Data', type: 'line', values: [{ x: new Date('2016-01-03T09:00'), y: 10 }, { x: new Date('2016-01-03T09:30'), y: 20 }], yAxis: 1, color: '#666666', processed: true, strokeWidth: 1 }, { key: 'Predicted Data', type: 'line', values: [{ x: new Date('2016-01-03T09:00'), y: 15 }, { x: new Date('2016-01-03T09:30'), y: 25 }], yAxis: 1, color: '#aec7e8', processed: true, strokeWidth: 1 }]; builder.updateData(processedData); var expectedDomain = [new Date('2016-01-03T09:00'), new Date('2016-01-03T09:30')]; builder.model.multiChart.xAxis.domain().should.be.deep.equal(expectedDomain); }); }); describe('margin', function () { it('by default, should be { top: 30, right: 20, bottom: 50, left: 75 }', function () { var defaultMargin = builder.model.margin(); var expectedMargin = { top: 30, right: 20, bottom: 50, left: 75 }; defaultMargin.should.deep.equal(expectedMargin); }); describe('if not all margin components passed, should use previous config', function () { var testCases = [{ testData: { top: 10 }, expectedMargin: { top: 10, right: 20, bottom: 50, left: 75 } }, { testData: {}, expectedMargin: { top: 30, right: 20, bottom: 50, left: 75 } }, { testData: { left: 10 }, expectedMargin: { top: 30, right: 20, bottom: 50, left: 10 } }, { testData: { right: 10 }, expectedMargin: { top: 30, right: 10, bottom: 50, left: 75 } }, { testData: { bottom: 10 }, expectedMargin: { top: 30, right: 20, bottom: 10, left: 75 } }, { testData: { left: 10 }, expectedMargin: { top: 30, right: 20, bottom: 50, left: 10 } }, { testData: { top: 10, left: 20 }, expectedMargin: { top: 10, right: 20, bottom: 50, left: 20 } }]; testCases.forEach(function (testCase) { it('updating margin with ' + JSON.stringify(testCase.testData) + ' should result in margin of ' + JSON.stringify(testCase.expectedMargin), function () { builder.model.margin(testCase.testData); builder.model.margin().should.deep.equal(testCase.expectedMargin); }); }); }); it('updating the margin should change the chart', function () { builder.model.margin({ top: 150 }); builder.model.update(); var yAxisTransform = builder.$('.nv-axisMaxMin-y')[0].getAttribute('transform'); yAxisTransform.should.equal('translate(0,400)'); }); }); it('x-axis labels should rotate as specified', function () { builder.model.focus.xAxis.rotateLabels(60); builder.model.focus.xAxis.rotateLabels().should.be.equal(60); }); it('after the user brushes, the x axis domain should be equal to the brush extent', function () { var expectedDomain = [new Date('2016-01-01T01:00:00+1100'), new Date('2016-01-01T03:30:00+1100')]; builder.model.focus.dispatch.onBrush(expectedDomain); var newDomain = builder.model.multiChart.xAxis.domain(); newDomain.should.be.deep.equal(expectedDomain); }); it('after the user brushes, the chart should only contain values within the brush extent', () => { builder.model.x((d) => new Date(d.x)); builder.updateData(sampleDataWithDates); var newBrushExtent = [new Date('2016-01-01T02:15:00+1100'), new Date('2016-01-01T02:45:00+1100')]; builder.model.focus.dispatch.onBrush(newBrushExtent); var dataFromChart = d3.select(builder.model.container).datum(); dataFromChart[0].values.forEach(function (value) { value.x.should.be.at.least(newBrushExtent[0]).and.be.at.most(newBrushExtent[1]); }); }); describe('focusMargin', function () { it('by default, should be { left: 0, right: 0, top: 10, bottom: 20 }', function () { var defaultMargin = builder.model.focusMargin(); var expectedMargin = { left: 20, right: 60, top: 0, bottom: 0 }; defaultMargin.should.deep.equal(expectedMargin); }); describe('if not all margin components passed, should use previous config', function () { var testCases = [{ testData: { top: 20 }, expectedMargin: { top: 20, right: 60, bottom: 0, left: 20 } }, { testData: {}, expectedMargin: { top: 0, right: 60, bottom: 0, left: 20 } }, { testData: { left: 10 }, expectedMargin: { top: 0, right: 60, bottom: 0, left: 10 } }, { testData: { right: 10 }, expectedMargin: { top: 0, right: 10, bottom: 0, left: 20 } }, { testData: { bottom: 10 }, expectedMargin: { top: 0, right: 60, bottom: 10, left: 20 } }, { testData: { top: 10, left: 20 }, expectedMargin: { top: 10, right: 60, bottom: 0, left: 20 } }]; testCases.forEach(function (testCase) { it('updating focus margin with ' + JSON.stringify(testCase.testData) + ' should result in margin of ' + JSON.stringify(testCase.expectedMargin), function () { builder.model.focusMargin(testCase.testData); builder.model.focusMargin().should.deep.equal(testCase.expectedMargin); }); }); }); it('updating the focus margin should change the chart', function () { builder.model.focusMargin({ bottom: 10 }); builder.model.update(); var xAxisTransform = builder.$('.nv-focus .nv-axis')[0].getAttribute('transform'); xAxisTransform.should.equal('translate(0,60)'); }); }); if (typeof require !== 'undefined') { var pretty = function pretty(html) { var result = void 0; clean(html, function (out) { result = out; }); return result.replace(/nv-edge-clip-[\d]*/g, '').replace(/nv-chart-[\d]*/g, '').replace(/id="[^"]*"/g, '').replace(/clip-path="[^"]*"/g, '').replace(/d="[^"]*"/g, '').replace(/class="[^"]*"/g, '').replace(/transform="[^"]*"/g, ''); }; describe('Snapshot', function () { it('should match expected snapshot', function () { builder.updateData(sampleDataWithDates); var svgData = pretty(builder.svg.innerHTML); snapshot(svgData); }); }); } }); }); })(); ================================================ FILE: test/mocha/discretebar.coffee ================================================ describe 'NVD3', -> describe 'Discrete Bar Chart', -> sampleData1 = [ key: 'Series 1' values: [ {label: 'America', value: 100} {label: 'Europe', value: 200} {label: 'Asia', value: 50} {label: 'Africa', value: 70} ] ] options = x: (d)-> d.label y: (d)-> d.value margin: top: 30 right: 20 bottom: 50 left: 75 color: nv.utils.defaultColor() showXAxis: true showYAxis: true rightAlignYAxis: false staggerLabels: true showValues: true valueFormat: (d)-> d.toFixed 2 noData: 'No Data Available' duration: 0 builder = null beforeEach -> builder = new ChartBuilder nv.models.discreteBarChart() builder.build options, sampleData1 afterEach -> builder.teardown() it 'api check', -> should.exist builder.model.options, 'options exposed' for opt of options should.exist builder.model[opt](), "#{opt} can be called" it 'renders', -> wrap = builder.$ 'g.nvd3.nv-discreteBarWithAxes' should.exist wrap[0] it 'clears chart objects for no data', -> builder = new ChartBuilder nv.models.discreteBarChart() builder.buildover options, sampleData1, [] groups = builder.$ 'g' groups.length.should.equal 0, 'removes chart components' it 'has correct structure', -> cssClasses = [ '.nv-x.nv-axis' '.nv-y.nv-axis' '.nv-barsWrap' '.nv-discretebar' ] for cssClass in cssClasses do (cssClass) -> should.exist builder.$("g.nvd3.nv-discreteBarWithAxes #{cssClass}")[0] it 'can override axis ticks', -> builder.model.xAxis.ticks(34) builder.model.yAxis.ticks(56) builder.model.update() builder.model.xAxis.ticks().should.equal 34 builder.model.yAxis.ticks().should.equal 56 ================================================ FILE: test/mocha/distrochart.coffee ================================================ describe 'NVD3', -> describe 'Distrochart', -> data = [ {subject: 3, weight: 19, isolator: 'C', study: 'V', treatment: 'delta', donor: 'two'}, {subject: 4, weight: 19.36, isolator: 'C', study: 'V', treatment: 'delta', donor: 'two'}, {subject: 5, weight: 17.96, isolator: 'C', study: 'V', treatment: 'delta', donor: 'two'}, {subject: 8, weight: 18.5, isolator: 'C', study: 'V', treatment: 'delta', donor: 'two'}, {subject: 12, weight: 18.6, isolator: 'C', study: 'V', treatment: 'delta', donor: 'two'}, {subject: 1, weight: 20.53, isolator: 'E', study: 'V', treatment: 'beta', donor: 'two'}, {subject: 3, weight: 19.63, isolator: 'E', study: 'V', treatment: 'beta', donor: 'two'}, {subject: 6, weight: 17.45, isolator: 'E', study: 'V', treatment: 'beta', donor: 'two'}, {subject: 11, weight: 18.67, isolator: 'E', study: 'V', treatment: 'beta', donor: 'two'}, {subject: 14, weight: 18.18, isolator: 'E', study: 'V', treatment: 'beta', donor: 'two'}, {subject: 2, weight: 17.81, isolator: 'E', study: 'V', treatment: 'beta', donor: 'two'}, {subject: 5, weight: 19.07, isolator: 'E', study: 'V', treatment: 'beta', donor: 'two'}, {subject: 7, weight: 18.33, isolator: 'E', study: 'V', treatment: 'beta', donor: 'two'}, {subject: 10, weight: 18.31, isolator: 'E', study: 'V', treatment: 'beta', donor: 'two'}, {subject: 13, weight: 17.1, isolator: 'E', study: 'V', treatment: 'beta', donor: 'two'}, {subject: 6, weight: 17.69, isolator: 'D', study: 'V', treatment: 'alpha', donor: 'two'}, {subject: 9, weight: 18.08, isolator: 'D', study: 'V', treatment: 'alpha', donor: 'two'}, {subject: 10, weight: 18.07, isolator: 'D', study: 'V', treatment: 'alpha', donor: 'two'}, {subject: 16, weight: 18.6, isolator: 'D', study: 'V', treatment: 'alpha', donor: 'two'}, {subject: 17, weight: 19.45, isolator: 'D', study: 'V', treatment: 'alpha', donor: 'two'}, {subject: 3, weight: 16.7, isolator: 'F', study: 'I', treatment: 'control', donor: 'two'}, {subject: 5, weight: 18.3, isolator: 'F', study: 'I', treatment: 'control', donor: 'two'}, {subject: 6, weight: 17.5, isolator: 'F', study: 'I', treatment: 'control', donor: 'two'}, {subject: 10, weight: 18.5, isolator: 'F', study: 'I', treatment: 'control', donor: 'two'}, {subject: 16, weight: 18.6, isolator: 'F', study: 'I', treatment: 'control', donor: 'two'}, {subject: 1, weight: 16.96, isolator: 'A', study: 'V', treatment: 'control', donor: 'two'}, {subject: 4, weight: 17.79, isolator: 'A', study: 'V', treatment: 'control', donor: 'two'}, {subject: 7, weight: 17.28, isolator: 'A', study: 'V', treatment: 'control', donor: 'two'}, {subject: 8, weight: 17.28, isolator: 'A', study: 'V', treatment: 'control', donor: 'two'}, {subject: 11, weight: 16.46, isolator: 'A', study: 'V', treatment: 'control', donor: 'two'}, {subject: 1, weight: 18.7, isolator: 'E', study: 'I', treatment: 'control', donor: 'three'}, {subject: 2, weight: 16.2, isolator: 'E', study: 'I', treatment: 'control', donor: 'three'}, {subject: 9, weight: 21.2, isolator: 'E', study: 'I', treatment: 'control', donor: 'three'}, {subject: 11, weight: 18.8, isolator: 'E', study: 'I', treatment: 'control', donor: 'three'}, {subject: 14, weight: 17.9, isolator: 'E', study: 'I', treatment: 'control', donor: 'three'}, {subject: 4, weight: 17.8, isolator: 'D', study: 'I', treatment: 'control', donor: 'four'}, {subject: 8, weight: 19.3, isolator: 'D', study: 'I', treatment: 'control', donor: 'four'}, {subject: 12, weight: 18.8, isolator: 'D', study: 'I', treatment: 'control', donor: 'four'}, {subject: 15, weight: 18.8, isolator: 'D', study: 'I', treatment: 'control', donor: 'four'}, {subject: 5, weight: 20.1, isolator: 'C', study: 'I', treatment: 'control', donor: 'six'}, {subject: 6, weight: 18.1, isolator: 'C', study: 'I', treatment: 'control', donor: 'six'}, {subject: 8, weight: 20.8, isolator: 'C', study: 'I', treatment: 'control', donor: 'six'}, {subject: 17, weight: 17.7, isolator: 'C', study: 'I', treatment: 'control', donor: 'six'}, {subject: 19, weight: 16.9, isolator: 'C', study: 'I', treatment: 'control', donor: 'six'}, {subject: 2, weight: 16.9, isolator: 'B', study: 'V', treatment: 'control', donor: 'seven'}, {subject: 9, weight: 18.33, isolator: 'B', study: 'V', treatment: 'control', donor: 'seven'}, {subject: 12, weight: 17.86, isolator: 'B', study: 'V', treatment: 'control', donor: 'seven'}, {subject: 13, weight: 16.64, isolator: 'B', study: 'V', treatment: 'control', donor: 'seven'}, {subject: 15, weight: 18.1, isolator: 'B', study: 'V', treatment: 'control', donor: 'seven'}, {subject: 1, weight: 19, isolator: 'B', study: 'I', treatment: 'control', donor: 'eight'}, {subject: 2, weight: 19.5, isolator: 'B', study: 'I', treatment: 'control', donor: 'eight'}, {subject: 10, weight: 20.9, isolator: 'B', study: 'I', treatment: 'control', donor: 'eight'}, {subject: 11, weight: 20, isolator: 'B', study: 'I', treatment: 'control', donor: 'eight'}, {subject: 14, weight: 18.3, isolator: 'B', study: 'I', treatment: 'control', donor: 'eight'}, {subject: 4, weight: 18.3, isolator: 'A', study: 'I', treatment: 'control', donor: 'nine'}, {subject: 7, weight: 17, isolator: 'A', study: 'I', treatment: 'control', donor: 'nine'}, {subject: 12, weight: 17.8, isolator: 'A', study: 'I', treatment: 'control', donor: 'nine'}, {subject: 13, weight: 17.8, isolator: 'A', study: 'I', treatment: 'control', donor: 'nine'}, {subject: 16, weight: 15.7, isolator: 'A', study: 'I', treatment: 'control', donor: 'nine'}, {subject: 15, weight: 17.4, isolator: 'E', study: 'II', treatment: 'delta', donor: 'two'}, {subject: 16, weight: 18.8, isolator: 'E', study: 'II', treatment: 'delta', donor: 'two'}, {subject: 18, weight: 18, isolator: 'E', study: 'II', treatment: 'delta', donor: 'two'}, {subject: 6, weight: 18.9, isolator: 'E', study: 'II', treatment: 'delta', donor: 'two'}, {subject: 7, weight: 16.9, isolator: 'E', study: 'II', treatment: 'delta', donor: 'two'}, {subject: 2, weight: 18.9, isolator: 'C', study: 'IV', treatment: 'delta', donor: 'two'}, {subject: 3, weight: 18.7, isolator: 'C', study: 'IV', treatment: 'delta', donor: 'two'}, {subject: 14, weight: 18.3, isolator: 'C', study: 'IV', treatment: 'delta', donor: 'two'}, {subject: 16, weight: 18, isolator: 'C', study: 'IV', treatment: 'delta', donor: 'two'}, {subject: 18, weight: 19.4, isolator: 'C', study: 'IV', treatment: 'delta', donor: 'two'}, {subject: 3, weight: 18.4, isolator: 'C', study: 'V', treatment: 'delta', donor: 'two'}, {subject: 4, weight: 18.6, isolator: 'C', study: 'V', treatment: 'delta', donor: 'two'}, {subject: 5, weight: 18.3, isolator: 'C', study: 'V', treatment: 'delta', donor: 'two'}, {subject: 8, weight: 18.3, isolator: 'C', study: 'V', treatment: 'delta', donor: 'two'}, {subject: 12, weight: 18.6, isolator: 'C', study: 'V', treatment: 'delta', donor: 'two'}, {subject: 14, weight: 19.9, isolator: 'D', study: 'II', treatment: 'delta', donor: 'nine'}, {subject: 2, weight: 18.4, isolator: 'D', study: 'II', treatment: 'delta', donor: 'nine'}, {subject: 3, weight: 17.4, isolator: 'D', study: 'II', treatment: 'delta', donor: 'nine'}, {subject: 4, weight: 17.9, isolator: 'D', study: 'II', treatment: 'delta', donor: 'nine'}, {subject: 8, weight: 17.6, isolator: 'D', study: 'II', treatment: 'delta', donor: 'nine'}, {subject: 1, weight: 20.1, isolator: 'E', study: 'IV', treatment: 'gamma', donor: 'two'}, {subject: 5, weight: 17.4, isolator: 'E', study: 'IV', treatment: 'gamma', donor: 'two'}, {subject: 7, weight: 17.8, isolator: 'E', study: 'IV', treatment: 'gamma', donor: 'two'}, {subject: 10, weight: 17.5, isolator: 'E', study: 'IV', treatment: 'gamma', donor: 'two'}, {subject: 15, weight: 16.3, isolator: 'E', study: 'IV', treatment: 'gamma', donor: 'two'}, {subject: 1, weight: 19.9, isolator: 'E', study: 'V', treatment: 'beta', donor: 'two'}, {subject: 3, weight: 19.3, isolator: 'E', study: 'V', treatment: 'beta', donor: 'two'}, {subject: 6, weight: 16.8, isolator: 'E', study: 'V', treatment: 'beta', donor: 'two'}, {subject: 11, weight: 18.8, isolator: 'E', study: 'V', treatment: 'beta', donor: 'two'}, {subject: 14, weight: 17.5, isolator: 'E', study: 'V', treatment: 'beta', donor: 'two'}, {subject: 2, weight: 17, isolator: 'E', study: 'V', treatment: 'beta', donor: 'two'}, {subject: 5, weight: 19.5, isolator: 'E', study: 'V', treatment: 'beta', donor: 'two'}, {subject: 7, weight: 18.2, isolator: 'E', study: 'V', treatment: 'beta', donor: 'two'}, {subject: 10, weight: 18.5, isolator: 'E', study: 'V', treatment: 'beta', donor: 'two'}, {subject: 13, weight: 17.2, isolator: 'E', study: 'V', treatment: 'beta', donor: 'two'}, {subject: 2, weight: 15.3, isolator: 'D', study: 'IV', treatment: 'alpha', donor: 'two'}, {subject: 4, weight: 18.9, isolator: 'D', study: 'IV', treatment: 'alpha', donor: 'two'}, {subject: 6, weight: 19.4, isolator: 'D', study: 'IV', treatment: 'alpha', donor: 'two'}, {subject: 8, weight: 17.8, isolator: 'D', study: 'IV', treatment: 'alpha', donor: 'two'}, {subject: 11, weight: 17.7, isolator: 'D', study: 'IV', treatment: 'alpha', donor: 'two'}, {subject: 6, weight: 18, isolator: 'D', study: 'V', treatment: 'alpha', donor: 'two'}, {subject: 9, weight: 18.7, isolator: 'D', study: 'V', treatment: 'alpha', donor: 'two'}, {subject: 10, weight: 18.1, isolator: 'D', study: 'V', treatment: 'alpha', donor: 'two'}, {subject: 16, weight: 18.9, isolator: 'D', study: 'V', treatment: 'alpha', donor: 'two'}, {subject: 17, weight: 19.4, isolator: 'D', study: 'V', treatment: 'alpha', donor: 'two'}, {subject: 10, weight: 18.9, isolator: 'D', study: 'III', treatment: 'control', donor: 'one'}, {subject: 13, weight: 17.5, isolator: 'D', study: 'III', treatment: 'control', donor: 'one'}, {subject: 16, weight: 17.9, isolator: 'D', study: 'III', treatment: 'control', donor: 'one'}, {subject: 4, weight: 18.7, isolator: 'D', study: 'III', treatment: 'control', donor: 'one'}, {subject: 6, weight: 17.5, isolator: 'D', study: 'III', treatment: 'control', donor: 'one'}, {subject: 3, weight: 16.5, isolator: 'F', study: 'I', treatment: 'control', donor: 'two'}, {subject: 5, weight: 18, isolator: 'F', study: 'I', treatment: 'control', donor: 'two'}, {subject: 6, weight: 17.1, isolator: 'F', study: 'I', treatment: 'control', donor: 'two'}, {subject: 10, weight: 17.6, isolator: 'F', study: 'I', treatment: 'control', donor: 'two'}, {subject: 16, weight: 18, isolator: 'F', study: 'I', treatment: 'control', donor: 'two'}, {subject: 1, weight: 17.7, isolator: 'C', study: 'II', treatment: 'control', donor: 'two'}, {subject: 13, weight: 19.1, isolator: 'C', study: 'II', treatment: 'control', donor: 'two'}, {subject: 15, weight: 17.7, isolator: 'C', study: 'II', treatment: 'control', donor: 'two'}, {subject: 17, weight: 17.5, isolator: 'C', study: 'II', treatment: 'control', donor: 'two'}, {subject: 6, weight: 18.1, isolator: 'C', study: 'II', treatment: 'control', donor: 'two'}, {subject: 1, weight: 19.3, isolator: 'B', study: 'IV', treatment: 'control', donor: 'two'}, {subject: 3, weight: 17.6, isolator: 'B', study: 'IV', treatment: 'control', donor: 'two'}, {subject: 6, weight: 17.4, isolator: 'B', study: 'IV', treatment: 'control', donor: 'two'}, {subject: 7, weight: 17.5, isolator: 'B', study: 'IV', treatment: 'control', donor: 'two'}, {subject: 1, weight: 16.7, isolator: 'A', study: 'V', treatment: 'control', donor: 'two'}, {subject: 4, weight: 18.2, isolator: 'A', study: 'V', treatment: 'control', donor: 'two'}, {subject: 7, weight: 16.8, isolator: 'A', study: 'V', treatment: 'control', donor: 'two'}, {subject: 8, weight: 16.9, isolator: 'A', study: 'V', treatment: 'control', donor: 'two'}, {subject: 11, weight: 16, isolator: 'A', study: 'V', treatment: 'control', donor: 'two'}, {subject: 1, weight: 18.8, isolator: 'E', study: 'I', treatment: 'control', donor: 'three'}, {subject: 2, weight: 15.8, isolator: 'E', study: 'I', treatment: 'control', donor: 'three'}, {subject: 9, weight: 21, isolator: 'E', study: 'I', treatment: 'control', donor: 'three'}, {subject: 11, weight: 18.5, isolator: 'E', study: 'I', treatment: 'control', donor: 'three'}, {subject: 14, weight: 17.3, isolator: 'E', study: 'I', treatment: 'control', donor: 'three'}, {subject: 4, weight: 18, isolator: 'D', study: 'I', treatment: 'control', donor: 'four'}, {subject: 8, weight: 19.4, isolator: 'D', study: 'I', treatment: 'control', donor: 'four'}, {subject: 12, weight: 18.8, isolator: 'D', study: 'I', treatment: 'control', donor: 'four'}, {subject: 15, weight: 18.8, isolator: 'D', study: 'I', treatment: 'control', donor: 'four'}, {subject: 1, weight: 18.3, isolator: 'C', study: 'III', treatment: 'control', donor: 'five'}, {subject: 17, weight: 19.8, isolator: 'C', study: 'III', treatment: 'control', donor: 'five'}, {subject: 18, weight: 18.5, isolator: 'C', study: 'III', treatment: 'control', donor: 'five'}, {subject: 2, weight: 18.2, isolator: 'C', study: 'III', treatment: 'control', donor: 'five'}, {subject: 8, weight: 17.4, isolator: 'C', study: 'III', treatment: 'control', donor: 'five'}, {subject: 5, weight: 20, isolator: 'C', study: 'I', treatment: 'control', donor: 'six'}, {subject: 6, weight: 17.2, isolator: 'C', study: 'I', treatment: 'control', donor: 'six'}, {subject: 8, weight: 20.7, isolator: 'C', study: 'I', treatment: 'control', donor: 'six'}, {subject: 17, weight: 17.8, isolator: 'C', study: 'I', treatment: 'control', donor: 'six'}, {subject: 19, weight: 17.5, isolator: 'C', study: 'I', treatment: 'control', donor: 'six'}, {subject: 10, weight: 19.3, isolator: 'B', study: 'III', treatment: 'control', donor: 'seven'}, {subject: 11, weight: 18.7, isolator: 'B', study: 'III', treatment: 'control', donor: 'seven'}, {subject: 4, weight: 18.9, isolator: 'B', study: 'III', treatment: 'control', donor: 'seven'}, {subject: 6, weight: 20.8, isolator: 'B', study: 'III', treatment: 'control', donor: 'seven'}, {subject: 7, weight: 19, isolator: 'B', study: 'III', treatment: 'control', donor: 'seven'}, {subject: 2, weight: 16.5, isolator: 'B', study: 'V', treatment: 'control', donor: 'seven'}, {subject: 9, weight: 18.4, isolator: 'B', study: 'V', treatment: 'control', donor: 'seven'}, {subject: 12, weight: 18.8, isolator: 'B', study: 'V', treatment: 'control', donor: 'seven'}, {subject: 13, weight: 17.1, isolator: 'B', study: 'V', treatment: 'control', donor: 'seven'}, {subject: 15, weight: 18.4, isolator: 'B', study: 'V', treatment: 'control', donor: 'seven'}, {subject: 1, weight: 18.5, isolator: 'B', study: 'I', treatment: 'control', donor: 'eight'}, {subject: 2, weight: 18.9, isolator: 'B', study: 'I', treatment: 'control', donor: 'eight'}, {subject: 10, weight: 20.1, isolator: 'B', study: 'I', treatment: 'control', donor: 'eight'}, {subject: 11, weight: 19.3, isolator: 'B', study: 'I', treatment: 'control', donor: 'eight'}, {subject: 14, weight: 18.6, isolator: 'B', study: 'I', treatment: 'control', donor: 'eight'}, {subject: 11, weight: 19.4, isolator: 'A', study: 'II', treatment: 'control', donor: 'eight'}, {subject: 14, weight: 19.3, isolator: 'A', study: 'II', treatment: 'control', donor: 'eight'}, {subject: 2, weight: 17.9, isolator: 'A', study: 'II', treatment: 'control', donor: 'eight'}, {subject: 3, weight: 18.1, isolator: 'A', study: 'II', treatment: 'control', donor: 'eight'}, {subject: 4, weight: 17.4, isolator: 'A', study: 'II', treatment: 'control', donor: 'eight'}, {subject: 4, weight: 17.8, isolator: 'A', study: 'IV', treatment: 'control', donor: 'eight'}, {subject: 9, weight: 17.2, isolator: 'A', study: 'IV', treatment: 'control', donor: 'eight'}, {subject: 12, weight: 16.4, isolator: 'A', study: 'IV', treatment: 'control', donor: 'eight'}, {subject: 13, weight: 17.9, isolator: 'A', study: 'IV', treatment: 'control', donor: 'eight'}, {subject: 17, weight: 19.9, isolator: 'A', study: 'IV', treatment: 'control', donor: 'eight'}, {subject: 12, weight: 18, isolator: 'A', study: 'III', treatment: 'control', donor: 'eight'}, {subject: 15, weight: 18.7, isolator: 'A', study: 'III', treatment: 'control', donor: 'eight'}, {subject: 2, weight: 19.6, isolator: 'A', study: 'III', treatment: 'control', donor: 'eight'}, {subject: 3, weight: 17.8, isolator: 'A', study: 'III', treatment: 'control', donor: 'eight'}, {subject: 9, weight: 18.3, isolator: 'A', study: 'III', treatment: 'control', donor: 'eight'}, {subject: 4, weight: 18.2, isolator: 'A', study: 'I', treatment: 'control', donor: 'nine'}, {subject: 7, weight: 16.9, isolator: 'A', study: 'I', treatment: 'control', donor: 'nine'}, {subject: 12, weight: 18.2, isolator: 'A', study: 'I', treatment: 'control', donor: 'nine'}, {subject: 13, weight: 17.6, isolator: 'A', study: 'I', treatment: 'control', donor: 'nine'}, {subject: 16, weight: 15.5, isolator: 'A', study: 'I', treatment: 'control', donor: 'nine'}, {subject: 1, weight: 17, isolator: 'B', study: 'II', treatment: 'control', donor: 'nine'}, {subject: 16, weight: 18.1, isolator: 'B', study: 'II', treatment: 'control', donor: 'nine'}, {subject: 17, weight: 18.3, isolator: 'B', study: 'II', treatment: 'control', donor: 'nine'}, {subject: 18, weight: 19.5, isolator: 'B', study: 'II', treatment: 'control', donor: 'nine'}, {subject: 5, weight: 18.3, isolator: 'B', study: 'II', treatment: 'control', donor: 'nine'}, ] options = x: (d)-> d.study y: (d)-> d.weight colorGroup: (d)-> d.donor maxBoxWidth: false plotType: 'box' observationType: 'random' whiskerDef: 'iqr' notchBox: false hideWhiskers: false centralTendency: 'mean' bandwidth: 'scott' clampViolin: true resolution: 50 showOnlyOutliers: true jitter: 0.7 squash: false pointSize: 4 margin: top: 30 right: 60 bottom: 80 left: 10 builder = null beforeEach -> builder = new ChartBuilder nv.models.distroPlotChart() builder.build options, data afterEach -> builder.teardown() it 'api check', -> should.exist builder.model.options, 'options exposed' for opt of options should.exist builder.model[opt](), "#{opt} can be called" builder.model.update() it 'renders', -> wrap = builder.$ 'g.nvd3.nv-distroPlot' should.exist wrap[0] it 'no data text', -> builder = new ChartBuilder nv.models.distroPlotChart() builder.build options, [] noData = builder.$ '.nv-noData' noData[0].textContent.should.equal 'No Data Available.' it 'has correct structure', -> cssClasses = [ '.nv-x.nv-axis' '.nv-y.nv-axis' '.nv-wrap' '.nv-distroWrap' '.nv-distroplot-x-group' '.nv-distroplot-whisker' '.nv-distroplot-low' '.nv-distroplot-tick' '.nv-distroplot-high' '.nv-distribution-area' '.nv-distribution-left' '.nv-distribution-right' '.nv-distribution-line' '.nv-distroplot-observation' '.nv-distroplot-outlier' '.nv-distroplot-non-outlier' ] for cssClass in cssClasses do (cssClass) -> should.exist builder.$("g.nvd3.nv-distroPlot #{cssClass}")[0] it 'has all x groups', -> groups = builder.$ '.nv-distroplot-x-group' groups.should.have.length 17, 'groups exist' it 'has all outliers', -> groups = builder.$ '.nv-distroplot-outlier' groups.should.have.length 11, 'outliers exist' ================================================ FILE: test/mocha/heatmap.coffee ================================================ describe 'NVD3', -> describe 'heatMapChart', -> data = [ {day: 'Mo', hour: 1, value: 16, group: 84, category: 1, level: 1}, {day: 'Mo', hour: 2, value: 20, group: 84, category: 1, level: 1}, {day: 'Mo', hour: 3, value: 0, group: 84, category: 1, level: 1}, {day: 'Mo', hour: 4, value: 0, group: 84, category: 1, level: 1}, {day: 'Mo', hour: 5, value: 0, group: 84, category: 1, level: 1}, {day: 'Mo', hour: 6, value: 2, group: 84, category: 1, level: 1}, {day: 'Mo', hour: 7, value: 0, group: 84, category: 1, level: 1}, {day: 'Mo', hour: 8, value: 9, group: 84, category: 1, level: 1}, {day: 'Mo', hour: 9, value: 25, group: 84, category: 1, level: 1}, {day: 'Mo', hour: 10, value: 49, group: 84, category: 1, level: 1}, {day: 'Mo', hour: 11, value: 57, group: 84, category: 1, level: 1}, {day: 'Mo', hour: 12, value: 61, group: 84, category: 1, level: 1}, {day: 'Mo', hour: 13, value: 37, group: 84, category: 2, level: 1}, {day: 'Mo', hour: 14, value: 66, group: 84, category: 2, level: 1}, {day: 'Mo', hour: 15, value: 70, group: 84, category: 2, level: 1}, {day: 'Mo', hour: 16, value: 55, group: 84, category: 2, level: 1}, {day: 'Mo', hour: 17, value: 51, group: 84, category: 2, level: 1}, {day: 'Mo', hour: 18, value: 55, group: 84, category: 2, level: 1}, {day: 'Mo', hour: 19, value: 17, group: 84, category: 2, level: 1}, {day: 'Mo', hour: 20, value: 20, group: 84, category: 2, level: 1}, {day: 'Mo', hour: 21, value: 9, group: 84, category: 2, level: 1}, {day: 'Mo', hour: 22, value: 4, group: 84, category: 2, level: 1}, {day: 'Mo', hour: 23, value: 0, group: 84, category: 2, level: 1}, {day: 'Mo', hour: 24, value: 12, group: 84, category: 2, level: 1}, {day: 'Tu', hour: 1, value: 6, group: 13, category: 1, level: 1}, {day: 'Tu', hour: 2, value: 2, group: 13, category: 1, level: 1}, {day: 'Tu', hour: 3, value: 0, group: 13, category: 1, level: 1}, {day: 'Tu', hour: 4, value: 0, group: 13, category: 1, level: 1}, {day: 'Tu', hour: 5, value: 0, group: 13, category: 1, level: 1}, {day: 'Tu', hour: 6, value: 2, group: 13, category: 1, level: 1}, {day: 'Tu', hour: 7, value: 4, group: 13, category: 1, level: 1}, {day: 'Tu', hour: 8, value: 11, group: 13, category: 1, level: 1}, {day: 'Tu', hour: 9, value: 28, group: 13, category: 1, level: 1}, {day: 'Tu', hour: 10, value: 49, group: 13, category: 1, level: 1}, {day: 'Tu', hour: 11, value: 51, group: 13, category: 1, level: 1}, {day: 'Tu', hour: 12, value: 47, group: 13, category: 1, level: 1}, {day: 'Tu', hour: 13, value: 38, group: 13, category: 2, level: 1}, {day: 'Tu', hour: 14, value: 65, group: 13, category: 2, level: 1}, {day: 'Tu', hour: 15, value: 60, group: 13, category: 2, level: 1}, {day: 'Tu', hour: 16, value: 50, group: 13, category: 2, level: 1}, {day: 'Tu', hour: 17, value: 65, group: 13, category: 2, level: 1}, {day: 'Tu', hour: 18, value: 50, group: 13, category: 2, level: 1}, {day: 'Tu', hour: 19, value: 22, group: 13, category: 2, level: 1}, {day: 'Tu', hour: 20, value: 11, group: 13, category: 2, level: 1}, {day: 'Tu', hour: 21, value: 12, group: 13, category: 2, level: 1}, {day: 'Tu', hour: 22, value: 9, group: 13, category: 2, level: 1}, {day: 'Tu', hour: 23, value: 0, group: 13, category: 2, level: 1}, {day: 'Tu', hour: 24, value: 13, group: 13, category: 2, level: 1}, {day: 'We', hour: 1, value: 5, group: 84, category: 1, level: 1}, {day: 'We', hour: 2, value: 8, group: 84, category: 1, level: 1}, {day: 'We', hour: 3, value: 8, group: 84, category: 1, level: 1}, {day: 'We', hour: 4, value: 0, group: 84, category: 1, level: 1}, {day: 'We', hour: 5, value: 0, group: 84, category: 1, level: 1}, {day: 'We', hour: 6, value: 2, group: 84, category: 1, level: 1}, {day: 'We', hour: 7, value: 5, group: 84, category: 1, level: 1}, {day: 'We', hour: 8, value: 12, group: 84, category: 1, level: 1}, {day: 'We', hour: 9, value: 34, group: 84, category: 1, level: 1}, {day: 'We', hour: 10, value: 43, group: 84, category: 1, level: 1}, {day: 'We', hour: 11, value: 54, group: 84, category: 1, level: 1}, {day: 'We', hour: 12, value: 44, group: 84, category: 1, level: 1}, {day: 'We', hour: 13, value: 40, group: 84, category: 2, level: 1}, {day: 'We', hour: 14, value: 48, group: 84, category: 2, level: 1}, {day: 'We', hour: 15, value: 54, group: 84, category: 2, level: 1}, {day: 'We', hour: 16, value: 59, group: 84, category: 2, level: 1}, {day: 'We', hour: 17, value: 60, group: 84, category: 2, level: 1}, {day: 'We', hour: 18, value: 51, group: 84, category: 2, level: 1}, {day: 'We', hour: 19, value: 21, group: 84, category: 2, level: 1}, {day: 'We', hour: 20, value: 16, group: 84, category: 2, level: 1}, {day: 'We', hour: 21, value: 9, group: 84, category: 2, level: 1}, {day: 'We', hour: 22, value: 5, group: 84, category: 2, level: 1}, {day: 'We', hour: 23, value: 4, group: 84, category: 2, level: 1}, {day: 'We', hour: 24, value: 7, group: 84, category: 2, level: 1}, {day: 'Th', hour: 1, value: 0, group: 13, category: 1, level: 1}, {day: 'Th', hour: 2, value: 0, group: 13, category: 1, level: 1}, {day: 'Th', hour: 3, value: 0, group: 13, category: 1, level: 1}, {day: 'Th', hour: 4, value: 0, group: 13, category: 1, level: 1}, {day: 'Th', hour: 5, value: 0, group: 13, category: 1, level: 1}, {day: 'Th', hour: 6, value: 2, group: 13, category: 1, level: 1}, {day: 'Th', hour: 7, value: 4, group: 13, category: 1, level: 1}, {day: 'Th', hour: 8, value: 13, group: 13, category: 1, level: 1}, {day: 'Th', hour: 9, value: 26, group: 13, category: 1, level: 1}, {day: 'Th', hour: 10, value: 58, group: 13, category: 1, level: 1}, {day: 'Th', hour: 11, value: 61, group: 13, category: 1, level: 1}, {day: 'Th', hour: 12, value: 59, group: 13, category: 1, level: 1}, {day: 'Th', hour: 13, value: 53, group: 13, category: 2, level: 1}, {day: 'Th', hour: 14, value: 54, group: 13, category: 2, level: 1}, {day: 'Th', hour: 15, value: 64, group: 13, category: 2, level: 1}, {day: 'Th', hour: 16, value: 55, group: 13, category: 2, level: 1}, {day: 'Th', hour: 17, value: 52, group: 13, category: 2, level: 1}, {day: 'Th', hour: 18, value: 53, group: 13, category: 2, level: 1}, {day: 'Th', hour: 19, value: 18, group: 13, category: 2, level: 1}, {day: 'Th', hour: 20, value: 3, group: 13, category: 2, level: 1}, {day: 'Th', hour: 21, value: 9, group: 13, category: 2, level: 1}, {day: 'Th', hour: 22, value: 12, group: 13, category: 2, level: 1}, {day: 'Th', hour: 23, value: 2, group: 13, category: 2, level: 1}, {day: 'Th', hour: 24, value: 8, group: 13, category: 2, level: 1}, {day: 'Fr', hour: 1, value: 2, group: 53, category: 1, level: 1}, {day: 'Fr', hour: 2, value: 0, group: 53, category: 1, level: 1}, {day: 'Fr', hour: 3, value: 8, group: 53, category: 1, level: 1}, {day: 'Fr', hour: 4, value: 2, group: 53, category: 1, level: 1}, {day: 'Fr', hour: 5, value: 0, group: 53, category: 1, level: 1}, {day: 'Fr', hour: 6, value: 2, group: 53, category: 1, level: 1}, {day: 'Fr', hour: 7, value: 4, group: 53, category: 1, level: 1}, {day: 'Fr', hour: 8, value: 14, group: 53, category: 1, level: 1}, {day: 'Fr', hour: 9, value: 31, group: 53, category: 1, level: 1}, {day: 'Fr', hour: 10, value: 48, group: 53, category: 1, level: 1}, {day: 'Fr', hour: 11, value: 46, group: 53, category: 1, level: 1}, {day: 'Fr', hour: 12, value: 50, group: 53, category: 1, level: 1}, {day: 'Fr', hour: 13, value: 66, group: 53, category: 2, level: 1}, {day: 'Fr', hour: 14, value: 54, group: 53, category: 2, level: 1}, {day: 'Fr', hour: 15, value: 56, group: 53, category: 2, level: 1}, {day: 'Fr', hour: 16, value: 67, group: 53, category: 2, level: 1}, {day: 'Fr', hour: 17, value: 54, group: 53, category: 2, level: 1}, {day: 'Fr', hour: 18, value: 23, group: 53, category: 2, level: 1}, {day: 'Fr', hour: 19, value: 14, group: 53, category: 2, level: 1}, {day: 'Fr', hour: 20, value: 6, group: 53, category: 2, level: 1}, {day: 'Fr', hour: 21, value: 8, group: 53, category: 2, level: 1}, {day: 'Fr', hour: 22, value: 7, group: 53, category: 2, level: 1}, {day: 'Fr', hour: 23, value: 0, group: 53, category: 2, level: 1}, {day: 'Fr', hour: 24, value: 8, group: 53, category: 2, level: 1}, {day: 'Sa', hour: 1, value: 2, group: 53, category: 1, level: 2}, {day: 'Sa', hour: 2, value: 0, group: 53, category: 1, level: 2}, {day: 'Sa', hour: 3, value: 2, group: 53, category: 1, level: 2}, {day: 'Sa', hour: 4, value: 0, group: 53, category: 1, level: 2}, {day: 'Sa', hour: 5, value: 0, group: 53, category: 1, level: 2}, {day: 'Sa', hour: 6, value: 0, group: 53, category: 1, level: 2}, {day: 'Sa', hour: 7, value: 4, group: 53, category: 1, level: 2}, {day: 'Sa', hour: 8, value: 8, group: 53, category: 1, level: 2}, {day: 'Sa', hour: 9, value: 8, group: 53, category: 1, level: 2}, {day: 'Sa', hour: 10, value: 6, group: 53, category: 1, level: 2}, {day: 'Sa', hour: 11, value: 14, group: 53, category: 1, level: 2}, {day: 'Sa', hour: 12, value: 12, group: 53, category: 1, level: 2}, {day: 'Sa', hour: 13, value: 9, group: 53, category: 2, level: 2}, {day: 'Sa', hour: 14, value: 14, group: 53, category: 2, level: 2}, {day: 'Sa', hour: 15, value: 0, group: 53, category: 2, level: 2}, {day: 'Sa', hour: 16, value: 4, group: 53, category: 2, level: 2}, {day: 'Sa', hour: 17, value: 7, group: 53, category: 2, level: 2}, {day: 'Sa', hour: 18, value: 6, group: 53, category: 2, level: 2}, {day: 'Sa', hour: 19, value: 0, group: 53, category: 2, level: 2}, {day: 'Sa', hour: 20, value: 0, group: 53, category: 2, level: 2}, {day: 'Sa', hour: 21, value: 0, group: 53, category: 2, level: 2}, {day: 'Sa', hour: 22, value: 0, group: 53, category: 2, level: 2}, {day: 'Sa', hour: 23, value: 0, group: 53, category: 2, level: 2}, {day: 'Sa', hour: 24, value: 0, group: 53, category: 2, level: 2}, {day: 'Su', hour: 1, value: 7, group: 53, category: 1, level: 2}, {day: 'Su', hour: 2, value: 6, group: 53, category: 1, level: 2}, {day: 'Su', hour: 3, value: 0, group: 53, category: 1, level: 2}, {day: 'Su', hour: 4, value: 0, group: 53, category: 1, level: 2}, {day: 'Su', hour: 5, value: 0, group: 53, category: 1, level: 2}, {day: 'Su', hour: 6, value: 0, group: 53, category: 1, level: 2}, {day: 'Su', hour: 7, value: 0, group: 53, category: 1, level: 2}, {day: 'Su', hour: 8, value: 0, group: 53, category: 1, level: 2}, {day: 'Su', hour: 9, value: 0, group: 53, category: 1, level: 2}, {day: 'Su', hour: 10, value: 0, group: 53, category: 1, level: 2}, {day: 'Su', hour: 11, value: 2, group: 53, category: 1, level: 2}, {day: 'Su', hour: 12, value: 2, group: 53, category: 1, level: 2}, {day: 'Su', hour: 13, value: 5, group: 53, category: 2, level: 2}, {day: 'Su', hour: 14, value: 6, group: 53, category: 2, level: 2}, {day: 'Su', hour: 15, value: 0, group: 53, category: 2, level: 2}, {day: 'Su', hour: 16, value: 4, group: 53, category: 2, level: 2}, {day: 'Su', hour: 17, value: 0, group: 53, category: 2, level: 2}, {day: 'Su', hour: 18, value: 2, group: 53, category: 2, level: 2}, {day: 'Su', hour: 19, value: 10, group: 53, category: 2, level: 2}, {day: 'Su', hour: 20, value: 7, group: 53, category: 2, level: 2}, {day: 'Su', hour: 21, value: 0, group: 53, category: 2, level: 2}, {day: 'Su', hour: 22, value: 19, group: 53, category: 2, level: 2}, {day: 'Su', hour: 23, value: 9, group: 53, category: 2, level: 2}, {day: 'Su', hour: 24, value: 4, group: 53, category: 2, level: 2}, ] options = x: (d)-> d.hour y: (d)-> d.day cellAspectRatio: 1 normalize: false highContrastText: true showXAxis: true showYAxis: true showLegend: true showCellValues: true alignXAxis: 'top' alignYAxis: 'left' cellValueFormat: d3.format(',.0f') cellBorderWidth: 4 xMeta: (d)-> d.category yMeta: (d)-> d.group margin: top: 30 right: 60 bottom: 80 left: 10 builder = null beforeEach -> builder = new ChartBuilder nv.models.heatMapChart() builder.build options, data afterEach -> builder.teardown() it 'api check', -> should.exist builder.model.options, 'options exposed' for opt of options should.exist builder.model[opt](), "#{opt} can be called" builder.model.update() it 'renders', -> wrap = builder.$ 'g.nvd3-svg.nv-heatMap' should.exist wrap[0] it 'no data text', -> builder = new ChartBuilder nv.models.heatMapChart() builder.build options, [] noData = builder.$ '.nv-noData' noData[0].textContent.should.equal 'No Data Available.' it 'has correct structure', -> cssClasses = [ '.nv-x.nv-axis' '.nv-y.nv-axis' '.nv-wrap' '.nv-heatMap' '.nv-heatMapWrap' '.xMetaWrap' '.nv-cell' '.yMetaWrap' '.meta' '.x-meta' '.y-meta' '.nv-legendWrap' '.nv-legend' ] for cssClass in cssClasses do (cssClass) -> should.exist builder.$("g.nvd3 #{cssClass}")[0] it 'has all cells', -> groups = builder.$ '.nv-cell' groups.should.have.length 168, 'cells exist' it 'has all x-meta', -> groups = builder.$ '.x-meta' groups.should.have.length 24, 'rects exist' it 'has all y-meta', -> groups = builder.$ '.y-meta' groups.should.have.length 7, 'rects exist' ================================================ FILE: test/mocha/historical-bar.coffee ================================================ describe 'NVD3', -> describe 'Historical Bar Chart', -> sampleData1 = [ key: 'Series 1' values: [ [-1,-1] [0,0] [1,1] [2,2] ] ] options = x: (d,i)-> i y: (d)-> d[1] margin: top: 30 right: 20 bottom: 50 left: 75 width: 200 height: 200 color: nv.utils.defaultColor() showLegend: true showXAxis: true showYAxis: true rightAlignYAxis: false noData: 'No Data Available' builder = null beforeEach -> builder = new ChartBuilder nv.models.historicalBarChart() builder.build options, sampleData1 afterEach -> builder.teardown() it 'api check', -> should.exist builder.model.options, 'options exposed' for opt of options should.exist builder.model[opt](), "#{opt} can be called" it 'renders', -> wrap = builder.$ 'g.nvd3.nv-historicalBarChart' should.exist wrap[0] it 'clears chart objects for no data', -> builder = new ChartBuilder nv.models.historicalBarChart() builder.buildover options, sampleData1, [] groups = builder.$ 'g' groups.length.should.equal 0, 'removes chart components' it 'has correct structure', -> cssClasses = [ '.nv-x.nv-axis' '.nv-y.nv-axis' '.nv-barsWrap' '.nv-bars' '.nv-legendWrap' ] for cssClass in cssClasses do (cssClass) -> should.exist builder.$("g.nvd3.nv-historicalBarChart #{cssClass}")[0] it 'can override axis ticks', -> builder.model.xAxis.ticks(34) builder.model.yAxis.ticks(56) builder.model.update() builder.model.xAxis.ticks().should.equal 34 builder.model.yAxis.ticks().should.equal 56 ================================================ FILE: test/mocha/legend.coffee ================================================ describe 'NVD3', -> describe 'Legend', -> sampleData1 = [ {"values":[{"x":1,"y":2},{"x":3,"y":4},{"x":5,"y":6}],"key":"key 1"} {"values":[{"x":7,"y":8},{"x":9,"y":10},{"x":11,"y":12}],"key":"key 2"} {"values":[{"x":13,"y":14},{"x":15,"y":16},{"x":17,"y":18}],"key":"key 3"} ] sampleData2 = [ key: 'series 1' , key: 'series 2' , key: 'series 3' , key: 'series 4' ] legendOptions = margin: top: 0 right: 0 bottom: 0 left: 0 width: 100 height: 100 key: (d) -> d.key color: nv.utils.defaultColor() align: true rightAlign: false updateState: true radioButtonMode: false builder = null beforeEach -> builder = new ChartBuilder nv.models.legend() builder.build legendOptions, sampleData1 legend = builder.model for opt, val of legendOptions legend[opt](val) afterEach -> builder.teardown() it 'api check', -> legend = builder.model for opt, val of legendOptions should.exist legend[opt](), "#{opt} can be called" it 'exists', -> legend = builder.$('.nvd3.nv-legend') should.exist legend[0], '.nvd3.nv-legend' describe 'appends items correctly', -> for item, i in sampleData1 do (item, i) -> key = item.key it "'#{key}' text, position and structure", -> nvSeries = builder.$(".nvd3.nv-legend .nv-series")[i] transformCalculated = "translate(0,#{i*20+5})" transform = nvSeries.getAttribute 'transform' transform.should.be.equal transformCalculated nvLegendSymbol = nvSeries.querySelector('.nv-legend-symbol') nvLegendText = nvSeries.querySelector('.nv-legend-text') should.exist nvLegendSymbol should.exist nvLegendText nvLegendText.textContent.should.be.equal key describe 'clicking and double clicking', -> it 'clicking one legend turns it off', -> legendItems = builder.$ '.nv-legend .nv-series' legendItems.length.should.equal 3 clickFn = d3.select(legendItems[0]).on 'click' clickFn(sampleData1[0]) sampleData1[0].disabled.should.equal true clickFn(sampleData1[1]) sampleData1[1].disabled.should.equal true clickFn(sampleData1[2]) sampleData1[0].disabled.should.equal false sampleData1[1].disabled.should.equal false sampleData1[2].disabled.should.equal false it 'double clicking legend keeps only one on', -> legendItems = builder.$ '.nv-legend .nv-series' clickFn = d3.select(legendItems[0]).on 'dblclick' clickFn(sampleData1[0]) sampleData1[0].disabled.should.equal false sampleData1[1].disabled.should.equal true sampleData1[2].disabled.should.equal true it 'updating legend data does not break double click (issue 784)', -> builder.updateData sampleData2 legendItems = builder.$ '.nv-legend .nv-series' clickFn = d3.select(legendItems[0]).on 'dblclick' clickFn(sampleData2[0]) sampleData2[0].disabled.should.equal false sampleData2[1].disabled.should.equal true sampleData2[2].disabled.should.equal true sampleData2[3].disabled.should.equal true it 'legend padding', -> builder = new ChartBuilder nv.models.legend() builder.build {padding: 40}, sampleData1 legendItems = builder.$ '.nv-legend .nv-series' xSpacing = [0, 80, 160] for legend,i in legendItems transform = legend.getAttribute 'transform' transform.should.equal "translate(#{xSpacing[i]},5)" ================================================ FILE: test/mocha/line.coffee ================================================ describe 'NVD3', -> describe 'Line Chart', -> sampleData1 = [ key: 'Series 1' values: [ [-1,-1] [0,0] [1,1] [2,2] ] ] sampleData2 = [ key: 'Series 1' classed: 'dashed' values: [ [-1,-3] [0,6] [1,12] [2,18] ] , key: 'Series 2' values: [ [-1,-4] [0,7] [1,13] [2,14] ] , key: 'Series 3' values: [ [-1,-5] [0,7.2] [1,11] [2,18.5] ] ] options = x: (d)-> d[0] y: (d)-> d[1] margin: top: 30 right: 20 bottom: 50 left: 75 color: nv.utils.defaultColor() height: 400 width: 800 showLegend: true showXAxis: true showYAxis: true rightAlignYAxis: true useInteractiveGuideline: true noData: 'No Data Available' duration: 0 clipEdge: false isArea: (d)-> d.area defined: (d)-> true interpolate: 'linear' builder = null beforeEach -> builder = new ChartBuilder nv.models.lineChart() builder.build options, sampleData1 afterEach -> builder.teardown() it 'api check', -> should.exist builder.model.options, 'options exposed' for opt of options should.exist builder.model[opt](), "#{opt} can be called" builder.model.update() it 'renders', -> wrap = builder.$ 'g.nvd3.nv-lineChart' should.exist wrap[0] it 'no data text', -> builder = new ChartBuilder nv.models.lineChart() builder.build options, [] noData = builder.$ '.nv-noData' noData[0].textContent.should.equal 'No Data Available' it 'clears chart objects for no data', -> builder = new ChartBuilder nv.models.lineChart() builder.buildover options, sampleData1, [] groups = builder.$ 'g' groups.length.should.equal 0, 'removes chart components' it 'has correct structure', -> cssClasses = [ '.nv-x.nv-axis' '.nv-y.nv-axis' '.nv-linesWrap' '.nv-legendWrap' '.nv-line' '.nv-scatter' '.nv-legend' ] for cssClass in cssClasses do (cssClass) -> should.exist builder.$("g.nvd3.nv-lineChart #{cssClass}")[0] it 'can override axis ticks', -> builder.model.xAxis.ticks(34) builder.model.yAxis.ticks(56) builder.model.update() builder.model.xAxis.ticks().should.equal 34 builder.model.yAxis.ticks().should.equal 56 it 'can add custom CSS class to series', -> builder.updateData sampleData2 classed = builder.$ '.nv-linesWrap .nv-groups .nv-group.dashed' # Since classing has been implemented at the data-level for # scatter points, there will actually be 2 elements matching # the above selector, one for the scatter g element, # and one for the line. classed.length.should.equal 2, 'dashed class exists' scatter = builder.$ '.nv-scatterWrap .nv-groups .nv-group.dashed' scatter.length.should.equal 1, 'one classed element is from scatter' it 'shows focus chart when focusEnable is set to true', -> builder.model.focusEnable(true).update(); focus = builder.$ '.nv-focusWrap .nv-focus' should.exist focus[0] it 'hides focus chart when focusEnable is set to false', -> builder.model.focusEnable(true).update(); builder.model.focusEnable(false).update(); focusWrap = builder.$ '.nv-focusWrap' focusWrap[0].style.display.should.equal 'none' it 'does not reset selected focus range when focusEnable is set to false', -> builder.model.focusEnable(true).update(); builder.model.brushExtent([0, 1]).update(); builder.model.focusEnable(false).update(); builder.model.brushExtent()[0].should.equal 0 builder.model.brushExtent()[1].should.equal 1 ================================================ FILE: test/mocha/multibar-horizontal.coffee ================================================ describe 'NVD3', -> describe 'MultiBar Horizontal Chart', -> sampleData1 = [ key: 'Series 1' values: [ {label: 'America', value: 100} {label: 'Europe', value: 200} {label: 'Asia', value: 50} {label: 'Africa', value: 70} ] , key: 'Series 2' values: [ {label: 'America', value: 110} {label: 'Europe', value: 230} {label: 'Asia', value: 51} {label: 'Africa', value: 78} ] , key: 'Series 3' values: [ {label: 'America', value: 230} {label: 'Europe', value: 280} {label: 'Asia', value: 31} {label: 'Africa', value: 13} ] ] options = x: (d)-> d.label y: (d)-> d.value margin: top: 30 right: 20 bottom: 50 left: 75 width: 200 height: 200 color: nv.utils.defaultColor() stacked: false showControls: true showLegend: true showXAxis: true showYAxis: true noData: 'No Data Available' duration: 0 builder = null beforeEach -> builder = new ChartBuilder nv.models.multiBarHorizontalChart() builder.build options, sampleData1 afterEach -> builder.teardown() it 'api check', -> should.exist builder.model.options, 'options exposed' for opt of options should.exist builder.model[opt](), "#{opt} can be called" it 'renders', -> wrap = builder.$ 'g.nvd3.nv-multiBarHorizontalChart' should.exist wrap[0] it 'clears chart objects for no data', -> builder = new ChartBuilder nv.models.multiBarHorizontalChart() builder.buildover options, sampleData1, [] groups = builder.$ 'g' groups.length.should.equal 0, 'removes chart components' it 'has correct structure', -> cssClasses = [ '.nv-x.nv-axis' '.nv-y.nv-axis' '.nv-barsWrap' '.nv-multibarHorizontal' '.nv-legendWrap' '.nv-controlsWrap' ] for cssClass in cssClasses do (cssClass) -> should.exist builder.$("g.nvd3.nv-multiBarHorizontalChart #{cssClass}")[0] it 'renders bars', -> bars = builder.$('g.nvd3.nv-multiBarHorizontalChart .nv-multibarHorizontal .nv-bar') bars.should.have.length 12 it 'can override axis ticks', -> builder.model.xAxis.ticks(34) builder.model.yAxis.ticks(56) builder.model.update() builder.model.xAxis.ticks().should.equal 34 builder.model.yAxis.ticks().should.equal 56 ================================================ FILE: test/mocha/multibar.coffee ================================================ describe 'NVD3', -> describe 'MultiBar Chart', -> sampleData1 = [ key: 'Series 1' values: [ {label: 'America', value: 100} {label: 'Europe', value: 200} {label: 'Asia', value: 50} {label: 'Africa', value: 70} ] , key: 'Series 2' values: [ {label: 'America', value: 110} {label: 'Europe', value: 230} {label: 'Asia', value: 51} {label: 'Africa', value: 78} ] , key: 'Series 3' values: [ {label: 'America', value: 230} {label: 'Europe', value: 280} {label: 'Asia', value: 31} {label: 'Africa', value: 13} ] ] options = x: (d)-> d.label y: (d)-> d.value margin: top: 30 right: 20 bottom: 50 left: 75 width: 200 height: 200 color: nv.utils.defaultColor() showControls: true showLegend: true showXAxis: true showYAxis: true rightAlignYAxis: false reduceXTicks: true staggerLabels: true rotateLabels: 0 noData: 'No Data Available' duration: 0 builder = null beforeEach -> builder = new ChartBuilder nv.models.multiBarChart() builder.build options, sampleData1 afterEach -> builder.teardown() it 'api check', -> should.exist builder.model.options, 'options exposed' for opt of options should.exist builder.model[opt](), "#{opt} can be called" it 'renders', -> wrap = builder.$ 'g.nvd3.nv-multiBarWithLegend' should.exist wrap[0] it 'clears chart objects for no data', -> builder = new ChartBuilder nv.models.multiBarChart() builder.buildover options, sampleData1, [] groups = builder.$ 'g' groups.length.should.equal 0, 'removes chart components' it 'has correct structure', -> cssClasses = [ '.nv-x.nv-axis' '.nv-y.nv-axis' '.nv-barsWrap' '.nv-multibar' '.nv-legendWrap' '.nv-controlsWrap' ] for cssClass in cssClasses do (cssClass) -> should.exist builder.$("g.nvd3.nv-multiBarWithLegend #{cssClass}")[0] it 'renders bars', -> bars = builder.$("g.nvd3.nv-multiBarWithLegend .nv-multibar .nv-bar") bars.should.have.length 12 it 'can override axis ticks', -> builder.model.xAxis.ticks(34) builder.model.yAxis.ticks(56) builder.model.update() builder.model.xAxis.ticks().should.equal 34 builder.model.yAxis.ticks().should.equal 56 describe "useInteractiveGuideline", -> it "true", -> options.useInteractiveGuideline = true builder.build options, sampleData1 builder.$(".nv-multiBarWithLegend .nv-interactiveLineLayer").should.have.length 1 it "false", -> options.useInteractiveGuideline = false builder.build options, sampleData1 builder.$(".nv-multiBarWithLegend .nv-interactiveLineLayer").should.have.length 0 ================================================ FILE: test/mocha/pie.coffee ================================================ describe 'NVD3', -> describe 'Pie Chart', -> sampleData1 = [ {label: 'America', value: 100} {label: 'Europe', value: 200} {label: 'Asia', value: 50} {label: 'Africa', value: 70} ] options = x: (d)-> d.label y: (d)-> d.value margin: top: 30 right: 20 bottom: 50 left: 75 width: 200 height: 200 color: nv.utils.defaultColor() showLegend: true valueFormat: (d)-> d.toFixed 2 showLabels: true labelsOutside: true donut: false donutRatio: 0.5 labelThreshold: 0.02 labelType: 'key' noData: 'No Data Available' duration: 0 startAngle: false endAngle: false padAngle: false cornerRadius: 0 labelSunbeamLayout: false builder = null beforeEach -> builder = new ChartBuilder nv.models.pieChart() builder.build options, sampleData1 afterEach -> builder.teardown() it 'api check', -> should.exist builder.model.options, 'options exposed' for opt of options should.exist builder.model[opt](), "#{opt} can be called" describe 'renders', -> wrap = null labels = null beforeEach -> wrap = builder.$ 'g.nvd3.nv-pieChart' labels = wrap[0].querySelectorAll('.nv-label text') it '.nv-pieChart', -> should.exist wrap[0] it 'can access margin', -> builder.model.margin top: 31 right: 21 bottom: 51 left: 76 m = builder.model.margin() m.should.deep.equal top: 31 right: 21 bottom: 51 left: 76 describe 'labels correctly', -> it "[#{sampleData1.length}] labels", -> wrap[0].querySelectorAll('.nv-label').should.have.length sampleData1.length for item, i in sampleData1 do (item, i) -> it "label '#{item.label}'", -> item.label.should.be.equal labels[i].textContent it 'clears chart objects for no data', -> builder = new ChartBuilder nv.models.pieChart() builder.buildover options, sampleData1, [] groups = builder.$ 'g' groups.length.should.equal 0, 'removes chart components' it 'has correct structure', -> cssClasses = [ '.nv-pieWrap' '.nv-pie' '.nv-pieLabels' '.nv-legendWrap' ] for cssClass in cssClasses do (cssClass) -> should.exist builder.$("g.nvd3.nv-pieChart #{cssClass}")[0] it 'can handle donut mode and options', (done)-> builder.teardown() options.donut = true options.labelSunbeamLayout = true options.startAngle = (d)-> d.startAngle/2 - Math.PI/2 options.endAngle = (d)-> d.endAngle/2 - Math.PI/2 builder.build options, sampleData1 done() it 'can handle cornerRadius and padAngle options', (done)-> builder.teardown() options.padAngle = 5 options.cornerRadius = 5 builder.build options, sampleData1 done() it 'can render pie labels in other formats', -> opts = x: (d)-> d.label y: (d)-> d.value labelType: 'value' valueFormat: d3.format('.2f') builder2 = new ChartBuilder nv.models.pie() builder2.build opts, [sampleData1] labels = builder2.$ '.nv-pieLabels .nv-label text' labels.length.should.equal 4 expected = ['100.00','200.00','50.00','70.00'] for label,i in labels label.textContent.should.equal expected[i] # Test labelType = 'percent' builder2.teardown() opts.labelType = 'percent' opts.valueFormat = d3.format('%') builder2.build opts, [sampleData1] labels = builder2.$ '.nv-pieLabels .nv-label text' labels.length.should.equal 4 expected = ['24%','48%','12%','17%'] for label,i in labels label.textContent.should.equal expected[i] ================================================ FILE: test/mocha/sankey.coffee ================================================ describe 'NVD3', -> describe 'Sankey Chart', -> sampleData1 = nodes: [ {'node': 1, 'name': 'Test 1'} {'node': 2, 'name': 'Test 2'} {'node': 3, 'name': 'Test 3'} {'node': 4, 'name': 'Test 4'} {'node': 5, 'name': 'Test 5'} {'node': 6, 'name': 'Test 6'} ] links: [ {'source': 0, 'target': 1, 'value': 2295} {'source': 0, 'target': 5, 'value': 1199} {'source': 1, 'target': 2, 'value': 1119} {'source': 1, 'target': 5, 'value': 1176} {'source': 2, 'target': 3, 'value': 487} {'source': 2, 'target': 5, 'value': 632} {'source': 3, 'target': 4, 'value': 301} {'source': 3, 'target': 5, 'value': 186} ] options = margin: top: 30 right: 20 bottom: 50 left: 75 width: 200 height: 200 units: 'test' format: -> linkTitle: -> 'link title test' nodeWidth: 77 nodePadding: 10 nodeStyle: nodeFillColor: -> '#f00' nodeStrokeColor: -> '#00f' nodeTitle: -> 'testing the title' builder = null beforeEach -> builder = new ChartBuilder nv.models.sankeyChart() builder.build options, sampleData1 afterEach -> builder.teardown() it 'api check', -> should.exist builder.model.options, 'options exposed' for opt of options should.exist builder.model[opt](), "#{opt} can be called" it 'renders', -> wrap = builder.$ 'g.nvd3.nv-sankeyChart' should.exist wrap[0] it 'has correct structure', -> cssClasses = [ '.node' '.link' ] for cssClass in cssClasses do (cssClass) -> should.exist builder.$("g.nvd3.nv-sankeyChart #{cssClass}")[0] it 'renders nodes', -> nodes = builder.$("g.nvd3.nv-sankeyChart .node") nodes.should.have.length 6 it 'nodes has the right width', -> should.exist builder.$("g.nvd3.nv-sankeyChart .node rect[width]")[0] builder.$("g.nvd3.nv-sankeyChart .node rect[width]")[0].width.animVal.value.should.equal 77 it 'renders links', -> links = builder.$("g.nvd3.nv-sankeyChart .link") links.should.have.length 8 it 'link titles has the test text', -> link = builder.$("g.nvd3.nv-sankeyChart .link title") link[0].textContent.should.equal 'link title test' ================================================ FILE: test/mocha/scatter.coffee ================================================ describe 'NVD3', -> describe 'Scatter Chart', -> sampleData1 = [ key: 'Series 1' slope: 0.5 intercept: 0.2 values: [ [-1,-1] [0,0] [1,1] [2,2] ] ] sampleData2 = [ key: 'Series 1' values: [ [-1,-3] [0,6] [1,12] [2,18] ] , key: 'Series 2' values: [ [-1,-4] [0,7] [1,13] [2,14] ] ] options = x: (d)-> d[0] y: (d)-> d[1] margin: right: 20 bottom: 50 left: 75 width: 200 height: 200 color: nv.utils.defaultColor() showDistX: true showDistY: true showLegend: true showXAxis: true showYAxis: true rightAlignYAxis: false noData: 'No Data Available' duration: 0 builder = null beforeEach -> builder = new ChartBuilder nv.models.scatterChart() builder.build options, sampleData1 afterEach -> builder.teardown() it 'api check', -> should.exist builder.model.options, 'options exposed' for opt of options should.exist builder.model[opt], "#{opt} exists" should.exist builder.model[opt](), "#{opt} can be called" it 'renders', -> wrap = builder.$ 'g.nvd3.nv-scatterChart' should.exist wrap[0] it 'clears chart objects for no data', -> builder = new ChartBuilder nv.models.scatterChart() builder.buildover options, sampleData1, [] groups = builder.$ 'g' groups.length.should.equal 0, 'removes chart components' it 'has correct structure', -> cssClasses = [ '.nv-background' '.nv-x.nv-axis' '.nv-y.nv-axis' '.nv-scatterWrap' '.nv-distWrap' '.nv-legendWrap' ] for cssClass in cssClasses do (cssClass) -> should.exist builder.$("g.nvd3.nv-scatterChart #{cssClass}")[0] it 'has data points', -> points = builder.$ '.nv-groups .nv-series-0 .nv-point' points.should.have.length 4 it 'has a legend', -> legend = builder.$ '.nv-legendWrap' should.exist legend, 'legend exists' it 'shows no data message', -> builder.teardown() builder.build options, [] noData = builder.$ 'text.nv-noData' should.exist noData[0] noData[0].textContent.should.equal 'No Data Available' it 'can update with new data', -> d3.select(builder.svg).datum(sampleData2) builder.model.update() points1 = builder.$ '.nv-groups .nv-series-0 .nv-point' points1.should.have.length 4 points2 = builder.$ '.nv-groups .nv-series-1 .nv-point' points2.should.have.length 4 it 'scatterPlusLineChart', -> builder.teardown() sampleData3 = [ key: 'Series 1' values: [ [-1,-3] [0,6] [1,12] [2,18] ] slope: 0.1 inercept: 5 ] builder.build options, sampleData3 wrap = builder.$ 'g.nvd3.nv-scatterChart' should.exist wrap[0] lines = builder.$ 'g.nvd3 .nv-regressionLinesWrap .nv-regLines' should.exist lines[0], 'regression lines exist' it 'sets legend.width same as availableWidth', -> builder.model.legend.width() .should.equal builder.model.scatter.width() it 'translates nv-wrap after legend height calculated', -> builder.teardown() sampleData4 = [] for i in [0..40] sampleData4.push key: "Series #{i}" values: [ [Math.random(),Math.random()] ] builder.build options, sampleData4 transform = builder.$('.nv-wrap')[0].getAttribute('transform') transform.should.equal 'translate(75,830)' it 'can override axis ticks', -> builder.model.xAxis.ticks(34) builder.model.yAxis.ticks(56) builder.model.update() builder.model.xAxis.ticks().should.equal 34 builder.model.yAxis.ticks().should.equal 56 it 'only appends one nv-point-clips group', (done)-> builder2 = new ChartBuilder nv.models.scatterChart() builder2.build options, sampleData1 window.setTimeout -> builder2.model.update() window.setTimeout((-> pointClips = builder2.svg.querySelector '.nv-point-clips' should.exist pointClips, 'nv-point-clips exists' builder2.svg.querySelector('.nv-wrap.nv-scatter') .childElementCount.should.equal 3 builder2.teardown() done() ), 500) , 500 it 'sets nv-single-point class if only one data point', -> builder.teardown() singleData = [ key: 'Series1' values: [ [1,1] ] ] builder.build options, singleData builder.svg.querySelector('.nv-wrap.nv-scatter') .className.should.contain 'nv-single-point' builder.updateData sampleData1 builder.svg.querySelector('.nv-wrap.nv-scatter') .className.should.not.contain 'nv-single-point' builder.updateData singleData builder.svg.querySelector('.nv-wrap.nv-scatter') .className.should.contain 'nv-single-point' it 'should set color property if not specified', -> builder.teardown() singleData = [ key: 'Series1' values: [ [1,1] ] ] builder.build options, singleData should.exist singleData[0].color ================================================ FILE: test/mocha/sparkline.coffee ================================================ describe 'NVD3', -> describe 'Sparkline Chart', -> sampleData1 = [ {x: 1, y: 100} {x: 2, y: 101} {x: 3, y: 99} {x: 4, y: 56} {x: 5, y: 87} ] options = x: (d)-> d.x y: (d)-> d.y margin: top: 30 right: 20 bottom: 50 left: 75 width: 200 height: 50 xTickFormat: (d)-> d yTickFormat: (d)-> d.toFixed 2 showLastValue: true alignValue: true rightAlignValue: false noData: 'No Data Available' builder = null beforeEach -> builder = new ChartBuilder nv.models.sparklinePlus() builder.build options, sampleData1 afterEach -> builder.teardown() it 'api check', -> should.exist builder.model.options, 'options exposed' for opt of options should.exist builder.model[opt](), "#{opt} can be called" it 'clears chart objects for no data', -> builder = new ChartBuilder nv.models.sparklinePlus() builder.buildover options, sampleData1, [] groups = builder.$ 'g' groups.length.should.equal 0, 'removes chart components' it 'renders', -> wrap = builder.$ 'g.nvd3.nv-sparklineplus' should.exist wrap[0] it 'has correct structure', -> cssClasses = [ '.nv-sparklineWrap' '.nv-sparkline' '.nv-minValue' '.nv-maxValue' '.nv-currentValue' '.nv-valueWrap' ] for cssClass in cssClasses do(cssClass) -> should.exist builder.$("g.nvd3.nv-sparklineplus #{cssClass}")[0] ================================================ FILE: test/mocha/stacked.coffee ================================================ describe 'NVD3', -> describe 'Stacked Area Chart', -> sampleData1 = [ key: 'Series 1' values: [ [-1,-1] [0,0] [1,1] [2,2] ] ] sampleData2 = [ key: 'Series 1' values: [ [-1,-3] [0,6] [1,12] [2,18] ] , key: 'Series 2' values: [ [-1,-4] [0,7] [1,13] [2,14] ] ] options = x: (d)-> d[0] y: (d)-> d[1] margin: top: 30 right: 20 bottom: 50 left: 75 color: nv.utils.defaultColor() showLegend: true showControls: true showXAxis: true showYAxis: true rightAlignYAxis: false useInteractiveGuideline: true noData: 'No Data Available' duration: 0 controlLabels: stacked: 'Stacked' stream: 'Stream' expanded: 'Expanded' builder = null beforeEach -> builder = new ChartBuilder nv.models.stackedAreaChart() builder.build options, sampleData1 afterEach -> builder.teardown() it 'api check', -> should.exist builder.model.options, 'options exposed' for opt of options should.exist builder.model[opt](), "#{opt} can be called" it 'renders', -> wrap = builder.$ 'g.nvd3.nv-stackedAreaChart' should.exist wrap[0] it 'clears chart objects for no data', -> builder = new ChartBuilder nv.models.stackedAreaChart() builder.buildover options, sampleData1, [] groups = builder.$ 'g' groups.length.should.equal 0, 'removes chart components' it 'has correct structure', -> cssClasses = [ '.nv-x.nv-axis' '.nv-y.nv-axis' '.nv-stackedWrap' '.nv-legendWrap' '.nv-controlsWrap' '.nv-interactive' ] for cssClass in cssClasses do (cssClass) -> should.exist builder.$("g.nvd3.nv-stackedAreaChart #{cssClass}")[0] it 'formats y-Axis correctly depending on stacked style', -> chart = nv.models.stackedAreaChart() chart.yAxis.tickFormat (d)-> "<#{d}>" builder = new ChartBuilder chart builder.build options, sampleData1 yTicks = builder.$ '.nv-y.nv-axis .tick text' yTicks.should.have.length.greaterThan 2 for tick in yTicks tick.textContent.should.match /<.*?>/ # Update chart to 'Expand' mode chart.dispatch.changeState style: 'expand' chart.stacked.style().should.equal 'expand' newTickFormat = chart.yAxis.tickFormat() newTickFormat(1).should.equal '100%' chart.dispatch.changeState style: 'stacked' chart.stacked.style().should.equal 'stacked' newTickFormat = chart.yAxis.tickFormat() newTickFormat(1).should.equal '<1>' it 'can override axis ticks', -> builder.model.xAxis.ticks(34) builder.model.yAxis.ticks(56) builder.model.update() builder.model.xAxis.ticks().should.equal 34 builder.model.yAxis.ticks().should.equal 56 it 'if stacked.offset is "wiggle", y ticks is zero', -> builder.model.stacked.offset 'wiggle' builder.model.update() builder.model.yAxis.ticks().should.equal 0 it 'should allow stream-center to be used', -> builder.model.controlOptions(['Stream_Center']) builder.model.update() builder.model.controls.dispatch.legendClick({ style: 'stream-center', disabled: true }) builder.model.style().should.equal 'stream-center' it 'should set color property if not specified', -> sampleData3 = [ key: 'Series 1' values: [ [-1,-1] [0,0] [1,1] [2,2] ] ] builder.build options, sampleData3 should.exist sampleData3[0].color ================================================ FILE: test/mocha/sunburst.coffee ================================================ describe 'NVD3', -> describe 'Sunburst', -> sampleData1 = [{ "name": "flare", "children": [ { "name": "analytics", "children": [ { "name": "cluster", "children": [ {"name": "AgglomerativeCluster", "size": 3938}, {"name": "CommunityStructure", "size": 3812}, {"name": "HierarchicalCluster", "size": 6714}, {"name": "MergeEdge", "size": 743} ] }, { "name": "graph", "children": [ {"name": "BetweennessCentrality", "size": 3534}, {"name": "LinkDistance", "size": 5731}, {"name": "MaxFlowMinCut", "size": 7840}, {"name": "ShortestPaths", "size": 5914}, {"name": "SpanningTree", "size": 3416} ] }, { "name": "optimization", "children": [ {"name": "AspectRatioBanker", "size": 7074} ] } ] }, { "name": "physics", "children": [ {"name": "DragForce", "size": 1082}, {"name": "GravityForce", "size": 1336}, {"name": "IForce", "size": 319}, {"name": "NBodyForce", "size": 10498}, {"name": "Particle", "size": 2822}, {"name": "Simulation", "size": 9983}, {"name": "Spring", "size": 2213}, {"name": "SpringForce", "size": 1681} ] }, { "name": "vis", "children": [ { "name": "data", "children": [ {"name": "Data", "size": 20544}, {"name": "DataList", "size": 19788}, {"name": "DataSprite", "size": 10349}, {"name": "EdgeSprite", "size": 3301}, {"name": "NodeSprite", "size": 19382}, { "name": "render", "children": [ {"name": "ArrowType", "size": 698}, {"name": "EdgeRenderer", "size": 5569}, {"name": "IRenderer", "size": 353}, {"name": "ShapeRenderer", "size": 2247} ] }, {"name": "ScaleBinding", "size": 11275}, {"name": "Tree", "size": 7147}, {"name": "TreeBuilder", "size": 9930} ] }, { "name": "operator", "children": [ { "name": "distortion", "children": [ {"name": "BifocalDistortion", "size": 4461}, {"name": "Distortion", "size": 6314}, {"name": "FisheyeDistortion", "size": 3444} ] }, { "name": "encoder", "children": [ {"name": "ColorEncoder", "size": 3179}, {"name": "Encoder", "size": 4060}, {"name": "PropertyEncoder", "size": 4138}, {"name": "ShapeEncoder", "size": 1690}, {"name": "SizeEncoder", "size": 1830} ] }, { "name": "filter", "children": [ {"name": "FisheyeTreeFilter", "size": 5219}, {"name": "GraphDistanceFilter", "size": 3165}, {"name": "VisibilityFilter", "size": 3509} ] }, {"name": "IOperator", "size": 1286}, { "name": "label", "children": [ {"name": "Labeler", "size": 9956}, {"name": "RadialLabeler", "size": 3899}, {"name": "StackedAreaLabeler", "size": 3202} ] }, { "name": "layout", "children": [ {"name": "AxisLayout", "size": 6725}, {"name": "BundledEdgeRouter", "size": 3727}, {"name": "CircleLayout", "size": 9317}, {"name": "CirclePackingLayout", "size": 12003}, {"name": "DendrogramLayout", "size": 4853}, {"name": "ForceDirectedLayout", "size": 8411}, {"name": "IcicleTreeLayout", "size": 4864}, {"name": "IndentedTreeLayout", "size": 3174}, {"name": "Layout", "size": 7881}, {"name": "NodeLinkTreeLayout", "size": 12870}, {"name": "PieLayout", "size": 2728}, {"name": "RadialTreeLayout", "size": 12348}, {"name": "RandomLayout", "size": 870}, {"name": "StackedAreaLayout", "size": 9121}, {"name": "TreeMapLayout", "size": 9191} ] }, {"name": "Operator", "size": 2490}, {"name": "OperatorList", "size": 5248}, {"name": "OperatorSequence", "size": 4190}, {"name": "OperatorSwitch", "size": 2581}, {"name": "SortOperator", "size": 2023} ] }, {"name": "Visualization", "size": 16540} ] } ] }] options = margin: top: 30 right: 20 bottom: 50 left: 75 width: 200 height: 200 color: d3.scale.category20c() duration: 0 builder = null beforeEach -> builder = new ChartBuilder nv.models.sunburst() builder.build options, sampleData1 afterEach -> builder.teardown() it 'api check', -> should.exist builder.model.options, 'options exposed' for opt of options should.exist builder.model[opt](), "#{opt} can be called" describe 'renders', -> wrap = null beforeEach -> wrap = builder.$ 'g.nvd3.nv-sunburst' it '.nv-pieChart', -> should.exist wrap[0] it 'can access margin', -> builder.model.margin top: 31 right: 21 bottom: 51 left: 76 m = builder.model.margin() m.should.deep.equal top: 31 right: 21 bottom: 51 left: 76 ================================================ FILE: test/mocha/test-utils.coffee ================================================ ### Utility to build an NVD3 chart. ### class ChartBuilder # @model should be something like nv.models.scatterChart() constructor: (@model)-> ### options: an object hash of chart options. data: sample data to pass in to chart. This method builds a chart and puts it on the element. ### build: (options, data)-> @svg = document.createElement 'svg' document.querySelector('body').appendChild @svg for opt, val of options unless @model[opt]? console.warn "#{opt} not property of model." else @model[opt](val) @updateData data ### Update the data while preserving the chart model. ### updateData: (data)-> d3.select(@svg).datum(data).call(@model) ### options: an object hash of chart options. data: sample data to pass in to initial chart render chart data2: sample data to pass to second chart render This method builds a chart, puts it on the element, and then rebuilds using the second set of data Useful for testing the results of transitioning and the 'noData' state after a chart has had data ### buildover: (options, data, data2)-> @svg = document.createElement 'svg' document.querySelector('body').appendChild @svg for opt, val of options unless @model[opt]? console.warn "#{opt} not property of model." else @model[opt](val) #Set initial data chart = d3.select(@svg) chart.datum(data) .call(@model) #Reset the data chart.datum(data2) .call(@model) # Removes chart from element. teardown: -> if @svg? document.querySelector('body').removeChild @svg # Runs a simple CSS selector to retrieve elements $: (cssSelector)-> @svg.querySelectorAll cssSelector ================================================ FILE: test/mocha/utils.coffee ================================================ describe 'NVD3', -> describe 'Utils', -> objects = [ 'nv.utils.windowSize' 'nv.utils.windowResize' 'nv.utils.getColor' 'nv.utils.defaultColor' 'nv.utils.customTheme' 'nv.utils.pjax' 'nv.utils.calcApproxTextWidth' 'nv.utils.NaNtoZero' 'nv.utils.renderWatch' 'nv.utils.deepExtend' 'nv.utils.state' 'nv.utils.optionsFunc' 'nv.utils.sanitizeHeight' 'nv.utils.sanitizeWidth' 'nv.utils.availableHeight' 'nv.utils.availableWidth' 'nv.utils.noData' ] describe 'has ', -> for obj in objects it " #{obj} object", -> should.exist eval obj it 'has working nv.utils.NaNtoZero function', -> nv.utils.NaNtoZero().should.be.equal 0 nv.utils.NaNtoZero(undefined ).should.be.equal 0 nv.utils.NaNtoZero(NaN).should.be.equal 0 nv.utils.NaNtoZero(null).should.be.equal 0 nv.utils.NaNtoZero(Infinity).should.be.equal 0 nv.utils.NaNtoZero(-Infinity).should.be.equal 0 nv.utils.NaNtoZero(1).should.be.equal 1 nv.utils.NaNtoZero(0).should.be.equal 0 nv.utils.NaNtoZero(-1).should.be.equal -1 it 'should return a function if passing a function into nv.utils.getColor', -> uno = (d,i) -> 1 nv.utils.getColor(uno).should.be.equal uno it 'should return a function wrapping an array if passing an array into nv.utils.getColor', -> arr = ['#fff', '#ccc', '#aaa', '#000'] returnedFunction = nv.utils.getColor(arr) returnedFunction({},0).should.be.equal '#fff' returnedFunction({},1).should.be.equal '#ccc' returnedFunction({},2).should.be.equal '#aaa' returnedFunction({},3).should.be.equal '#000' createCont = (wh = false)-> obj = document.createElement('div') obj.style.cssText = 'width:964px;height:404px' if wh d3.select(obj) describe 'Sanitize Height and Width for a Container', -> it 'provides default height and width', -> cont = createCont() expect(nv.utils.sanitizeHeight(null, cont)).to.equal 400 expect(nv.utils.sanitizeWidth(null, cont)).to.equal 960 expect(nv.utils.sanitizeHeight(undefined, cont)).to.equal 400 expect(nv.utils.sanitizeWidth(undefined, cont)).to.equal 960 expect(nv.utils.sanitizeHeight(0, cont)).to.equal 400 expect(nv.utils.sanitizeWidth(0, cont)).to.equal 960 it 'uses container width and height', -> cont = createCont(true) expect(nv.utils.sanitizeHeight(null, cont)).to.equal 404 expect(nv.utils.sanitizeWidth(null, cont)).to.equal 964 it 'uses given width and height', -> cont = createCont(true) expect(nv.utils.sanitizeHeight(408, cont)).to.equal 408 expect(nv.utils.sanitizeWidth(968, cont)).to.equal 968 describe 'Available Container Height and Width', -> it 'calculates height and width properly', -> cont = createCont(true) m = { left: 5, right: 6, top: 7, bottom: 8 } expect(nv.utils.availableHeight(300, cont, m)).to.equal 285 expect(nv.utils.availableWidth(300, cont, m)).to.equal 289 expect(nv.utils.availableHeight(0, cont, m)).to.equal 389 expect(nv.utils.availableWidth(0, cont, m)).to.equal 953 describe 'Interactive Bisect', -> it 'works with no accessor', -> list = [{ x:0 },{ x:1 },{ x:1 },{ x:2 },{ x:3 },{ x:5 },{ x:8 },{ x:13 },{ x:21 },{ x:34 }] expect(nv.interactiveBisect(list,7)).to.equal 6 runTest = (list, searchVal, accessor = null)-> xAcc = unless accessor? (d)-> d else accessor nv.interactiveBisect list, searchVal, xAcc it 'exists', -> expect(nv.interactiveBisect).to.exist it 'returns null when no array', -> expect(nv.interactiveBisect('bad', 'a')).to.equal null it 'basic test', -> expect(runTest([0,1,2,3,4,5], 3)).to.equal 3 it 'zero bound', -> expect(runTest([0,1,2,3,4,5], 0)).to.equal 0 it 'length bound', -> expect(runTest([0,1,2,3,4,5], 5)).to.equal 5 it 'negative number', -> expect(runTest([0,1,2,3,4,5], -4)).to.equal 0 it 'past the end', -> expect(runTest([0,1,2,3,4,5], 10)).to.equal 5 it 'floating point number 1', -> expect(runTest([0,1,2,3,4,5], 0.34)).to.equal 0 it 'floating point number 2', -> expect(runTest([0,1,2,3,4,5], 1.50001)).to.equal 2 it 'fibonacci - existing', -> list = [0,1,1,2,3,5,8,13,21,34] expect(runTest(list,8)).to.equal 6 it 'fibonacci - inbetween item (left)', -> list = [0,1,1,2,3,5,8,13,21,34] expect(runTest(list,15)).to.equal 7 it 'fibonacci - inbetween item (right)', -> list = [0,1,1,2,3,5,8,13,21,34] expect(runTest(list,20)).to.equal 8 it 'empty array', -> expect(runTest([],4)).to.equal 0 it 'single element array', -> expect(runTest([0],0)).to.equal 0 it 'single element array - negative bound', -> expect(runTest([0],-4)).to.equal 0 it 'single element array - past the end', -> expect(runTest([0],1)).to.equal 0 describe 'NoData Chart Clearing', -> sampleData1 = [ key: 'Series 1' values: [ [-1,-1] [0,0] [1,1] [2,2] ] ] options = x: (d)-> d[0] y: (d)-> d[1] margin: top: 30 right: 20 bottom: 50 left: 75 color: nv.utils.defaultColor() height: 400 width: 800 showLegend: true showXAxis: true showYAxis: true rightAlignYAxis: true useInteractiveGuideline: true noData: 'No Data Available' duration: 0 clipEdge: false isArea: (d)-> d.area defined: (d)-> true interpolate: 'linear' it 'shows no data text', -> builder = new ChartBuilder nv.models.lineChart() builder.build options, [] noData = builder.$ '.nv-noData' noData[0].textContent.should.equal 'No Data Available' it 'clears chart objects for no data', -> builder = new ChartBuilder nv.models.lineChart() builder.buildover options, sampleData1, [] groups = builder.$ 'g' groups.length.should.equal 0, 'removes chart components' ================================================ FILE: test/multiBarChartTest.html ================================================

Multibar chart test cases - feel free to add more tests

Transition delay 1200ms, 0 non-stackable series and bar color set.
No transitionDuration or delay, 0 non-stackable series and no bar color set.
No transitionDuration or delay, 1 non-stackable series and no bar color set.
TransitionDuration or delay 500ms, 1 non-stackable series(first) and color set.
TransitionDuration or delay 500ms, 1 non-stackable series(mid) and color set.
TransitionDuration or delay 500ms, 1 non-stackable series(last) and color set.
Chart with single series, no group spacing.
Chart with 1 data point
Chart with 2 data points
Chart with 18 series, 7 data points per series and no non-stackable series.
Chart with no stackable series -> same as grouped graphs
Chart with multi stackable series
Chart with multi more non stackable series
Chart with 0 data points
================================================ FILE: test/multiBarHorizontalChart.html ================================================
Chart with forceY([10])
================================================ FILE: test/node/GruntFile.js ================================================ module.exports = function(grunt) { grunt.initConfig({ browserify: { js: { src: './nodeTest.js', dest: './build/nodeTest.js', }, }, copy: { all: { src: ['../../build/nv.d3.css'], dest: './build/nv.d3.css', }, }, }); grunt.loadNpmTasks('grunt-browserify'); grunt.loadNpmTasks('grunt-contrib-copy'); grunt.registerTask('default', ['browserify', 'copy']); }; ================================================ FILE: test/node/README.md ================================================ Build steps: - Build `nvd3`. - Build the example. - Start an HTTP server. nvd3 $ grunt production nvd3 $ cd test/node nvd3/test/node $ npm install . nvd3/test/node $ grunt nvd3/test/node $ python -m SimpleHTTPServer 8000 Browse to `http://localhost:8000/nodeTest.html` ================================================ FILE: test/node/nodeTest.html ================================================ Node Test
================================================ FILE: test/node/nodeTest.js ================================================ window.d3 = require('d3'); var nv = require('../../build/nv.d3'); var invariant = require('invariant'); window.addEventListener("load", function load(event) { window.removeEventListener("load", load, false); invariant(typeof(nv) !== 'undefined', "Cannot resolve NVD3 via CommonJS"); nv.addGraph(function() { var chart = nv.models.bulletChart(); d3.select('#chart svg') .datum(exampleData()) .transition().duration(1000) .call(chart); return chart; }); }, false); function exampleData() { return { "title":"Revenue", "subtitle":"US$, in thousands", "ranges":[150,225,300], "measures":[220], "markers":[250] } } ================================================ FILE: test/node/package.json ================================================ { "name": "node-test", "version": "0.0.0", "private": true, "dependencies": { "d3": "<=3.4.4", "invariant": "1.0.2" }, "devDependencies": { "grunt-browserify": "3.3.0", "grunt-contrib-copy": "~0.4.1" } } ================================================ FILE: test/pieChartTest.html ================================================

Standard Pie Chart

Donut pie chart

Pie chart with 30 series'

Pie chart with percent label type

Empty array passed in

Series' have only zero values

NaN, null, undefined values passed in

Half donut pie chart with outside label

================================================ FILE: test/polylinearTest.html ================================================

Test cases for Domain and Range overrides - Example of a polylinear scale

Line chart: yDomain = [0,2,200], yRange = [500,50,0]
Historical bar chart: yDomain = [0,2,130], yRange = [500,50,0]
Notes: The chart.yRange() and chart.xRange() properties are an advanced feature. They are useful in situations where your data has wild extremes: ie, you have lots of smaller numbers, and lots of really big numbers.

Without a polylinear scale, those really big data points will overwhelm the small points.

Please look at the examples to understand how polylinear scales work. Comment/uncomment the lines that alter yDomain and yRange to see the effect it has on the charts.
================================================ FILE: test/realTimeChartTest.html ================================================

Example showing real time chart updating

The chart below is a historical bar chart, which is ideal for visualizing time series data.
First, you need to update the data model for the chart. In the example, we append a random number every half a second. Then, you call chart.update().
================================================ FILE: test/scatterPlusLineChart.html ================================================
================================================ FILE: test/scrollTest.html ================================================

Charts:

Chart 1

================================================ FILE: test/scrollTest2.html ================================================

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

================================================ FILE: test/stackedAreaChartMissingData.html ================================================ ================================================ FILE: test/stackedAreaChartTest.html ================================================

Stacked area chart test cases - feel free to add more tests

Full chart example with new tooltip and guideline
Chart with old tooltips (with-transitions)
Chart with single point
Chart with two points
Chart with 'holes'
Total random points
Less than four points, old tooltips
No data
Data is all negative
================================================ FILE: test/stream_layers.js ================================================ /* Inspired by Lee Byron's test data generator. */ function stream_layers(n, m, o) { if (arguments.length < 3) o = 0; function bump(a) { var x = 1 / (.1 + Math.random()), y = 2 * Math.random() - .5, z = 10 / (.1 + Math.random()); for (var i = 0; i < m; i++) { var w = (i / m - y) * z; a[i] += x * Math.exp(-w * w); } } return d3.range(n).map(function() { var a = [], i; for (i = 0; i < m; i++) a[i] = o + o * Math.random(); for (i = 0; i < 5; i++) bump(a); return a.map(stream_index); }); } /* Another layer generator using gamma distributions. */ function stream_waves(n, m) { return d3.range(n).map(function(i) { return d3.range(m).map(function(j) { var x = 20 * j / m - i / 3; return 2 * x * Math.exp(-.5 * x); }).map(stream_index); }); } function stream_index(d, i) { return {x: i, y: Math.max(0, d)}; } ================================================ FILE: test/testScript.js ================================================ //A little snippet of D3 code that creates a button that lets you toggle whether a chart is the only one visible on a page or not. d3.selectAll(".chart button").on("click",function() { var thisId = this.parentElement.id; var chartContainer = d3.select("#" + thisId); if (chartContainer.attr("class").match("selected")) chartContainer.classed("selected",false); else chartContainer.classed("selected",true); d3.selectAll(".chart").style("display",function() { if (thisId === this.id) return "block"; if (d3.select(this).style("display") === "none") return "block"; else return "none"; }); window.onresize(); }); ================================================ FILE: test/teststyle.css ================================================ body { overflow-y:scroll; font-family: arial; } text { font: 12px sans-serif; } .chart { float:left; height: 500px; text-align: center; font-weight: bold; margin-bottom: 2em; } .chart.full { width: 100%; } .chart.half { width: 50%; } .chart.third { width: 33%; } .chart.selected { width: 100% !important; } .navigation a{ margin-right: 1em; } .navigation { margin-bottom: 1em; } ================================================ FILE: test/tinytest/nv-is-defined-test.js ================================================ // nv-is-defined-test.js Tinytest.add('nv object is defined', function(test) { test.isNotUndefined(nv, 'nv is undefined at global scope for Meteor'); }); ================================================ FILE: test/translateTest.html ================================================