├── .babelrc ├── .editorconfig ├── .eslintrc.json ├── .gitignore ├── .mocharc ├── .nycrc ├── .travis.yml ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE.md ├── Makefile ├── README.md ├── ROADMAP.md ├── bk_docs ├── API.md ├── development_setup.md └── svg_treemap.md ├── dist ├── dbox.js ├── dbox.js.map └── dbox.min.js ├── docs ├── .nojekyll ├── README.md ├── _sidebar.md ├── bars │ └── README.md ├── chart │ └── README.md └── index.html ├── index.dev.js ├── index.js ├── jsdocs.config.json ├── lib ├── chart.js └── helper.js ├── out ├── fonts │ ├── OpenSans-Bold-webfont.eot │ ├── OpenSans-Bold-webfont.svg │ ├── OpenSans-Bold-webfont.woff │ ├── OpenSans-BoldItalic-webfont.eot │ ├── OpenSans-BoldItalic-webfont.svg │ ├── OpenSans-BoldItalic-webfont.woff │ ├── OpenSans-Italic-webfont.eot │ ├── OpenSans-Italic-webfont.svg │ ├── OpenSans-Italic-webfont.woff │ ├── OpenSans-Light-webfont.eot │ ├── OpenSans-Light-webfont.svg │ ├── OpenSans-Light-webfont.woff │ ├── OpenSans-LightItalic-webfont.eot │ ├── OpenSans-LightItalic-webfont.svg │ ├── OpenSans-LightItalic-webfont.woff │ ├── OpenSans-Regular-webfont.eot │ ├── OpenSans-Regular-webfont.svg │ └── OpenSans-Regular-webfont.woff ├── index.html ├── scripts │ ├── linenumber.js │ └── prettify │ │ ├── Apache-License-2.0.txt │ │ ├── lang-css.js │ │ └── prettify.js └── styles │ ├── jsdoc-default.css │ ├── prettify-jsdoc.css │ └── prettify-tomorrow.css ├── package-lock.json ├── package.json ├── rollup.config.js └── test ├── bars.test.txt ├── chart.test.js ├── helper.test.js ├── index.test.txt ├── istanbul.reporter.js ├── mocha.opts └── scatter.test.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["env"] 3 | } 4 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: http://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | # Unix-style newlines with a newline ending every file 7 | [*] 8 | end_of_line = lf 9 | insert_final_newline = true 10 | indent_size = 2 11 | indent_style = space 12 | charset = utf-8 13 | 14 | [Makefile] 15 | indent_style = tab 16 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": true, 4 | "commonjs": true, 5 | "es6": true, 6 | "node": true 7 | }, 8 | "globals": { 9 | "ENV": true 10 | }, 11 | "extends": "eslint:recommended", 12 | "parserOptions": { 13 | "sourceType": "module" 14 | }, 15 | "rules": { 16 | "indent": ["error", 2], 17 | "linebreak-style": ["error", "unix"], 18 | "quotes": ["error", "single"], 19 | "semi": ["error", "always"], 20 | "one-line": [ 21 | true, 22 | "check-open-brace", 23 | "check-catch", 24 | "check-else", 25 | "check-whitespace" 26 | ], 27 | "no-console": ["warn", "always"] 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Coverage directory used by tools like istanbul 13 | coverage 14 | *.lcov 15 | 16 | # nyc test coverage 17 | .nyc_output 18 | 19 | # Dependency directories 20 | node_modules/ 21 | 22 | # Optional eslint cache 23 | .eslintcache 24 | 25 | # Optional REPL history 26 | .node_repl_history 27 | 28 | # Output of 'npm pack' 29 | *.tgz 30 | 31 | # Yarn Integrity file 32 | .yarn-integrity 33 | yarn.lock 34 | 35 | # dotenv environment variables file 36 | .env 37 | .env.test 38 | 39 | # parcel-bundler cache (https://parceljs.org/) 40 | .cache 41 | 42 | # rollup.js default build output 43 | # dist/ 44 | rollup.config.dev.js 45 | 46 | # Temporary folders 47 | tmp/ 48 | temp/ 49 | .DS_Store 50 | -------------------------------------------------------------------------------- /.mocharc: -------------------------------------------------------------------------------- 1 | test 2 | --require babel-polyfill 3 | --compilers js:babel-register 4 | -------------------------------------------------------------------------------- /.nycrc: -------------------------------------------------------------------------------- 1 | { 2 | "check-coverage": true, 3 | "per-file": true, 4 | "lines": 99, 5 | "statements": 99, 6 | "functions": 99, 7 | "branches": 99, 8 | "include": [ 9 | "src/**/*.js" 10 | ], 11 | "exclude": [ 12 | "src/**/*.spec.js" 13 | ], 14 | "reporter": [ 15 | "lcov", 16 | "text-summary" 17 | ], 18 | "require": [ 19 | "babel-register" 20 | ], 21 | "sourceMap": false, 22 | "instrument": false 23 | } 24 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "4.0" 4 | - "5.0" 5 | - "6.0" 6 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # 0.0.9 2 | 3 | ## @upgrades 4 | * Implemented Delegation Design instead of Object Oriented Design 5 | * helper.js - delegated general chart/layer data/functions with OLOO (Object linked to another object) 6 | * use of *.hasOwnProperty()* to verify properties 7 | 8 | ## @deprecated 9 | * Chart.prototype.generateScale() 10 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at info@dboxjs.org. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to DboxJS 2 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 DboxJs 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | install: 4 | for file in ../*/ ; \ 5 | do \ 6 | echo "$$file"; \ 7 | cd $$file; \ 8 | npm install; \ 9 | cd ../core; \ 10 | done 11 | 12 | pull: 13 | for file in ../*/ ; \ 14 | do \ 15 | echo "$$file"; \ 16 | cd $$file; \ 17 | git pull origin dev; \ 18 | cd ../core; \ 19 | done 20 | 21 | pull_master: 22 | for file in ../*/ ; \ 23 | do \ 24 | echo "$$file"; \ 25 | cd $$file; \ 26 | git pull origin master; \ 27 | cd ../core; \ 28 | done 29 | 30 | checkout_dev: 31 | for file in ../*/ ; \ 32 | do \ 33 | echo "$$file"; \ 34 | cd $$file; \ 35 | git checkout dev; \ 36 | cd ../core; \ 37 | done 38 | 39 | status: 40 | for file in ../*/ ; \ 41 | do \ 42 | echo "$$file"; \ 43 | cd $$file; \ 44 | git status; \ 45 | cd ../core; \ 46 | done 47 | 48 | fetch: 49 | for file in ../*/ ; \ 50 | do \ 51 | echo "$$file"; \ 52 | cd $$file; \ 53 | git fetch --all --prune; \ 54 | cd ../core; \ 55 | done 56 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Dbox.js 2 | 3 | A library to create easy reusable charts 4 | 5 | ## Dependencies 6 | 7 | Dbox uses `d3`, `d3-queue`, `d3-tip`, `lodash`, `topojson` 8 | 9 | ## Instalation 10 | 11 | Using npm 12 | 13 | ``` 14 | npm install @dboxjs/core 15 | ``` 16 | 17 | ## Usage 18 | 19 | Dbox uses one chart that allows to draw different layers 20 | 21 | ```javascript 22 | var config = { 23 | size: { 24 | width: width, 25 | height: 500, 26 | margin: { top: 20, right: 20, bottom: 30, left: 40 } 27 | }, 28 | xAxis: { 29 | scale: "time" 30 | } 31 | }; 32 | 33 | dbox 34 | .chart(config) 35 | .bindTo("#timeline-chart") 36 | .data({ csv: "assets/data/linea.csv" }) 37 | .layer(dbox.timeline) 38 | .x("year") 39 | .series(["tot"]) 40 | .color("species") 41 | .end() 42 | .draw(); 43 | ``` 44 | 45 | Check examples on [dboxjs.org](http://dboxjs.org) 46 | -------------------------------------------------------------------------------- /ROADMAP.md: -------------------------------------------------------------------------------- 1 | #ROADMAP 2 | 3 | ##Legend 4 | * Remove series on click 5 | 6 | ##Aestetics 7 | * title 8 | ** text 9 | ** color 10 | ** fontSize 11 | 12 | * subtitle 13 | ** text 14 | ** color 15 | ** fontSize 16 | 17 | * axes 18 | ** text 19 | ** color 20 | ** fontSize 21 | -------------------------------------------------------------------------------- /bk_docs/API.md: -------------------------------------------------------------------------------- 1 | # DboxJS API Reference 2 | 3 | DboxJS is a collection of modules that are designed to work together. The source and documentation for each module is available in its repository. 4 | 5 | ## Chart 6 | 7 | Main module. 8 | 9 | Methods for generating layers. 10 | 11 | * chart.config - define the layout 12 | * chart.size - define the size 13 | * chart.grid 14 | * chart.bindTo 15 | * chart.data - load the data 16 | * chart.layer 17 | * chart.getLayer 18 | * chart.draw 19 | 20 | ## Bars 21 | 22 | ## Heatmap 23 | 24 | Heatmap layer module. 25 | 26 | Methods for generating heatmap layers. 27 | 28 | * heatmap.x - 29 | * heatmap.y - 30 | * heatmap.color - 31 | * heatmap.tip - 32 | * heatmap.buckets - 33 | * heatmap.end - 34 | * heatmap.chart - 35 | * heatmap.data - 36 | * heatmap.scales - 37 | * heatmap.axes - 38 | * heatmap.domains - 39 | * heatmap.draw - 40 | 41 | ## Radar 42 | 43 | ## Scatter 44 | 45 | Scatter layer module. 46 | 47 | Methods for generating scatter layers. 48 | 49 | * scatter.x - 50 | * scatter.y - 51 | * scatter.radius - 52 | * scatter.radiusRange - 53 | * scatter.properties - 54 | * scatter.color - 55 | * scatter.opacity - 56 | * scatter.tip - 57 | * scatter.end - 58 | * scatter.chart - 59 | * scatter.data - 60 | * scatter.scales - 61 | * scatter.axes - 62 | * scatter.domains - 63 | * scatter.draw - 64 | * scatter.select - 65 | * scatter.selectAll - 66 | 67 | ## Timeline 68 | 69 | Timeline layer module. 70 | 71 | Methods for generating timeline layers. 72 | 73 | * timeline.x - 74 | * timeline.y - 75 | * timeline.series - 76 | * timeline.colors - 77 | * timeline.timeParse - 78 | * timeline.area - 79 | * timeline.color - 80 | * timeline.end - 81 | * timeline.chart - 82 | * timeline.data - 83 | * timeline.scales - 84 | * timeline.axes - 85 | * timeline.domains - 86 | * timeline.draw - 87 | 88 | ## Treemap 89 | 90 | Treemap layer module. 91 | 92 | Methods for generating treemap layers. 93 | 94 | * treemap.end - 95 | * treemap.size - 96 | * treemap.colorScale - 97 | * treemap.padding - 98 | * treemap.nestBy - 99 | * treemap.format - 100 | * treemap.labels - 101 | * treemap.tip - 102 | * treemap.chart - 103 | * treemap.scales - 104 | * treemap.axes - 105 | * treemap.domains - 106 | * treemap.isValidStructure - 107 | * treemap.formatNestedData - 108 | * treemap.data - 109 | * treemap.draw - 110 | -------------------------------------------------------------------------------- /bk_docs/development_setup.md: -------------------------------------------------------------------------------- 1 | # Development Setup 2 | 3 | Setting up a development environment 4 | 5 | ## Getting started 6 | 7 | 1. Create a directory *dboxjs* 8 | 9 | 2. Clone the following repositories: 10 | * core 11 | * bars 12 | * heatmap 13 | * radar 14 | * scatter 15 | * timeline 16 | * treemap 17 | 18 | ``` 19 | git clone git@github.com:dboxjs/core.git 20 | git clone git@github.com:dboxjs/bars.git 21 | git clone git@github.com:dboxjs/heatmap.git 22 | git clone git@github.com:dboxjs/radar.git 23 | git clone git@github.com:dboxjs/scatter.git 24 | git clone git@github.com:dboxjs/timeline.git 25 | git clone git@github.com:dboxjs/treemap.git 26 | ``` 27 | 28 | 29 | 3. In all the repositories execute 30 | ``` 31 | npm install 32 | ``` 33 | 4. In @dboxjs/core 34 | * Duplicate rollup.conf.js save as rollup.config.dev.js 35 | * Modify entry as `entry: 'index.dev.js'` 36 | * Modify targets > dest to the desired destination 37 | ```javascript 38 | targets: [ 39 | { 40 | dest: "your/desired/folder", 41 | format: 'umd', 42 | moduleName: 'dbox', 43 | sourceMap: true 44 | } 45 | ``` 46 | 47 | 6. Run rollup 48 | ``` 49 | npm run dev 50 | ``` 51 | -------------------------------------------------------------------------------- /bk_docs/svg_treemap.md: -------------------------------------------------------------------------------- 1 | # SVG Treemap 2 | 3 | Draws a treemap chart using SVG Rects. 4 | 5 | ## Treemap.nestBy() 6 | 7 | **(Required)** Expects an array of column names that will be used to generate hierarchical data. 8 | 9 | __nestBy('columnName')__: Uses only one level nesting 10 | 11 | __nestBy(['columnName1', 'columnName2', ...])__: Nests data using many levels of hierarchy 12 | 13 | ```javascript 14 | { 15 | "name": "grandparent", 16 | "children": [ 17 | { 18 | "name": "parent", 19 | "children": [ 20 | { 21 | "name": "child", 22 | "value": 464 23 | } 24 | ] 25 | } 26 | ] 27 | } 28 | ``` 29 | 30 | ## Treemap.size() 31 | 32 | **(Required)** Expects a column name that will be used to determine each rect size. It **must ** be a _Number_ 33 | 34 | ```javascript 35 | data = {"name": "foo", "value": 32}; 36 | layer.size('value') 37 | ``` 38 | 39 | ## Treemap.colorScale() 40 | 41 | **(Optional)** Expects an array of colors what will be used to match each children fill color 42 | 43 | **Default:** d3.colorScale20c 44 | 45 | ``` 46 | layer.colorScale(['red','#45f530','blue']) 47 | ``` 48 | 49 | ## Treemap.padding() 50 | 51 | **(Optional)** Expects a _Number_ set as inner padding 52 | 53 | **Default:** 4 54 | 55 | ```javascript 56 | layer.padding(5) 57 | ``` 58 | 59 | ## Treemap.labels() 60 | 61 | **(Optional)** Expects ```true``` or ```false``` to show or hide labels on each rect. 62 | 63 | **Default:** ```true``` 64 | 65 | ```javascript 66 | layer.labels(false) 67 | ``` 68 | 69 | ## Treemap.tip() 70 | 71 | **(Optional)** Expects a function that will be used as HTML option for d3-tip 72 | 73 | **Default:** ```function(d) { return d.data.name + "\n" + vm._config._format(d.value); };``` 74 | 75 | ```javascript 76 | layer.tip(function(d) { return d.data.name; }); 77 | ``` 78 | -------------------------------------------------------------------------------- /docs/.nojekyll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dboxjs/core/8596333d88dcf41eb9ed577dfcf54656070bdc99/docs/.nojekyll -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # Dbox.js - @dboxjs/core 2 | 3 | --- 4 | 5 | A library to create easy reusable charts 6 | 7 | ## Installation 8 | 9 | Using npm 10 | 11 | ``` 12 | npm install @dboxjs/core 13 | ``` 14 | 15 | ## Usage 16 | 17 | Dbox uses one chart that allows to draw different layers 18 | 19 | ```javascript 20 | var config = { 21 | size: { 22 | width: width, 23 | height: 500, 24 | margin: { top: 20, right: 20, bottom: 30, left: 40 } 25 | }, 26 | xAxis: { 27 | scale: "time" 28 | } 29 | }; 30 | 31 | dbox 32 | .chart(config) 33 | .bindTo("#timeline-chart") 34 | .data({ csv: "assets/data/linea.csv" }) 35 | .layer(dbox.timeline) 36 | .x("year") 37 | .series(["tot"]) 38 | .color("species") 39 | .end() 40 | .draw(); 41 | ``` 42 | 43 | Check examples on [dboxjs.org](http://dboxjs.org) 44 | 45 | ## Dependencies 46 | 47 | Dbox uses `d3`, `d3-queue`, `d3-tip`, `lodash`, `topojson` 48 | 49 | --- 50 | 51 | # Layers 52 | 53 | --- 54 | 55 | dbox.js has several layers currently implemented. Each layer is developed independently. However all instances should at least have the following listed methods. 56 | 57 | | Public Methods | Description | @dboxjs/bar | 58 | | -------------------- | -------------------------------------------------------------- | :---------: | 59 | | .data(_object_) | Passes the data to the layer | X | 60 | | .map(_function_) | Used to create a new array of data | - | 61 | | .filter(_function_) | Used to filter rows in the data | - | 62 | | .sortBy(_function_) | Used to sort the rows in the data | - | 63 | | .color(_string_) | Specify which column as the input for color selection | X | 64 | | .colorScale(_array_) | Specify the range of hexadecimal colors for each serie of data | X | 65 | | .tip(_function_) | Specify the html to render on mouse hover | - | 66 | | .format(_function_) | Pending | - | 67 | 68 | ​ 69 | 70 | --- 71 | 72 | # @dboxjs/bar 73 | 74 | --- 75 | 76 | ## Usage 77 | 78 | ```javascript 79 | var data = [ 80 | { 81 | State: "CA", 82 | "Under 5 Years": 2704659, 83 | "5 to 13 Years": 4499890, 84 | "14 to 17 Years": 2159981, 85 | "18 to 24 Years": 3853788, 86 | "25 to 44 Years": 10604510, 87 | "45 to 64 Years": 8819342, 88 | "65 Years and Over": 4114496 89 | }, 90 | { 91 | State: "TX", 92 | "Under 5 Years": 2027307, 93 | "5 to 13 Years": 3277946, 94 | "14 to 17 Years": 1420518, 95 | "18 to 24 Years": 2454721, 96 | "25 to 44 Years": 7017731, 97 | "45 to 64 Years": 5656528, 98 | "65 Years and Over": 2472223 99 | }, 100 | { 101 | State: "NY", 102 | "Under 5 Years": 1208495, 103 | "5 to 13 Years": 2141490, 104 | "14 to 17 Years": 1058031, 105 | "18 to 24 Years": 1999120, 106 | "25 to 44 Years": 5355235, 107 | "45 to 64 Years": 5120254, 108 | "65 Years and Over": 2607672 109 | } 110 | ]; 111 | 112 | var config = { 113 | size: { 114 | width: 600, 115 | height: 400, 116 | margin: { top: 5, right: 5, bottom: 40, left: 100 } 117 | }, 118 | xAxis: { 119 | enabled: true, 120 | scale: "band" 121 | }, 122 | yAxis: { 123 | enabled: true, 124 | scale: "linear" 125 | } 126 | }; 127 | 128 | var chart = dbox 129 | .chart(config) 130 | .bindTo("#chart") 131 | .data({ raw: data }) 132 | .layer(dbox.bars) 133 | .x("State") 134 | .y("Under 5 Years") 135 | .end() 136 | .draw(); 137 | ``` 138 | 139 | ### Normal Bar chart 140 | 141 | - Set the x and y attributes according to the dataset 142 | 143 | ```javascript 144 | var chart = dbox 145 | .chart(config) 146 | .bindTo("#chart") 147 | .data({ raw: data }) 148 | .layer(dbox.bars) 149 | .x("State") 150 | .y("Under 5 Years") 151 | .end() 152 | .draw(); 153 | ``` 154 | 155 | ### GroupBy Bar Chart 156 | 157 | - Set the x attribute according to the dataset. This attribute will serve as the parent category 158 | - Set the groupBy with an array of attributes. This attributes will serve as the "children" categories 159 | 160 | ```javascript 161 | var chart = dbox 162 | .chart(config) 163 | .bindTo("#chart") 164 | .data({ raw: data }) 165 | .layer(dbox.bars) 166 | .x("State") 167 | .groupBy([ 168 | "Under 5 Years", 169 | "5 to 13 Years", 170 | "14 to 17 Years", 171 | "18 to 24 Years", 172 | "25 to 44 Years", 173 | "45 to 64 Years", 174 | "65 Years and Over" 175 | ]) 176 | .end() 177 | .draw(); 178 | ``` 179 | 180 | ### StackBy Bar Chart 181 | 182 | - Set the x attribute according to the dataset. This attribute will serve as the parent category 183 | - Set the stackBy with an array of attributes. This attributes will serve as the "children" categories 184 | 185 | ```javascript 186 | var chart = dbox 187 | .chart(config) 188 | .bindTo("#chart") 189 | .data({ raw: data }) 190 | .layer(dbox.bars) 191 | .x("State") 192 | .stackBy([ 193 | "Under 5 Years", 194 | "5 to 13 Years", 195 | "14 to 17 Years", 196 | "18 to 24 Years", 197 | "25 to 44 Years", 198 | "45 to 64 Years", 199 | "65 Years and Over" 200 | ]) 201 | .end() 202 | .draw(); 203 | ``` 204 | 205 | ## Methods 206 | 207 | ### .x(string) 208 | 209 | --- 210 | 211 | | Parameter | Description | 212 | | ---------- | ----------------------------------------------- | 213 | | columnName | Attribute from the dataset to use in the x Axis | 214 | 215 | ### .y(string) 216 | 217 | --- 218 | 219 | | Parameter | Description | 220 | | ---------- | ----------------------------------------------- | 221 | | columnName | Attribute from the dataset to use in the y Axis | 222 | 223 | ### .groupBy(array) 224 | 225 | --- 226 | 227 | | Parameter | Description | 228 | | --------- | ---------------------------------------- | 229 | | columns | Array of columns to groupBy in the xAxis | 230 | 231 | --- 232 | 233 | # Contribute 234 | 235 | --- 236 | 237 | Setting up a development environment 238 | 239 | ## Getting started 240 | 241 | 1. Create a directory _dboxjs_ 242 | 243 | 2. Clone the following repositories: 244 | 245 | - core 246 | - bars 247 | - heatmap 248 | - radar 249 | - scatter 250 | - timeline 251 | - treemap 252 | 253 | ``` 254 | git clone git@github.com:dboxjs/core.git 255 | git clone git@github.com:dboxjs/bars.git 256 | git clone git@github.com:dboxjs/heatmap.git 257 | git clone git@github.com:dboxjs/radar.git 258 | git clone git@github.com:dboxjs/scatter.git 259 | git clone git@github.com:dboxjs/timeline.git 260 | git clone git@github.com:dboxjs/treemap.git 261 | ``` 262 | 263 | 3. In all the repositories execute 264 | 265 | ``` 266 | npm install 267 | ``` 268 | 269 | 4. In @dboxjs/core 270 | - Duplicate rollup.conf.js save as rollup.config.dev.js 271 | - Modify entry as `entry: 'index.dev.js'` 272 | - Modify output > file to the desired destination 273 | ```javascript 274 | output: [ 275 | { 276 | file: "your/desired/folder", 277 | format : 'umd', 278 | name : 'dbox', 279 | sourcemap : true 280 | } 281 | ``` 282 | 283 | ``` 284 | 285 | 6. Run rollup 286 | ``` 287 | 288 | npm run dev 289 | 290 | ``` 291 | 292 | ``` 293 | -------------------------------------------------------------------------------- /docs/_sidebar.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dboxjs/core/8596333d88dcf41eb9ed577dfcf54656070bdc99/docs/_sidebar.md -------------------------------------------------------------------------------- /docs/bars/README.md: -------------------------------------------------------------------------------- 1 | # dboxjs/bars 2 | 3 | -------------------------------------------------------------------------------- /docs/chart/README.md: -------------------------------------------------------------------------------- 1 | # Chart 2 | 3 | ## What is it? 4 | 5 | ## The config object 6 | 7 | ```javascript 8 | { 9 | size: { 10 | width: number, 11 | height: number, 12 | margin:'' 13 | } 14 | } 15 | ``` 16 | 17 | 18 | 19 | ## Usage 20 | 21 | ## Examples 22 | 23 | ## Methods 24 | 25 | .size({height: number, width: number: margin: {top: number, right: number, bottom: number, left: number}}) 26 | 27 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | @dboxjs/core - A library to create easy reusable charts 6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /index.dev.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Dboxjs 3 | * 4 | * You can import other modules here, including external packages. When 5 | * bundling using rollup you can mark those modules as external and have them 6 | * excluded or, if they have a jsnext:main entry in their package.json (like 7 | * this package does), let rollup bundle them into your dist file. 8 | */ 9 | 10 | /* Core */ 11 | 12 | export { default as chart } from './lib/chart'; 13 | 14 | /* Chart modules */ 15 | export { default as bars } from '../bars/bars.js'; 16 | 17 | export { default as distro } from '../distro/distro.js'; 18 | 19 | export { default as heatmap } from '../heatmap/heatmap.js'; 20 | 21 | export { default as leaflet } from '../leaflet/leaflet.js'; 22 | 23 | export { default as map } from '../map/map.js'; 24 | 25 | export { default as radar } from '../radar/radar.js'; 26 | 27 | export { default as scatter } from '../scatter/scatter.js'; 28 | 29 | export { default as spineplot } from '../spineplot/spineplot.js'; 30 | 31 | export { default as timeline } from '../timeline/timeline.js'; 32 | 33 | export { default as treemap } from '../treemap/treemap.js'; 34 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Dboxjs 3 | * 4 | * You can import other modules here, including external packages. When 5 | * bundling using rollup you can mark those modules as external and have them 6 | * excluded or, if they have a jsnext:main entry in their package.json (like 7 | * this package does), let rollup bundle them into your dist file. 8 | */ 9 | 10 | /* Core */ 11 | export { default as chart } from './lib/chart'; 12 | 13 | /* Chart modules */ 14 | export { default as bars } from '@dboxjs/bars'; 15 | 16 | export { default as distro } from '@dboxjs/distro'; 17 | 18 | export { default as heatmap } from '@dboxjs/heatmap'; 19 | 20 | export { default as leaflet } from '@dboxjs/leaflet'; 21 | 22 | export { default as map } from '@dboxjs/map'; 23 | 24 | export { default as radar } from '@dboxjs/radar'; 25 | 26 | export { default as scatter } from '@dboxjs/scatter'; 27 | 28 | export { default as spineplot } from '@dboxjs/spineplot'; 29 | 30 | export { default as timeline } from '@dboxjs/timeline'; 31 | 32 | export { default as treemap } from '@dboxjs/treemap'; 33 | -------------------------------------------------------------------------------- /jsdocs.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": [], 3 | "recurseDepth": 10, 4 | "source": { 5 | "includePattern": ["./lib/.+\\.js(doc|x)?$", "../*/.+\\.js(doc|x)?$"], 6 | "excludePattern": "(^|\\/|\\\\)_" 7 | }, 8 | "sourceType": "module", 9 | "tags": { 10 | "allowUnknownTags": true, 11 | "dictionaries": ["jsdoc","closure"] 12 | }, 13 | "templates": { 14 | "cleverLinks": false, 15 | "monospaceLinks": false 16 | } 17 | } -------------------------------------------------------------------------------- /lib/chart.js: -------------------------------------------------------------------------------- 1 | import Helper from './helper.js'; 2 | 3 | import * as d3 from 'd3'; 4 | import * as _ from 'lodash'; 5 | 6 | /** 7 | * Dbox Chart core 8 | */ 9 | 10 | /** 11 | * Creates a chart type object 12 | * @constructor 13 | * @param {Object} config - Object with params to set chart size, xAxis and yAxis properties 14 | */ 15 | 16 | export default function Chart(config) { 17 | var Chart = {}; 18 | // Internet Explorer 6-11 19 | var isIE; 20 | try { 21 | isIE = /*@cc_on!@*/ false || (document && !!document.documentMode); 22 | } catch (err) { 23 | isIE = false; 24 | } 25 | // Edge 20+ 26 | var isEdge; 27 | try { 28 | isEdge = !isIE && window && !!window.StyleMedia; 29 | } catch (err) { 30 | isEdge = false; 31 | } 32 | 33 | /** 34 | * Initialize chart object configuration 35 | * @param {Object} config - Object with params to configure the chart (developer's configure) 36 | */ 37 | Chart.init = function (config) { 38 | var vm = this; 39 | 40 | /** 41 | * Set default size and default margins 42 | * for chart container (SVG) 43 | */ 44 | var defaultConfig = { 45 | size: { 46 | width: 800, 47 | height: 600, 48 | margin: { 49 | left: 0, 50 | right: 0, 51 | top: 0, 52 | bottom: 0, 53 | }, 54 | }, 55 | }; 56 | 57 | var defaultStyle = { 58 | chart: { 59 | backgroundColor: { 60 | color: 'transparent', 61 | // linearGradient : { x1: 0, y1: 0, x2: 1, y2: 1 }, 62 | // stops: [ [0, '#FCFCFC'], [1, '#F3F2F2'] ] 63 | }, 64 | }, 65 | title: { 66 | textColor: '#E6B537', 67 | fontSize: '30px', 68 | fontWeight: 600, 69 | textAlign: 'center', 70 | hr: { 71 | enabled: true, 72 | borderWidth: '1px', 73 | borderColor: '#fff', 74 | }, 75 | }, 76 | legend: { 77 | position: 'bottom', 78 | figure: 'circle', 79 | text: { 80 | textColor: '#fff', 81 | fontSize: '12px', 82 | fontWeight: 600, 83 | }, 84 | }, 85 | tooltip: { 86 | backgroundColor: '#757575', 87 | opacity: 0.9, 88 | text: { 89 | textColor: '#fff', 90 | fontSize: '12px', 91 | fontWeight: 600, 92 | textAlign: 'center', 93 | fontFamily: 'sans-serif', 94 | padding: '0.8em', 95 | }, 96 | border: { 97 | color: '#5A5C5D', 98 | radius: '5px', 99 | width: '1px', 100 | }, 101 | }, 102 | yAxis: { 103 | enabled: true, 104 | axis: { 105 | strokeWidth: 3, 106 | strokeColor: '#5F6C6C', 107 | strokeOpacity: 0, 108 | paddingTick: 0, 109 | }, 110 | ticks: { 111 | strokeWidth: 3, 112 | strokeColor: '#929D9E', 113 | grid: 'dashed', 114 | gridDashed: '3, 5', 115 | opacity: 0.6, 116 | }, 117 | labels: { 118 | fontSize: 12, 119 | fontWeight: 600, 120 | textColor: '#fff', 121 | textAnchor: 'end', 122 | }, 123 | title: { 124 | fontSize: 17, 125 | fontWeight: 600, 126 | textColor: '#fff', 127 | textAnchor: 'middle', 128 | // rotation 129 | // text align or position 130 | }, 131 | }, 132 | xAxis: { 133 | enabled: true, 134 | axis: { 135 | strokeWidth: 3, 136 | strokeColor: '#5F6C6C', 137 | strokeOpacity: 1, //??? 138 | paddingTick: 5, 139 | }, 140 | ticks: { 141 | strokeWidth: 1, 142 | strokeColor: '#5F6C6C', 143 | // ticksize 144 | }, 145 | labels: { 146 | fontSize: 12, 147 | fontWeight: 400, 148 | textColor: '#fff', 149 | textAnchor: 'middle', 150 | }, 151 | title: { 152 | fontSize: 17, 153 | fontWeight: 600, 154 | textColor: '#fff', 155 | textAnchor: 'middle', 156 | // text align 157 | }, 158 | }, 159 | }; 160 | 161 | /** 162 | * Clone recursively the config object if it has content. 163 | * Keep default configuration in other case. 164 | */ 165 | vm._config = config ? _.cloneDeep(config) : defaultConfig; 166 | 167 | if (vm._config.xAxis) { 168 | vm._config.xAxis.axis = 'xAxis'; 169 | /** 170 | * @deprecated Allow to use general config if axis-based is not especified 171 | */ 172 | if ( 173 | vm._config.xAxis.decimals === undefined && 174 | vm._config.decimals !== undefined 175 | ) { 176 | vm._config.xAxis.decimals = vm._config.decimals; 177 | } 178 | if ( 179 | vm._config.xAxis.formatPreffix === undefined && 180 | vm._config.formatPreffix !== undefined 181 | ) { 182 | vm._config.xAxis.formatPreffix = vm._config.formatPreffix; 183 | } 184 | if ( 185 | vm._config.xAxis.formatSuffix === undefined && 186 | vm._config.formatSuffix !== undefined 187 | ) { 188 | vm._config.xAxis.formatSuffix = vm._config.formatSuffix; 189 | } 190 | } 191 | if (vm._config.yAxis) { 192 | vm._config.yAxis.axis = 'yAxis'; 193 | /** 194 | * @deprecated Allow to use general config if axis-based is not especified 195 | */ 196 | if ( 197 | vm._config.yAxis.decimals === undefined && 198 | vm._config.decimals !== undefined 199 | ) { 200 | vm._config.yAxis.decimals = vm._config.decimals; 201 | } 202 | if ( 203 | vm._config.yAxis.formatPreffix === undefined && 204 | vm._config.formatPreffix !== undefined 205 | ) { 206 | vm._config.yAxis.formatPreffix = vm._config.formatPreffix; 207 | } 208 | if ( 209 | vm._config.yAxis.formatSuffix === undefined && 210 | vm._config.formatSuffix !== undefined 211 | ) { 212 | vm._config.yAxis.formatSuffix = vm._config.formatSuffix; 213 | } 214 | } 215 | // Initialize data array 216 | vm._data = []; 217 | 218 | // Define margin sizes and styles 219 | vm._margin = vm._config.size.margin; 220 | vm._addStyle = vm._config.addStyle ? vm._config.addStyle : defaultStyle; 221 | 222 | // Define width and height 223 | vm._width = vm._config.size.width - vm._margin.left - vm._margin.right; 224 | vm._height = vm._config.size.height - vm._margin.top - vm._margin.bottom; 225 | vm._svg = ''; 226 | vm._scales = {}; 227 | vm._axes = {}; 228 | 229 | // Public 230 | vm.layers = []; 231 | 232 | // Helper data/functions for layers to use 233 | vm.helper = Helper.bind(vm)(); 234 | }; 235 | 236 | //------------------------ 237 | // User 238 | /** 239 | * User can set config object using this method 240 | * @param {Object} config - Objec with params to configure the chart (user's configure) 241 | */ 242 | Chart.config = function (config) { 243 | var vm = this; 244 | vm._config = _.cloneDeep(config); 245 | return vm; 246 | }; 247 | 248 | /** 249 | * User can set size of the chart using this method 250 | * @param {object} sizeObj - Size object 251 | * @param {number} [sizeObj.height] - Height of the chart 252 | * @param {number} [sizeObj.width] - Width of the chart 253 | * @param {object} [sizeObj.margin] - Margins of the chart 254 | * @param {number} [sizeObj.margin.top] - Margin top of the chart 255 | * @param {number} [sizeObj.margin.right] - Margin right of the chart 256 | * @param {number} [sizeObj.margin.bottom] - Margin bottom of the chart 257 | * @param {number} [sizeObj.margin.left] - Margin left of the chart 258 | */ 259 | Chart.size = function (sizeObj) { 260 | var vm = this; 261 | if (sizeObj) { 262 | if (sizeObj.margin) { 263 | if (!Number.isNaN(+sizeObj.margin.left)) { 264 | vm._config.size.margin.left = sizeObj.margin.left; 265 | vm._margin.left = sizeObj.margin.left; 266 | } 267 | if (!Number.isNaN(+sizeObj.margin.right)) { 268 | vm._config.size.margin.right = sizeObj.margin.right; 269 | vm._margin.right = sizeObj.margin.right; 270 | } 271 | if (!Number.isNaN(+sizeObj.margin.top)) { 272 | vm._config.size.margin.top = sizeObj.margin.top; 273 | vm._margin.top = sizeObj.margin.top; 274 | } 275 | if (!Number.isNaN(+sizeObj.margin.bottom)) { 276 | vm._config.size.margin.bottom = sizeObj.margin.bottom; 277 | vm._margin.bottom = sizeObj.margin.bottom; 278 | } 279 | } 280 | if (!Number.isNaN(+sizeObj.width)) { 281 | vm._config.size.width = sizeObj.width; 282 | vm._width = sizeObj.width; 283 | } 284 | if (!Number.isNaN(+sizeObj.height)) { 285 | vm._config.size.height = sizeObj.height; 286 | vm._height = sizeObj.height; 287 | } 288 | } 289 | return vm; 290 | }; 291 | 292 | /** 293 | * User can set a personalized style object 294 | * @param {object} stylesObj 295 | */ 296 | Chart.addStyle = function (stylesObj) { 297 | var vm = this; 298 | if (stylesObj) { 299 | vm._addStyle = stylesObj; 300 | } 301 | return vm; 302 | }; 303 | 304 | /** 305 | * Set if background grid is enabled and should be drawn 306 | * @param {boolean} enabled - Grid status 307 | */ 308 | Chart.grid = function (enabled) { 309 | var vm = this; 310 | vm._config.grid = enabled ? true : false; 311 | return vm; 312 | }; 313 | 314 | /** 315 | * Set selector of HTML node to embed the whole chart 316 | * @param {string} selector - HTML node selector 317 | */ 318 | Chart.bindTo = function (selector) { 319 | var vm = this; 320 | vm._config.bindTo = selector; 321 | return vm; 322 | }; 323 | 324 | /** 325 | * Set data to be used in chart 326 | * @param {Object[]} data - Data structure to be used 327 | */ 328 | Chart.data = function (data) { 329 | var vm = this; 330 | if (vm._config.data !== undefined) { 331 | vm._config.data = Object.assign({}, vm._config.data, data); 332 | } else { 333 | vm._config.data = data; 334 | } 335 | return vm; 336 | }; 337 | 338 | /** 339 | * Set configuration for legend 340 | * @param {Object} legend - Legend configuration 341 | */ 342 | Chart.legend = function (legend) { 343 | var vm = this; 344 | vm._config.legend = legend; 345 | return vm; 346 | }; 347 | 348 | Chart.legendType = function (legendType) { 349 | var vm = this; 350 | vm._config.legendType = legendType; 351 | return vm; 352 | }; 353 | 354 | Chart.legendTitle = function (legendTitle) { 355 | var vm = this; 356 | vm._config.legendTitle = legendTitle; 357 | return vm; 358 | }; 359 | 360 | Chart.layer = function (_layer, _config) { 361 | var vm = this; 362 | var layer; 363 | var config = _config ? _config : vm._config; 364 | if (_layer === undefined && _layer === null) { 365 | /** @todo Throw Error */ 366 | } else { 367 | layer = _layer(config, vm.helper); 368 | vm.layers.push(layer); 369 | return layer; 370 | } 371 | }; 372 | 373 | Chart.getLayer = function (layerIndex) { 374 | var vm = this; 375 | return vm.layers[layerIndex]; 376 | }; 377 | 378 | Chart.draw = function () { 379 | var vm = this, 380 | q; 381 | vm._scales = vm.scales(); 382 | // vm._axes = vm.axes(); // CALL THE AXES AFTER DATA LOADING IN ORDER TO UPDATE THE DOMAINS OF THE SCALES 383 | 384 | q = vm.loadData(); 385 | 386 | q.awaitAll(function (error, results) { 387 | if (error) throw error; 388 | 389 | if (Array.isArray(results) && results.length === 1) { 390 | vm._data = results[0]; 391 | } else { 392 | vm._data = results; 393 | } 394 | 395 | vm.initLayers(); 396 | vm.drawSVG(); 397 | 398 | /** @todo ONE MAIN AXES THEN ADD THE POSSIBILITY FOR THE LAYER TO OVERRIDE */ 399 | vm._axes = vm.axes(); 400 | vm.drawAxes(); 401 | 402 | // Draw layers after axes 403 | vm.drawLayers(); 404 | 405 | // Trigger load chart event 406 | if (vm._config.events && vm._config.events.load) { 407 | vm.dispatch.on('load.chart', vm._config.events.load(vm)); 408 | } 409 | }); 410 | return vm; 411 | }; 412 | 413 | Chart.addStyle = function (theme) { 414 | var vm = this; 415 | vm._addStyle = theme; 416 | return vm; 417 | }; 418 | 419 | //---------------------- 420 | // Helper functions 421 | Chart.scales = function () { 422 | var vm = this; 423 | 424 | var scales = {}; 425 | // xAxis scale 426 | if (vm._config.xAxis && vm._config.xAxis.scale) { 427 | switch (vm._config.xAxis.scale) { 428 | case 'linear': 429 | scales.x = d3.scaleLinear().range([0, vm._width]); 430 | break; 431 | 432 | case 'time': 433 | scales.x = d3.scaleTime().range([0, vm._width]); 434 | break; 435 | 436 | case 'ordinal': 437 | scales.x = d3.scaleOrdinal().range([0, vm._width], 0.1); 438 | break; 439 | 440 | case 'band': 441 | scales.x = d3.scaleBand().rangeRound([0, vm._width]).padding(0.1); 442 | break; 443 | 444 | case 'quantile': 445 | scales.x = d3.scaleOrdinal().range([0, vm._width], 0.1); 446 | 447 | scales.q = d3 448 | .scaleQuantile() 449 | .range(d3.range(vm._config.xAxis.buckets)); 450 | break; 451 | 452 | default: 453 | scales.x = d3.scaleLinear().range([0, vm._width]); 454 | break; 455 | } 456 | } else { 457 | scales.x = d3.scaleLinear().range([0, vm._width]); 458 | } 459 | 460 | // yAxis scale 461 | if (vm._config.yAxis && vm._config.yAxis.scale) { 462 | switch (vm._config.yAxis.scale) { 463 | case 'linear': 464 | scales.y = d3.scaleLinear().range([vm._height, 0]); 465 | break; 466 | 467 | case 'time': 468 | scales.y = d3.scaleTime().range([vm._height, 0]); 469 | break; 470 | 471 | case 'ordinal': 472 | scales.y = d3.scaleOrdinal().range([vm._height, 0], 0.1); 473 | break; 474 | 475 | case 'band': 476 | scales.y = d3.scaleBand().rangeRound([vm._height, 0]).padding(0.1); 477 | break; 478 | 479 | case 'quantile': 480 | scales.y = d3.scaleOrdinal().range([0, vm._width], 0.1); 481 | 482 | scales.q = d3 483 | .scaleQuantile() 484 | .range(d3.range(vm._config.yAxis.buckets)); 485 | break; 486 | 487 | default: 488 | scales.y = d3.scaleLinear().range([vm._height, 0]); 489 | break; 490 | } 491 | } else { 492 | scales.y = d3.scaleLinear().range([vm._height, 0]); 493 | } 494 | 495 | scales.color = d3.scaleOrdinal(d3.schemeCategory10); 496 | if (vm._config.legend && vm._config.legend.length > 0) { 497 | scales.color.domain(vm._config.legend.map((o) => o.name)); 498 | } 499 | 500 | return scales; 501 | }; 502 | 503 | Chart.setScales = function () {}; 504 | 505 | Chart.axes = function () { 506 | var vm = this, 507 | axes = {}; 508 | axes.x = d3.axisBottom(vm._scales.x); 509 | axes.y = d3.axisLeft(vm._scales.y); 510 | 511 | // Remove corners in axis line 512 | axes.x.tickSizeOuter(0); 513 | axes.y.tickSizeOuter(0); 514 | 515 | // Replaced with *addStyle -check 516 | if ( 517 | vm._config.xAxis && 518 | vm._config.xAxis.ticks && 519 | vm._config.xAxis.ticks.enabled === true && 520 | vm._config.xAxis.ticks.style 521 | ) { 522 | switch (vm._config.xAxis.ticks.style) { 523 | case 'straightLine': 524 | axes.x.tickSize(-vm._height, 0); 525 | break; 526 | case 'dashLine': 527 | axes.x.tickSize(-vm._width, 0); 528 | break; 529 | } 530 | } 531 | // addStyle 532 | if (vm._addStyle.xAxis.ticks.grid) { 533 | switch (vm._addStyle.xAxis.ticks.grid) { 534 | case 'straight': 535 | axes.y.tickSize(-vm._width, 0); 536 | break; 537 | case 'dashed': 538 | axes.y.tickSize(-vm._width, 0); 539 | break; 540 | } 541 | } 542 | 543 | if ( 544 | vm._config.xAxis && 545 | vm._config.xAxis.ticks && 546 | vm._config.xAxis.ticks.ticks 547 | ) { 548 | axes.x.ticks(vm._config.xAxis.ticks.ticks); 549 | } 550 | 551 | if ( 552 | vm._config.xAxis && 553 | vm._config.xAxis.ticks && 554 | vm._config.xAxis.ticks.values 555 | ) { 556 | axes.x.tickValues(vm._config.xAxis.ticks.values); 557 | } 558 | 559 | if ( 560 | vm._config.xAxis && 561 | vm._config.xAxis.ticks && 562 | vm._config.xAxis.scale === 'linear' 563 | ) { 564 | vm._scales.x.domain()[1]; 565 | axes.x.tickFormat(vm.helper.utils.format(vm._config.xAxis, true)); 566 | } 567 | if ( 568 | vm._config.xAxis && 569 | vm._config.xAxis.ticks && 570 | vm._config.xAxis.ticks.format 571 | ) { 572 | axes.x.tickFormat(vm._config.xAxis.ticks.format); 573 | } 574 | 575 | // Replaced with *addStyle -check 576 | if ( 577 | vm._config.yAxis && 578 | vm._config.yAxis.ticks && 579 | vm._config.yAxis.ticks.enabled === true && 580 | vm._config.yAxis.ticks.style 581 | ) { 582 | switch (vm._config.yAxis.ticks.style) { 583 | case 'straightLine': 584 | axes.y.tickSize(-vm._width, 0); 585 | break; 586 | case 'dashLine': 587 | axes.y.tickSize(-vm._width, 0); 588 | break; 589 | } 590 | } 591 | // addStyle 592 | if (vm._addStyle.yAxis.ticks.grid) { 593 | switch (vm._addStyle.yAxis.ticks.grid) { 594 | case 'straight': 595 | axes.y.tickSize(-vm._width, 0); 596 | break; 597 | case 'dashed': 598 | axes.y.tickSize(-vm._width, 0); 599 | break; 600 | } 601 | } 602 | if ( 603 | vm._config.yAxis && 604 | vm._config.yAxis.ticks && 605 | vm._config.yAxis.scale === 'linear' 606 | ) { 607 | axes.y.tickFormat(vm.helper.utils.format(vm._config.yAxis, true)); 608 | } 609 | if ( 610 | vm._config.yAxis && 611 | vm._config.yAxis.ticks && 612 | vm._config.yAxis.ticks.format 613 | ) { 614 | axes.y.tickFormat(vm._config.yAxis.ticks.format); 615 | } 616 | if ( 617 | vm._config.yAxis && 618 | vm._config.yAxis.ticks && 619 | vm._config.yAxis.ticks.ticks 620 | ) { 621 | axes.y.ticks(vm._config.yAxis.ticks.ticks); 622 | } 623 | return axes; 624 | }; 625 | 626 | Chart.loadData = function () { 627 | var vm = this; 628 | var q; 629 | 630 | if (vm._config.data.tsv) { 631 | q = d3.queue().defer(d3.tsv, vm._config.data.tsv); 632 | } 633 | 634 | if (vm._config.data.json) { 635 | q = d3.queue().defer(d3.json, vm._config.data.json); 636 | } 637 | 638 | if (vm._config.data.csv) { 639 | q = d3.queue().defer(d3.csv, vm._config.data.csv); 640 | } 641 | 642 | if (vm._config.data.raw) { 643 | q = d3.queue().defer(vm.mapData, vm._config.data.raw); 644 | } 645 | 646 | if ( 647 | vm._config.map && 648 | vm._config.map.topojson && 649 | vm._config.map.topojson.url 650 | ) { 651 | q.defer(d3.json, vm._config.map.topojson.url); 652 | } 653 | 654 | return q; 655 | }; 656 | 657 | Chart.initLayers = function () { 658 | var vm = this; 659 | vm.layers.forEach(function (ly) { 660 | ly.data(vm._data).scales(); 661 | 662 | /** @todo validate domains from multiple layers */ 663 | vm._scales = ly._scales; 664 | }); 665 | }; 666 | 667 | Chart.drawSVG = function () { 668 | var vm = this; 669 | 670 | // Remove any previous svg 671 | d3.select(vm._config.bindTo).select('svg').remove(); 672 | d3.select(vm._config.bindTo).html(''); 673 | 674 | // Add the css template class 675 | if (vm._config.template) { 676 | d3.select(vm._config.bindTo).classed(vm._config.template, true); 677 | } 678 | 679 | // Add title to the chart 680 | if (vm._config && vm._config.title) { 681 | d3.select(vm._config.bindTo) 682 | .append('div') 683 | .attr('class', 'chart-title') 684 | .html(vm._config.title) 685 | .style('display', 'flex') 686 | .style('justify-content', 'center') 687 | .style('align-items', 'center') 688 | .style('font-size', vm._addStyle.title.fontSize) 689 | .style('font-weight', vm._addStyle.title.fontWeight) 690 | .style('color', vm._addStyle.title.textColor) 691 | .style('text-align', vm._addStyle.title.textAlign); 692 | 693 | if (vm._addStyle.title.hr.enabled) { 694 | d3.select(vm._config.bindTo) 695 | .append('hr') 696 | .attr('class', 'hr-title') 697 | .style('width', '80%') 698 | .style('margin-left', '10%') 699 | .style('margin-top', '0.5em') 700 | .style('border-width', vm._addStyle.title.hr.borderWidth) 701 | .style('border-color', vm._addStyle.title.hr.borderColor); 702 | } 703 | } 704 | 705 | // Add Legend to the chart 706 | /** @todo PASS THE STYLES TO DBOX.CSS */ 707 | /** @todo ALLOW DIFFERENT POSSITIONS FOR THE LEGEND */ 708 | if ( 709 | vm._config.legend && 710 | vm._config.legend.enabled === true && 711 | vm._config.legend.position === 'top' 712 | ) { 713 | var legend = d3 714 | .select(vm._config.bindTo) 715 | .append('div') 716 | .attr('class', 'chart-legend-top'); 717 | 718 | var html = ''; 719 | html += 720 | '
'; 721 | vm._config.legend.categories.forEach(function (c) { 722 | html += 723 | '
' + 726 | c.title + 727 | '
'; 728 | }); 729 | html += '
'; 730 | legend.html(html); 731 | } 732 | 733 | const width = vm._width + vm._margin.left + vm._margin.right; 734 | const height = vm._height + vm._margin.top + vm._margin.bottom; 735 | // Create the svg 736 | vm._fullSvg = d3 737 | .select(vm._config.bindTo) 738 | .append('svg') 739 | .style( 740 | 'font-size', 741 | vm._config.chart 742 | ? vm._config.chart['font-size'] 743 | ? vm._config.chart['font-size'] 744 | : '12px' 745 | : '12px' 746 | ) 747 | .attr('width', width) 748 | .attr('height', height) 749 | .attr('viewBox', `0 0 ${width} ${height}`); 750 | 751 | vm._svg = vm._fullSvg 752 | .append('g') 753 | .attr( 754 | 'transform', 755 | 'translate(' + vm._margin.left + ',' + vm._margin.top + ')' 756 | ); 757 | 758 | //Apply background color 759 | 760 | d3.select(vm._config.bindTo + ' svg').style( 761 | 'background-color', 762 | vm._addStyle.chart.backgroundColor.color 763 | ); 764 | 765 | // Legend for average lines 766 | /* 767 | d3.select(vm._config.bindTo).append('div') 768 | .attr('class', 'chart-legend-bottom'); 769 | if (vm._config.plotOptions && vm._config.plotOptions.bars 770 | && vm._config.plotOptions.bars.averageLines && Array.isArray(vm._config.plotOptions.bars.averageLines) 771 | && vm._config.plotOptions.bars.averageLines.length >0 ){ 772 | 773 | d3.select(vm._config.bindTo).append('div') 774 | .attr('class', 'container-average-lines') 775 | .append('div') 776 | .attr('class', 'legend-average-lines') 777 | .html('Average Lines Controller') 778 | } 779 | */ 780 | 781 | if ( 782 | vm._config.hasOwnProperty('legend') && 783 | vm._config.legendEnabled === true 784 | ) { 785 | vm.drawLegend(); 786 | } 787 | }; 788 | 789 | Chart.drawLayers = function () { 790 | var vm = this; 791 | vm.layers.forEach(function (ly) { 792 | ly.draw(); 793 | }); 794 | }; 795 | 796 | /** 797 | * Draw chart legends section 798 | */ 799 | Chart.drawLegend = function () { 800 | // Reference to chart object 801 | var vm = this, 802 | legendBox, 803 | virtualScroller, 804 | legendX = vm._config.size.width - vm._config.size.margin.right + 10, 805 | marginTop = vm._config.size.margin.top + 10; 806 | // Set color domain 807 | if (!vm._scales.color && vm._config.colors) { 808 | vm._scales.color = d3.scaleOrdinal(vm._config.colors); 809 | } 810 | if (vm._config.legend && vm._config.legend.length > 0) { 811 | vm._scales.color.domain(vm._config.legend.map((o) => o.name)); 812 | } 813 | // Create information tips for each legend 814 | const legendTip = vm.helper.utils.d3.tip().html((d) => { 815 | return '
' + (d.name || d) + '
'; 816 | }); 817 | vm._fullSvg.call(legendTip); 818 | 819 | // Draw legend, defaults to right 820 | legendBox = vm._fullSvg 821 | .append('g') 822 | .attr('class', 'legendBox') 823 | .attr('transform', 'translate(' + legendX + ', ' + marginTop + ')') 824 | .attr('width', vm._width) 825 | .attr('height', vm._height); 826 | // Add legends title (on top of legendBox) 827 | if (vm._config.legendTitle) { 828 | legendBox 829 | .append('g') 830 | .attr('width', '150px') 831 | .append('text') 832 | .attr('class', 'legend-title') 833 | .attr('x', 5) 834 | .style('font-weight', 'bold') 835 | .text(vm._config.legendTitle); 836 | // Wrap legend title if text size exceeds 70% of container 837 | let lWidth = vm._config.size.margin.right; 838 | var text = d3.selectAll('.legend-title'), 839 | words = text.text().split(/\s+/).reverse(), 840 | word, 841 | line = [], 842 | lineNumber = 1, 843 | lineHeight = 1.1, // ems 844 | y = text.attr('y'), 845 | dy = 0, 846 | tspan = text 847 | .text(null) 848 | .append('tspan') 849 | .attr('x', 0) 850 | .attr('y', y) 851 | .attr('dy', dy + 'em'); 852 | while ((word = words.pop())) { 853 | line.push(word); 854 | tspan.text(line.join(' ')); 855 | if (tspan.node().getComputedTextLength() > lWidth) { 856 | line.pop(); 857 | tspan.text(line.join(' ')); 858 | line = [word]; 859 | ++lineNumber; 860 | tspan = text 861 | .append('tspan') 862 | .attr('x', -6) 863 | .attr('y', y) 864 | .attr('dy', lineHeight + 'em') 865 | .text(word); 866 | } 867 | } 868 | } 869 | 870 | // Label width 871 | let lbWidth = vm._config.size.margin.right * 0.8; 872 | if (vm._config.legendType === 'checkbox') { 873 | // Size and position of every checkbox 874 | let size = 18, 875 | x = 0, 876 | y = 0, 877 | rx = 2, 878 | ry = 2, 879 | markStrokeWidth = 3; 880 | 881 | vm._scales.color.domain(vm._config.legend.map((o) => o.name)); 882 | 883 | var legendEnter = function (legendCheck) { 884 | legendCheck 885 | .append('rect') 886 | .attr('width', size) 887 | .attr('height', size) 888 | .attr('x', x) 889 | .attr('rx', rx) 890 | .attr('ry', ry) 891 | .attr('fill-opacity', 1); 892 | let coordinates = [ 893 | { 894 | x: x + size / 8, 895 | y: y + size / 2, 896 | }, 897 | { 898 | x: x + size / 2.2, 899 | y: y + size - size / 4, 900 | }, 901 | { 902 | x: x + size - size / 8, 903 | y: y + size / 10, 904 | }, 905 | ]; 906 | 907 | let line = d3 908 | .line() 909 | .x(function (d) { 910 | return d.x; 911 | }) 912 | .y(function (d) { 913 | return d.y; 914 | }); 915 | 916 | // Mark (inside checkbox) 917 | legendCheck 918 | .append('path') 919 | .attr('d', line(coordinates)) 920 | .attr('stroke-width', markStrokeWidth) 921 | .attr('stroke', 'white') 922 | .attr('fill', 'none') 923 | .attr('class', 'mark') 924 | .property('checked', function (d) { 925 | // External function call. It must be after all the internal code; allowing the user to overide 926 | return d.active; 927 | }) 928 | .attr('opacity', function () { 929 | if (d3.select(this).property('checked')) { 930 | return 1; 931 | } else { 932 | return 0; 933 | } 934 | }); 935 | 936 | legendCheck 937 | .append('text') 938 | .attr('class', 'labelText') 939 | .attr('x', 20) 940 | .attr('y', 9) 941 | .attr('dy', '.35em') 942 | .attr('text-anchor', 'start'); 943 | 944 | legendCheck.select('rect').attr('fill', function (d) { 945 | return vm._scales.color(d.name); 946 | }); 947 | 948 | legendCheck.select('text').text(function (d) { 949 | // External function call. It must be after all the internal code; allowing the user to overide 950 | // External function call. It must be after all the internal code; allowing the user to overide 951 | // External function call. It must be after all the internal code; allowing the user to overide 952 | return d.name; 953 | }); 954 | 955 | // Cut label text if text size exceeds 80% of container 956 | legendCheck.selectAll('text').each(function (d) { 957 | if (typeof d.name === 'string') { 958 | // getComputedTextLenght: Returns a float representing the computed length for the text within the element. 959 | if (this.getComputedTextLength() > lbWidth) { 960 | d3.select(this) 961 | .attr('title', d.name) 962 | .on('mouseover', legendTip.show) 963 | .on('mouseout', legendTip.hide); 964 | let i = 1; 965 | while (this.getComputedTextLength() > lbWidth) { 966 | d3.select(this).text(function (d) { 967 | return d['name'].slice(0, -i) + '...'; 968 | }); 969 | ++i; 970 | } 971 | } else { 972 | return d; 973 | } 974 | } 975 | }); 976 | }; // legendEnter ends 977 | 978 | // Let scroll legendBox from anywhere inside g container 979 | legendBox 980 | .append('rect') 981 | .attr('class', 'legendBoxBackground') 982 | .attr('width', '160px') 983 | .attr('height', '90%') 984 | .attr('transform', 'translate(0,0)') 985 | .style('fill', 'transparent'); 986 | 987 | var legendUpdate = function (legendCheck) { 988 | legendCheck.select('rect').attr('fill', function (d) { 989 | return vm._scales.color(d.name); 990 | }); 991 | 992 | legendCheck.select('text').text(function (d) { 993 | // External function call. It must be after all the internal code; allowing the user to overide 994 | // External function call. It must be after all the internal code; allowing the user to overide 995 | // External function call. It must be after all the internal code; allowing the user to overide 996 | return d.name; 997 | }); 998 | 999 | legendCheck.selectAll('text').each(function (d) { 1000 | if (typeof d.name === 'string') { 1001 | // getComputedTextLenght: Returns a float representing the computed length for the text within the element. 1002 | if (this.getComputedTextLength() > lbWidth) { 1003 | d3.select(this) 1004 | .attr('title', d.name) 1005 | .on('mouseover', legendTip.show) 1006 | .on('mouseout', legendTip.hide); 1007 | let i = 1; 1008 | while (this.getComputedTextLength() > lbWidth) { 1009 | d3.select(this).text(function (d) { 1010 | return d['name'].slice(0, -i) + '...'; 1011 | }); 1012 | ++i; 1013 | } 1014 | } else { 1015 | return d; 1016 | } 1017 | } 1018 | }); 1019 | }; 1020 | 1021 | var legendExit = function (legendCheck) {}; 1022 | 1023 | virtualScroller = vm.helper.utils 1024 | .VirtualScroller() 1025 | .rowHeight(size) 1026 | .enter(legendEnter) 1027 | .update(legendUpdate) 1028 | .exit(legendExit) 1029 | .svg(vm._fullSvg) 1030 | .totalRows(vm._config.legend.length) 1031 | .viewport(d3.select('.empty-chart')) 1032 | .lineNumber(lineNumber); 1033 | 1034 | virtualScroller.data(vm._config.legend, function (d) { 1035 | return d.name; 1036 | }); 1037 | legendBox.call(virtualScroller); 1038 | 1039 | // End of checkbox case 1040 | } else { 1041 | var legend; 1042 | if (vm._config.styles && vm._addStyle.legend.position === 'bottom') { 1043 | legend = legendBox 1044 | .selectAll('.legend') 1045 | .data(vm._config.legend) 1046 | .enter() 1047 | .append('g') 1048 | .attr('class', 'legend') 1049 | .attr('width', vm._width / (vm._config.legend.length + 1)) 1050 | .attr('transform', function (d, i) { 1051 | // Horizontal position 1052 | // What if there are too many legends? 1053 | return ( 1054 | 'translate(' + 1055 | (vm._width / (vm._config.legend.length + 1)) * i + 1056 | ',' + 1057 | (vm._config.legendTitle && lineNumber > 1 1058 | ? lineNumber * lineHeight 1059 | : 0) * 1060 | 19 + 1061 | ')' 1062 | ); 1063 | }); 1064 | } else { 1065 | legend = legendBox 1066 | .selectAll('.legend') 1067 | .data(vm._config.legend) 1068 | .enter() 1069 | .append('g') 1070 | .attr('class', 'legend') 1071 | .attr('transform', function (d, i) { 1072 | return ( 1073 | 'translate(' + 1074 | 5 + 1075 | ',' + 1076 | (vm._config.legendTitle && lineNumber > 1 1077 | ? lineNumber * lineHeight + i 1078 | : 1 + i) * 1079 | 19 + 1080 | ')' 1081 | ); 1082 | }); 1083 | } 1084 | 1085 | if (vm._addStyle.legend.figure === 'circle') { 1086 | legend 1087 | .append('circle') 1088 | .attr('cx', 2) 1089 | .attr('cy', 9) 1090 | .attr('r', 7) 1091 | .attr('stroke-width', 2) 1092 | .attr('stroke', function (d) { 1093 | return vm._scales.color(d.name); 1094 | }) 1095 | .attr('fill', function (d) { 1096 | return vm._scales.color(d.name); 1097 | }) 1098 | .attr('fill-opacity', 0.8); 1099 | } else { 1100 | legend 1101 | .append('rect') 1102 | .attr('x', 0) 1103 | .attr('width', 18) 1104 | .attr('height', 18) 1105 | .attr('fill', function (d) { 1106 | return vm._scales.color(d.name); 1107 | }); 1108 | } 1109 | 1110 | legend 1111 | .append('text') 1112 | .attr('x', 20) 1113 | .attr('y', 9) 1114 | .attr('dy', '.35em') 1115 | .attr('text-anchor', 'start') 1116 | .text(function (d) { 1117 | // External function call. It must be after all the internal code; allowing the user to overide 1118 | return d.name; 1119 | }); 1120 | 1121 | // Cut label text if text size exceeds 80% of container 1122 | let lbWidth = vm._config.size.margin.right - 19; 1123 | legend.selectAll('text').each(function (d) { 1124 | if (typeof d.name === 'string') { 1125 | if (this.getComputedTextLength() > lbWidth) { 1126 | d3.select(this) 1127 | .attr('title', d.name) 1128 | .on('mouseover', legendTip.show) 1129 | .on('mouseout', legendTip.hide); 1130 | let i = 1; 1131 | while (this.getComputedTextLength() > lbWidth) { 1132 | d3.select(this).text(function (d) { 1133 | return d['name'].slice(0, -i) + '...'; 1134 | }); 1135 | ++i; 1136 | } 1137 | } else { 1138 | return d; 1139 | } 1140 | } 1141 | }); 1142 | } 1143 | 1144 | /** 1145 | * Give some extra style 1146 | */ 1147 | 1148 | legendBox 1149 | .selectAll('.legend text') 1150 | .attr('fill', vm._addStyle.legend.text.textColor) 1151 | .attr('font-size', vm._addStyle.legend.text.fontSize) 1152 | .attr('font-weight', vm._addStyle.legend.text.fontWeight); 1153 | 1154 | // Prevent default scrolling of all elements inside legendBox 1155 | let isFirefox = typeof InstallTrigger !== 'undefined'; 1156 | let support = 1157 | 'onwheel' in d3.select('.legendBox') 1158 | ? 'wheel' // Modern browsers support 'wheel' 1159 | : document.onmousewheel !== undefined 1160 | ? 'mousewheel' // Webkit and IE support at least 'mousewheel' 1161 | : 'DOMMouseScroll'; // let's assume that remaining browsers are older Firefox 1162 | if (isFirefox) { 1163 | // Newer Firefox versions support wheel events. 1164 | // DOMMouseScroll is not supported yet. 1165 | support = 'wheel'; 1166 | } 1167 | d3.select('.legendBoxBackground').on(support, function () { 1168 | var evt = d3.event; 1169 | evt.preventDefault(); 1170 | }); 1171 | 1172 | d3.select('.scroll-legend').on(support, function () { 1173 | var evt = d3.event; 1174 | evt.preventDefault(); 1175 | }); 1176 | 1177 | legendBox.selectAll('text').on(support, function () { 1178 | var evt = d3.event; 1179 | evt.preventDefault(); 1180 | }); 1181 | 1182 | legendBox.selectAll('rect').on(support, function () { 1183 | var evt = d3.event; 1184 | evt.preventDefault(); 1185 | }); 1186 | 1187 | legendBox.selectAll('path').on(support, function () { 1188 | var evt = d3.event; 1189 | evt.preventDefault(); 1190 | }); 1191 | }; 1192 | 1193 | Chart.drawGrid = function () { 1194 | var vm = this; 1195 | return vm; 1196 | }; 1197 | 1198 | Chart.drawAxes = function () { 1199 | var vm = this; 1200 | var yAxis; 1201 | 1202 | /** 1203 | * Draw axes depends on axes config and styles. 1204 | * Let's start with config. 1205 | */ 1206 | 1207 | //Axes tooltip 1208 | const axesTip = vm.helper.utils.d3.tip().html((d) => { 1209 | return '
' + d + '
'; 1210 | }); 1211 | 1212 | if ( 1213 | (!vm._config.yAxis || 1214 | (vm._config.yAxis && vm._config.yAxis.enabled !== false)) && 1215 | (!vm._config.xAxis || 1216 | (vm._config.xAxis && vm._config.xAxis.enabled !== false)) 1217 | ) { 1218 | vm._svg.call(axesTip); 1219 | } 1220 | 1221 | /** 1222 | * Config axes 1223 | */ 1224 | 1225 | // y 1226 | 1227 | if ( 1228 | !vm._config.yAxis || 1229 | (vm._config.yAxis && vm._config.yAxis.enabled !== false) 1230 | ) { 1231 | yAxis = vm._svg.append('g').attr('class', 'y axis').call(vm._axes.y); 1232 | 1233 | if (vm._config.yAxis && vm._config.yAxis.text) { 1234 | yAxis 1235 | .append('text') 1236 | .attr('class', 'axis-title') 1237 | .attr('y', -vm._margin.left * 0.7) 1238 | .attr('x', -vm._height / 2) 1239 | .attr('transform', 'rotate(-90)') 1240 | .attr('text-anchor', 'middle') 1241 | .text(vm._config.yAxis.text); 1242 | } 1243 | 1244 | if (vm._config.yAxis && vm._config.yAxis.scaleText) { 1245 | yAxis 1246 | .append('text') 1247 | .attr('class', 'axis-scale-title') 1248 | .attr('y', -12) 1249 | .attr('x', -12) 1250 | .attr('font-weight', 'bold') 1251 | .attr('text-anchor', 'middle') 1252 | .text(vm._config.yAxis.scaleText); 1253 | } 1254 | } 1255 | 1256 | if ( 1257 | vm._config.yAxis.domain && 1258 | vm._config.yAxis.domain.hasOwnProperty('enabled') 1259 | ) { 1260 | if (vm._config.yAxis.ticks) { 1261 | if ( 1262 | vm._config.yAxis.domain.enabled === false && 1263 | vm._config.yAxis.ticks.enabled === false 1264 | ) { 1265 | d3.select('g.y.axis .domain').remove(); 1266 | d3.selectAll('g.y.axis .tick').remove(); 1267 | } else if ( 1268 | vm._config.yAxis.domain.enabled === false && 1269 | vm._config.yAxis.ticks.enabled === true 1270 | ) { 1271 | d3.select('g.y.axis .domain').remove(); 1272 | // d3.selectAll('g.y.axis .tick text').remove(); 1273 | } 1274 | } else { 1275 | if (vm._config.yAxis.domain.enabled === false) { 1276 | d3.select('g.y.axis .domain').remove(); 1277 | d3.selectAll('g.y.axis .tick').remove(); 1278 | } 1279 | } 1280 | } 1281 | 1282 | if ( 1283 | !vm._config.yAxis || 1284 | (vm._config.yAxis && vm._config.yAxis.enabled !== false) 1285 | ) { 1286 | // Add ellipsis to cut label text when too long 1287 | // for yAxis on the left 1288 | yAxis.selectAll('text').each(function (d) { 1289 | let element = this; 1290 | if (typeof d === 'string') { 1291 | if (this.getComputedTextLength() > 0.8 * vm._margin.left) { 1292 | d3.select(element) 1293 | .on('mouseover', axesTip.show) 1294 | .on('mouseout', axesTip.hide); 1295 | let i = 1; 1296 | while (this.getComputedTextLength() > 0.8 * vm._margin.left) { 1297 | d3.select(this) 1298 | .text(function (d) { 1299 | return d.slice(0, -i) + '...'; 1300 | }) 1301 | .attr('title', d); 1302 | ++i; 1303 | } 1304 | } else { 1305 | return d; 1306 | } 1307 | } 1308 | }); 1309 | } 1310 | 1311 | // Dropdown Y axis 1312 | if ( 1313 | vm._config.yAxis && 1314 | vm._config.yAxis.dropdown && 1315 | vm._config.yAxis.dropdown.enabled === true 1316 | ) { 1317 | var yAxisDropDown = d3 1318 | .select(vm._config.bindTo) 1319 | .append('div') 1320 | .attr('class', 'dbox-yAxis-select') 1321 | .append('select') 1322 | .on('change', function () { 1323 | vm.updateAxis('y', this.value); 1324 | }); 1325 | 1326 | /* 1327 | .attr('style', function(){ 1328 | var x = -1*d3.select(vm._config.bindTo).node().getBoundingClientRect().width/2+ vm._chart._margin.left/4; 1329 | var y = -1*d3.select(vm._config.bindTo).node().getBoundingClientRect().height/2; 1330 | return 'transform: translate('+x+'px,'+y+'px) rotate(-90deg);' 1331 | }) 1332 | */ 1333 | 1334 | var x = 1335 | (-1 * 1336 | d3.select(vm._config.bindTo).node().getBoundingClientRect().width) / 1337 | 2 + 1338 | vm._margin.left / 2.5; 1339 | var y = 1340 | (-1 * 1341 | d3.select(vm._config.bindTo).node().getBoundingClientRect().height) / 1342 | 1.5; 1343 | 1344 | if (vm._config.yAxis.dropdown.styles) { 1345 | var styles = vm._config.yAxis.dropdown.styles; 1346 | styles.display = 'block'; 1347 | styles.transform = 'translate(' + x + 'px,' + y + 'px) rotate(-90deg)'; 1348 | styles.margin = 'auto'; 1349 | styles['text-align'] = 'center'; 1350 | styles['text-align-last'] = 'center'; 1351 | 1352 | d3.select('.dbox-yAxis-select select').styles(styles); 1353 | 1354 | d3.select('.dbox-yAxis-select select option').styles({ 1355 | 'text-align': 'left', 1356 | }); 1357 | } else { 1358 | d3.select('.dbox-yAxis-select select').styles({ 1359 | display: 'block', 1360 | transform: 'translate(' + x + 'px,' + y + 'px) rotate(-90deg)', 1361 | margin: 'auto', 1362 | 'text-align': 'center', 1363 | 'text-align-last': 'center', 1364 | }); 1365 | 1366 | d3.select('.dbox-yAxis-select select option').styles({ 1367 | 'text-align': 'left', 1368 | }); 1369 | } 1370 | 1371 | if (vm._config.yAxis.dropdown.options) { 1372 | yAxisDropDown 1373 | .selectAll('option') 1374 | .data(vm._config.yAxis.dropdown.options) 1375 | .enter() 1376 | .append('option') 1377 | .attr('class', function (d) { 1378 | return d.value; 1379 | }) 1380 | .attr('value', function (d) { 1381 | return d.value; 1382 | }) 1383 | .text(function (d) { 1384 | return d.title; 1385 | }) 1386 | .property('selected', function (d) { 1387 | return d.selected; 1388 | }); 1389 | } else { 1390 | console.log('No options present in config'); 1391 | } 1392 | } 1393 | 1394 | // y 1395 | 1396 | ///////////////////////////// 1397 | 1398 | // x 1399 | if ( 1400 | !vm._config.xAxis || 1401 | (vm._config.xAxis && vm._config.xAxis.enabled !== false) 1402 | ) { 1403 | vm._xAxis = vm._svg 1404 | .append('g') 1405 | .attr('class', 'x axis') 1406 | .attr('transform', 'translate(0,' + vm._height + ')') 1407 | .call(vm._axes.x); 1408 | 1409 | // Move axis domain line 1410 | if (vm._config.yAxis.scale === 'linear' && vm._scales.y.domain()[0] < 0) { 1411 | vm._xAxis 1412 | .select('.domain') 1413 | .attr( 1414 | 'transform', 1415 | 'translate(0,-' + 1416 | Math.abs(vm._scales.y.range()[0] - vm._scales.y(0)) + 1417 | ')' 1418 | ); 1419 | } 1420 | 1421 | // Do not show line if axis is disabled 1422 | if (vm._config.xAxis.line && vm._config.xAxis.line.enabled === false) { 1423 | vm._xAxis.selectAll('path').style('display', 'none'); 1424 | } 1425 | 1426 | // Set custom position for ticks 1427 | if (vm._config.xAxis.ticks && vm._config.xAxis.ticks.x) { 1428 | vm._xAxis.selectAll('text').attr('dx', vm._config.xAxis.ticks.x); 1429 | } 1430 | 1431 | if (vm._config.xAxis.ticks && vm._config.xAxis.ticks.y) { 1432 | vm._xAxis.selectAll('text').attr('dy', vm._config.xAxis.ticks.y); 1433 | } 1434 | 1435 | // Disable ticks when set to false 1436 | if ( 1437 | vm._config.xAxis.ticks && 1438 | vm._config.xAxis.ticks.line && 1439 | vm._config.xAxis.ticks.line.enabled === false 1440 | ) { 1441 | vm._xAxis.selectAll('line').style('display', 'none'); 1442 | } 1443 | } 1444 | 1445 | if (vm._config.xAxis && vm._config.xAxis.text) { 1446 | vm._svg 1447 | .select('.x.axis') 1448 | .append('text') 1449 | .attr('class', 'axis-title') 1450 | .attr('x', vm._width / 2) 1451 | .attr('y', 40) 1452 | .style('text-anchor', 'middle') 1453 | .text(vm._config.xAxis.text); 1454 | } 1455 | 1456 | if (vm._config.xAxis && vm._config.xAxis.scaleText && vm._xAxis) { 1457 | vm._xAxis 1458 | .append('text') 1459 | .attr('class', 'axis-scale-title') 1460 | .attr('x', vm._width) 1461 | .attr('y', 15) 1462 | .style('text-anchor', 'start') 1463 | .text(vm._config.xAxis.scaleText); 1464 | } 1465 | 1466 | if ( 1467 | vm._config.xAxis.domain !== undefined && 1468 | vm._config.xAxis.domain.hasOwnProperty('enabled') 1469 | ) { 1470 | if (vm._config.xAxis.ticks) { 1471 | if ( 1472 | vm._config.xAxis.domain.enabled === false && 1473 | vm._config.xAxis.ticks.enabled === false 1474 | ) { 1475 | d3.select(vm._config.bindTo + ' g.x.axis .domain').remove(); 1476 | d3.selectAll('g.x.axis .tick').remove(); 1477 | } else if ( 1478 | vm._config.xAxis.domain.enabled === false && 1479 | vm._config.xAxis.ticks.enabled === true 1480 | ) { 1481 | d3.select(vm._config.bindTo + ' g.x.axis .domain').remove(); 1482 | // d3.selectAll('g.x.axis .tick text').remove(); 1483 | } 1484 | } else { 1485 | if (vm._config.xAxis.domain.enabled === false) { 1486 | d3.select(vm._config.bindTo + ' g.x.axis .domain').remove(); 1487 | d3.selectAll(vm._config.bindTo + ' g.x.axis .tick').remove(); 1488 | } 1489 | } 1490 | } 1491 | 1492 | // Dropdown X axis 1493 | if ( 1494 | vm._config.xAxis && 1495 | vm._config.xAxis.dropdown && 1496 | vm._config.xAxis.dropdown.enabled === true 1497 | ) { 1498 | var xAxisDropDown = d3 1499 | .select(vm._config.bindTo) 1500 | .append('div') 1501 | .attr('class', 'dbox-xAxis-select') 1502 | .append('select') 1503 | .on('change', function () { 1504 | vm.updateAxis('x', this.value); 1505 | }); 1506 | 1507 | if (vm._config.xAxis.dropdown.styles) { 1508 | var styles = vm._config.xAxis.dropdown.styles; 1509 | styles.display = 'block'; 1510 | styles.margin = 'auto'; 1511 | styles['text-align'] = 'center'; 1512 | styles['text-align-last'] = 'center'; 1513 | 1514 | d3.select('.dbox-xAxis-select select').styles(styles); 1515 | 1516 | d3.select('.dbox-xAxis-select select option').styles({ 1517 | 'text-align': 'left', 1518 | }); 1519 | } else { 1520 | d3.select('.dbox-xAxis-select select').styles({ 1521 | display: 'block', 1522 | margin: 'auto', 1523 | 'text-align': 'center', 1524 | 'text-align-last': 'center', 1525 | }); 1526 | 1527 | d3.select('.dbox-xAxis-select select option').styles({ 1528 | 'text-align': 'left', 1529 | }); 1530 | } 1531 | 1532 | if (vm._config.xAxis.dropdown.options) { 1533 | xAxisDropDown 1534 | .selectAll('option') 1535 | .data(vm._config.xAxis.dropdown.options) 1536 | .enter() 1537 | .append('option') 1538 | .attr('class', function (d) { 1539 | return d.value; 1540 | }) 1541 | .attr('value', function (d) { 1542 | return d.value; 1543 | }) 1544 | .text(function (d) { 1545 | return d.title; 1546 | }) 1547 | .property('selected', function (d) { 1548 | return d.selected; 1549 | }); 1550 | } else { 1551 | console.log('No options present in config'); 1552 | } 1553 | } 1554 | 1555 | /** 1556 | * Let's style axes 1557 | */ 1558 | // Style Y axis 1559 | if (vm._config.yAxis.enabled !== false && vm._addStyle.yAxis.enabled) { 1560 | // Axis line 1561 | yAxis 1562 | .selectAll('.domain') 1563 | .attr('stroke-linecap', 'round') 1564 | .attr('stroke-width', vm._addStyle.yAxis.axis.strokeWidth) 1565 | .attr('stroke', vm._addStyle.yAxis.axis.strokeColor) 1566 | .attr('opacity', vm._addStyle.yAxis.axis.strokeOpacity); 1567 | 1568 | //axis title 1569 | yAxis 1570 | .selectAll('.axis-title') 1571 | .attr('font-size', vm._addStyle.yAxis.title.fontSize) 1572 | .attr('font-weight', vm._addStyle.yAxis.title.fontWeight) 1573 | .attr('fill', vm._addStyle.yAxis.title.textColor) 1574 | .attr('text-anchor', vm._addStyle.yAxis.title.textAnchor); 1575 | 1576 | // Tick lines 1577 | yAxis 1578 | .selectAll('.tick line') 1579 | .attr('stroke-width', vm._addStyle.yAxis.ticks.strokeWidth) 1580 | .attr('stroke', vm._addStyle.yAxis.ticks.strokeColor) 1581 | .attr('stroke-opacity', vm._addStyle.yAxis.ticks.opacity) 1582 | .attr('width', vm._addStyle.yAxis.ticks.tickWidth) 1583 | // Condition gridline 1584 | .attr('stroke-dasharray', vm._addStyle.yAxis.ticks.gridDashed) 1585 | .attr( 1586 | 'transform', 1587 | 'translate(-' + vm._addStyle.yAxis.axis.paddingTick + ', 0)' 1588 | ); 1589 | // Don't draw first tick when styled as grid 1590 | if (vm._addStyle.yAxis.ticks.grid) { 1591 | yAxis 1592 | .selectAll('.tick:first-of-type line:first-of-type') 1593 | .attr('stroke', 'none'); 1594 | } 1595 | 1596 | // Tick text 1597 | yAxis 1598 | .selectAll('.tick text') 1599 | .attr('font-size', vm._addStyle.yAxis.labels.fontSize) 1600 | .attr('font-weight', vm._addStyle.yAxis.labels.fontWeight) 1601 | .attr('fill', vm._addStyle.yAxis.labels.textColor) 1602 | .attr('text-anchor', vm._addStyle.yAxis.labels.textAnchor) 1603 | .attr( 1604 | 'transform', 1605 | 'translate(-' + vm._addStyle.yAxis.axis.paddingTick + ', 0)' 1606 | ); 1607 | } 1608 | 1609 | // Style X axis 1610 | if (vm._config.xAxis.enabled !== false && vm._addStyle.xAxis.enabled) { 1611 | // Axis line 1612 | vm._xAxis 1613 | .selectAll('.domain') 1614 | .attr('stroke-linecap', 'round') 1615 | .attr('stroke-width', vm._addStyle.xAxis.axis.strokeWidth) 1616 | .attr('stroke', vm._addStyle.xAxis.axis.strokeColor) 1617 | .attr('opacity', vm._addStyle.xAxis.axis.strokeOpacity); 1618 | 1619 | // Tick lines 1620 | vm._xAxis 1621 | .selectAll('.tick line') 1622 | .attr('stroke-width', vm._addStyle.xAxis.ticks.strokeWidth) 1623 | .attr('stroke', vm._addStyle.xAxis.ticks.strokeColor) 1624 | .attr( 1625 | 'transform', 1626 | 'translate(0, ' + vm._addStyle.xAxis.axis.paddingTick + ')' 1627 | ); 1628 | // Don't draw first tick when styled as grid 1629 | if (vm._addStyle.xAxis.ticks.grid) { 1630 | vm._xAxis 1631 | .selectAll('.tick:first-of-type line:first-of-type') 1632 | .attr('stroke', 'none'); 1633 | } 1634 | 1635 | // Tick text 1636 | vm._xAxis 1637 | .selectAll('.tick text') 1638 | .attr('font-size', vm._addStyle.xAxis.labels.fontSize) 1639 | .attr('font-weight', vm._addStyle.xAxis.labels.fontWeight) 1640 | .attr('fill', vm._addStyle.xAxis.labels.textColor) 1641 | .attr('text-anchor', vm._addStyle.xAxis.labels.textAnchor) 1642 | .attr( 1643 | 'transform', 1644 | vm._addStyle.xAxis.labels.rotate 1645 | ? 'translate(0,55) rotate(' + 1646 | vm._addStyle.xAxis.axis.labels.rotate + 1647 | ')' 1648 | : 'translate(0, ' + vm._addStyle.xAxis.axis.paddingTick + ')' 1649 | ); 1650 | } 1651 | 1652 | const biggestLabelWidth = d3.max( 1653 | d3 1654 | .select('.x.axis') 1655 | .selectAll('text') 1656 | .nodes() 1657 | .map((o) => o.getComputedTextLength()) 1658 | ); 1659 | if ( 1660 | !vm._config.xAxis || 1661 | (vm._config.xAxis && vm._config.xAxis.enabled !== false) 1662 | ) { 1663 | // Add ellipsis to cut label text 1664 | // when it is too long 1665 | 1666 | // Biggest label computed text length 1667 | 1668 | let xBandWidth = 1669 | (vm._scales.x.bandwidth 1670 | ? vm._scales.x.bandwidth() 1671 | : (vm._config.size.width - 1672 | (vm._config.size.margin.left + vm._config.size.margin.right)) / 1673 | vm._scales.x.ticks()) - 5; 1674 | if (biggestLabelWidth > xBandWidth) { 1675 | vm._addStyle.xAxis.labels.rotate = true; 1676 | // Biggest label doesn't fit 1677 | vm._xAxis.selectAll('text').each(function (d) { 1678 | if (typeof d === 'string') { 1679 | // Vertical labels 1680 | d3.select(this) 1681 | .attr('text-anchor', 'end') 1682 | .attr('dy', 0) 1683 | .attr('transform', 'translate(-6,12)rotate(-90)'); 1684 | // Still doesn't fit! 1685 | if ( 1686 | this.getComputedTextLength() > 1687 | 0.8 * vm._config.size.margin.bottom 1688 | ) { 1689 | d3.select(this) 1690 | .on('mouseover', axesTip.show) 1691 | .on('mouseout', axesTip.hide); 1692 | let i = 1; 1693 | while ( 1694 | this.getComputedTextLength() > 1695 | 0.8 * vm._config.size.margin.bottom 1696 | ) { 1697 | d3.select(this) 1698 | .text(function (d) { 1699 | return d.slice(0, -i) + '...'; 1700 | }) 1701 | .attr('title', d); 1702 | ++i; 1703 | } 1704 | } else { 1705 | return d; 1706 | } 1707 | } 1708 | }); 1709 | } 1710 | } 1711 | 1712 | if (vm._config.xAxis.enabled !== false && vm._addStyle.xAxis.enabled) { 1713 | // Axis title 1714 | vm._xAxis 1715 | .selectAll('.axis-title') 1716 | .attr('font-size', vm._addStyle.xAxis.title.fontSize) 1717 | .attr('font-weight', vm._addStyle.xAxis.title.fontWeight) 1718 | .attr('fill', vm._addStyle.xAxis.title.textColor) 1719 | .attr('text-anchor', vm._addStyle.xAxis.title.textAnchor) 1720 | .attr( 1721 | 'transform', 1722 | 'translate(0, ' + 1723 | (vm._addStyle.xAxis.labels.rotate 1724 | ? d3.min([vm._config.size.margin.bottom * 0.7, biggestLabelWidth]) 1725 | : vm._addStyle.xAxis.axis.paddingTick) + 1726 | ')' 1727 | ); 1728 | } 1729 | 1730 | /** 1731 | * Already replaced with addStyle 1732 | */ 1733 | /*if (vm._config.yAxis && vm._config.yAxis.enabled !== false) { 1734 | 1735 | if (vm._config.yAxis && vm._config.yAxis.text) { 1736 | yAxis.append('text') 1737 | .attr('class', 'label title') 1738 | .attr('transform', 'rotate(-90)') 1739 | .attr('y', vm._config.yAxis.y ? vm._config.yAxis.y : -50) 1740 | .attr('x', -150) 1741 | .attr('dy', '.71em') 1742 | .style('text-anchor', 'middle') 1743 | .style('fill', vm._config.yAxis.fill ? vm._config.yAxis.fill : 'black') 1744 | .style('font-size', vm._config.yAxis['font-size'] ? vm._config.yAxis['font-size'] : '12px') 1745 | .style('font-weight', vm._config.xAxis['font-weight'] ? vm._config.xAxis['font-weight'] : '600') 1746 | .text(vm._config.yAxis.text); 1747 | } 1748 | }*/ 1749 | 1750 | // Set ticks straight or dashed, to be replaced with *addStyle -checked 1751 | if ( 1752 | vm._config.yAxis.ticks && 1753 | vm._config.yAxis.ticks.enabled && 1754 | vm._config.yAxis.ticks.style 1755 | ) { 1756 | switch (vm._config.yAxis.ticks.style) { 1757 | case 'straightLine': 1758 | break; 1759 | case 'dashLine': 1760 | d3.selectAll('g.y.axis .tick line').attr('stroke-dasharray', '5, 5'); 1761 | break; 1762 | } 1763 | } 1764 | // To be replaced with *addStyle -checked 1765 | if ( 1766 | vm._config.yAxis.domain && 1767 | vm._config.yAxis.domain.enabled && 1768 | vm._config.yAxis.domain.stroke 1769 | ) { 1770 | d3.select('g.y.axis .domain').attr( 1771 | 'stroke', 1772 | vm._config.yAxis.domain.stroke 1773 | ); 1774 | } 1775 | 1776 | // To be replaced with *addStyle -checked 1777 | if ( 1778 | vm._config.yAxis.domain && 1779 | vm._config.yAxis.domain.enabled && 1780 | vm._config.yAxis.domain['stroke-width'] 1781 | ) { 1782 | d3.select('g.y.axis .domain').attr( 1783 | 'stroke-width', 1784 | vm._config.yAxis.domain['stroke-width'] 1785 | ); 1786 | } 1787 | 1788 | // y 1789 | 1790 | ///////////////////////////// 1791 | 1792 | // x 1793 | 1794 | if ( 1795 | !vm._config.xAxis || 1796 | (vm._config.xAxis && vm._config.xAxis.enabled !== false) 1797 | ) { 1798 | // To be replaced with *addStyle -checked 1799 | if (vm._config.xAxis.ticks && vm._config.xAxis.ticks.style) { 1800 | Object.keys(vm._config.xAxis.ticks.style).forEach(function (k) { 1801 | vm._xAxis.selectAll('text').style(k, vm._config.xAxis.ticks.style[k]); 1802 | }); 1803 | } 1804 | 1805 | // Set rotation for ticks, to be replaced with *addStyle -checked 1806 | if (vm._config.xAxis.ticks && vm._config.xAxis.ticks.rotate) { 1807 | vm._xAxis 1808 | .selectAll('text') 1809 | .attr('text-anchor', 'end') 1810 | .attr('transform', 'rotate(' + vm._config.xAxis.ticks.rotate + ')'); 1811 | } 1812 | 1813 | // Set ticks straight or dashed, to be replaced with *addStyle -checked 1814 | if ( 1815 | vm._config.xAxis.ticks && 1816 | vm._config.xAxis.ticks.enabled && 1817 | vm._config.xAxis.ticks.style 1818 | ) { 1819 | switch (vm._config.xAxis.ticks.style) { 1820 | case 'straightLine': 1821 | break; 1822 | case 'dashLine': 1823 | d3.selectAll(vm._config.bindTo + ' g.x.axis .tick line').attr( 1824 | 'stroke-dasharray', 1825 | '5, 5' 1826 | ); 1827 | break; 1828 | } 1829 | } 1830 | } 1831 | 1832 | // To be replaced with *addStyle -checked 1833 | if ( 1834 | vm._config.xAxis.domain && 1835 | vm._config.xAxis.domain.enabled && 1836 | vm._config.xAxis.domain.stroke 1837 | ) { 1838 | d3.select(vm._config.bindTo + ' g.x.axis .domain').attr( 1839 | 'stroke', 1840 | vm._config.xAxis.domain.stroke 1841 | ); 1842 | } 1843 | 1844 | // To be replaced with *addStyle -checked 1845 | if ( 1846 | vm._config.xAxis.domain && 1847 | vm._config.xAxis.domain.enabled && 1848 | vm._config.xAxis.domain['stroke-width'] 1849 | ) { 1850 | d3.select(vm._config.bindTo + ' g.x.axis .domain').attr( 1851 | 'stroke-width', 1852 | vm._config.xAxis.domain['stroke-width'] 1853 | ); 1854 | } 1855 | }; 1856 | 1857 | Chart.updateAxis = function (axis, value) { 1858 | var vm = this; 1859 | 1860 | if (axis === 'x') { 1861 | vm._config.xAxis.dropdown.options.map((obj) => { 1862 | if (obj.value === value) { 1863 | obj.selected = true; 1864 | } else { 1865 | obj.selected = false; 1866 | } 1867 | }); 1868 | } else if (axis === 'y') { 1869 | vm._config.yAxis.dropdown.options.map((obj) => { 1870 | if (obj.value === value) { 1871 | obj.selected = true; 1872 | } else { 1873 | obj.selected = false; 1874 | } 1875 | }); 1876 | } 1877 | 1878 | vm._config[axis] = value; 1879 | 1880 | var layer = vm.layers[0]; 1881 | 1882 | layer._config = vm._config; 1883 | 1884 | vm.draw(); 1885 | 1886 | // Trigger update chart axis 1887 | if (vm._config.events && vm._config.events.change) { 1888 | vm.dispatch.on('change.axis', vm._config.events.change(vm)); 1889 | } 1890 | }; 1891 | 1892 | Chart.dispatch = d3.dispatch('load', 'change'); 1893 | 1894 | Chart.mapData = function (data, callback) { 1895 | callback(null, data); 1896 | }; 1897 | 1898 | Chart.getDomains = function (data) { 1899 | var vm = this; 1900 | 1901 | var domains = {}; 1902 | var minMax = []; 1903 | var sorted = []; 1904 | 1905 | // Default ascending function 1906 | var sortFunctionY = function (a, b) { 1907 | return vm.utils.sortAscending(a.y, b.y); 1908 | }; 1909 | var sortFunctionX = function (a, b) { 1910 | return vm.utils.sortAscending(a.x, b.x); 1911 | }; 1912 | 1913 | // If applying sort 1914 | if (vm._config.data.sort && vm._config.data.sort.order) { 1915 | switch (vm._config.data.sort.order) { 1916 | case 'asc': 1917 | sortFunctionY = function (a, b) { 1918 | return vm.utils.sortAscending(a.y, b.y); 1919 | }; 1920 | sortFunctionX = function (a, b) { 1921 | return vm.utils.sortAscending(a.x, b.x); 1922 | }; 1923 | break; 1924 | 1925 | case 'desc': 1926 | sortFunctionY = function (a, b) { 1927 | return vm.utils.sortDescending(a.y, b.y); 1928 | }; 1929 | sortFunctionX = function (a, b) { 1930 | return vm.utils.sortDescending(a.x, b.x); 1931 | }; 1932 | break; 1933 | } 1934 | } 1935 | 1936 | // xAxis 1937 | if (vm._config.xAxis && vm._config.xAxis.scale) { 1938 | switch (vm._config.xAxis.scale) { 1939 | case 'linear': 1940 | minMax = d3.extent(data, function (d) { 1941 | return d.x; 1942 | }); 1943 | domains.x = minMax; 1944 | break; 1945 | 1946 | case 'time': 1947 | minMax = d3.extent(data, function (d) { 1948 | return d.x; 1949 | }); 1950 | domains.x = minMax; 1951 | break; 1952 | 1953 | case 'ordinal': 1954 | // If the xAxis' order depends on the yAxis values 1955 | if (vm._config.data.sort && vm._config.data.sort.axis === 'y') { 1956 | sorted = data.sort(sortFunctionY); 1957 | } else { 1958 | sorted = data.sort(sortFunctionX); 1959 | } 1960 | 1961 | domains.x = []; 1962 | sorted.forEach(function (d) { 1963 | domains.x.push(d.x); 1964 | }); 1965 | 1966 | break; 1967 | 1968 | case 'quantile': 1969 | // The xAxis order depends on the yAxis values 1970 | if (vm._config.data.sort && vm._config.data.sort.axis === 'y') { 1971 | sorted = data.sort(sortFunctionY); 1972 | } else { 1973 | sorted = data.sort(sortFunctionX); 1974 | } 1975 | 1976 | domains.q = []; 1977 | sorted.forEach(function (d) { 1978 | domains.q.push(d.x); 1979 | }); 1980 | 1981 | domains.x = d3.range(vm._config.xAxis.buckets); 1982 | 1983 | break; 1984 | 1985 | default: 1986 | minMax = d3.extent(data, function (d) { 1987 | return d.x; 1988 | }); 1989 | domains.x = minMax; 1990 | break; 1991 | } 1992 | } else { 1993 | minMax = d3.extent(data, function (d) { 1994 | return d.x; 1995 | }); 1996 | domains.x = minMax; 1997 | } 1998 | 1999 | // yAxis 2000 | if (vm._config.yAxis && vm._config.yAxis.scale) { 2001 | switch (vm._config.yAxis.scale) { 2002 | case 'linear': 2003 | minMax = d3.extent(data, function (d) { 2004 | return d.y; 2005 | }); 2006 | 2007 | // Adjust for min values greater than zero 2008 | // Set the min value to -10% 2009 | if (minMax[0] > 0) { 2010 | minMax[0] = minMax[0] - (minMax[1] - minMax[0]) * 0.1; 2011 | } 2012 | domains.y = minMax; 2013 | break; 2014 | 2015 | case 'time': 2016 | minMax = d3.extent(data, function (d) { 2017 | return d.y; 2018 | }); 2019 | domains.y = minMax; 2020 | break; 2021 | 2022 | case 'ordinal': 2023 | if (vm._config.data.sort && vm._config.data.sort.axis === 'y') { 2024 | sorted = data.sort(function (a, b) { 2025 | return vm.utils.sortAscending(a.y, b.y); 2026 | }); 2027 | domains.y = []; 2028 | sorted.forEach(function (d) { 2029 | domains.y.push(d.x); 2030 | }); 2031 | } else { 2032 | domains.y = d3 2033 | .map(data, function (d) { 2034 | return d.y; 2035 | }) 2036 | .keys() 2037 | .sort(function (a, b) { 2038 | return vm.utils.sortAscending(a, b); 2039 | }); 2040 | } 2041 | 2042 | break; 2043 | 2044 | default: 2045 | minMax = d3.extent(data, function (d) { 2046 | return d.y; 2047 | }); 2048 | domains.y = minMax; 2049 | break; 2050 | } 2051 | } else { 2052 | minMax = d3.extent(data, function (d) { 2053 | return d.y; 2054 | }); 2055 | domains.y = minMax; 2056 | } 2057 | 2058 | return domains; 2059 | }; 2060 | 2061 | Chart.destroy = function () { 2062 | var vm = this; 2063 | d3.select(vm._config.bindTo).html(''); 2064 | }; 2065 | 2066 | Chart.init(config); 2067 | 2068 | return Chart; 2069 | } 2070 | -------------------------------------------------------------------------------- /lib/helper.js: -------------------------------------------------------------------------------- 1 | import * as d3 from 'd3'; 2 | var d3Tip = require('d3-tip'); 3 | import * as _ from 'lodash'; 4 | 5 | export default function () { 6 | var vm = this; // Hard binded to chart 7 | 8 | var Helper = { 9 | chart: { 10 | config: vm._config, 11 | width: vm._width, 12 | height: vm._height, 13 | style: vm._addStyle, 14 | fullSvg: function () { 15 | return vm._fullSvg; 16 | }, 17 | svg: function () { 18 | return vm._svg; 19 | } 20 | }, 21 | utils: { 22 | d3: {} 23 | } 24 | }; 25 | Helper.utils.d3.tip = typeof d3Tip === 'function' ? d3Tip : d3Tip.default; 26 | 27 | /** 28 | * Generate scale based on data and config 29 | * @param {*} data 30 | * @param {*} config 31 | * @returns 32 | */ 33 | Helper.utils.generateScale = function (data, config) { 34 | var scale = {}; 35 | var domains; 36 | if (!config.range) { 37 | throw 'Range is not defined'; 38 | } 39 | // Used in bars.js when we want to create a groupBy or stackBy bar chart 40 | if (config.groupBy && config.groupBy === 'parent') { 41 | // Axis of type band 42 | domains = data.map(function (d) { 43 | return d[config.column]; 44 | }); 45 | } else if (config.stackBy && config.stackBy === 'parent') { 46 | domains = data[0].map(function (d) { 47 | return d.data[config.column]; 48 | }); 49 | } else if (config.groupBy === 'children') { 50 | // GroupBy Columns 51 | domains = config.column; 52 | } else if (config.groupBy === 'data') { 53 | // Considering the highest value on all the columns for each groupBy column 54 | domains = [ 55 | 0, 56 | d3.max(data, function (d) { 57 | return d3.max(config.column, function (column) { 58 | return d[column]; 59 | }); 60 | }) 61 | ]; 62 | } else if (config.stackBy === 'data') { 63 | // Using a d3.stack() 64 | domains = [ 65 | 0, 66 | d3.max(data, function (serie) { 67 | return d3.max(serie, function (d) { 68 | return d[1]; 69 | }); 70 | }) 71 | ]; 72 | } else if (config.groupBy === undefined && config.type === 'band') { 73 | // In case the axis is of type band and there is no groupby 74 | domains = data.map(function (d) { 75 | return d[config.column]; 76 | }); 77 | } else if (config.type === 'linear') { 78 | // Axis of type numeric 79 | if (config.minZero) { 80 | domains = [ 81 | 0, 82 | d3.max(data, function (d) { 83 | return +d[config.column]; 84 | }) 85 | ]; 86 | } else { 87 | domains = d3.extent(data, function (d) { 88 | return +d[config.column]; 89 | }); 90 | } 91 | } else { 92 | // Axis of type band 93 | domains = data.map(function (d) { 94 | return d[config.column]; 95 | }); 96 | } 97 | 98 | if (config.domains && Array.isArray(config.domains)) { 99 | domains = config.domains; 100 | } 101 | 102 | if (config.type) { 103 | switch (config.type) { 104 | case 'linear': 105 | scale = d3 106 | .scaleLinear() 107 | .rangeRound(config.range) 108 | .domain(domains) 109 | .nice(); 110 | break; 111 | 112 | case 'time': 113 | scale = d3.scaleTime().range(config.range); 114 | // .domain(domains); 115 | break; 116 | 117 | case 'ordinal': 118 | scale = d3 119 | .scaleBand() 120 | .rangeRound(config.range) 121 | .padding(0.1) 122 | .domain(domains); 123 | break; 124 | 125 | case 'band': 126 | scale = d3 127 | .scaleBand() 128 | .rangeRound(config.range) 129 | .domain(domains) 130 | .padding(0.1); 131 | break; 132 | 133 | case 'quantile': 134 | scale = d3 135 | .scaleBand() 136 | .rangeRound(config.range) 137 | .padding(0.1) 138 | .domain( 139 | data.map(function (d) { 140 | return d[config.column]; 141 | }) 142 | ); 143 | if (!config.bins) { 144 | config.bins = 10; 145 | } 146 | scale = d3.scaleQuantile().range(d3.range(config.bins)); 147 | break; 148 | 149 | default: 150 | scale = d3 151 | .scaleLinear() 152 | .rangeRound(config.range) 153 | .domain(domains) 154 | .nice(); 155 | break; 156 | } 157 | } else { 158 | scale = d3 159 | .scaleLinear() 160 | .rangeRound(config.range) 161 | .domain(domains) 162 | .nice(); 163 | } 164 | 165 | return scale; 166 | }; 167 | 168 | /** 169 | * Format numbers 170 | * @param {Object} config - configurate current formatter 171 | * @param {number} config.decimals - Quantity of decimals to use 172 | * @param {string} config.axis - Current scale selected from axis ['xAxis', 'yAxis'] 173 | * @param {string} config.formatPreffix - Preffix to use in formatting. Eg. '$' 174 | * @param {string} config.formatSuffix - Suffix to use in formatting. Eg. '%' 175 | * @param {boolean} [smallNumber] - Display number in small format 176 | * @returns Function configured to parse a number [d] 177 | */ 178 | Helper.utils.format = function (config, smallNumber) { 179 | if (!config) { 180 | // Default config 181 | var linearAxis = 182 | vm._config.yAxis && vm._config.yAxis.scale === 'linear' ? 183 | 'yAxis' : 184 | vm._config.xAxis && vm._config.xAxis.scale === 'linear' ? 185 | 'xAxis' : 186 | ''; 187 | config = { 188 | decimals: vm._config.decimals, 189 | axis: linearAxis, 190 | formatPreffix: vm._config.formatPreffix, 191 | formatSuffix: vm._config.formatSuffix 192 | }; 193 | } 194 | return function (d) { 195 | if (Number.isNaN(Number(d))) { 196 | // d is not a number, return original value 197 | return d; 198 | } 199 | var fullNumber = smallNumber ? false : true; 200 | var floatingPoints = 1; // Default 201 | if (config.decimals !== undefined && Number.isInteger(config.decimals)) { 202 | floatingPoints = Number(config.decimals); 203 | } 204 | var value = ''; 205 | if (config.formatPreffix) { 206 | value += config.formatPreffix; 207 | } 208 | var suffix = ''; 209 | 210 | if (smallNumber) { 211 | var currentAxis = config.axis; 212 | var mean = currentAxis ? 213 | d3.mean(vm._scales[currentAxis.replace('Axis', '')].ticks()) : 214 | d; 215 | 216 | if (mean >= 1000000000000) { 217 | if (currentAxis) { 218 | vm._config[currentAxis].scaleText = 'Billones'; 219 | } else { 220 | suffix = ' billones'; 221 | } 222 | d = d / 1000000000000; 223 | } else if (mean >= 1000000000) { 224 | // Thousands of millions 225 | if (currentAxis) { 226 | vm._config[currentAxis].scaleText = 'Miles de millones'; 227 | } else { 228 | suffix = ' mil millones'; 229 | } 230 | d = d / 1000000000; 231 | } else if (mean >= 1000000) { 232 | // Millions 233 | if (currentAxis) { 234 | vm._config[currentAxis].scaleText = 'Millones'; 235 | } else { 236 | suffix = ' millones'; 237 | } 238 | d = d / 1000000; 239 | } else if (mean >= 10000) { 240 | // Thousands 241 | if (currentAxis) { 242 | vm._config[currentAxis].scaleText = 'Miles'; 243 | } else { 244 | suffix = ' mil'; 245 | } 246 | d = d / 1000; 247 | } 248 | } 249 | 250 | if (Number.isInteger(d)) { 251 | value += d3.format(',.0f')(d); 252 | } else if (d > 1) { 253 | value += d3.format(',.' + floatingPoints + 'f')(d); 254 | } else { 255 | var floats = d.toString().split('.')[1]; 256 | var points = 1; 257 | if (floats) { 258 | for (let index = 0; index < floats.length; index++) { 259 | const number = Number(floats[index]); 260 | if (number === 0) { 261 | points += 1; 262 | } else { 263 | break; 264 | } 265 | } 266 | value += d3.format(',.' + points + 'f')(d); 267 | } 268 | } 269 | value += suffix; 270 | 271 | if (config.formatSuffix && value.indexOf(config.formatSuffix) < 0) { 272 | value += config.formatSuffix; 273 | } 274 | return value; 275 | }; 276 | }; 277 | 278 | // wrap function used in x axis labels 279 | Helper.utils.wrap = function (text, width, tooltip) { 280 | text.each(function () { 281 | var text = d3.select(this), 282 | words = text 283 | .text() 284 | .split(/\s+/) 285 | .reverse(), 286 | word, 287 | line = [], 288 | lineNumber = 0, 289 | lineHeight = 1.1, // ems 290 | y = text.attr('y'), 291 | dy = parseFloat(text.attr('dy')) || 0, 292 | tspan = text 293 | .text(null) 294 | .append('tspan') 295 | .attr('x', 0) 296 | .attr('y', y) 297 | .attr('dy', dy + 'em'); 298 | 299 | while ((word = words.pop())) { 300 | line.push(word); 301 | tspan.text(line.join(' ')); 302 | if (tspan.node().getComputedTextLength() > width) { 303 | line.pop(); 304 | tspan.text(line.join(' ')); 305 | line = [word]; 306 | tspan = text 307 | .append('tspan') 308 | .attr('x', 0) 309 | .attr('y', y) 310 | .attr('dy', ++lineNumber * lineHeight + dy + 'em') 311 | .text(word); 312 | 313 | if (lineNumber > 0) { 314 | if ( 315 | words.length > 0 && 316 | tspan.node().getComputedTextLength() > width 317 | ) { 318 | if (tooltip) { 319 | text.on('mouseover', tooltip.show).on('mouseout', tooltip.hide); 320 | } 321 | let i = 1; 322 | while (tspan.node().getComputedTextLength() > width) { 323 | tspan.text(function () { 324 | return tspan.text().slice(0, -i) + '...'; 325 | }); 326 | ++i; 327 | } 328 | } 329 | words = []; 330 | } else { 331 | let i = 1; 332 | while (tspan.node().getComputedTextLength() > width) { 333 | tspan.text(function () { 334 | return tspan.text().slice(0, -i) + '...'; 335 | }); 336 | ++i; 337 | } 338 | } 339 | } 340 | } 341 | }); 342 | }; 343 | 344 | Helper.utils.sortAscending = function (a, b) { 345 | if (!Number.isNaN(+a) && !Number.isNaN(+b)) { 346 | // If both values are numbers use numeric value 347 | return Number(a) - Number(b); 348 | } else if (!Number.isNaN(+a) && Number.isNaN(+b)) { 349 | return -1; 350 | } else if (Number.isNaN(+a) && !Number.isNaN(+b)) { 351 | return 1; 352 | } else if (a <= b) { 353 | return -1; 354 | } else { 355 | return 1; 356 | } 357 | }; 358 | 359 | Helper.utils.sortDescending = function (a, b) { 360 | if (!Number.isNaN(+b) && !Number.isNaN(+a)) { 361 | // If both values are numbers use numeric value 362 | return Number(b) - Number(a); 363 | } else if (!Number.isNaN(+b) && Number.isNaN(+a)) { 364 | return -1; 365 | } else if (Number.isNaN(+b) && !Number.isNaN(+a)) { 366 | return 1; 367 | } else if (b <= a) { 368 | return -1; 369 | } else { 370 | return 1; 371 | } 372 | }; 373 | 374 | Helper.utils.VirtualScroller = function () { 375 | var enter = null, 376 | update = null, 377 | exit = null, 378 | data = [], 379 | dataid = null, 380 | svg = null, 381 | viewport = null, 382 | totalRows = 0, 383 | position = 0, 384 | rowHeight = 30, 385 | totalHeight = 0, 386 | viewportHeight = 0, 387 | visibleRows = 0, 388 | delta = 0, 389 | lineNumber = 0, 390 | lineHeight = 0.7, //ems 391 | scrollTop = 0; 392 | 393 | function virtualscroller(container) { 394 | function render(resize) { 395 | if (resize) { 396 | /* 397 | * Tested values: 398 | * 240 -> 9 rows 399 | * 170 -> 13 rows 400 | */ 401 | viewportHeight = parseInt(viewport.style('height')) - 170; 402 | visibleRows = Math.ceil(viewportHeight / rowHeight); 403 | } 404 | var lastPosition = position; 405 | if (position < data.length && position >= 0 && scrollTop < 0) { 406 | position += 1; 407 | } else if (position <= data.length && position > 0 && scrollTop > 0) { 408 | position -= 1; 409 | } 410 | delta = position - lastPosition; 411 | scrollRenderFrame(position); 412 | } 413 | 414 | function scrollRenderFrame(scrollPosition) { 415 | var position0 = Math.max( 416 | 0, 417 | Math.min(scrollPosition, totalRows - visibleRows + 1) 418 | ), 419 | position1 = position0 + visibleRows; 420 | container.each(function () { 421 | var rowSelection = container 422 | .selectAll('.legend-checkbox') 423 | .data( 424 | data.slice(position0, Math.min(position1, totalRows)), 425 | dataid 426 | ); 427 | rowSelection 428 | .exit() 429 | .call(exit) 430 | .remove(); 431 | rowSelection 432 | .enter() 433 | .append('g') 434 | .attr('class', 'legend-checkbox legend') 435 | .attr('random', function (d) { 436 | return d; 437 | }) 438 | .call(enter) 439 | .attr('transform', function (d, i) { 440 | return ( 441 | 'translate(0,' + 442 | (vm._config.legendTitle && lineNumber > 1 ? 443 | lineNumber * lineHeight + i : 444 | 1 + i) * 445 | 21 + 446 | ')' 447 | ); 448 | }) 449 | .on('click', function (d) { 450 | // Run the custom function 451 | var i = data.findIndex(x => x.name === d.name); 452 | if (typeof vm._config.events.onClickLegend === 'function') { 453 | vm._config.events.onClickLegend.call(this, d, i); 454 | } 455 | d3.event.stopPropagation(); 456 | }); 457 | 458 | rowSelection.order(); 459 | var rowUpdateSelection = container.selectAll('.legend-checkbox'); 460 | 461 | rowUpdateSelection.call(update); 462 | 463 | rowUpdateSelection.each(function (d, i) { 464 | d3.select(this) 465 | .attr('font-weight', 'bold') 466 | .attr('transform', function (d) { 467 | return ( 468 | 'translate(0,' + 469 | (vm._config.legendTitle && lineNumber > 1 ? 470 | lineNumber * lineHeight + i : 471 | 1 + i) * 472 | 21 + 473 | ')' 474 | ); 475 | }); 476 | }); 477 | }); 478 | } 479 | 480 | virtualscroller.render = render; 481 | let isFirefox = typeof InstallTrigger !== 'undefined'; 482 | let support = 483 | 'onwheel' in d3.select('.legendBox') ? 484 | 'wheel' // Modern browsers support "wheel" 485 | : 486 | document.onmousewheel !== undefined ? 487 | 'mousewheel' // Webkit and IE support at least "mousewheel" 488 | : 489 | 'wheel'; // let's assume that remaining browsers are older Firefox 490 | d3.select('.legendBox').on(support, function () { 491 | // isFirefox ? 'wheel' : 'mousewheel.zoom' 492 | //Chrome & IE: mousewheel.zoom | Firefox: DOMMouseScroll (not supported yet). 493 | var evt = d3.event; 494 | evt.preventDefault(); 495 | scrollTop = isFirefox ? evt.deltaY : evt.wheelDelta; 496 | render(true); 497 | }); 498 | render(true); 499 | drawScrollLegend(visibleRows); 500 | } 501 | 502 | function drawScrollLegend(visibleRows) { 503 | var scrollLegend = d3 504 | .select('.legendBox') 505 | .append('g') 506 | .attr('class', 'scroll-legend') 507 | .append('text') 508 | .attr('transform', `translate(0,${visibleRows * 25})`); 509 | 510 | scrollLegend 511 | .append('tspan') 512 | .attr('class', 'material-icons expand-more') 513 | .text('mouse'); 514 | 515 | scrollLegend 516 | .append('tspan') 517 | .attr('x', 30) 518 | .attr('y', -12) 519 | .text('Desplázate con el'); 520 | 521 | scrollLegend 522 | .append('tspan') 523 | .attr('x', 60) 524 | .attr('y', -1) 525 | .text('cursor'); 526 | 527 | if (totalRows < visibleRows) { 528 | d3.selectAll('.scroll-legend').style('display', 'none'); 529 | } else { 530 | d3.selectAll('.scroll-legend').style('display', 'flex'); 531 | } 532 | } 533 | 534 | virtualscroller.render = function (resize) {}; 535 | 536 | virtualscroller.data = function (_, __) { 537 | if (!arguments.length) return data; 538 | data = _; 539 | dataid = __; 540 | return virtualscroller; 541 | }; 542 | 543 | virtualscroller.dataid = function (_) { 544 | if (!arguments.length) return dataid; 545 | dataid = _; 546 | return virtualscroller; 547 | }; 548 | 549 | virtualscroller.enter = function (_) { 550 | if (!arguments.length) return enter; 551 | enter = _; 552 | return virtualscroller; 553 | }; 554 | 555 | virtualscroller.update = function (_) { 556 | if (!arguments.length) return update; 557 | update = _; 558 | return virtualscroller; 559 | }; 560 | 561 | virtualscroller.exit = function (_) { 562 | if (!arguments.length) return exit; 563 | exit = _; 564 | return virtualscroller; 565 | }; 566 | 567 | virtualscroller.totalRows = function (_) { 568 | if (!arguments.length) return totalRows; 569 | totalRows = _; 570 | return virtualscroller; 571 | }; 572 | 573 | virtualscroller.rowHeight = function (_) { 574 | if (!arguments.length) return rowHeight; 575 | rowHeight = +_; 576 | return virtualscroller; 577 | }; 578 | 579 | virtualscroller.totalHeight = function (_) { 580 | if (!arguments.length) return totalHeight; 581 | totalHeight = +_; 582 | return virtualscroller; 583 | }; 584 | 585 | virtualscroller.position = function (_) { 586 | if (!arguments.length) return position; 587 | position = +_; 588 | if (viewport) { 589 | viewport.node().scrollTop = position; 590 | } 591 | return virtualscroller; 592 | }; 593 | 594 | virtualscroller.svg = function (_) { 595 | if (!arguments.length) return svg; 596 | svg = _; 597 | return virtualscroller; 598 | }; 599 | 600 | virtualscroller.viewport = function (_) { 601 | if (!arguments.length) return viewport; 602 | viewport = _; 603 | return virtualscroller; 604 | }; 605 | 606 | virtualscroller.delta = function () { 607 | return delta; 608 | }; 609 | 610 | virtualscroller.legendTitle = function (_) { 611 | return legendTitle; 612 | }; 613 | 614 | virtualscroller.lineNumber = function (_) { 615 | if (!arguments.length) return lineNumber; 616 | lineNumber = _; 617 | return virtualscroller; 618 | }; 619 | 620 | const rebind = function (target, source) { 621 | var i = 1, 622 | n = arguments.length, 623 | method; 624 | while (++i < n) 625 | target[(method = arguments[i])] = d3_rebind( 626 | target, 627 | source, 628 | source[method] 629 | ); 630 | return target; 631 | }; 632 | 633 | // Method is assumed to be a standard D3 getter-setter: 634 | // If passed with no arguments, gets the value. 635 | // If passed with arguments, sets the value and returns the target. 636 | function d3_rebind(target, source, method) { 637 | return function () { 638 | var value = method.apply(source, arguments); 639 | return value === source ? target : value; 640 | }; 641 | } 642 | 643 | return virtualscroller; 644 | }; 645 | 646 | return Helper; 647 | } 648 | -------------------------------------------------------------------------------- /out/fonts/OpenSans-Bold-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dboxjs/core/8596333d88dcf41eb9ed577dfcf54656070bdc99/out/fonts/OpenSans-Bold-webfont.eot -------------------------------------------------------------------------------- /out/fonts/OpenSans-Bold-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dboxjs/core/8596333d88dcf41eb9ed577dfcf54656070bdc99/out/fonts/OpenSans-Bold-webfont.woff -------------------------------------------------------------------------------- /out/fonts/OpenSans-BoldItalic-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dboxjs/core/8596333d88dcf41eb9ed577dfcf54656070bdc99/out/fonts/OpenSans-BoldItalic-webfont.eot -------------------------------------------------------------------------------- /out/fonts/OpenSans-BoldItalic-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dboxjs/core/8596333d88dcf41eb9ed577dfcf54656070bdc99/out/fonts/OpenSans-BoldItalic-webfont.woff -------------------------------------------------------------------------------- /out/fonts/OpenSans-Italic-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dboxjs/core/8596333d88dcf41eb9ed577dfcf54656070bdc99/out/fonts/OpenSans-Italic-webfont.eot -------------------------------------------------------------------------------- /out/fonts/OpenSans-Italic-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dboxjs/core/8596333d88dcf41eb9ed577dfcf54656070bdc99/out/fonts/OpenSans-Italic-webfont.woff -------------------------------------------------------------------------------- /out/fonts/OpenSans-Light-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dboxjs/core/8596333d88dcf41eb9ed577dfcf54656070bdc99/out/fonts/OpenSans-Light-webfont.eot -------------------------------------------------------------------------------- /out/fonts/OpenSans-Light-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dboxjs/core/8596333d88dcf41eb9ed577dfcf54656070bdc99/out/fonts/OpenSans-Light-webfont.woff -------------------------------------------------------------------------------- /out/fonts/OpenSans-LightItalic-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dboxjs/core/8596333d88dcf41eb9ed577dfcf54656070bdc99/out/fonts/OpenSans-LightItalic-webfont.eot -------------------------------------------------------------------------------- /out/fonts/OpenSans-LightItalic-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dboxjs/core/8596333d88dcf41eb9ed577dfcf54656070bdc99/out/fonts/OpenSans-LightItalic-webfont.woff -------------------------------------------------------------------------------- /out/fonts/OpenSans-Regular-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dboxjs/core/8596333d88dcf41eb9ed577dfcf54656070bdc99/out/fonts/OpenSans-Regular-webfont.eot -------------------------------------------------------------------------------- /out/fonts/OpenSans-Regular-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dboxjs/core/8596333d88dcf41eb9ed577dfcf54656070bdc99/out/fonts/OpenSans-Regular-webfont.woff -------------------------------------------------------------------------------- /out/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSDoc: Home 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 |

Home

21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |

30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 |
51 | 52 | 55 | 56 |
57 | 58 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /out/scripts/linenumber.js: -------------------------------------------------------------------------------- 1 | /*global document */ 2 | (function() { 3 | var source = document.getElementsByClassName('prettyprint source linenums'); 4 | var i = 0; 5 | var lineNumber = 0; 6 | var lineId; 7 | var lines; 8 | var totalLines; 9 | var anchorHash; 10 | 11 | if (source && source[0]) { 12 | anchorHash = document.location.hash.substring(1); 13 | lines = source[0].getElementsByTagName('li'); 14 | totalLines = lines.length; 15 | 16 | for (; i < totalLines; i++) { 17 | lineNumber++; 18 | lineId = 'line' + lineNumber; 19 | lines[i].id = lineId; 20 | if (lineId === anchorHash) { 21 | lines[i].className += ' selected'; 22 | } 23 | } 24 | } 25 | })(); 26 | -------------------------------------------------------------------------------- /out/scripts/prettify/Apache-License-2.0.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /out/scripts/prettify/lang-css.js: -------------------------------------------------------------------------------- 1 | PR.registerLangHandler(PR.createSimpleLexer([["pln",/^[\t\n\f\r ]+/,null," \t\r\n "]],[["str",/^"(?:[^\n\f\r"\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*"/,null],["str",/^'(?:[^\n\f\r'\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*'/,null],["lang-css-str",/^url\(([^"')]*)\)/i],["kwd",/^(?:url|rgb|!important|@import|@page|@media|@charset|inherit)(?=[^\w-]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*)\s*:/i],["com",/^\/\*[^*]*\*+(?:[^*/][^*]*\*+)*\//],["com", 2 | /^(?:<\!--|--\>)/],["lit",/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],["lit",/^#[\da-f]{3,6}/i],["pln",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i],["pun",/^[^\s\w"']+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[["kwd",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[["str",/^[^"')]+/]]),["css-str"]); 3 | -------------------------------------------------------------------------------- /out/scripts/prettify/prettify.js: -------------------------------------------------------------------------------- 1 | var q=null;window.PR_SHOULD_USE_CONTINUATION=!0; 2 | (function(){function L(a){function m(a){var f=a.charCodeAt(0);if(f!==92)return f;var b=a.charAt(1);return(f=r[b])?f:"0"<=b&&b<="7"?parseInt(a.substring(1),8):b==="u"||b==="x"?parseInt(a.substring(2),16):a.charCodeAt(1)}function e(a){if(a<32)return(a<16?"\\x0":"\\x")+a.toString(16);a=String.fromCharCode(a);if(a==="\\"||a==="-"||a==="["||a==="]")a="\\"+a;return a}function h(a){for(var f=a.substring(1,a.length-1).match(/\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\[0-3][0-7]{0,2}|\\[0-7]{1,2}|\\[\S\s]|[^\\]/g),a= 3 | [],b=[],o=f[0]==="^",c=o?1:0,i=f.length;c122||(d<65||j>90||b.push([Math.max(65,j)|32,Math.min(d,90)|32]),d<97||j>122||b.push([Math.max(97,j)&-33,Math.min(d,122)&-33]))}}b.sort(function(a,f){return a[0]-f[0]||f[1]-a[1]});f=[];j=[NaN,NaN];for(c=0;ci[0]&&(i[1]+1>i[0]&&b.push("-"),b.push(e(i[1])));b.push("]");return b.join("")}function y(a){for(var f=a.source.match(/\[(?:[^\\\]]|\\[\S\s])*]|\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\\d+|\\[^\dux]|\(\?[!:=]|[()^]|[^()[\\^]+/g),b=f.length,d=[],c=0,i=0;c=2&&a==="["?f[c]=h(j):a!=="\\"&&(f[c]=j.replace(/[A-Za-z]/g,function(a){a=a.charCodeAt(0);return"["+String.fromCharCode(a&-33,a|32)+"]"}));return f.join("")}for(var t=0,s=!1,l=!1,p=0,d=a.length;p=5&&"lang-"===b.substring(0,5))&&!(o&&typeof o[1]==="string"))c=!1,b="src";c||(r[f]=b)}i=d;d+=f.length;if(c){c=o[1];var j=f.indexOf(c),k=j+c.length;o[2]&&(k=f.length-o[2].length,j=k-c.length);b=b.substring(5);B(l+i,f.substring(0,j),e,p);B(l+i+j,c,C(b,c),p);B(l+i+k,f.substring(k),e,p)}else p.push(l+i,b)}a.e=p}var h={},y;(function(){for(var e=a.concat(m), 9 | l=[],p={},d=0,g=e.length;d=0;)h[n.charAt(k)]=r;r=r[1];n=""+r;p.hasOwnProperty(n)||(l.push(r),p[n]=q)}l.push(/[\S\s]/);y=L(l)})();var t=m.length;return e}function u(a){var m=[],e=[];a.tripleQuotedStrings?m.push(["str",/^(?:'''(?:[^'\\]|\\[\S\s]|''?(?=[^']))*(?:'''|$)|"""(?:[^"\\]|\\[\S\s]|""?(?=[^"]))*(?:"""|$)|'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$))/,q,"'\""]):a.multiLineStrings?m.push(["str",/^(?:'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$)|`(?:[^\\`]|\\[\S\s])*(?:`|$))/, 10 | q,"'\"`"]):m.push(["str",/^(?:'(?:[^\n\r'\\]|\\.)*(?:'|$)|"(?:[^\n\r"\\]|\\.)*(?:"|$))/,q,"\"'"]);a.verbatimStrings&&e.push(["str",/^@"(?:[^"]|"")*(?:"|$)/,q]);var h=a.hashComments;h&&(a.cStyleComments?(h>1?m.push(["com",/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,q,"#"]):m.push(["com",/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\n\r]*)/,q,"#"]),e.push(["str",/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,q])):m.push(["com",/^#[^\n\r]*/, 11 | q,"#"]));a.cStyleComments&&(e.push(["com",/^\/\/[^\n\r]*/,q]),e.push(["com",/^\/\*[\S\s]*?(?:\*\/|$)/,q]));a.regexLiterals&&e.push(["lang-regex",/^(?:^^\.?|[!+-]|!=|!==|#|%|%=|&|&&|&&=|&=|\(|\*|\*=|\+=|,|-=|->|\/|\/=|:|::|;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|[?@[^]|\^=|\^\^|\^\^=|{|\||\|=|\|\||\|\|=|~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\s*(\/(?=[^*/])(?:[^/[\\]|\\[\S\s]|\[(?:[^\\\]]|\\[\S\s])*(?:]|$))+\/)/]);(h=a.types)&&e.push(["typ",h]);a=(""+a.keywords).replace(/^ | $/g, 12 | "");a.length&&e.push(["kwd",RegExp("^(?:"+a.replace(/[\s,]+/g,"|")+")\\b"),q]);m.push(["pln",/^\s+/,q," \r\n\t\xa0"]);e.push(["lit",/^@[$_a-z][\w$@]*/i,q],["typ",/^(?:[@_]?[A-Z]+[a-z][\w$@]*|\w+_t\b)/,q],["pln",/^[$_a-z][\w$@]*/i,q],["lit",/^(?:0x[\da-f]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+-]?\d+)?)[a-z]*/i,q,"0123456789"],["pln",/^\\[\S\s]?/,q],["pun",/^.[^\s\w"-$'./@\\`]*/,q]);return x(m,e)}function D(a,m){function e(a){switch(a.nodeType){case 1:if(k.test(a.className))break;if("BR"===a.nodeName)h(a), 13 | a.parentNode&&a.parentNode.removeChild(a);else for(a=a.firstChild;a;a=a.nextSibling)e(a);break;case 3:case 4:if(p){var b=a.nodeValue,d=b.match(t);if(d){var c=b.substring(0,d.index);a.nodeValue=c;(b=b.substring(d.index+d[0].length))&&a.parentNode.insertBefore(s.createTextNode(b),a.nextSibling);h(a);c||a.parentNode.removeChild(a)}}}}function h(a){function b(a,d){var e=d?a.cloneNode(!1):a,f=a.parentNode;if(f){var f=b(f,1),g=a.nextSibling;f.appendChild(e);for(var h=g;h;h=g)g=h.nextSibling,f.appendChild(h)}return e} 14 | for(;!a.nextSibling;)if(a=a.parentNode,!a)return;for(var a=b(a.nextSibling,0),e;(e=a.parentNode)&&e.nodeType===1;)a=e;d.push(a)}var k=/(?:^|\s)nocode(?:\s|$)/,t=/\r\n?|\n/,s=a.ownerDocument,l;a.currentStyle?l=a.currentStyle.whiteSpace:window.getComputedStyle&&(l=s.defaultView.getComputedStyle(a,q).getPropertyValue("white-space"));var p=l&&"pre"===l.substring(0,3);for(l=s.createElement("LI");a.firstChild;)l.appendChild(a.firstChild);for(var d=[l],g=0;g=0;){var h=m[e];A.hasOwnProperty(h)?window.console&&console.warn("cannot override language handler %s",h):A[h]=a}}function C(a,m){if(!a||!A.hasOwnProperty(a))a=/^\s*=o&&(h+=2);e>=c&&(a+=2)}}catch(w){"console"in window&&console.log(w&&w.stack?w.stack:w)}}var v=["break,continue,do,else,for,if,return,while"],w=[[v,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"], 18 | "catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"],F=[w,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"],G=[w,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"], 19 | H=[G,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"],w=[w,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"],I=[v,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"], 20 | J=[v,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"],v=[v,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"],K=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/,N=/\S/,O=u({keywords:[F,H,w,"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END"+ 21 | I,J,v],hashComments:!0,cStyleComments:!0,multiLineStrings:!0,regexLiterals:!0}),A={};k(O,["default-code"]);k(x([],[["pln",/^[^]*(?:>|$)/],["com",/^<\!--[\S\s]*?(?:--\>|$)/],["lang-",/^<\?([\S\s]+?)(?:\?>|$)/],["lang-",/^<%([\S\s]+?)(?:%>|$)/],["pun",/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\S\s]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\S\s]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\S\s]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]), 22 | ["default-markup","htm","html","mxml","xhtml","xml","xsl"]);k(x([["pln",/^\s+/,q," \t\r\n"],["atv",/^(?:"[^"]*"?|'[^']*'?)/,q,"\"'"]],[["tag",/^^<\/?[a-z](?:[\w-.:]*\w)?|\/?>$/i],["atn",/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^\s"'>]*(?:[^\s"'/>]|\/(?=\s)))/],["pun",/^[/<->]+/],["lang-js",/^on\w+\s*=\s*"([^"]+)"/i],["lang-js",/^on\w+\s*=\s*'([^']+)'/i],["lang-js",/^on\w+\s*=\s*([^\s"'>]+)/i],["lang-css",/^style\s*=\s*"([^"]+)"/i],["lang-css",/^style\s*=\s*'([^']+)'/i],["lang-css", 23 | /^style\s*=\s*([^\s"'>]+)/i]]),["in.tag"]);k(x([],[["atv",/^[\S\s]+/]]),["uq.val"]);k(u({keywords:F,hashComments:!0,cStyleComments:!0,types:K}),["c","cc","cpp","cxx","cyc","m"]);k(u({keywords:"null,true,false"}),["json"]);k(u({keywords:H,hashComments:!0,cStyleComments:!0,verbatimStrings:!0,types:K}),["cs"]);k(u({keywords:G,cStyleComments:!0}),["java"]);k(u({keywords:v,hashComments:!0,multiLineStrings:!0}),["bsh","csh","sh"]);k(u({keywords:I,hashComments:!0,multiLineStrings:!0,tripleQuotedStrings:!0}), 24 | ["cv","py"]);k(u({keywords:"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END",hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["perl","pl","pm"]);k(u({keywords:J,hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["rb"]);k(u({keywords:w,cStyleComments:!0,regexLiterals:!0}),["js"]);k(u({keywords:"all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes", 25 | hashComments:3,cStyleComments:!0,multilineStrings:!0,tripleQuotedStrings:!0,regexLiterals:!0}),["coffee"]);k(x([],[["str",/^[\S\s]+/]]),["regex"]);window.prettyPrintOne=function(a,m,e){var h=document.createElement("PRE");h.innerHTML=a;e&&D(h,e);E({g:m,i:e,h:h});return h.innerHTML};window.prettyPrint=function(a){function m(){for(var e=window.PR_SHOULD_USE_CONTINUATION?l.now()+250:Infinity;p=0){var k=k.match(g),f,b;if(b= 26 | !k){b=n;for(var o=void 0,c=b.firstChild;c;c=c.nextSibling)var i=c.nodeType,o=i===1?o?b:c:i===3?N.test(c.nodeValue)?b:o:o;b=(f=o===b?void 0:o)&&"CODE"===f.tagName}b&&(k=f.className.match(g));k&&(k=k[1]);b=!1;for(o=n.parentNode;o;o=o.parentNode)if((o.tagName==="pre"||o.tagName==="code"||o.tagName==="xmp")&&o.className&&o.className.indexOf("prettyprint")>=0){b=!0;break}b||((b=(b=n.className.match(/\blinenums\b(?::(\d+))?/))?b[1]&&b[1].length?+b[1]:!0:!1)&&D(n,b),d={g:k,h:n,i:b},E(d))}}p th:last-child { border-right: 1px solid #ddd; } 224 | 225 | .ancestors, .attribs { color: #999; } 226 | .ancestors a, .attribs a 227 | { 228 | color: #999 !important; 229 | text-decoration: none; 230 | } 231 | 232 | .clear 233 | { 234 | clear: both; 235 | } 236 | 237 | .important 238 | { 239 | font-weight: bold; 240 | color: #950B02; 241 | } 242 | 243 | .yes-def { 244 | text-indent: -1000px; 245 | } 246 | 247 | .type-signature { 248 | color: #aaa; 249 | } 250 | 251 | .name, .signature { 252 | font-family: Consolas, Monaco, 'Andale Mono', monospace; 253 | } 254 | 255 | .details { margin-top: 14px; border-left: 2px solid #DDD; } 256 | .details dt { width: 120px; float: left; padding-left: 10px; padding-top: 6px; } 257 | .details dd { margin-left: 70px; } 258 | .details ul { margin: 0; } 259 | .details ul { list-style-type: none; } 260 | .details li { margin-left: 30px; padding-top: 6px; } 261 | .details pre.prettyprint { margin: 0 } 262 | .details .object-value { padding-top: 0; } 263 | 264 | .description { 265 | margin-bottom: 1em; 266 | margin-top: 1em; 267 | } 268 | 269 | .code-caption 270 | { 271 | font-style: italic; 272 | font-size: 107%; 273 | margin: 0; 274 | } 275 | 276 | .prettyprint 277 | { 278 | border: 1px solid #ddd; 279 | width: 80%; 280 | overflow: auto; 281 | } 282 | 283 | .prettyprint.source { 284 | width: inherit; 285 | } 286 | 287 | .prettyprint code 288 | { 289 | font-size: 100%; 290 | line-height: 18px; 291 | display: block; 292 | padding: 4px 12px; 293 | margin: 0; 294 | background-color: #fff; 295 | color: #4D4E53; 296 | } 297 | 298 | .prettyprint code span.line 299 | { 300 | display: inline-block; 301 | } 302 | 303 | .prettyprint.linenums 304 | { 305 | padding-left: 70px; 306 | -webkit-user-select: none; 307 | -moz-user-select: none; 308 | -ms-user-select: none; 309 | user-select: none; 310 | } 311 | 312 | .prettyprint.linenums ol 313 | { 314 | padding-left: 0; 315 | } 316 | 317 | .prettyprint.linenums li 318 | { 319 | border-left: 3px #ddd solid; 320 | } 321 | 322 | .prettyprint.linenums li.selected, 323 | .prettyprint.linenums li.selected * 324 | { 325 | background-color: lightyellow; 326 | } 327 | 328 | .prettyprint.linenums li * 329 | { 330 | -webkit-user-select: text; 331 | -moz-user-select: text; 332 | -ms-user-select: text; 333 | user-select: text; 334 | } 335 | 336 | .params .name, .props .name, .name code { 337 | color: #4D4E53; 338 | font-family: Consolas, Monaco, 'Andale Mono', monospace; 339 | font-size: 100%; 340 | } 341 | 342 | .params td.description > p:first-child, 343 | .props td.description > p:first-child 344 | { 345 | margin-top: 0; 346 | padding-top: 0; 347 | } 348 | 349 | .params td.description > p:last-child, 350 | .props td.description > p:last-child 351 | { 352 | margin-bottom: 0; 353 | padding-bottom: 0; 354 | } 355 | 356 | .disabled { 357 | color: #454545; 358 | } 359 | -------------------------------------------------------------------------------- /out/styles/prettify-jsdoc.css: -------------------------------------------------------------------------------- 1 | /* JSDoc prettify.js theme */ 2 | 3 | /* plain text */ 4 | .pln { 5 | color: #000000; 6 | font-weight: normal; 7 | font-style: normal; 8 | } 9 | 10 | /* string content */ 11 | .str { 12 | color: #006400; 13 | font-weight: normal; 14 | font-style: normal; 15 | } 16 | 17 | /* a keyword */ 18 | .kwd { 19 | color: #000000; 20 | font-weight: bold; 21 | font-style: normal; 22 | } 23 | 24 | /* a comment */ 25 | .com { 26 | font-weight: normal; 27 | font-style: italic; 28 | } 29 | 30 | /* a type name */ 31 | .typ { 32 | color: #000000; 33 | font-weight: normal; 34 | font-style: normal; 35 | } 36 | 37 | /* a literal value */ 38 | .lit { 39 | color: #006400; 40 | font-weight: normal; 41 | font-style: normal; 42 | } 43 | 44 | /* punctuation */ 45 | .pun { 46 | color: #000000; 47 | font-weight: bold; 48 | font-style: normal; 49 | } 50 | 51 | /* lisp open bracket */ 52 | .opn { 53 | color: #000000; 54 | font-weight: bold; 55 | font-style: normal; 56 | } 57 | 58 | /* lisp close bracket */ 59 | .clo { 60 | color: #000000; 61 | font-weight: bold; 62 | font-style: normal; 63 | } 64 | 65 | /* a markup tag name */ 66 | .tag { 67 | color: #006400; 68 | font-weight: normal; 69 | font-style: normal; 70 | } 71 | 72 | /* a markup attribute name */ 73 | .atn { 74 | color: #006400; 75 | font-weight: normal; 76 | font-style: normal; 77 | } 78 | 79 | /* a markup attribute value */ 80 | .atv { 81 | color: #006400; 82 | font-weight: normal; 83 | font-style: normal; 84 | } 85 | 86 | /* a declaration */ 87 | .dec { 88 | color: #000000; 89 | font-weight: bold; 90 | font-style: normal; 91 | } 92 | 93 | /* a variable name */ 94 | .var { 95 | color: #000000; 96 | font-weight: normal; 97 | font-style: normal; 98 | } 99 | 100 | /* a function name */ 101 | .fun { 102 | color: #000000; 103 | font-weight: bold; 104 | font-style: normal; 105 | } 106 | 107 | /* Specify class=linenums on a pre to get line numbering */ 108 | ol.linenums { 109 | margin-top: 0; 110 | margin-bottom: 0; 111 | } 112 | -------------------------------------------------------------------------------- /out/styles/prettify-tomorrow.css: -------------------------------------------------------------------------------- 1 | /* Tomorrow Theme */ 2 | /* Original theme - https://github.com/chriskempson/tomorrow-theme */ 3 | /* Pretty printing styles. Used with prettify.js. */ 4 | /* SPAN elements with the classes below are added by prettyprint. */ 5 | /* plain text */ 6 | .pln { 7 | color: #4d4d4c; } 8 | 9 | @media screen { 10 | /* string content */ 11 | .str { 12 | color: #718c00; } 13 | 14 | /* a keyword */ 15 | .kwd { 16 | color: #8959a8; } 17 | 18 | /* a comment */ 19 | .com { 20 | color: #8e908c; } 21 | 22 | /* a type name */ 23 | .typ { 24 | color: #4271ae; } 25 | 26 | /* a literal value */ 27 | .lit { 28 | color: #f5871f; } 29 | 30 | /* punctuation */ 31 | .pun { 32 | color: #4d4d4c; } 33 | 34 | /* lisp open bracket */ 35 | .opn { 36 | color: #4d4d4c; } 37 | 38 | /* lisp close bracket */ 39 | .clo { 40 | color: #4d4d4c; } 41 | 42 | /* a markup tag name */ 43 | .tag { 44 | color: #c82829; } 45 | 46 | /* a markup attribute name */ 47 | .atn { 48 | color: #f5871f; } 49 | 50 | /* a markup attribute value */ 51 | .atv { 52 | color: #3e999f; } 53 | 54 | /* a declaration */ 55 | .dec { 56 | color: #f5871f; } 57 | 58 | /* a variable name */ 59 | .var { 60 | color: #c82829; } 61 | 62 | /* a function name */ 63 | .fun { 64 | color: #4271ae; } } 65 | /* Use higher contrast and text-weight for printable form. */ 66 | @media print, projection { 67 | .str { 68 | color: #060; } 69 | 70 | .kwd { 71 | color: #006; 72 | font-weight: bold; } 73 | 74 | .com { 75 | color: #600; 76 | font-style: italic; } 77 | 78 | .typ { 79 | color: #404; 80 | font-weight: bold; } 81 | 82 | .lit { 83 | color: #044; } 84 | 85 | .pun, .opn, .clo { 86 | color: #440; } 87 | 88 | .tag { 89 | color: #006; 90 | font-weight: bold; } 91 | 92 | .atn { 93 | color: #404; } 94 | 95 | .atv { 96 | color: #060; } } 97 | /* Style */ 98 | /* 99 | pre.prettyprint { 100 | background: white; 101 | font-family: Consolas, Monaco, 'Andale Mono', monospace; 102 | font-size: 12px; 103 | line-height: 1.5; 104 | border: 1px solid #ccc; 105 | padding: 10px; } 106 | */ 107 | 108 | /* Specify class=linenums on a pre to get line numbering */ 109 | ol.linenums { 110 | margin-top: 0; 111 | margin-bottom: 0; } 112 | 113 | /* IE indents via margin-left */ 114 | li.L0, 115 | li.L1, 116 | li.L2, 117 | li.L3, 118 | li.L4, 119 | li.L5, 120 | li.L6, 121 | li.L7, 122 | li.L8, 123 | li.L9 { 124 | /* */ } 125 | 126 | /* Alternate shading for lines */ 127 | li.L1, 128 | li.L3, 129 | li.L5, 130 | li.L7, 131 | li.L9 { 132 | /* */ } 133 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@dboxjs/core", 3 | "version": "0.1.9", 4 | "description": "A library to create easy reusable charts", 5 | "main": "dist/dbox.js", 6 | "module": "dist/dbox.mjs", 7 | "jsnext:main": "dist/dbox.mjs", 8 | "scripts": { 9 | "eslint": "eslint -c .eslintrc lib test", 10 | "build": "rollup -c rollup.config.js; uglifyjs ./dist/dbox.js -c -m -o ./dist/dbox.min.js", 11 | "dev": "rollup -c rollup.config.dev.js -w", 12 | "pretest": "npm run build", 13 | "docs": "jsdoc -c jsdocs.config.json" 14 | }, 15 | "repository": { 16 | "type": "git", 17 | "url": "git+https://github.com/dboxjs/core.git" 18 | }, 19 | "keywords": [ 20 | "d3", 21 | "charts", 22 | "dataviz", 23 | "dbox", 24 | "dboxjs" 25 | ], 26 | "author": "", 27 | "license": "MIT", 28 | "bugs": { 29 | "url": "https://github.com/dboxjs/dbox/issues" 30 | }, 31 | "files": [ 32 | "lib", 33 | "dist", 34 | "docs" 35 | ], 36 | "homepage": "https://github.com/dboxjs/dbox#readme", 37 | "prettier": { 38 | "singleQuote": true 39 | }, 40 | "dependencies": { 41 | "d3": "^4.13.0", 42 | "d3-queue": "^3.0.7", 43 | "d3-tip": "^0.9.1", 44 | "leaflet": "^1.3.1", 45 | "lodash": "^4.17.15", 46 | "textures": "^1.0.4", 47 | "topojson": "^2.2.0" 48 | }, 49 | "devDependencies": { 50 | "@dboxjs/bars": "0", 51 | "@dboxjs/distro": "0", 52 | "@dboxjs/heatmap": "0", 53 | "@dboxjs/leaflet": "^0.1.2", 54 | "@dboxjs/map": "0", 55 | "@dboxjs/radar": "0", 56 | "@dboxjs/scatter": "0", 57 | "@dboxjs/spineplot": "0", 58 | "@dboxjs/timeline": "0", 59 | "@dboxjs/treemap": "0", 60 | "babel": "^6.23.0", 61 | "babel-eslint": "^7.1.1", 62 | "babel-plugin-external-helpers": "^6.22.0", 63 | "babel-preset-env": "^1.6.0", 64 | "babel-register": "^6.18.0", 65 | "babelrc-rollup": "^3.0.0", 66 | "eslint": "^4.18.2", 67 | "istanbul": "^0.4.5", 68 | "jsdoc": "^3.6.3", 69 | "mocha": "^5.1.1", 70 | "mocha-phantomjs": "^4.1.0", 71 | "redux": "^4.0.1", 72 | "rollup": "^0.57.1", 73 | "rollup-plugin-babel": "^3.0.7", 74 | "rollup-plugin-commonjs": "^9.1.0", 75 | "rollup-plugin-istanbul": "^2.0.1", 76 | "rollup-plugin-legacy": "^1.0.0", 77 | "rollup-plugin-node-resolve": "^2.1.1", 78 | "rollup-watch": "^2.5.0", 79 | "uglify-js": "^2.8.10" 80 | }, 81 | "directories": { 82 | "doc": "docs", 83 | "test": "test" 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import resolve from 'rollup-plugin-node-resolve'; 2 | import babel from 'rollup-plugin-babel'; 3 | import babelrc from 'babelrc-rollup'; 4 | 5 | let pkg = require('./package.json'); 6 | let external = Object.keys(pkg.dependencies); 7 | 8 | export default { 9 | input: 'index.js', 10 | plugins: [resolve(), 'external-helpers', babel(babelrc())], 11 | external: external, 12 | output: { 13 | file: pkg.main, 14 | format: 'umd', 15 | name: 'dbox', 16 | sourcemap: true, 17 | globals: { 18 | lodash: '_', 19 | d3: 'd3', 20 | cartodb: 'cartodb', 21 | textures: 'textures', 22 | topojson: 'topojson', 23 | leaflet: 'L', 24 | }, 25 | }, 26 | }; 27 | -------------------------------------------------------------------------------- /test/bars.test.txt: -------------------------------------------------------------------------------- 1 | import * as dbox from '../'; 2 | import * as assert from 'assert'; 3 | 4 | describe('Bar chart', () => { 5 | it('Should create a base chart', () => { 6 | var config = { 7 | size: { 8 | width: 600, 9 | height: 400, 10 | margin: { 11 | top: 5, 12 | right: 5, 13 | bottom: 20, 14 | left: 20 15 | } 16 | }, 17 | xAxis: { 18 | enabled:true, 19 | scale: 'linear' 20 | }, 21 | yAxis: { 22 | enabled: true, 23 | scale: 'linear' 24 | } 25 | }; 26 | 27 | var chart = dbox.chart(config) 28 | .bindTo('body') 29 | .data({'raw': [{name: 'female', value: 35},{name: 'male', value: 24},{name: 'NA', value: 4}]}) 30 | assert.equal(chart._config.bindTo, 'body'); 31 | }); 32 | 33 | it('Bars should be defined in dbox', () => { 34 | assert.ok(dbox.bars); 35 | }); 36 | 37 | it('Should create a bar chart', () => { 38 | var config = { 39 | size: { 40 | width: 600, 41 | height: 400, 42 | margin: { 43 | top: 5, 44 | right: 5, 45 | bottom: 20, 46 | left: 20 47 | } 48 | }, 49 | xAxis: { 50 | enabled:true, 51 | scale: 'ordinal' 52 | }, 53 | yAxis: { 54 | enabled: true, 55 | scale: 'linear' 56 | }, 57 | events: { 58 | load: onLoad 59 | } 60 | }; 61 | var data = [{name: 'female', value: 35},{name: 'male', value: 24},{name: 'NA', value: 4}]; 62 | 63 | var chart = dbox.chart(config) 64 | .bindTo(this) 65 | .data({'raw': data}) 66 | .layer(dbox.bars) 67 | .x('name') 68 | .y('value') 69 | .end() 70 | .draw(); 71 | function onLoad(chart){ 72 | setTimeout(function(){ 73 | console.log(chart.getLayer(0)); 74 | assert.ok(chart.getLayer(0)._scales.x); 75 | assert.ok(chart.getLayer(0)._scales.y); 76 | }, 2000); 77 | } 78 | }) 79 | }); 80 | -------------------------------------------------------------------------------- /test/chart.test.js: -------------------------------------------------------------------------------- 1 | import * as dbox from '../'; 2 | import * as assert from 'assert'; 3 | 4 | describe('Chart', () => { 5 | it('Chart should be defined on dbox', () => { 6 | assert.ok(dbox.chart); 7 | }); 8 | }); 9 | -------------------------------------------------------------------------------- /test/helper.test.js: -------------------------------------------------------------------------------- 1 | import * as dbox from '../'; 2 | import * as assert from 'assert'; 3 | 4 | describe('Helper.utils', function() { 5 | describe('format()', function() { 6 | it('Should format 5450000 to 5.5 millones', function() { 7 | var chart = dbox.chart(); 8 | var result = chart.helper.utils.format(null, true)(5450000); 9 | assert.equal(result, '5.5 millones'); 10 | }); 11 | it('Should format 430958 to 431.0 mil', function() { 12 | var chart = dbox.chart(); 13 | var result = chart.helper.utils.format(null, true)(430958); 14 | assert.equal(result, '431.0 mil'); 15 | }); 16 | it('Should format 6234 to 6,234', function() { 17 | var chart = dbox.chart(); 18 | var result = chart.helper.utils.format(null, true)(6234); 19 | assert.equal(result, '6,234'); 20 | }); 21 | it('Should format 345.23 to 345.2', function() { 22 | var chart = dbox.chart(); 23 | var result = chart.helper.utils.format(null, true)(345.23); 24 | assert.equal(result, '345.2'); 25 | }); 26 | it('Should format 5.2093 to 5.2', function() { 27 | var chart = dbox.chart(); 28 | var result = chart.helper.utils.format(null, true)(5.2093); 29 | assert.equal(result, '5.2'); 30 | }); 31 | it('Should format 12.0 to 12', function() { 32 | var chart = dbox.chart(); 33 | var result = chart.helper.utils.format(null, true)(12.0); 34 | assert.equal(result, '12'); 35 | }); 36 | it('Should format 1.4904 to 1.5', function() { 37 | var chart = dbox.chart(); 38 | var result = chart.helper.utils.format(null, true)(1.4904); 39 | assert.equal(result, '1.5'); 40 | }); 41 | it('Should format 0.4935 to 0.5 ', function() { 42 | var chart = dbox.chart(); 43 | var result = chart.helper.utils.format(null, true)(0.4935); 44 | assert.equal(result, '0.5'); 45 | }); 46 | it('Should format 0.00435 to 0.004 ', function() { 47 | var chart = dbox.chart(); 48 | var result = chart.helper.utils.format(null, true)(0.00435); 49 | assert.equal(result, '0.004'); 50 | }); 51 | }); 52 | }); 53 | -------------------------------------------------------------------------------- /test/index.test.txt: -------------------------------------------------------------------------------- 1 | import * as dbox from '../'; 2 | import * as assert from 'assert'; 3 | 4 | describe('chart core', () => { 5 | it('Creates a default chart config template', () => { 6 | var chart = dbox.chart(); 7 | assert.deepEqual(chart._config, {size: {width: 800, height: 600, margin: {left: 0, right: 0, top: 0, bottom: 0}}}); 8 | }); 9 | 10 | it('Should set size options using chained method', () => { 11 | var size = { 12 | width: 400, 13 | height: 400, 14 | margin: { 15 | top: 0, 16 | right: 10, 17 | bottom: 5, 18 | left: 10 19 | } 20 | }; 21 | var chart = dbox.chart() 22 | .size(size); 23 | 24 | assert.deepEqual(chart._config.size, size); 25 | assert.deepEqual(chart._width, size.width); 26 | assert.deepEqual(chart._height, size.height); 27 | assert.deepEqual(chart._margin, size.margin); 28 | }); 29 | 30 | it('Should bind chart to element', () => { 31 | var chart = dbox.chart() 32 | .bindTo('body') 33 | assert.strictEqual(chart._config.bindTo, 'body'); 34 | }); 35 | 36 | it('Should return generated scales', () => { 37 | var data = [{name: 'female', value: 52, date: new Date('2017-05-12')},{name: 'male', value: 25, date: new Date('2017-05-11')},{name: 'NA', value: 8, date: new Date('2017-05-10')}]; 38 | var options = { 39 | column: 'name', 40 | type: 'ordinal', 41 | range: [0, 600] 42 | }; 43 | var xScale = dbox.chart().generateScale(data, options); 44 | 45 | options = { 46 | column: 'value', 47 | type: 'linear', 48 | range: [0, 400] 49 | }; 50 | var yScale = dbox.chart().generateScale(data, options); 51 | console.log(xScale.range(), xScale.domain()); 52 | console.log(yScale.range(), yScale.domain()); 53 | assert.strictEqual(xScale('male'), 213); 54 | assert.strictEqual(yScale(25), 155); 55 | }); 56 | }); 57 | -------------------------------------------------------------------------------- /test/istanbul.reporter.js: -------------------------------------------------------------------------------- 1 | const instanbul = require('istanbul'); 2 | const MochaSpecReporter = require('mocha/lib/reporters/spec'); 3 | 4 | module.exports = function(runner) { 5 | const collector = new instanbul.Collector(); 6 | const reporter = new instanbul.Reporter(); 7 | reporter.addAll(['lcov', 'json']); 8 | new MochaSpecReporter(runner); 9 | 10 | runner.on('end', function() { 11 | collector.add(global.__coverage__); 12 | 13 | reporter.write(collector, true, function() { 14 | process.stdout.write('report generated'); 15 | }); 16 | }); 17 | }; 18 | -------------------------------------------------------------------------------- /test/mocha.opts: -------------------------------------------------------------------------------- 1 | --recursive --compilers js:babel-register 2 | -------------------------------------------------------------------------------- /test/scatter.test.js: -------------------------------------------------------------------------------- 1 | import * as dbox from '../'; 2 | import * as assert from 'assert'; 3 | 4 | describe('Scatter chart', () => { 5 | it('Scatter should be defined on dbox', () => { 6 | console.log(dbox.scatter); 7 | assert.ok(dbox.scatter); 8 | }); 9 | }); 10 | --------------------------------------------------------------------------------