├── .gitignore ├── .jshintrc ├── Gruntfile.js ├── README.md ├── bower.json ├── c3-angular.js ├── c3-angular.min.js ├── c3-angular.min.js.map ├── examples ├── assets │ ├── css │ │ ├── app.css │ │ ├── c3.min.css │ │ ├── shCore.css │ │ └── shCoreDefault.css │ └── js │ │ ├── angular.min.js │ │ ├── angular.min.js.map │ │ ├── app.js │ │ ├── bar │ │ ├── bar.js │ │ └── bar.tpl.html │ │ ├── c3-angular.js │ │ ├── c3-angular.min.js │ │ ├── c3-angular.min.js.map │ │ ├── c3.min.js │ │ ├── callback │ │ ├── callback.js │ │ └── callback.tpl.html │ │ ├── config │ │ ├── config.js │ │ └── config.tpl.html │ │ ├── d3.min.js │ │ ├── dashboard │ │ ├── dashboard.js │ │ └── dashboard.tpl.html │ │ ├── donut │ │ ├── donut.js │ │ └── donut.tpl.html │ │ ├── dynamic │ │ ├── dynamic.js │ │ └── dynamic.tpl.html │ │ ├── gauge │ │ ├── gauge.js │ │ └── gauge.tpl.html │ │ ├── line │ │ ├── line.js │ │ └── line.tpl.html │ │ ├── pie │ │ ├── pie.js │ │ └── pie.tpl.html │ │ ├── shBrushJScript.js │ │ ├── shBrushXml.js │ │ └── shCore.js └── index.html ├── license.md ├── package.json └── src ├── _main.js ├── axes-directive.js ├── axis-directive.js ├── axis-x-directive.js ├── axis-x-tick-directive.js ├── axis-y-directive.js ├── axis-y-tick-directive.js ├── bar-directive.js ├── c3chart-directive.js ├── colors-directive.js ├── column-directive.js ├── controller.js ├── donut-directive.js ├── events-directive.js ├── gauge-directive.js ├── grid-directive.js ├── grid-optional-directive.js ├── group-directive.js ├── legend-directive.js ├── line-directive.js ├── pie-directive.js ├── points-directive.js ├── region-directive.js ├── selection-directive.js ├── size-directive.js └── tooltip-directive.js /.gitignore: -------------------------------------------------------------------------------- 1 | bower_components 2 | node_modules 3 | .idea 4 | docs -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "bitwise": true, 3 | "eqeqeq": true, 4 | "eqnull": true, 5 | "immed": true, 6 | "newcap": true, 7 | "esnext": true, 8 | "camelcase": true, 9 | "latedef": true, 10 | "noarg": true, 11 | "node": true, 12 | "undef": true, 13 | "browser": true, 14 | "trailing": true, 15 | "jquery": true, 16 | "curly": true, 17 | "supernew": true, 18 | "globals": { 19 | "Backbone": true, 20 | "_": true, 21 | "jQuery": true 22 | } 23 | } -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = function (grunt) { 4 | grunt.initConfig({ 5 | pkg:grunt.file.readJSON('package.json'), 6 | banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' + 7 | '<%= grunt.template.today("yyyy-mm-dd") %>\n' + 8 | '<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' + 9 | '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' + 10 | ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n', 11 | watch: { 12 | js: { 13 | files: '<%= jshint.all %>', 14 | tasks: ['combine','copy:examples'] 15 | }, 16 | docs: { 17 | files: '<%= jshint.all %>', 18 | tasks: ['jsdoc'] 19 | } 20 | }, 21 | concat: { 22 | options: { 23 | banner: '<%= banner %>', 24 | stripBanners: true 25 | }, 26 | dist: { 27 | src: [ 28 | 'src/*.js' 29 | ], 30 | dest: '<%= pkg.name %>.js' 31 | } 32 | }, 33 | jshint: { 34 | options: { 35 | jshintrc: '.jshintrc', 36 | "force": true 37 | }, 38 | all: [ 39 | 'Gruntfile.js', 40 | 'src/*.js' 41 | ] 42 | }, 43 | uglify: { 44 | options: { 45 | banner: '<%= banner %>', 46 | sourceMap: '<%= pkg.name %>.js.map', 47 | sourceMappingURL: '<%= pkg.name %>.js.map', 48 | sourceMapPrefix: 2 49 | }, 50 | dist: { 51 | src: '<%= concat.dist.dest %>', 52 | dest: '<%= pkg.name %>.min.js' 53 | } 54 | }, 55 | copy: { 56 | examples: { 57 | files: [ 58 | {expand: true, flatten: true, src: ['bower_components/angular/angular.min.js'], dest: 'examples/assets/js/', filter: 'isFile'}, 59 | {expand: true, flatten: true, src: ['bower_components/angular/angular.min.js.map'], dest: 'examples/assets/js/', filter: 'isFile'}, 60 | {expand: true, flatten: true, src: ['bower_components/d3/d3.min.js'], dest: 'examples/assets/js/', filter: 'isFile'}, 61 | {expand: true, flatten: true, src: ['bower_components/c3/c3.min.js'], dest: 'examples/assets/js/', filter: 'isFile'}, 62 | {expand: true, flatten: true, src: ['bower_components/c3/c3.min.css'], dest: 'examples/assets/css/', filter: 'isFile'}, 63 | {expand: true, flatten: true, src: ['c3-angular.js'], dest: 'examples/assets/js/', filter: 'isFile'}, 64 | {expand: true, flatten: true, src: ['c3-angular.min.js'], dest: 'examples/assets/js/', filter: 'isFile'}, 65 | {expand: true, flatten: true, src: ['c3-angular.min.js.map'], dest: 'examples/assets/js/', filter: 'isFile'} 66 | ] 67 | }, 68 | bysource: { 69 | files: [ 70 | {expand: true, flatten: true, src: ['c3-angular.js'], dest: 'examples/assets/js/', filter: 'isFile'} 71 | ] 72 | } 73 | }, 74 | devserver: { 75 | options: { 76 | base: 'examples', 77 | port:8000 78 | }, 79 | server: {} 80 | }, 81 | jsdoc : { 82 | dist: { 83 | src: [ 84 | 'src/**/*.js' 85 | ], 86 | options: { 87 | destination: 'docs', 88 | configure: 'node_modules/angular-jsdoc/conf.json', 89 | template: 'node_modules/angular-jsdoc/template' 90 | } 91 | } 92 | } 93 | }); 94 | 95 | grunt.loadNpmTasks('grunt-contrib-concat'); 96 | grunt.loadNpmTasks('grunt-contrib-uglify'); 97 | grunt.loadNpmTasks('grunt-contrib-jshint'); 98 | grunt.loadNpmTasks('grunt-contrib-watch'); 99 | grunt.loadNpmTasks('grunt-contrib-copy'); 100 | grunt.loadNpmTasks('grunt-devserver'); 101 | grunt.loadNpmTasks('grunt-jsdoc'); 102 | 103 | grunt.registerTask('combine',['concat:dist','uglify:dist','copy:examples']); 104 | }; -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # C3JS AngularJS directives 2 | 3 | [![Join the chat at https://gitter.im/jettro/c3-angular-directive](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/jettro/c3-angular-directive?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 4 | [![CDNJS](https://img.shields.io/cdnjs/v/c3-angular.svg)](https://cdnjs.com/libraries/c3-angular/) 5 | 6 | This repository contains directives that let you easily create graphs using the c3js library. Most of the options that are available in c3js are now also available to you in angularjs. Below one of the most basic examples: 7 | ```html 8 | 9 | 12 | 13 | 14 | ``` 15 | 16 | ## Documentation 17 | There is a page with samples and documentation available: 18 | http://jettro.github.io/c3-angular-directive/ 19 | 20 | There is now extensive API docs available here: 21 | http://jettro.github.io/c3-angular-directive/api-docs/1.3/index.html 22 | 23 | The project contains a number of examples that can be started using grunt: 24 | 25 | ``` 26 | grunt devserver 27 | ``` 28 | 29 | ## Goal 30 | Come up with a number of directives to integrate C3js with AngularJS 31 | 32 | ## References 33 | Homepage c3js library [http://c3js.org] 34 | Homepage AngularJS [https://angularjs.org] 35 | Homepage d3 library [http://d3js.org] 36 | 37 | Blogpost about AngularJS Directives for c3js: [Angularjs directives for c3js chart library](http://blog.trifork.com/2014/08/19/angularjs-directives-for-c3-js-chart-library/) 38 | 39 | Blogpost about the improvements I made using grunt and bower: [C3JS directives using angularjs](http://amsterdam.luminis.eu/2015/01/01/c3js-directives-for-angularjs/) 40 | 41 | Blogpost about c3js by Roberto van der Linden: [Creating charts with c3.js](http://blog.trifork.com/2014/07/29/creating-charts-with-c3-js/) 42 | Blogpost about integrating c3js and angularjs by Jettro Coenradie: [Using C3js with AngularJS](http://www.gridshore.nl/2014/07/29/using-c3js-angularjs/) 43 | 44 | ## Installation and development 45 | We are using grunt and bower during development. Bower makes it easier to use it for your own project as well. More on this in the next section. If you want to try out the project and change sources or something like that, you can use bower and grunt to do development. 46 | 47 | First use npm to install all grunt plugins, than use bower to install all bower dependencies. 48 | ``` 49 | npm install 50 | bower install 51 | ``` 52 | Now grunt is available, you can use some of the utilities that grunt has in store for you. A nice one is to use the watch task and change one of the samples. There is also a plugin in place for running a development server. Just type _grunt devserver_ and connect to port 8888 on your localhost. 53 | 54 | 55 | ## Using it in your own project 56 | The easiest way to use the directives is to use bower to install it to your project. 57 | ``` 58 | bower install c3-angular --save 59 | ``` 60 | In the end you just need one file in your project: c3-angular.min.js 61 | 62 | ## Version History 63 | 64 | ### 1.4.0 65 | - Upgrade to version 0.4.18 of c3js library 66 | - Merged pull request #174 by adamczykmichael update to material css 67 | - Merged pull request #172 by esahekmat with a fix for documentation 68 | - Merged pull request #169 by vmanchev with a new option for interaction enabled 69 | - Merged pull request #134 by ishank18 with a more consistent tick labelling 70 | 71 | 72 | 73 | 74 | ### 1.3.1 75 | Merged pull request #131 by mumuxin 76 | Made doc change based on comment from LucasBassetti 77 | 78 | ### 1.3 79 | Closed the following issues 80 | - 126: Merge request with tooltip documentation fix 81 | - 118: Zoom documentation 82 | - 88: Added example for using category labels on the x-axis with dynamic values 83 | - 100: Added the selections directive 84 | - 97: Problems with colors are fixed 85 | - 108: Added support for tooltip contents callback 86 | - 112: Fixed bug with numeric grid values 87 | - 125: Upgraded angular to 1.5 and c3 to 0.4.11 88 | 89 | Pull request by LucasBassetti to fix tooltip docs 90 | 91 | ### 1.2 92 | - In issue 104 @AesSedai proposed more properties for the legend inset directive. These are now added. 93 | - In issue 102 @jtaylor1022 asked for the grid-class attribute and I added the position as well. 94 | 95 | Bugs fixed: 96 | - Issue 104: Fixed problem with the time format function 97 | 98 | ### 1.1 99 | Added pull requests 100 | - marton987 (Martin Freytes): Added regions to line charts by adding a new directive 101 | - stevezau (Steve): Added support for empty data labels. 102 | 103 | Bugs fixed: 104 | - Issue 86: Has to do with the colors. 105 | 106 | ### 1.0 107 | Squashed a number of bugs, some of them related to tick formatting of timeseries data. 108 | 109 | Added the click and mouse events on the legend. 110 | 111 | Bigger refactoring to the structure of the source code and a big change to the examples. 112 | 113 | ### 0.7.0 114 | Focus is improvements to the structure of the project and the documentation. Also fixed some bugs. 115 | 116 | ### 0.6.0 117 | Main part to move to a higher version is that we have the possibility now to add a callback function. In the examples folder there is a page callback-sample.html that shows how to do this. You can register the callback function to recevei the actual chart object that you can manipulate using the c3js API methods. 118 | http://c3js.org/reference.html#api 119 | 120 | ### 0.5.0 121 | Added a big pull request by EmmN that includes formatting improvements. All charts now support adding a format function to format labels and tooltips. 122 | 123 | ### 0.4.0 124 | Added config for the pie and donut charts 125 | Added config for points as requested by Lazymondaysunday 126 | Added an extensive tutorial in the examples package 127 | Finalized the events as requested by pehrlich and Tropicalista 128 | Improved the sample on the project page 129 | http://jettro.github.io/c3-angular-directive/ 130 | 131 | ### 0.3.1 132 | Added a gauge config by richardthombs 133 | Added a stacked bar chart requested by vinnytheviking 134 | Added events to the chart as well as data, now you can add callbacks to data click, chart mouse over, etc. requested by Tropicalista and pehrlich 135 | 136 | Also added a better project page: 137 | http://jettro.github.io/c3-angular-directive/ 138 | 139 | Working on improved documentation and better examples for release 0.4.0 140 | 141 | ### 0.3.0 142 | Upgraded to the latest versions of: 143 | c3js - 0.4.10 144 | 145 | Added a number of pull requests by: 146 | mark-lai: formatting and x/y tick enhancements 147 | yourivdlans: Some very nice enhancements in the axis, also the sample with the bubble. 148 | Resseguie: Added a feature to pass a color function to the chart 149 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "c3-angular", 3 | "version": "1.4.0", 4 | "homepage": "https://github.com/jettro/c3-angular-sample", 5 | "authors": [ 6 | "Jettro Coenradie " 7 | ], 8 | "description": "An angularjs directive to integrate c3.js within your angularjs project.", 9 | "main": "c3-angular.js", 10 | "moduleType": [ 11 | "yui" 12 | ], 13 | "keywords": [ 14 | "c3.js", 15 | "angularjs", 16 | "graph" 17 | ], 18 | "license": "MIT", 19 | "ignore": [ 20 | "**/.*", 21 | "node_modules", 22 | "bower_components", 23 | "test", 24 | "tests" 25 | ], 26 | "dependencies": { 27 | "angular": "~1.6", 28 | "c3": "0.4.18" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /examples/assets/css/app.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jettro/c3-angular-directive/f8123c6b3dce24cdbe15889cdf563d43c639dcb6/examples/assets/css/app.css -------------------------------------------------------------------------------- /examples/assets/css/c3.min.css: -------------------------------------------------------------------------------- 1 | .c3 svg{font:10px sans-serif;-webkit-tap-highlight-color:transparent}.c3 line,.c3 path{fill:none;stroke:#000}.c3 text{-webkit-user-select:none;-moz-user-select:none;user-select:none}.c3-bars path,.c3-event-rect,.c3-legend-item-tile,.c3-xgrid-focus,.c3-ygrid{shape-rendering:crispEdges}.c3-chart-arc path{stroke:#fff}.c3-chart-arc text{fill:#fff;font-size:13px}.c3-grid line{stroke:#aaa}.c3-grid text{fill:#aaa}.c3-xgrid,.c3-ygrid{stroke-dasharray:3 3}.c3-text.c3-empty{fill:grey;font-size:2em}.c3-line{stroke-width:1px}.c3-circle._expanded_{stroke-width:1px;stroke:#fff}.c3-selected-circle{fill:#fff;stroke-width:2px}.c3-bar{stroke-width:0}.c3-bar._expanded_{fill-opacity:1;fill-opacity:.75}.c3-target.c3-focused{opacity:1}.c3-target.c3-focused path.c3-line,.c3-target.c3-focused path.c3-step{stroke-width:2px}.c3-target.c3-defocused{opacity:.3!important}.c3-region{fill:#4682b4;fill-opacity:.1}.c3-brush .extent{fill-opacity:.1}.c3-legend-item{font-size:12px}.c3-legend-item-hidden{opacity:.15}.c3-legend-background{opacity:.75;fill:#fff;stroke:#d3d3d3;stroke-width:1}.c3-title{font:14px sans-serif}.c3-tooltip-container{z-index:10}.c3-tooltip{border-collapse:collapse;border-spacing:0;background-color:#fff;empty-cells:show;-webkit-box-shadow:7px 7px 12px -9px #777;-moz-box-shadow:7px 7px 12px -9px #777;box-shadow:7px 7px 12px -9px #777;opacity:.9}.c3-tooltip tr{border:1px solid #ccc}.c3-tooltip th{background-color:#aaa;font-size:14px;padding:2px 5px;text-align:left;color:#fff}.c3-tooltip td{font-size:13px;padding:3px 6px;background-color:#fff;border-left:1px dotted #999}.c3-tooltip td>span{display:inline-block;width:10px;height:10px;margin-right:6px}.c3-tooltip td.value{text-align:right}.c3-area{stroke-width:0;opacity:.2}.c3-chart-arcs-title{dominant-baseline:middle;font-size:1.3em}.c3-chart-arcs .c3-chart-arcs-background{fill:#e0e0e0;stroke:none}.c3-chart-arcs .c3-chart-arcs-gauge-unit{fill:#000;font-size:16px}.c3-chart-arcs .c3-chart-arcs-gauge-max{fill:#777}.c3-chart-arcs .c3-chart-arcs-gauge-min{fill:#777}.c3-chart-arc .c3-gauge-value{fill:#000}.c3-chart-arc.c3-target g path{opacity:1}.c3-chart-arc.c3-target.c3-focused g path{opacity:1} -------------------------------------------------------------------------------- /examples/assets/css/shCore.css: -------------------------------------------------------------------------------- 1 | /** 2 | * SyntaxHighlighter 3 | * http://alexgorbatchev.com/SyntaxHighlighter 4 | * 5 | * SyntaxHighlighter is donationware. If you are using it, please donate. 6 | * http://alexgorbatchev.com/SyntaxHighlighter/donate.html 7 | * 8 | * @version 9 | * 3.0.83 (July 02 2010) 10 | * 11 | * @copyright 12 | * Copyright (C) 2004-2010 Alex Gorbatchev. 13 | * 14 | * @license 15 | * Dual licensed under the MIT and GPL licenses. 16 | */ 17 | .syntaxhighlighter a, 18 | .syntaxhighlighter div, 19 | .syntaxhighlighter code, 20 | .syntaxhighlighter table, 21 | .syntaxhighlighter table td, 22 | .syntaxhighlighter table tr, 23 | .syntaxhighlighter table tbody, 24 | .syntaxhighlighter table thead, 25 | .syntaxhighlighter table caption, 26 | .syntaxhighlighter textarea { 27 | -moz-border-radius: 0 0 0 0 !important; 28 | -webkit-border-radius: 0 0 0 0 !important; 29 | background: none !important; 30 | border: 0 !important; 31 | bottom: auto !important; 32 | float: none !important; 33 | height: auto !important; 34 | left: auto !important; 35 | line-height: 1.1em !important; 36 | margin: 0 !important; 37 | outline: 0 !important; 38 | overflow: visible !important; 39 | padding: 0 !important; 40 | position: static !important; 41 | right: auto !important; 42 | text-align: left !important; 43 | top: auto !important; 44 | vertical-align: baseline !important; 45 | width: auto !important; 46 | box-sizing: content-box !important; 47 | font-family: "Consolas", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; 48 | font-weight: normal !important; 49 | font-style: normal !important; 50 | font-size: 1em !important; 51 | min-height: inherit !important; 52 | min-height: auto !important; 53 | } 54 | 55 | .syntaxhighlighter { 56 | width: 100% !important; 57 | margin: 1em 0 1em 0 !important; 58 | position: relative !important; 59 | overflow: auto !important; 60 | font-size: 1em !important; 61 | } 62 | .syntaxhighlighter.source { 63 | overflow: hidden !important; 64 | } 65 | .syntaxhighlighter .bold { 66 | font-weight: bold !important; 67 | } 68 | .syntaxhighlighter .italic { 69 | font-style: italic !important; 70 | } 71 | .syntaxhighlighter .line { 72 | white-space: pre !important; 73 | } 74 | .syntaxhighlighter table { 75 | width: 100% !important; 76 | } 77 | .syntaxhighlighter table caption { 78 | text-align: left !important; 79 | padding: .5em 0 0.5em 1em !important; 80 | } 81 | .syntaxhighlighter table td.code { 82 | width: 100% !important; 83 | } 84 | .syntaxhighlighter table td.code .container { 85 | position: relative !important; 86 | } 87 | .syntaxhighlighter table td.code .container textarea { 88 | box-sizing: border-box !important; 89 | position: absolute !important; 90 | left: 0 !important; 91 | top: 0 !important; 92 | width: 100% !important; 93 | height: 100% !important; 94 | border: none !important; 95 | background: white !important; 96 | padding-left: 1em !important; 97 | overflow: hidden !important; 98 | white-space: pre !important; 99 | } 100 | .syntaxhighlighter table td.gutter .line { 101 | text-align: right !important; 102 | padding: 0 0.5em 0 1em !important; 103 | } 104 | .syntaxhighlighter table td.code .line { 105 | padding: 0 1em !important; 106 | } 107 | .syntaxhighlighter.nogutter td.code .container textarea, .syntaxhighlighter.nogutter td.code .line { 108 | padding-left: 0em !important; 109 | } 110 | .syntaxhighlighter.show { 111 | display: block !important; 112 | } 113 | .syntaxhighlighter.collapsed table { 114 | display: none !important; 115 | } 116 | .syntaxhighlighter.collapsed .toolbar { 117 | padding: 0.1em 0.8em 0em 0.8em !important; 118 | font-size: 1em !important; 119 | position: static !important; 120 | width: auto !important; 121 | height: auto !important; 122 | } 123 | .syntaxhighlighter.collapsed .toolbar span { 124 | display: inline !important; 125 | margin-right: 1em !important; 126 | } 127 | .syntaxhighlighter.collapsed .toolbar span a { 128 | padding: 0 !important; 129 | display: none !important; 130 | } 131 | .syntaxhighlighter.collapsed .toolbar span a.expandSource { 132 | display: inline !important; 133 | } 134 | .syntaxhighlighter .toolbar { 135 | position: absolute !important; 136 | right: 1px !important; 137 | top: 1px !important; 138 | width: 11px !important; 139 | height: 11px !important; 140 | font-size: 10px !important; 141 | z-index: 10 !important; 142 | } 143 | .syntaxhighlighter .toolbar span.title { 144 | display: inline !important; 145 | } 146 | .syntaxhighlighter .toolbar a { 147 | display: block !important; 148 | text-align: center !important; 149 | text-decoration: none !important; 150 | padding-top: 1px !important; 151 | } 152 | .syntaxhighlighter .toolbar a.expandSource { 153 | display: none !important; 154 | } 155 | .syntaxhighlighter.ie { 156 | font-size: .9em !important; 157 | padding: 1px 0 1px 0 !important; 158 | } 159 | .syntaxhighlighter.ie .toolbar { 160 | line-height: 8px !important; 161 | } 162 | .syntaxhighlighter.ie .toolbar a { 163 | padding-top: 0px !important; 164 | } 165 | .syntaxhighlighter.printing .line.alt1 .content, 166 | .syntaxhighlighter.printing .line.alt2 .content, 167 | .syntaxhighlighter.printing .line.highlighted .number, 168 | .syntaxhighlighter.printing .line.highlighted.alt1 .content, 169 | .syntaxhighlighter.printing .line.highlighted.alt2 .content { 170 | background: none !important; 171 | } 172 | .syntaxhighlighter.printing .line .number { 173 | color: #bbbbbb !important; 174 | } 175 | .syntaxhighlighter.printing .line .content { 176 | color: black !important; 177 | } 178 | .syntaxhighlighter.printing .toolbar { 179 | display: none !important; 180 | } 181 | .syntaxhighlighter.printing a { 182 | text-decoration: none !important; 183 | } 184 | .syntaxhighlighter.printing .plain, .syntaxhighlighter.printing .plain a { 185 | color: black !important; 186 | } 187 | .syntaxhighlighter.printing .comments, .syntaxhighlighter.printing .comments a { 188 | color: #008200 !important; 189 | } 190 | .syntaxhighlighter.printing .string, .syntaxhighlighter.printing .string a { 191 | color: blue !important; 192 | } 193 | .syntaxhighlighter.printing .keyword { 194 | color: #006699 !important; 195 | font-weight: bold !important; 196 | } 197 | .syntaxhighlighter.printing .preprocessor { 198 | color: gray !important; 199 | } 200 | .syntaxhighlighter.printing .variable { 201 | color: #aa7700 !important; 202 | } 203 | .syntaxhighlighter.printing .value { 204 | color: #009900 !important; 205 | } 206 | .syntaxhighlighter.printing .functions { 207 | color: #ff1493 !important; 208 | } 209 | .syntaxhighlighter.printing .constants { 210 | color: #0066cc !important; 211 | } 212 | .syntaxhighlighter.printing .script { 213 | font-weight: bold !important; 214 | } 215 | .syntaxhighlighter.printing .color1, .syntaxhighlighter.printing .color1 a { 216 | color: gray !important; 217 | } 218 | .syntaxhighlighter.printing .color2, .syntaxhighlighter.printing .color2 a { 219 | color: #ff1493 !important; 220 | } 221 | .syntaxhighlighter.printing .color3, .syntaxhighlighter.printing .color3 a { 222 | color: red !important; 223 | } 224 | .syntaxhighlighter.printing .break, .syntaxhighlighter.printing .break a { 225 | color: black !important; 226 | } 227 | -------------------------------------------------------------------------------- /examples/assets/css/shCoreDefault.css: -------------------------------------------------------------------------------- 1 | /** 2 | * SyntaxHighlighter 3 | * http://alexgorbatchev.com/SyntaxHighlighter 4 | * 5 | * SyntaxHighlighter is donationware. If you are using it, please donate. 6 | * http://alexgorbatchev.com/SyntaxHighlighter/donate.html 7 | * 8 | * @version 9 | * 3.0.83 (July 02 2010) 10 | * 11 | * @copyright 12 | * Copyright (C) 2004-2010 Alex Gorbatchev. 13 | * 14 | * @license 15 | * Dual licensed under the MIT and GPL licenses. 16 | */ 17 | .syntaxhighlighter a, 18 | .syntaxhighlighter div, 19 | .syntaxhighlighter code, 20 | .syntaxhighlighter table, 21 | .syntaxhighlighter table td, 22 | .syntaxhighlighter table tr, 23 | .syntaxhighlighter table tbody, 24 | .syntaxhighlighter table thead, 25 | .syntaxhighlighter table caption, 26 | .syntaxhighlighter textarea { 27 | -moz-border-radius: 0 0 0 0 !important; 28 | -webkit-border-radius: 0 0 0 0 !important; 29 | background: none !important; 30 | border: 0 !important; 31 | bottom: auto !important; 32 | float: none !important; 33 | height: auto !important; 34 | left: auto !important; 35 | line-height: 1.1em !important; 36 | margin: 0 !important; 37 | outline: 0 !important; 38 | overflow: visible !important; 39 | padding: 0 !important; 40 | position: static !important; 41 | right: auto !important; 42 | text-align: left !important; 43 | top: auto !important; 44 | vertical-align: baseline !important; 45 | width: auto !important; 46 | box-sizing: content-box !important; 47 | font-family: "Consolas", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; 48 | font-weight: normal !important; 49 | font-style: normal !important; 50 | font-size: 1em !important; 51 | min-height: inherit !important; 52 | min-height: auto !important; 53 | } 54 | 55 | .syntaxhighlighter { 56 | width: 100% !important; 57 | margin: 1em 0 1em 0 !important; 58 | position: relative !important; 59 | overflow: auto !important; 60 | font-size: 1em !important; 61 | } 62 | .syntaxhighlighter.source { 63 | overflow: hidden !important; 64 | } 65 | .syntaxhighlighter .bold { 66 | font-weight: bold !important; 67 | } 68 | .syntaxhighlighter .italic { 69 | font-style: italic !important; 70 | } 71 | .syntaxhighlighter .line { 72 | white-space: pre !important; 73 | } 74 | .syntaxhighlighter table { 75 | width: 100% !important; 76 | } 77 | .syntaxhighlighter table caption { 78 | text-align: left !important; 79 | padding: .5em 0 0.5em 1em !important; 80 | } 81 | .syntaxhighlighter table td.code { 82 | width: 100% !important; 83 | } 84 | .syntaxhighlighter table td.code .container { 85 | position: relative !important; 86 | } 87 | .syntaxhighlighter table td.code .container textarea { 88 | box-sizing: border-box !important; 89 | position: absolute !important; 90 | left: 0 !important; 91 | top: 0 !important; 92 | width: 100% !important; 93 | height: 100% !important; 94 | border: none !important; 95 | background: white !important; 96 | padding-left: 1em !important; 97 | overflow: hidden !important; 98 | white-space: pre !important; 99 | } 100 | .syntaxhighlighter table td.gutter .line { 101 | text-align: right !important; 102 | padding: 0 0.5em 0 1em !important; 103 | } 104 | .syntaxhighlighter table td.code .line { 105 | padding: 0 1em !important; 106 | } 107 | .syntaxhighlighter.nogutter td.code .container textarea, .syntaxhighlighter.nogutter td.code .line { 108 | padding-left: 0em !important; 109 | } 110 | .syntaxhighlighter.show { 111 | display: block !important; 112 | } 113 | .syntaxhighlighter.collapsed table { 114 | display: none !important; 115 | } 116 | .syntaxhighlighter.collapsed .toolbar { 117 | padding: 0.1em 0.8em 0em 0.8em !important; 118 | font-size: 1em !important; 119 | position: static !important; 120 | width: auto !important; 121 | height: auto !important; 122 | } 123 | .syntaxhighlighter.collapsed .toolbar span { 124 | display: inline !important; 125 | margin-right: 1em !important; 126 | } 127 | .syntaxhighlighter.collapsed .toolbar span a { 128 | padding: 0 !important; 129 | display: none !important; 130 | } 131 | .syntaxhighlighter.collapsed .toolbar span a.expandSource { 132 | display: inline !important; 133 | } 134 | .syntaxhighlighter .toolbar { 135 | position: absolute !important; 136 | right: 1px !important; 137 | top: 1px !important; 138 | width: 11px !important; 139 | height: 11px !important; 140 | font-size: 10px !important; 141 | z-index: 10 !important; 142 | } 143 | .syntaxhighlighter .toolbar span.title { 144 | display: inline !important; 145 | } 146 | .syntaxhighlighter .toolbar a { 147 | display: block !important; 148 | text-align: center !important; 149 | text-decoration: none !important; 150 | padding-top: 1px !important; 151 | } 152 | .syntaxhighlighter .toolbar a.expandSource { 153 | display: none !important; 154 | } 155 | .syntaxhighlighter.ie { 156 | font-size: .9em !important; 157 | padding: 1px 0 1px 0 !important; 158 | } 159 | .syntaxhighlighter.ie .toolbar { 160 | line-height: 8px !important; 161 | } 162 | .syntaxhighlighter.ie .toolbar a { 163 | padding-top: 0px !important; 164 | } 165 | .syntaxhighlighter.printing .line.alt1 .content, 166 | .syntaxhighlighter.printing .line.alt2 .content, 167 | .syntaxhighlighter.printing .line.highlighted .number, 168 | .syntaxhighlighter.printing .line.highlighted.alt1 .content, 169 | .syntaxhighlighter.printing .line.highlighted.alt2 .content { 170 | background: none !important; 171 | } 172 | .syntaxhighlighter.printing .line .number { 173 | color: #bbbbbb !important; 174 | } 175 | .syntaxhighlighter.printing .line .content { 176 | color: black !important; 177 | } 178 | .syntaxhighlighter.printing .toolbar { 179 | display: none !important; 180 | } 181 | .syntaxhighlighter.printing a { 182 | text-decoration: none !important; 183 | } 184 | .syntaxhighlighter.printing .plain, .syntaxhighlighter.printing .plain a { 185 | color: black !important; 186 | } 187 | .syntaxhighlighter.printing .comments, .syntaxhighlighter.printing .comments a { 188 | color: #008200 !important; 189 | } 190 | .syntaxhighlighter.printing .string, .syntaxhighlighter.printing .string a { 191 | color: blue !important; 192 | } 193 | .syntaxhighlighter.printing .keyword { 194 | color: #006699 !important; 195 | font-weight: bold !important; 196 | } 197 | .syntaxhighlighter.printing .preprocessor { 198 | color: gray !important; 199 | } 200 | .syntaxhighlighter.printing .variable { 201 | color: #aa7700 !important; 202 | } 203 | .syntaxhighlighter.printing .value { 204 | color: #009900 !important; 205 | } 206 | .syntaxhighlighter.printing .functions { 207 | color: #ff1493 !important; 208 | } 209 | .syntaxhighlighter.printing .constants { 210 | color: #0066cc !important; 211 | } 212 | .syntaxhighlighter.printing .script { 213 | font-weight: bold !important; 214 | } 215 | .syntaxhighlighter.printing .color1, .syntaxhighlighter.printing .color1 a { 216 | color: gray !important; 217 | } 218 | .syntaxhighlighter.printing .color2, .syntaxhighlighter.printing .color2 a { 219 | color: #ff1493 !important; 220 | } 221 | .syntaxhighlighter.printing .color3, .syntaxhighlighter.printing .color3 a { 222 | color: red !important; 223 | } 224 | .syntaxhighlighter.printing .break, .syntaxhighlighter.printing .break a { 225 | color: black !important; 226 | } 227 | 228 | .syntaxhighlighter { 229 | background-color: white !important; 230 | } 231 | .syntaxhighlighter .line.alt1 { 232 | background-color: white !important; 233 | } 234 | .syntaxhighlighter .line.alt2 { 235 | background-color: white !important; 236 | } 237 | .syntaxhighlighter .line.highlighted.alt1, .syntaxhighlighter .line.highlighted.alt2 { 238 | background-color: #e0e0e0 !important; 239 | } 240 | .syntaxhighlighter .line.highlighted.number { 241 | color: black !important; 242 | } 243 | .syntaxhighlighter table caption { 244 | color: black !important; 245 | } 246 | .syntaxhighlighter .gutter { 247 | color: #afafaf !important; 248 | } 249 | .syntaxhighlighter .gutter .line { 250 | border-right: 3px solid #6ce26c !important; 251 | } 252 | .syntaxhighlighter .gutter .line.highlighted { 253 | background-color: #6ce26c !important; 254 | color: white !important; 255 | } 256 | .syntaxhighlighter.printing .line .content { 257 | border: none !important; 258 | } 259 | .syntaxhighlighter.collapsed { 260 | overflow: visible !important; 261 | } 262 | .syntaxhighlighter.collapsed .toolbar { 263 | color: blue !important; 264 | background: white !important; 265 | border: 1px solid #6ce26c !important; 266 | } 267 | .syntaxhighlighter.collapsed .toolbar a { 268 | color: blue !important; 269 | } 270 | .syntaxhighlighter.collapsed .toolbar a:hover { 271 | color: red !important; 272 | } 273 | .syntaxhighlighter .toolbar { 274 | color: white !important; 275 | background: #6ce26c !important; 276 | border: none !important; 277 | } 278 | .syntaxhighlighter .toolbar a { 279 | color: white !important; 280 | } 281 | .syntaxhighlighter .toolbar a:hover { 282 | color: black !important; 283 | } 284 | .syntaxhighlighter .plain, .syntaxhighlighter .plain a { 285 | color: black !important; 286 | } 287 | .syntaxhighlighter .comments, .syntaxhighlighter .comments a { 288 | color: #008200 !important; 289 | } 290 | .syntaxhighlighter .string, .syntaxhighlighter .string a { 291 | color: blue !important; 292 | } 293 | .syntaxhighlighter .keyword { 294 | color: #006699 !important; 295 | } 296 | .syntaxhighlighter .preprocessor { 297 | color: gray !important; 298 | } 299 | .syntaxhighlighter .variable { 300 | color: #aa7700 !important; 301 | } 302 | .syntaxhighlighter .value { 303 | color: #009900 !important; 304 | } 305 | .syntaxhighlighter .functions { 306 | color: #ff1493 !important; 307 | } 308 | .syntaxhighlighter .constants { 309 | color: #0066cc !important; 310 | } 311 | .syntaxhighlighter .script { 312 | font-weight: bold !important; 313 | color: #006699 !important; 314 | background-color: none !important; 315 | } 316 | .syntaxhighlighter .color1, .syntaxhighlighter .color1 a { 317 | color: gray !important; 318 | } 319 | .syntaxhighlighter .color2, .syntaxhighlighter .color2 a { 320 | color: #ff1493 !important; 321 | } 322 | .syntaxhighlighter .color3, .syntaxhighlighter .color3 a { 323 | color: red !important; 324 | } 325 | 326 | .syntaxhighlighter .keyword { 327 | font-weight: bold !important; 328 | } 329 | -------------------------------------------------------------------------------- /examples/assets/js/app.js: -------------------------------------------------------------------------------- 1 | // app-module 2 | (function(){ 3 | 'use strict'; 4 | angular.module('graphApp', [ 5 | 'gridshore.c3js.chart', 6 | //'graphApp.services', 7 | 'ngMaterial', 8 | 'ui.router', 9 | 'gridshore.c3js.dashboard', 10 | 'gridshore.c3js.bar', 11 | 'gridshore.c3js.line', 12 | 'gridshore.c3js.pie', 13 | 'gridshore.c3js.callback', 14 | 'gridshore.c3js.donut', 15 | 'gridshore.c3js.config', 16 | 'gridshore.c3js.gauge', 17 | 'gridshore.c3js.dynamic' 18 | ]); 19 | })(); 20 | 21 | // app-config 22 | (function(){ 23 | 'use strict'; 24 | angular.module('graphApp') 25 | .config(defaultRouteConfig); 26 | 27 | defaultRouteConfig.$inject = ['$urlRouterProvider']; 28 | 29 | function defaultRouteConfig($urlRouterProvider) { 30 | $urlRouterProvider.otherwise("/dashboard"); 31 | } 32 | })(); -------------------------------------------------------------------------------- /examples/assets/js/bar/bar.js: -------------------------------------------------------------------------------- 1 | // bar-module 2 | (function(){ 3 | 'use strict'; 4 | angular.module('gridshore.c3js.bar', [ 5 | //'graphApp.services', 6 | 'ui.router' 7 | ]); 8 | })(); 9 | 10 | (function(){ 11 | 'use strict'; 12 | angular.module('gridshore.c3js.bar') 13 | .config(routeConfig); 14 | 15 | routeConfig.$inject = ['$stateProvider']; 16 | function routeConfig($stateProvider) { 17 | $stateProvider 18 | .state('bar', { 19 | url: '/bar', 20 | templateUrl: 'assets/js/bar/bar.tpl.html', 21 | controller: 'BarCtrl', 22 | controllerAs: 'vm' 23 | }); 24 | } 25 | })(); 26 | 27 | (function(){ 28 | 'use strict'; 29 | angular.module('gridshore.c3js.bar') 30 | .controller('BarCtrl', BarCtrl); 31 | 32 | BarCtrl.$inject = []; 33 | function BarCtrl() { 34 | var vm = this; 35 | vm.chartObj = {}; 36 | vm.isGrouped = false; 37 | 38 | vm.handleCallbackGroup = handleCallbackGroup; 39 | vm.toggleGroup = toggleGroup; 40 | 41 | vm.datapoints = [ 42 | {"x": "one", "top-1": 10, "top-2": 12}, 43 | {"x": "two", "top-1": 11, "top-2": 13}, 44 | {"x": "three", "top-1": 12, "top-2": 14}, 45 | {"x": "four", "top-1": 13, "top-2": 15}, 46 | {"x": "five", "top-1": 14, "top-2": 16} 47 | ]; 48 | 49 | vm.rescalezoomdatapoints = [ 50 | {"x": "one", "top-1": 10, "top-2": 12}, 51 | {"x": "two", "top-1": 13, "top-2": 11}, 52 | {"x": "three", "top-1": 2, "top-2": 3}, 53 | {"x": "four", "top-1": 3, "top-2": 5}, 54 | {"x": "five", "top-1": 4, "top-2": 3}, 55 | {"x": "six", "top-1": 5, "top-2": 5}, 56 | {"x": "seven", "top-1": 3, "top-2": 6}, 57 | {"x": "eight", "top-1": 2, "top-2": 4}, 58 | {"x": "nine", "top-1": 17, "top-2": 12}, 59 | {"x": "ten", "top-1": 10, "top-2": 18} 60 | ]; 61 | 62 | vm.datacolumns = [{"id": "top-1", "type": "bar", "name": "Top one"}, 63 | {"id": "top-2", "type": "bar", "name": "Top two"}]; 64 | vm.datax = {"id": "x"}; 65 | 66 | function handleCallbackGroup(chartObj) { 67 | vm.chartObj = chartObj; 68 | } 69 | 70 | function toggleGroup() { 71 | if (vm.isGrouped) { 72 | vm.chartObj.groups([]); 73 | } else { 74 | vm.chartObj.groups([['bar1','bar2']]); 75 | } 76 | vm.isGrouped = !vm.isGrouped; 77 | vm.chartObj.flush(); 78 | } 79 | } 80 | })(); -------------------------------------------------------------------------------- /examples/assets/js/bar/bar.tpl.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |

A basic bar chart with a specified color and values through the chart-column directive. The 4 | other directive shown 5 | is the chart-bar directive. In this case we specify the ration of the bar width in relation to 6 | the total available with. 7 | A value smaller than 1 gives more space.

8 |
  9 | <c3chart bindto-id="chart1" show-labels="true">
 10 |     <chart-column column-id="bar1"
 11 |                   column-name="Bar 1"
 12 |                   column-color="green"
 13 |                   column-values="30,200,100,400,150,250"
 14 |                   column-type="bar"/>
 15 |     <chart-bar ratio="0.8"/>
 16 | </c3chart>
 17 | 
18 |
19 |
20 | 21 | 26 | 27 | 28 |
29 |
30 |

In the next example we add a second column, or better bar. This time we also add a chart-column 31 | for x values. We have to specify 32 | this column as a type Category in the chart-axis-x directive.

33 |
 34 | <c3chart bindto-id="chart2" show-labels="true">
 35 |     <chart-column column-id="x"
 36 |                   column-values="period 1,period 2,period 3,period 4,period 5,period 6"/>
 37 |     <chart-column column-id="bar1"
 38 |                   column-name="Bar 1"
 39 |                   column-color="green"
 40 |                   column-values="30,200,100,400,150,250"
 41 |                   column-type="bar"/>
 42 |     <chart-column column-id="bar2"
 43 |                   column-name="Bar 2"
 44 |                   column-color="red"
 45 |                   column-values="50,100,200,300,350,450"
 46 |                   column-type="bar"/>
 47 |     <chart-bar width="10"/>
 48 |     <chart-axes values-x="x"/>
 49 |     <chart-axis>
 50 |         <chart-axis-x axis-position="outer-center"
 51 |                       axis-label="The periods"
 52 |                       axis-type="category"/>
 53 |     </chart-axis>
 54 | </c3chart>
 55 | 
56 |
57 |
58 | 59 | 61 | 66 | 71 | 72 | 73 | 74 | 77 | 78 | 79 |
80 |
81 |

If you have a bar chart with multiple chart-columns, the default behavior is to place the bars next to each 82 | other. You can also group the bars so that are stacked. That is what the following example shows. Using the 83 | chart-group directive we can use the group-values attribute. Give it a comma 84 | separated column id's that need to be grouped.

85 |
 86 |     <chart-group group-values="bar1,bar2"/>
 87 | 
88 |
89 |
90 | 91 | 93 | 98 | 103 | 104 | 105 | 106 | 109 | 110 | 111 | 112 |
113 |
114 |

Now to show that you can also create a button to use grouping or not, we use the callback feature of the 115 | library

116 |
117 |
118 | 119 | 121 | 126 | 131 | 132 | 133 | 134 | 137 | 138 | 139 | Toggle grouping 140 |
141 |
142 |
143 |
144 |

In the next example we show that it is possible to have dynamic data fields while still using category 145 | labels for the x-axis.

146 |
147 |     <c3chart bindto-id="chartGroupDataPoints" chart-data="vm.datapoints" chart-columns="vm.datacolumns"
148 |              chart-x="vm.datax">
149 |         <chart-bar ratio="0.5"/>
150 |         <chart-axes values-x="x"/>
151 |         <chart-axis>
152 |             <chart-axis-x axis-position="outer-center"
153 |                           axis-label="The numbers"
154 |                           axis-type="category"/>
155 |         </chart-axis>
156 |     </c3chart>
157 | 
158 |
159 |
160 |
161 |
162 |
163 |     vm.datapoints = [
164 |         {"x": "one", "top-1": 10, "top-2": 12},
165 |         {"x": "two", "top-1": 11, "top-2": 13},
166 |         {"x": "three", "top-1": 12, "top-2": 14},
167 |         {"x": "four", "top-1": 13, "top-2": 15},
168 |         {"x": "five", "top-1": 14, "top-2": 16}
169 |     ];
170 |     vm.datacolumns = [{"id": "top-1", "type": "bar", "name": "Top one"},
171 |         {"id": "top-2", "type": "bar", "name": "Top two"}];
172 |     vm.datax = {"id": "x"};
173 | 
174 |
175 |
176 |
177 |
178 | 180 | 181 | 182 | 183 | 186 | 187 | 188 |
189 |
190 | 191 |
192 |
193 |

In the next example we show that it is possible to have dynamic data fields while still using category 194 | labels for the x-axis.

195 |
196 |     <c3chart bindto-id="chartGroupDataPoints" chart-data="vm.rescalezoomdatapoints" chart-columns="vm.datacolumns"
197 |              chart-x="vm.datax" enable-zoom="true" rescale-zoom="true">
198 |         <chart-bar ratio="0.5"/>
199 |         <chart-axes values-x="x"/>
200 |         <chart-axis>
201 |             <chart-axis-x axis-position="outer-center"
202 |                           axis-label="The numbers"
203 |                           axis-type="category"/>
204 |         </chart-axis>
205 |     </c3chart>
206 | 
207 |
208 |
209 |
210 |
211 |
212 |     vm.rescalezoomdatapoints = [
213 |             {"x": "one", "top-1": 10, "top-2": 12},
214 |             {"x": "two", "top-1": 13, "top-2": 11},
215 |             {"x": "three", "top-1": 2, "top-2": 3},
216 |             {"x": "four", "top-1": 3, "top-2": 5},
217 |             {"x": "five", "top-1": 4, "top-2": 3},
218 |             {"x": "six", "top-1": 5, "top-2": 5},
219 |             {"x": "seven", "top-1": 3, "top-2": 6},
220 |             {"x": "eight", "top-1": 2, "top-2": 4},
221 |             {"x": "nine", "top-1": 17, "top-2": 12},
222 |             {"x": "ten", "top-1": 10, "top-2": 18}
223 |         ];
224 | 
225 |     vm.datacolumns = [{"id": "top-1", "type": "bar", "name": "Top one"},
226 |         {"id": "top-2", "type": "bar", "name": "Top two"}];
227 |     vm.datax = {"id": "x"};
228 | 
229 |
230 |
231 |
232 |
233 | 235 | 236 | 237 | 240 | 241 | 242 |
243 |
244 |
245 |
-------------------------------------------------------------------------------- /examples/assets/js/callback/callback.js: -------------------------------------------------------------------------------- 1 | (function(){ 2 | 'use strict'; 3 | angular.module('gridshore.c3js.callback', [ 4 | 'ui.router' 5 | ]); 6 | })(); 7 | 8 | (function(){ 9 | 'use strict'; 10 | angular.module('gridshore.c3js.callback') 11 | .config(routeConfig); 12 | 13 | routeConfig.$inject = ['$stateProvider']; 14 | function routeConfig($stateProvider) { 15 | $stateProvider 16 | .state('callback', { 17 | url: '/callback', 18 | templateUrl: 'assets/js/callback/callback.tpl.html', 19 | controller: 'CallbackCtrl', 20 | controllerAs: 'vm' 21 | }); 22 | } 23 | })(); 24 | 25 | (function(){ 26 | 'use strict'; 27 | angular.module('gridshore.c3js.callback') 28 | .controller('CallbackCtrl', CallbackCtrl); 29 | 30 | CallbackCtrl.$inject = []; 31 | function CallbackCtrl() { 32 | var vm = this; 33 | vm.clicked = {}; 34 | vm.selected = undefined; 35 | vm.legendIsShown = true; 36 | 37 | vm.piePoints = [{"data1": 70, "data2": 30, "data3": "100"}]; 38 | vm.pieColumns = [{"id": "data1", "type": "pie"}, {"id": "data2", "type": "pie"}, 39 | {"id": "data3","type": "pie"}]; 40 | 41 | vm.piePointsSelected = []; 42 | vm.pieColumnsSelected = []; 43 | 44 | vm.piePointsLabel = [{"data1": 1, "data2": 1}]; 45 | vm.pieColumnsLabel = [{"id": "data1", "type": "pie"}, {"id": "data2", "type": "pie"}]; 46 | 47 | vm.selectItem = selectItem; 48 | vm.handleCallback = handleCallback; 49 | vm.toggleLegend = toggleLegend; 50 | vm.showClick = showClick; 51 | vm.clickLegend = clickLegend; 52 | 53 | function selectItem(data) { 54 | vm.selected = data; 55 | if (data.name === 'data1') { 56 | vm.piePointsSelected = [{'data11':35},{'data12':40},{'data13':10}]; 57 | vm.pieColumnsSelected = [{'id':'data11','type':'pie'},{'id':'data12','type':'pie'},{'id':'data13','type':'pie'}] 58 | } else if(data.name === 'data2') { 59 | vm.piePointsSelected = [{'data21':65},{'data22':80}]; 60 | vm.pieColumnsSelected = [{'id':'data21','type':'pie'},{'id':'data22','type':'pie'}]; 61 | } else if (data.name === 'data3') { 62 | vm.piePointsSelected = [{'data31':95},{'data32':10}]; 63 | vm.pieColumnsSelected = [{'id':'data31','type':'pie'},{'id':'data32','type':'pie'}]; 64 | } 65 | } 66 | 67 | function handleCallback(chartObj) { 68 | vm.theChart = chartObj; 69 | } 70 | 71 | function toggleLegend() { 72 | if (vm.legendIsShown) { 73 | vm.theChart.legend.hide(); 74 | } else { 75 | vm.theChart.legend.show(); 76 | } 77 | vm.legendIsShown= !vm.legendIsShown; 78 | vm.theChart.flush(); 79 | } 80 | 81 | function clickLegend(data) { 82 | vm.piePointsLabel[0][data]+=1; 83 | } 84 | 85 | function showClick(data) { 86 | vm.clicked = data; 87 | } 88 | } 89 | })(); -------------------------------------------------------------------------------- /examples/assets/js/callback/callback.tpl.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |

There are a number of events available to interact with your charts. There are two different levels of 4 | events. There are events related to the complete chart like mouseover and mouseout, but also on initialize 5 | and on render. You can register a callback to these events. But there are also events more related to the 6 | plotted data. You can respond to clicks on data points, but also on mouseovers and mouseout. All these 7 | callbacks are registered using the chart-events directive. In the example we show the on-data-click 8 | attribute. The other callback attribute are: on-init, on-mouseover, on-mouseout, 9 | on-resize, on-resized, on-rendered, on-click-data, 10 | on-mouseover-data and on-mouseout-data.

11 |
 12 | <c3chart bindto-id="interactive-plot1-chart" show-labels="false">
 13 |     <chart-column column-id="data1"
 14 |                   column-name="Data 1"
 15 |                   column-values="70"
 16 |                   column-type="donut"/>
 17 |     <chart-column column-id="Data 2"
 18 |                   column-values="35"
 19 |                   column-type="donut"/>
 20 |     <chart-column column-id="Data 3"
 21 |                   column-values="60"
 22 |                   column-type="donut"/>
 23 |     <chart-donut title="Donut" width="60"/>
 24 |     <chart-events on-click-data="vm.showClick(data)"/>
 25 | </c3chart>
 26 | 
27 |
 28 | function CallbackCtrl() {
 29 |     var vm = this;
 30 |     vm.clicked = {};
 31 | 
 32 |     vm.showClick = showClick;
 33 | 
 34 |     function showClick(data) {
 35 |         vm.clicked = data;
 36 |     }
 37 | }
 38 | 
39 | 40 |
41 |
42 | 43 | 47 | 50 | 53 | 54 | 55 | 56 |
57 |
58 |

Data clicked: Name {{vm.clicked.name}}, Value {{vm.clicked.value}} 59 |

60 |
61 |
62 | 63 |

In the next sample we are demonstrating the use of the callback function. C3js comes with the option to call 64 | some api methods of the chart object Using this callback function the chart is returned to expose this c3js 65 | api. It also shows loading the data from the controller instead of using the chart-column 66 | directive.

67 |
 68 | <c3chart bindto-id="dynamicpie" chart-data="vm.piePoints" chart-columns="vm.pieColumns"
 69 |          callback-function="vm.handleCallback"/>
 70 | <md-button class="md-raised" ng-click="vm.toggleLegend()">Toggle legend</md-button>
 71 | 
72 |
 73 | function CallbackCtrl() {
 74 |     var vm = this;
 75 | 
 76 |     vm.piePoints = [{"data1": 70, "data2": 30, "data3": "100"}];
 77 |     vm.pieColumns = [{"id": "data1", "type": "pie"}, {"id": "data2", "type": "pie"}, {
 78 |         "id": "data3",
 79 |         "type": "pie"
 80 |     }];
 81 | 
 82 |     vm.handleCallback = function (chartObj) {
 83 |         vm.theChart = chartObj;
 84 |     };
 85 | 
 86 |     vm.legendIsShown = true;
 87 |     vm.toggleLegend = function() {
 88 |         if (vm.legendIsShown) {
 89 |             vm.theChart.legend.hide();
 90 |         } else {
 91 |             vm.theChart.legend.show();
 92 |         }
 93 |         vm.legendIsShown= !vm.legendIsShown;
 94 |         vm.theChart.flush();
 95 |     };
 96 | }
 97 | 
98 |
99 |
100 | 102 |
103 |
104 | Toggle legend 105 |
106 |
107 |
108 |
109 |

The next sample is a bit more complicated, this time we have two charts with the first chart 110 | influencing the content of the second chart. If an item in the first pie is selected, items for the 111 | second pie will be obtained. In the sample the data points are hard coded but of course they can 112 | come from somewhere else.

113 |
114 | <c3chart bindto-id="interactivepie1" chart-data="vm.piePoints" chart-columns="vm.pieColumns">
115 |     <chart-events on-click-data="vm.selectItem(data)"/>
116 | </c3chart>
117 | <c3chart bindto-id="interactivepie2" chart-data="vm.piePointsSelected" chart-columns="vm.pieColumnsSelected">
118 | </c3chart>
119 | 
120 | 121 |
122 | vm.piePoints = [{"data1": 70, "data2": 30, "data3": "100"}];
123 | vm.pieColumns = [{"id": "data1", "type": "pie"}, {"id": "data2", "type": "pie"},
124 |     {"id": "data3","type": "pie"}];
125 | 
126 | vm.piePointsSelected = [];
127 | vm.pieColumnsSelected = [];
128 | 
129 | function selectItem(data) {
130 |     vm.selected = data;
131 |     if (data.name === 'data1') {
132 |         vm.piePointsSelected = [{'data11':35},{'data12':40},{'data13':10}];
133 |         vm.pieColumnsSelected = [{'id':'data11','type':'pie'},{'id':'data12','type':'pie'},{'id':'data13','type':'pie'}]
134 |     } else if(data.name === 'data2') {
135 |         vm.piePointsSelected = [{'data21':65},{'data22':80}];
136 |         vm.pieColumnsSelected = [{'id':'data21','type':'pie'},{'id':'data22','type':'pie'}];
137 |     } else if (data.name === 'data3') {
138 |         vm.piePointsSelected = [{'data31':95},{'data32':10}];
139 |         vm.pieColumnsSelected = [{'id':'data31','type':'pie'},{'id':'data32','type':'pie'}];
140 |     }
141 | }
142 | 
143 |
144 |
145 | 146 | 147 | 148 |
149 | 151 | 152 |
153 |
154 |

Click on the pie diagram above to select values belonging to that part of the pie.

155 |
156 |
157 |
158 |
159 |
160 |

In this sample we demonstrate having dynamic values in a pie diagram. Next to that we show how to use 161 | the events in the legend. By clicking the legend we increase the value if that specific column.

162 |

Below the code, first the pie with dynamic columns and next the code for the event callback 163 | function.

164 |
165 | <c3chart bindto-id="interactivelegend" chart-data="vm.piePointsLabel" chart-columns="vm.pieColumnsLabel">
166 |     <chart-legend on-click="vm.clickLegend(data)" legend-inset="top-right"
167 |     legend-inset-x="50" legend-inset-y="50" legend-inset-step="5"/>
168 | </c3chart>
169 | 
170 | 171 |
172 | vm.piePointsLabel = [{"data1": 1, "data2": 1}];
173 | vm.pieColumnsLabel = [{"id": "data1", "type": "pie"}, {"id": "data2", "type": "pie"}];
174 | 
175 | function clickLegend(data) {
176 |     vm.piePointsLabel[0][data]+=1;
177 | }
178 | 
179 | 180 |
181 |
182 | 184 | 186 | 187 |
188 |
189 |
190 |
-------------------------------------------------------------------------------- /examples/assets/js/config/config.js: -------------------------------------------------------------------------------- 1 | (function(){ 2 | 'use strict'; 3 | angular.module('gridshore.c3js.config', [ 4 | 'ui.router' 5 | ]); 6 | })(); 7 | 8 | (function(){ 9 | 'use strict'; 10 | angular.module('gridshore.c3js.config') 11 | .config(routeConfig); 12 | 13 | routeConfig.$inject = ['$stateProvider']; 14 | function routeConfig($stateProvider) { 15 | $stateProvider 16 | .state('config', { 17 | url: '/config', 18 | templateUrl: 'assets/js/config/config.tpl.html', 19 | controller: 'ConfigCtrl', 20 | controllerAs: 'vm' 21 | }); 22 | } 23 | })(); 24 | 25 | (function(){ 26 | 'use strict'; 27 | angular.module('gridshore.c3js.config') 28 | .controller('ConfigCtrl', ConfigCtrl); 29 | 30 | ConfigCtrl.$inject = []; 31 | function ConfigCtrl() { 32 | var vm = this; 33 | 34 | activate(); 35 | 36 | function activate() { 37 | 38 | } 39 | } 40 | })(); -------------------------------------------------------------------------------- /examples/assets/js/config/config.tpl.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |

Configure the grid of the graph

4 | 5 |

Another feature is that we can add a grid to the chart. We return to our one line of data chart and now add a 6 | horizontal grid. In the sample we add a horizontal grid, set show-y to true. But we also add two 7 | extra lines with a label. We have to configure the axis to use, the value to draw the line for and the label 8 | to place on top of the line.

9 | 10 |
 11 | <c3chart bindto-id="chart3">
 12 |     <chart-column column-id="line 1"
 13 |                   column-values="30,200,100,400,150,250"
 14 |                   column-type="line"/>
 15 |     <chart-grid show-x="false" show-y="true">
 16 |         <chart-grid-optional axis-id="y" grid-value="20" grid-text="Minimum" position="start"/>
 17 |         <chart-grid-optional axis-id="y" grid-value="200" grid-text="Maximum" grid-class="top-item"/>
 18 |     </chart-grid>
 19 | </c3chart>
 20 | 
21 | 22 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |

Configure the legend

32 | 33 |

You can hide the legend using the show-legend attribute. A more interesting property is the legend-position 34 | attribute. Legitimate values for this property are: bottom, right and inset. When inset is used you can also 35 | configure where to place the legend using one of the following values:top-left, top-right, bottom-left, 36 | bottom-right.

37 |
 38 | <c3chart bindto-id="chart-configure-legend">
 39 |     <chart-column column-id="line 1"
 40 |                   column-values="30,200,100,400,150,250"
 41 |                   column-type="line"/>
 42 |     <chart-grid show-x="false" show-y="true">
 43 |         <chart-grid-optional axis-id="y" grid-value="20" grid-text="Minimum"/>
 44 |         <chart-grid-optional axis-id="y" grid-value="200" grid-text="Maximum"/>
 45 |     </chart-grid>
 46 |     <chart-legend legend-position="inset" legend-inset="top-left"/>
 47 | </c3chart>
 48 | 
49 | 50 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 |

Configure the Tooltip

61 | 62 |

When moving you cursor over the chart points, you get a tooltip with the line name and the value. If you have 63 | multiple lines by default you see all the values for the same horizontal item. Using this directive you can hide the 64 | tooltip, but you can also disable the grouping of values. That way you only get the value for the line your cursor 65 | is on.

66 |
 67 |     <chart-tooltip group-tooltip="false"/>
 68 | 
69 | 70 | 75 | 80 | 81 | 82 | 83 |

Configure the dynamic nature of chart sizes

84 | 85 |

By default the chart fits within the space you give it. Maybe you have a good reason to explicitly set the size of a 86 | chart. This can be done with the chart-size directive. It has two attributes, chart-width and chart-height 87 |

88 | 89 | 90 | 95 | 100 | 101 | 102 | 103 |
104 | <chart-size chart-width="200" chart-height="200"/>
105 | 
106 |

Configure the colors of the chart

107 | 108 |

With each chart-column you can specify a color. So why more color configuration. With this directive you can give a 109 | number of colors to use throughout the graph. That way you do not specify which color to take, but you do specify the 110 | colors to chose from.

111 | 112 |
113 | 114 | 118 | 122 | 123 | 124 |
125 |
126 | <chart-colors color-pattern="green,blue,red,yellow"/>
127 | 
128 | 129 |
130 |
-------------------------------------------------------------------------------- /examples/assets/js/dashboard/dashboard.js: -------------------------------------------------------------------------------- 1 | (function(){ 2 | 'use strict'; 3 | angular.module('gridshore.c3js.dashboard', [ 4 | 'ui.router' 5 | ]); 6 | })(); 7 | 8 | (function(){ 9 | 'use strict'; 10 | angular.module('gridshore.c3js.dashboard') 11 | .config(routeConfig); 12 | 13 | routeConfig.$inject = ['$stateProvider']; 14 | function routeConfig($stateProvider) { 15 | $stateProvider 16 | .state('dashboard', { 17 | url: '/dashboard', 18 | templateUrl: 'assets/js/dashboard/dashboard.tpl.html', 19 | controller: 'DashboardCtrl', 20 | controllerAs: 'vm' 21 | }); 22 | } 23 | })(); 24 | 25 | (function(){ 26 | 'use strict'; 27 | angular.module('gridshore.c3js.dashboard') 28 | .controller('LeftCtrl', LeftCtrl); 29 | 30 | LeftCtrl.$inject = ['$scope','$timeout','$mdSidenav','$log']; 31 | function LeftCtrl($scope, $timeout, $mdSidenav, $log) { 32 | $scope.close = function () { 33 | $mdSidenav('left').close() 34 | .then(function () { 35 | $log.debug("close LEFT is done"); 36 | }); 37 | }; 38 | } 39 | })(); 40 | 41 | (function(){ 42 | 'use strict'; 43 | angular.module('gridshore.c3js.dashboard') 44 | .controller('DashboardCtrl', DashboardCtrl); 45 | 46 | DashboardCtrl.$inject = []; 47 | function DashboardCtrl() { 48 | var vm = this; 49 | 50 | activate(); 51 | 52 | function activate() { 53 | 54 | } 55 | } 56 | })(); -------------------------------------------------------------------------------- /examples/assets/js/dashboard/dashboard.tpl.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |

Welcome to the tutorial for using the c3js angular directives. We created these directives to make it easier to 4 | integrate graphs in your AngularJS project.

5 | 6 |

Installation

7 | 8 |

If you want to run this tutorial you have to run this as a website. There are a few ways you can do this. For all 9 | means you have to get a copy from this github 10 | repository. You can download the zip/tar or clone the repository.

11 |
    12 |
  • Using Python: Step into the examples folder and run python -m SimpleHTTPServer 8000
  • 13 |
  • Using grunt: From the root run: grunt devserver
  • 14 |
15 |

Setting up your project

16 | 17 |

Before you can show your graphs, you need to do the boilerplate stuff. You have to create an html page that loads the 18 | appropriate javascript libraries and stylesheets. The next code block shows this very basic html page.

19 | 20 |
21 | <html lang="en" ng-app="graphApp">
22 | <head>
23 | <link href="assets/css/c3.min.css" rel="stylesheet" type="text/css"/>
24 | </head>
25 | <body ng-controller="GraphCtrl">
26 | 
27 |     <script src="assets/js/d3.min.js" charset="utf-8"></script>
28 |     <script src="assets/js/c3.min.js"></script>
29 |     <script src="assets/js/angular.min.js"></script>
30 |     <script src="assets/js/c3-angular.min.js"></script>
31 | 
32 |     <script src="assets/js/app.js"></script>
33 | </body>
34 | </html>
35 | 
36 | 
37 | 38 |

Besides the html we also need a bit of JavaScript to initialize the application. The next code block shows 39 | initilizing the app and a controller.

40 |
41 | var graphApp = angular.module('graphApp', ['gridshore.c3js.chart']);
42 | 
43 | graphApp.controller('GraphCtrl', function ($scope) {
44 | 
45 | });
46 | 
47 |

That is it, before we move on to your first graph lets have a look at the different directives that are available. 48 | The main element is c3chart. All other directives are children of this element. This directive has a few 49 | attributes to configure the chart. The most important attribute is the bind-id, if you want multiple graphs 50 | on one page, this has to be unique. Other attributes are padding-top/right/left/bottom, 51 | show-labels, show-subchart and enable-zoom

52 |
53 |
-------------------------------------------------------------------------------- /examples/assets/js/donut/donut.js: -------------------------------------------------------------------------------- 1 | (function(){ 2 | 'use strict'; 3 | angular.module('gridshore.c3js.donut', [ 4 | 'ui.router' 5 | ]); 6 | })(); 7 | 8 | (function(){ 9 | 'use strict'; 10 | angular.module('gridshore.c3js.donut') 11 | .config(routeConfig); 12 | 13 | routeConfig.$inject = ['$stateProvider']; 14 | function routeConfig($stateProvider) { 15 | $stateProvider 16 | .state('donut', { 17 | url: '/donut', 18 | templateUrl: 'assets/js/donut/donut.tpl.html', 19 | controller: 'DonutCtrl', 20 | controllerAs: 'vm' 21 | }); 22 | } 23 | })(); 24 | 25 | (function(){ 26 | 'use strict'; 27 | angular.module('gridshore.c3js.donut') 28 | .controller('DonutCtrl', DonutCtrl); 29 | 30 | DonutCtrl.$inject = []; 31 | function DonutCtrl() { 32 | var vm = this; 33 | vm.donutPoints = [{"data1": 70, "data2": 30, "data3": 50, "data4": 40, "data5": 10}]; 34 | vm.donutColumns = [ 35 | {"id": "data1", "type": "donut"}, 36 | {"id": "data2", "type": "donut"}, 37 | {"id": "data3", "type": "donut"}, 38 | {"id": "data4", "type": "donut"}, 39 | {"id": "data5", "type": "donut"}]; 40 | vm.selectedItems = []; 41 | 42 | vm.formatDonut = formatDonut; 43 | vm.handleCallback = handleCallback; 44 | vm.handleClick = handleClick; 45 | 46 | function formatDonut(value, ratio, id) { 47 | return d3.format('$')(value); 48 | } 49 | 50 | function handleCallback(chartObj) { 51 | vm.theChart = chartObj; 52 | } 53 | 54 | function handleClick(data) { 55 | vm.selectedItems = vm.theChart.selected(); 56 | } 57 | } 58 | })(); -------------------------------------------------------------------------------- /examples/assets/js/donut/donut.tpl.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |

A donut is almost a pie, but without the middle. Threfore it has the same configuration options. One 4 | additional attribute is the title. This gives you a title in the middle of the donut. In the 5 | example below we also demonstrate formatting the label using a function. With the function we replace the 6 | percentage sign with the dollar sign.

7 | 8 |
 9 | <c3chart bindto-id="donut-plot1-chart">
10 |     <chart-column column-id="Data 1"
11 |                   column-values="70"
12 |                   column-type="donut"/>
13 |     <chart-column column-id="Data 2"
14 |                   column-values="35"
15 |                   column-type="donut"/>
16 |     <chart-column column-id="Data 3"
17 |                   column-values="60"
18 |                   column-type="donut"/>
19 |     <chart-donut title="Donut" width="60" show-label="true" label-format-function="formatDonut"
20 |                  threshold-label="0.1"/>
21 | </c3chart>
22 | 
23 |
24 | function DonutCtrl() {
25 |     var vm = this;
26 |     vm.formatDonut = formatDonut;
27 | 
28 |     function formatDonut(value, ratio, id) {
29 |         return d3.format('$')(value);
30 |     }
31 | }
32 | 
33 | 34 | 37 | 40 | 43 | 45 | 46 | 47 |

In the next sample we use data coming from angularjs objects. Also we remove the sorting which is from large 48 | to small by default. And in the chart-donut directive we also configure the width of the donut 49 | and whether to show the label or not. In our case we don't show it.

50 |
51 | <c3chart bindto-id="eventchart" chart-data="vm.donutPoints" chart-columns="vm.donutColumns" sort-data="null">
52 |     <chart-legend show-legend="true"/>
53 |     <chart-donut expand="true" width="30" show-label="false" title="Donut Title"/>
54 | </c3chart>
55 | 
56 | 57 | 58 | 59 | 60 | 61 |

In the next sample we continue with the previous sample, we now make it possible to configure the selection and on data click present the selected columns.

62 |
63 | <c3chart bindto-id="eventchart" chart-data="vm.donutPoints" chart-columns="vm.donutColumns" sort-data="null">
64 |     <chart-legend show-legend="true"/>
65 |     <chart-donut expand="true" width="30" show-label="false" title="Donut Title"/>
66 |     <selection enabled="true"/>
67 |     <chart-events on-click-data="vm.handleClick(data)"/>
68 | </c3chart>
69 | 
70 |
71 |
72 | 73 | 74 | 75 | 76 | 77 | 78 |
79 |
80 |

Selected items:

81 |
    82 |
  • {{item.id}}
  • 83 |
84 |
85 |
86 |
87 |
-------------------------------------------------------------------------------- /examples/assets/js/dynamic/dynamic.js: -------------------------------------------------------------------------------- 1 | (function(){ 2 | 'use strict'; 3 | angular.module('gridshore.c3js.dynamic', [ 4 | 'ui.router' 5 | ]); 6 | })(); 7 | 8 | (function(){ 9 | 'use strict'; 10 | angular.module('gridshore.c3js.dynamic') 11 | .config(routeConfig); 12 | 13 | routeConfig.$inject = ['$stateProvider']; 14 | function routeConfig($stateProvider) { 15 | $stateProvider 16 | .state('dynamic', { 17 | url: '/dynamic', 18 | templateUrl: 'assets/js/dynamic/dynamic.tpl.html', 19 | controller: 'DynamicCtrl', 20 | controllerAs: 'vm' 21 | }); 22 | } 23 | })(); 24 | 25 | (function(){ 26 | 'use strict'; 27 | angular.module('gridshore.c3js.dynamic') 28 | .controller('DynamicCtrl', DynamicCtrl); 29 | 30 | DynamicCtrl.$inject = ['$interval','dateFilter']; 31 | function DynamicCtrl($interval, dateFilter) { 32 | var vm = this; 33 | vm.generateData = generateData; 34 | vm.datapoints = []; 35 | vm.datacolumns = [{"id": "top-1", "type": "line", "name": "Top one"}, 36 | {"id": "top-2", "type": "spline", "name": "Top two"}]; 37 | vm.datax = {"id": "x"}; 38 | 39 | function generateData() { 40 | $interval(function () { 41 | loadData(function (data) { 42 | if (vm.datapoints.length > 10) { 43 | vm.datapoints.shift(); 44 | } 45 | vm.datapoints.push(data); 46 | }); 47 | }, 1000, 10); 48 | } 49 | 50 | function loadData (callback) { 51 | var aDate = dateFilter(new Date(),'yyyy-MM-dd hh:mm:ss'); 52 | callback({"x": aDate, "top-1": randomNumber(), "top-2": randomNumber()}); 53 | } 54 | 55 | function randomNumber() { 56 | return Math.floor((Math.random() * 200) + 1); 57 | } 58 | } 59 | })(); -------------------------------------------------------------------------------- /examples/assets/js/dynamic/dynamic.tpl.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |

The next chart is really different from all the other charts. Up till now we added the data using chart-column 4 | elements. In a lot of situations this is fine, but what if the data is dynamic of nature. Than we want to 5 | load the data using an angular controller. That is what this sample does. after clicking the button we 6 | generate 10 additional datapoints. Also the chart-columns are taken from a scope parameter. This is all 7 | taken care of using the attributes: chart-data, chart-columns and chart-x.

8 |
9 |
10 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 |
20 | Generate data 21 |
22 |
23 |
24 |
-------------------------------------------------------------------------------- /examples/assets/js/gauge/gauge.js: -------------------------------------------------------------------------------- 1 | (function(){ 2 | 'use strict'; 3 | angular.module('gridshore.c3js.gauge', [ 4 | 'ui.router' 5 | ]); 6 | })(); 7 | 8 | (function(){ 9 | 'use strict'; 10 | angular.module('gridshore.c3js.gauge') 11 | .config(routeConfig); 12 | 13 | routeConfig.$inject = ['$stateProvider']; 14 | function routeConfig($stateProvider) { 15 | $stateProvider 16 | .state('gauge', { 17 | url: '/gauge', 18 | templateUrl: 'assets/js/gauge/gauge.tpl.html', 19 | controller: 'GaugeCtrl', 20 | controllerAs: 'vm' 21 | }); 22 | } 23 | })(); 24 | 25 | (function(){ 26 | 'use strict'; 27 | angular.module('gridshore.c3js.gauge') 28 | .controller('GaugeCtrl', GaugeCtrl); 29 | 30 | GaugeCtrl.$inject = ['$interval']; 31 | function GaugeCtrl($interval) { 32 | var vm = this; 33 | 34 | activate(); 35 | 36 | function activate() { 37 | vm.gaugePoint = [{"data1": 70}]; 38 | vm.gaugeColumn = [ 39 | {"id": "data1", "type": "gauge"}]; 40 | 41 | $interval(function () { 42 | vm.gaugePoint[0]['data1'] = randomNumber(); 43 | }, 1000, 10); 44 | 45 | } 46 | 47 | function randomNumber() { 48 | return Math.floor((Math.random() * 100) + 1); 49 | } 50 | } 51 | })(); -------------------------------------------------------------------------------- /examples/assets/js/gauge/gauge.tpl.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |

You can create a gauge using column-type gauge. There are some specific configuration options that you can 4 | provide using the chart-gauge directive.

5 | 6 |
 7 | <c3chart bindto-id="gauge-plot1-chart">
 8 |     <chart-column column-id="Data 1"
 9 |                   column-values="70"
10 |                   column-type="gauge"/>
11 |     <chart-gauge min="50"
12 |                  max="75"
13 |                  units=" hours"
14 |                  width="39"
15 |                  show-label="true"
16 |                  expand="true"
17 |     />
18 | </c3chart>
19 | 
20 | 21 | 22 | 25 | 32 | 33 | 34 |
35 | <c3chart bindto-id="gauge-plot2-chart"
36 |          chart-data="vm.gaugePoint"
37 |          chart-columns="vm.gaugeColumn">
38 |     <chart-gauge units=" hours"
39 |                  width="39"
40 |                  show-label="true"
41 |                  expand="true"
42 |     />
43 | </c3chart>
44 | 
45 |

Now a more complicated example, we use the gauge chart to show how to dynamically change the value of the gauge.

46 |
47 | GaugeCtrl.$inject = ['$interval'];
48 | function GaugeCtrl($interval) {
49 |     var vm = this;
50 | 
51 |     activate();
52 | 
53 |     function activate() {
54 |         vm.gaugePoint = [{"data1": 70}];
55 |         vm.gaugeColumn = [
56 |             {"id": "data1", "type": "gauge"}];
57 | 
58 |         $interval(function () {
59 |             vm.gaugePoint[0]['data1'] = randomNumber();
60 |         }, 1000, 10);
61 | 
62 |     }
63 | 
64 |     function randomNumber() {
65 |         return Math.floor((Math.random() * 100) + 1);
66 |     }
67 | }
68 | 
69 | 70 | 73 | 78 | 79 | 80 |
81 |
-------------------------------------------------------------------------------- /examples/assets/js/line/line.js: -------------------------------------------------------------------------------- 1 | (function(){ 2 | 'use strict'; 3 | angular.module('gridshore.c3js.line', [ 4 | 'ui.router' 5 | ]); 6 | })(); 7 | 8 | (function(){ 9 | 'use strict'; 10 | angular.module('gridshore.c3js.line') 11 | .config(routeConfig); 12 | 13 | routeConfig.$inject = ['$stateProvider']; 14 | function routeConfig($stateProvider) { 15 | $stateProvider 16 | .state('line', { 17 | url: '/line', 18 | templateUrl: 'assets/js/line/line.tpl.html', 19 | controller: 'LineCtrl', 20 | controllerAs: 'vm' 21 | }); 22 | } 23 | })(); 24 | 25 | (function(){ 26 | 'use strict'; 27 | angular.module('gridshore.c3js.line') 28 | .controller('LineCtrl', LineCtrl); 29 | 30 | LineCtrl.$inject = []; 31 | function LineCtrl() { 32 | var vm = this; 33 | 34 | vm.formatTitleFunction = formatTitleFunction; 35 | 36 | function formatTitleFunction(x) { 37 | return 'Category ' + x; 38 | } 39 | } 40 | })(); -------------------------------------------------------------------------------- /examples/assets/js/line/line.tpl.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |

The next chart shows how to create a basic line chart, there is one additional configuration using the chart-points directive. 4 | You can set the size of the points using this diective.

5 |
  6 |     <c3chart bindto-id="chart1" show-labels="true">
  7 |         <chart-column column-id="line1"
  8 |                       column-name="Line 1"
  9 |                       column-color="green"
 10 |                       column-values="30,200,100,400,150,250"
 11 |                       column-type="line"/>
 12 |         <chart-points point-radius="5"
 13 |                       show-point="true"
 14 |                       point-expand-enabled="true"
 15 |                       point-expand-radius="10"/>
 16 |     </c3chart>
 17 | 
18 | 19 | 24 | 28 | 29 |

Now there are a lot of options available to you to configure. We can add a second line of data, but we can also 30 | configure vertical axes. That is what we will do in the next example. We add a second chart-column 31 | element. This line1 and bar1 axis have a different scale, that is what we configure in the chart-axes 32 | element. The attributes y and y2 which columns use which y axis. If you have more than two 33 | chart-columns you can comma separate them to attach them to the two different vertical axes.

34 |
 35 | <c3chart bindto-id="chart2">
 36 |     <chart-column column-id="line1"
 37 |                   column-name="Line 1"
 38 |                   column-color="red"
 39 |                   column-values="30,200,100,400,150,250"
 40 |                   column-type="spline"/>
 41 |     <chart-column column-id="bar1"
 42 |                   column-name="Bar 1"
 43 |                   column-color="green"
 44 |                   column-values="50,20,10,40,15,25"
 45 |                   column-type="bar"/>
 46 |     <chart-axes y="line1" y2="bar1"/>
 47 | </c3chart>
 48 | 
49 | 50 | 55 | 60 | 61 | 62 | 63 | 64 |

In the next sample we are going to do something else that is cool, we are going to rotate the graph using the directive 65 | chart-axis.

66 |
 67 | <chart-axis axis-rotate="true"/>
 68 | 
69 | 70 | 75 | 80 | 81 | 82 | 83 |

In the next bar chart we are demonstrating what you can do with formatting ticks. We add multiple 84 | configurations for the x-tick as well as the y-tick.

85 |
 86 | <c3chart bindto-id="chartTickSample">
 87 |     <chart-column column-id="line1"
 88 |                   column-name="Line 1"
 89 |                   column-color="red"
 90 |                   column-values="30,200,100,400,150,250"
 91 |                   column-type="spline"/>
 92 |     <chart-column column-id="bar1"
 93 |                   column-name="Bar 1"
 94 |                   column-color="green"
 95 |                   column-values="50,20,10,40,15,25"
 96 |                   column-type="bar"/>
 97 |     <chart-axis>
 98 |         <chart-axis-x axis-position="outer-center" axis-label="Number by 10"
 99 |                       axis-type="category">
100 |             <chart-axis-x-tick tick-rotate="50"/>
101 |         </chart-axis-x>
102 |         <chart-axis-y>
103 |             <chart-axis-y-tick tick-values="50,100,150,200,250"/>
104 |         </chart-axis-y>
105 |     </chart-axis>
106 | </c3chart>
107 | 
108 | 109 | 114 | 119 | 120 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 |

In the next bar chart we are demonstrating what you can do with regions. We add multiple 134 | regions for each line.

135 |
136 | <c3chart bindto-id="chartRegionSample">
137 |     <chart-column column-id="line1"
138 |                   column-name="Line 1"
139 |                   column-color="green"
140 |                   column-values="2010,2011,2012,2013,2014,2015"
141 |                   column-type="line"/>
142 |     <chart-column column-id="x1"
143 |                   column-name="Line 1"
144 |                   column-color="green"
145 |                   column-values="30,200,100,400,150,250"
146 |                   column-type="line"/>
147 |     <chart-column column-id="line2"
148 |                   column-name="Line 1"
149 |                   column-color="green"
150 |                   column-values="2011,2012,2013,2014,2015"
151 |                   column-type="line"/>
152 |     <chart-column column-id="x2"
153 |                   column-name="Line 1"
154 |                   column-color="green"
155 |                   column-values="250,150,300,250,200"
156 |                   column-type="line"/>
157 |     <chart-points point-radius="5"
158 |                   show-point="true"
159 |                   point-expand-enabled="true"
160 |                   point-expand-radius="10"/>
161 |     <chart-region region-id="x1"
162 |                   region-style="dashed"
163 |                   region-starts="2011"
164 |                   region-ends="2013"></chart-region>
165 |     <chart-axes values-xs="x1:line1,x2:line2"></chart-axes>
166 | </c3chart>
167 | 
168 | 169 | 174 | 179 | 184 | 189 | 193 | 197 | 198 | 199 |
200 |
-------------------------------------------------------------------------------- /examples/assets/js/pie/pie.js: -------------------------------------------------------------------------------- 1 | (function () { 2 | 'use strict'; 3 | angular.module('gridshore.c3js.pie', [ 4 | 'ui.router' 5 | ]); 6 | })(); 7 | 8 | (function () { 9 | 'use strict'; 10 | angular.module('gridshore.c3js.pie') 11 | .config(routeConfig); 12 | 13 | routeConfig.$inject = ['$stateProvider']; 14 | function routeConfig($stateProvider) { 15 | $stateProvider 16 | .state('pie', { 17 | url: '/pie', 18 | templateUrl: 'assets/js/pie/pie.tpl.html', 19 | controller: 'PieCtrl', 20 | controllerAs: 'vm' 21 | }); 22 | } 23 | })(); 24 | 25 | (function () { 26 | 'use strict'; 27 | angular.module('gridshore.c3js.pie') 28 | .controller('PieCtrl', PieCtrl); 29 | 30 | PieCtrl.$inject = []; 31 | function PieCtrl() { 32 | var vm = this; 33 | vm.calculateColor = calculateColor; 34 | 35 | activate(); 36 | 37 | function activate() { 38 | 39 | } 40 | 41 | function calculateColor(color, value) { 42 | if (value === "Data 1") { 43 | return "red"; 44 | } else if (value === "Data 2") { 45 | return "blue"; 46 | } else if (value === "Data 3") { 47 | return "yellow"; 48 | } else { 49 | return "green"; 50 | } 51 | } 52 | } 53 | })(); -------------------------------------------------------------------------------- /examples/assets/js/pie/pie.tpl.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |

Creating a pie diagram is as easy as providing a number of chart-column elements. You can configure 4 | a few options using the chart-pie directive.

5 |
  6 | <c3chart bindto-id="pie-plot1-chart" sort-data="desc">
  7 |     <chart-column column-id="Data 1"
  8 |                   column-values="70"
  9 |                   column-type="pie"/>
 10 |     <chart-column column-id="Data 2"
 11 |                   column-values="35"
 12 |                   column-type="pie"/>
 13 |     <chart-column column-id="Data 3"
 14 |                   column-values="60"
 15 |                   column-type="pie"/>
 16 |     <chart-pie expand="true" show-label="true" threshold-label="0.1"/>
 17 | </c3chart>
 18 | 
 19 | 
20 | 21 | 24 | 27 | 30 | 31 | 32 | 33 |

Using the color configuration options it is possible to specify the colors to use in the pie chart. In the 34 | following sample we specify the colors to use in a pattern array.

35 |
 36 | <c3chart bindto-id="pie-plot1-chart" sort-data="desc">
 37 |     <chart-column column-id="Data 1"
 38 |                   column-values="70"
 39 |                   column-type="pie"/>
 40 |     <chart-column column-id="Data 2"
 41 |                   column-values="35"
 42 |                   column-type="pie"/>
 43 |     <chart-column column-id="Data 3"
 44 |                   column-values="60"
 45 |                   column-type="pie"/>
 46 |     <chart-colors color-pattern="#000,#888,#ccc"/>
 47 |     <chart-pie expand="true" show-label="true" threshold-label="0.1"/>
 48 | </c3chart>
 49 | 
 50 | 
51 | 52 | 53 | 56 | 59 | 62 | 63 | 64 | 65 |

Using the color configuration options it is possible to specify the colors to use in the pie chart. In the 66 | following sample we specify the colors using a color function. At the moment I cannot use the value, but 67 | I can use the name of the columns in the function

68 |
 69 | <c3chart bindto-id="pie-plot1-chart" sort-data="desc">
 70 |     <chart-column column-id="Data 1"
 71 |                   column-values="70"
 72 |                   column-type="pie"/>
 73 |     <chart-column column-id="Data 2"
 74 |                   column-values="35"
 75 |                   column-type="pie"/>
 76 |     <chart-column column-id="Data 3"
 77 |                   column-values="60"
 78 |                   column-type="pie"/>
 79 |     <chart-colors color-function="vm.calculateColor"/>
 80 |     <chart-pie expand="true" show-label="true" threshold-label="0.1"/>
 81 | </c3chart>
 82 | 
83 |
 84 | function calculateColor(color, value) {
 85 |     if (value === "Data 1") {
 86 |         return "red";
 87 |     } else if (value === "Data 2") {
 88 |         return "blue";
 89 |     } else if (value === "Data 3") {
 90 |         return "yellow";
 91 |     } else {
 92 |         return "green";
 93 |     }
 94 | }
 95 | 
96 | 97 | 98 | 101 | 104 | 107 | 108 | 109 |

Using the color configuration options it is possible to specify the colors to use in the pie chart. In the 110 | following sample we specify the colors however in the columns themselves.

111 |
112 | <c3chart bindto-id="pie-plot1-chart" sort-data="desc">
113 |     <chart-column column-id="Data 1"
114 |                   column-values="70"
115 |                   column-type="pie"
116 |                   column-color="red"/>
117 |     <chart-column column-id="Data 2"
118 |                   column-values="35"
119 |                   column-type="pie"
120 |                   column-color="orange"/>
121 |     <chart-column column-id="Data 3"
122 |                   column-values="60"
123 |                   column-type="pie"
124 |                   column-color="cyan"/>
125 |     <chart-pie expand="true" show-label="true" threshold-label="0.1"/>
126 | </c3chart>
127 | 
128 | 129 | 133 | 137 | 141 | 142 | 143 | 144 |
145 |
-------------------------------------------------------------------------------- /examples/assets/js/shBrushJScript.js: -------------------------------------------------------------------------------- 1 | /** 2 | * SyntaxHighlighter 3 | * http://alexgorbatchev.com/SyntaxHighlighter 4 | * 5 | * SyntaxHighlighter is donationware. If you are using it, please donate. 6 | * http://alexgorbatchev.com/SyntaxHighlighter/donate.html 7 | * 8 | * @version 9 | * 3.0.83 (July 02 2010) 10 | * 11 | * @copyright 12 | * Copyright (C) 2004-2010 Alex Gorbatchev. 13 | * 14 | * @license 15 | * Dual licensed under the MIT and GPL licenses. 16 | */ 17 | ;(function() 18 | { 19 | // CommonJS 20 | typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null; 21 | 22 | function Brush() 23 | { 24 | var keywords = 'break case catch continue ' + 25 | 'default delete do else false ' + 26 | 'for function if in instanceof ' + 27 | 'new null return super switch ' + 28 | 'this throw true try typeof var while with' 29 | ; 30 | 31 | var r = SyntaxHighlighter.regexLib; 32 | 33 | this.regexList = [ 34 | { regex: r.multiLineDoubleQuotedString, css: 'string' }, // double quoted strings 35 | { regex: r.multiLineSingleQuotedString, css: 'string' }, // single quoted strings 36 | { regex: r.singleLineCComments, css: 'comments' }, // one line comments 37 | { regex: r.multiLineCComments, css: 'comments' }, // multiline comments 38 | { regex: /\s*#.*/gm, css: 'preprocessor' }, // preprocessor tags like #region and #endregion 39 | { regex: new RegExp(this.getKeywords(keywords), 'gm'), css: 'keyword' } // keywords 40 | ]; 41 | 42 | this.forHtmlScript(r.scriptScriptTags); 43 | }; 44 | 45 | Brush.prototype = new SyntaxHighlighter.Highlighter(); 46 | Brush.aliases = ['js', 'jscript', 'javascript']; 47 | 48 | SyntaxHighlighter.brushes.JScript = Brush; 49 | 50 | // CommonJS 51 | typeof(exports) != 'undefined' ? exports.Brush = Brush : null; 52 | })(); 53 | -------------------------------------------------------------------------------- /examples/assets/js/shBrushXml.js: -------------------------------------------------------------------------------- 1 | /** 2 | * SyntaxHighlighter 3 | * http://alexgorbatchev.com/SyntaxHighlighter 4 | * 5 | * SyntaxHighlighter is donationware. If you are using it, please donate. 6 | * http://alexgorbatchev.com/SyntaxHighlighter/donate.html 7 | * 8 | * @version 9 | * 3.0.83 (July 02 2010) 10 | * 11 | * @copyright 12 | * Copyright (C) 2004-2010 Alex Gorbatchev. 13 | * 14 | * @license 15 | * Dual licensed under the MIT and GPL licenses. 16 | */ 17 | ;(function() 18 | { 19 | // CommonJS 20 | typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null; 21 | 22 | function Brush() 23 | { 24 | function process(match, regexInfo) 25 | { 26 | var constructor = SyntaxHighlighter.Match, 27 | code = match[0], 28 | tag = new XRegExp('(<|<)[\\s\\/\\?]*(?[:\\w-\\.]+)', 'xg').exec(code), 29 | result = [] 30 | ; 31 | 32 | if (match.attributes != null) 33 | { 34 | var attributes, 35 | regex = new XRegExp('(? [\\w:\\-\\.]+)' + 36 | '\\s*=\\s*' + 37 | '(? ".*?"|\'.*?\'|\\w+)', 38 | 'xg'); 39 | 40 | while ((attributes = regex.exec(code)) != null) 41 | { 42 | result.push(new constructor(attributes.name, match.index + attributes.index, 'color1')); 43 | result.push(new constructor(attributes.value, match.index + attributes.index + attributes[0].indexOf(attributes.value), 'string')); 44 | } 45 | } 46 | 47 | if (tag != null) 48 | result.push( 49 | new constructor(tag.name, match.index + tag[0].indexOf(tag.name), 'keyword') 50 | ); 51 | 52 | return result; 53 | } 54 | 55 | this.regexList = [ 56 | { regex: new XRegExp('(\\<|<)\\!\\[[\\w\\s]*?\\[(.|\\s)*?\\]\\](\\>|>)', 'gm'), css: 'color2' }, // 57 | { regex: SyntaxHighlighter.regexLib.xmlComments, css: 'comments' }, // 58 | { regex: new XRegExp('(<|<)[\\s\\/\\?]*(\\w+)(?.*?)[\\s\\/\\?]*(>|>)', 'sg'), func: process } 59 | ]; 60 | }; 61 | 62 | Brush.prototype = new SyntaxHighlighter.Highlighter(); 63 | Brush.aliases = ['xml', 'xhtml', 'xslt', 'html']; 64 | 65 | SyntaxHighlighter.brushes.Xml = Brush; 66 | 67 | // CommonJS 68 | typeof(exports) != 'undefined' ? exports.Brush = Brush : null; 69 | })(); 70 | -------------------------------------------------------------------------------- /examples/assets/js/shCore.js: -------------------------------------------------------------------------------- 1 | /** 2 | * SyntaxHighlighter 3 | * http://alexgorbatchev.com/SyntaxHighlighter 4 | * 5 | * SyntaxHighlighter is donationware. If you are using it, please donate. 6 | * http://alexgorbatchev.com/SyntaxHighlighter/donate.html 7 | * 8 | * @version 9 | * 3.0.83 (July 02 2010) 10 | * 11 | * @copyright 12 | * Copyright (C) 2004-2010 Alex Gorbatchev. 13 | * 14 | * @license 15 | * Dual licensed under the MIT and GPL licenses. 16 | */ 17 | eval(function(p,a,c,k,e,d){e=function(c){return(c35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('K M;I(M)1S 2U("2a\'t 4k M 4K 2g 3l 4G 4H");(6(){6 r(f,e){I(!M.1R(f))1S 3m("3s 15 4R");K a=f.1w;f=M(f.1m,t(f)+(e||""));I(a)f.1w={1m:a.1m,19:a.19?a.19.1a(0):N};H f}6 t(f){H(f.1J?"g":"")+(f.4s?"i":"")+(f.4p?"m":"")+(f.4v?"x":"")+(f.3n?"y":"")}6 B(f,e,a,b){K c=u.L,d,h,g;v=R;5K{O(;c--;){g=u[c];I(a&g.3r&&(!g.2p||g.2p.W(b))){g.2q.12=e;I((h=g.2q.X(f))&&h.P===e){d={3k:g.2b.W(b,h,a),1C:h};1N}}}}5v(i){1S i}5q{v=11}H d}6 p(f,e,a){I(3b.Z.1i)H f.1i(e,a);O(a=a||0;a-1},3d:6(g){e+=g}};c1&&p(e,"")>-1){a=15(J.1m,n.Q.W(t(J),"g",""));n.Q.W(f.1a(e.P),a,6(){O(K c=1;c<14.L-2;c++)I(14[c]===1d)e[c]=1d})}I(J.1w&&J.1w.19)O(K b=1;be.P&&J.12--}H e};I(!D)15.Z.1A=6(f){(f=n.X.W(J,f))&&J.1J&&!f[0].L&&J.12>f.P&&J.12--;H!!f};1r.Z.1C=6(f){M.1R(f)||(f=15(f));I(f.1J){K e=n.1C.1p(J,14);f.12=0;H e}H f.X(J)};1r.Z.Q=6(f,e){K a=M.1R(f),b,c;I(a&&1j e.58()==="3f"&&e.1i("${")===-1&&y)H n.Q.1p(J,14);I(a){I(f.1w)b=f.1w.19}Y f+="";I(1j e==="6")c=n.Q.W(J,f,6(){I(b){14[0]=1f 1r(14[0]);O(K d=0;dd.L-3;){i=1r.Z.1a.W(g,-1)+i;g=1Q.3i(g/10)}H(g?d[g]||"":"$")+i}Y{g=+i;I(g<=d.L-3)H d[g];g=b?p(b,i):-1;H g>-1?d[g+1]:h}})})}I(a&&f.1J)f.12=0;H c};1r.Z.1e=6(f,e){I(!M.1R(f))H n.1e.1p(J,14);K a=J+"",b=[],c=0,d,h;I(e===1d||+e<0)e=5D;Y{e=1Q.3i(+e);I(!e)H[]}O(f=M.3c(f);d=f.X(a);){I(f.12>c){b.U(a.1a(c,d.P));d.L>1&&d.P=e)1N}f.12===d.P&&f.12++}I(c===a.L){I(!n.1A.W(f,"")||h)b.U("")}Y b.U(a.1a(c));H b.L>e?b.1a(0,e):b};M.1h(/\\(\\?#[^)]*\\)/,6(f){H n.1A.W(A,f.2S.1a(f.P+f[0].L))?"":"(?:)"});M.1h(/\\((?!\\?)/,6(){J.19.U(N);H"("});M.1h(/\\(\\?<([$\\w]+)>/,6(f){J.19.U(f[1]);J.2N=R;H"("});M.1h(/\\\\k<([\\w$]+)>/,6(f){K e=p(J.19,f[1]);H e>-1?"\\\\"+(e+1)+(3R(f.2S.3a(f.P+f[0].L))?"":"(?:)"):f[0]});M.1h(/\\[\\^?]/,6(f){H f[0]==="[]"?"\\\\b\\\\B":"[\\\\s\\\\S]"});M.1h(/^\\(\\?([5A]+)\\)/,6(f){J.3d(f[1]);H""});M.1h(/(?:\\s+|#.*)+/,6(f){H n.1A.W(A,f.2S.1a(f.P+f[0].L))?"":"(?:)"},M.1B,6(){H J.2K("x")});M.1h(/\\./,6(){H"[\\\\s\\\\S]"},M.1B,6(){H J.2K("s")})})();1j 2e!="1d"&&(2e.M=M);K 1v=6(){6 r(a,b){a.1l.1i(b)!=-1||(a.1l+=" "+b)}6 t(a){H a.1i("3e")==0?a:"3e"+a}6 B(a){H e.1Y.2A[t(a)]}6 p(a,b,c){I(a==N)H N;K d=c!=R?a.3G:[a.2G],h={"#":"1c",".":"1l"}[b.1o(0,1)]||"3h",g,i;g=h!="3h"?b.1o(1):b.5u();I((a[h]||"").1i(g)!=-1)H a;O(a=0;d&&a\'+c+""});H a}6 n(a,b){a.1e("\\n");O(K c="",d=0;d<50;d++)c+=" ";H a=v(a,6(h){I(h.1i("\\t")==-1)H h;O(K g=0;(g=h.1i("\\t"))!=-1;)h=h.1o(0,g)+c.1o(0,b-g%b)+h.1o(g+1,h.L);H h})}6 x(a){H a.Q(/^\\s+|\\s+$/g,"")}6 D(a,b){I(a.Pb.P)H 1;Y I(a.Lb.L)H 1;H 0}6 y(a,b){6 c(k){H k[0]}O(K d=N,h=[],g=b.2D?b.2D:c;(d=b.1I.X(a))!=N;){K i=g(d,b);I(1j i=="3f")i=[1f e.2L(i,d.P,b.23)];h=h.1O(i)}H h}6 E(a){K b=/(.*)((&1G;|&1y;).*)/;H a.Q(e.3A.3M,6(c){K d="",h=N;I(h=b.X(c)){c=h[1];d=h[2]}H\'\'+c+""+d})}6 z(){O(K a=1E.36("1k"),b=[],c=0;c<1z 4I="1Z://2y.3L.3K/4L/5L"><3J><4N 1Z-4M="5G-5M" 6K="2O/1z; 6J=6I-8" /><1t>6L 1v<3B 1L="25-6M:6Q,6P,6O,6N-6F;6y-2f:#6x;2f:#6w;25-22:6v;2O-3D:3C;">1v3v 3.0.76 (72 73 3x)1Z://3u.2w/1v70 17 6U 71.6T 6X-3x 6Y 6D.6t 61 60 J 1k, 5Z 5R 5V <2R/>5U 5T 5S!\'}},1Y:{2j:N,2A:{}},1U:{},3A:{6n:/\\/\\*[\\s\\S]*?\\*\\//2c,6m:/\\/\\/.*$/2c,6l:/#.*$/2c,6k:/"([^\\\\"\\n]|\\\\.)*"/g,6o:/\'([^\\\\\'\\n]|\\\\.)*\'/g,6p:1f M(\'"([^\\\\\\\\"]|\\\\\\\\.)*"\',"3z"),6s:1f M("\'([^\\\\\\\\\']|\\\\\\\\.)*\'","3z"),6q:/(&1y;|<)!--[\\s\\S]*?--(&1G;|>)/2c,3M:/\\w+:\\/\\/[\\w-.\\/?%&=:@;]*/g,6a:{18:/(&1y;|<)\\?=?/g,1b:/\\?(&1G;|>)/g},69:{18:/(&1y;|<)%=?/g,1b:/%(&1G;|>)/g},6d:{18:/(&1y;|<)\\s*1k.*?(&1G;|>)/2T,1b:/(&1y;|<)\\/\\s*1k\\s*(&1G;|>)/2T}},16:{1H:6(a){6 b(i,k){H e.16.2o(i,k,e.13.1x[k])}O(K c=\'\',d=e.16.2x,h=d.2X,g=0;g";H c},2o:6(a,b,c){H\'<2W>\'+c+""},2b:6(a){K b=a.1F,c=b.1l||"";b=B(p(b,".20",R).1c);K d=6(h){H(h=15(h+"6f(\\\\w+)").X(c))?h[1]:N}("6g");b&&d&&e.16.2x[d].2B(b);a.3N()},2x:{2X:["21","2P"],21:{1H:6(a){I(a.V("2l")!=R)H"";K b=a.V("1t");H e.16.2o(a,"21",b?b:e.13.1x.21)},2B:6(a){a=1E.6j(t(a.1c));a.1l=a.1l.Q("47","")}},2P:{2B:6(){K a="68=0";a+=", 18="+(31.30-33)/2+", 32="+(31.2Z-2Y)/2+", 30=33, 2Z=2Y";a=a.Q(/^,/,"");a=1P.6Z("","38",a);a.2C();K b=a.1E;b.6W(e.13.1x.37);b.6V();a.2C()}}}},35:6(a,b){K c;I(b)c=[b];Y{c=1E.36(e.13.34);O(K d=[],h=0;h(.*?))\\\\]$"),s=1f M("(?<27>[\\\\w-]+)\\\\s*:\\\\s*(?<1T>[\\\\w-%#]+|\\\\[.*?\\\\]|\\".*?\\"|\'.*?\')\\\\s*;?","g");(j=s.X(k))!=N;){K o=j.1T.Q(/^[\'"]|[\'"]$/g,"");I(o!=N&&m.1A(o)){o=m.X(o);o=o.2V.L>0?o.2V.1e(/\\s*,\\s*/):[]}l[j.27]=o}g={1F:g,1n:C(i,l)};g.1n.1D!=N&&d.U(g)}H d},1M:6(a,b){K c=J.35(a,b),d=N,h=e.13;I(c.L!==0)O(K g=0;g")==o-3){m=m.4h(0,o-3);s=R}l=s?m:l}I((i.1t||"")!="")k.1t=i.1t;k.1D=j;d.2Q(k);b=d.2F(l);I((i.1c||"")!="")b.1c=i.1c;i.2G.74(b,i)}}},2E:6(a){w(1P,"4k",6(){e.1M(a)})}};e.2E=e.2E;e.1M=e.1M;e.2L=6(a,b,c){J.1T=a;J.P=b;J.L=a.L;J.23=c;J.1V=N};e.2L.Z.1q=6(){H J.1T};e.4l=6(a){6 b(j,l){O(K m=0;md)1N;Y I(g.P==c.P&&g.L>c.L)a[b]=N;Y I(g.P>=c.P&&g.P\'+c+""},3Q:6(a,b){K c="",d=a.1e("\\n").L,h=2u(J.V("2i-1s")),g=J.V("2z-1s-2t");I(g==R)g=(h+d-1).1q().L;Y I(3R(g)==R)g=0;O(K i=0;i\'+j+"":"")+i)}H a},4f:6(a){H a?"<4a>"+a+"":""},4b:6(a,b){6 c(l){H(l=l?l.1V||g:g)?l+" ":""}O(K d=0,h="",g=J.V("1D",""),i=0;i|&1y;2R\\s*\\/?&1G;/2T;I(e.13.46==R)b=b.Q(h,"\\n");I(e.13.44==R)b=b.Q(h,"");b=b.1e("\\n");h=/^\\s*/;g=4Q;O(K i=0;i0;i++){K k=b[i];I(x(k).L!=0){k=h.X(k);I(k==N){a=a;1N a}g=1Q.4q(k[0].L,g)}}I(g>0)O(i=0;i\'+(J.V("16")?e.16.1H(J):"")+\'<3Z 5z="0" 5H="0" 5J="0">\'+J.4f(J.V("1t"))+"<3T><3P>"+(1u?\'<2d 1g="1u">\'+J.3Q(a)+"":"")+\'<2d 1g="17">\'+b+""},2F:6(a){I(a===N)a="";J.17=a;K b=J.3Y("T");b.3X=J.1H(a);J.V("16")&&w(p(b,".16"),"5c",e.16.2b);J.V("3V-17")&&w(p(b,".17"),"56",f);H b},2Q:6(a){J.1c=""+1Q.5d(1Q.5n()*5k).1q();e.1Y.2A[t(J.1c)]=J;J.1n=C(e.2v,a||{});I(J.V("2k")==R)J.1n.16=J.1n.1u=11},5j:6(a){a=a.Q(/^\\s+|\\s+$/g,"").Q(/\\s+/g,"|");H"\\\\b(?:"+a+")\\\\b"},5f:6(a){J.28={18:{1I:a.18,23:"1k"},1b:{1I:a.1b,23:"1k"},17:1f M("(?<18>"+a.18.1m+")(?<17>.*?)(?<1b>"+a.1b.1m+")","5o")}}};H e}();1j 2e!="1d"&&(2e.1v=1v);',62,441,'||||||function|||||||||||||||||||||||||||||||||||||return|if|this|var|length|XRegExp|null|for|index|replace|true||div|push|getParam|call|exec|else|prototype||false|lastIndex|config|arguments|RegExp|toolbar|code|left|captureNames|slice|right|id|undefined|split|new|class|addToken|indexOf|typeof|script|className|source|params|substr|apply|toString|String|line|title|gutter|SyntaxHighlighter|_xregexp|strings|lt|html|test|OUTSIDE_CLASS|match|brush|document|target|gt|getHtml|regex|global|join|style|highlight|break|concat|window|Math|isRegExp|throw|value|brushes|brushName|space|alert|vars|http|syntaxhighlighter|expandSource|size|css|case|font|Fa|name|htmlScript|dA|can|handler|gm|td|exports|color|in|href|first|discoveredBrushes|light|collapse|object|cache|getButtonHtml|trigger|pattern|getLineHtml|nbsp|numbers|parseInt|defaults|com|items|www|pad|highlighters|execute|focus|func|all|getDiv|parentNode|navigator|INSIDE_CLASS|regexList|hasFlag|Match|useScriptTags|hasNamedCapture|text|help|init|br|input|gi|Error|values|span|list|250|height|width|screen|top|500|tagName|findElements|getElementsByTagName|aboutDialog|_blank|appendChild|charAt|Array|copyAsGlobal|setFlag|highlighter_|string|attachEvent|nodeName|floor|backref|output|the|TypeError|sticky|Za|iterate|freezeTokens|scope|type|textarea|alexgorbatchev|version|margin|2010|005896|gs|regexLib|body|center|align|noBrush|require|childNodes|DTD|xhtml1|head|org|w3|url|preventDefault|container|tr|getLineNumbersHtml|isNaN|userAgent|tbody|isLineHighlighted|quick|void|innerHTML|create|table|links|auto|smart|tab|stripBrs|tabs|bloggerMode|collapsed|plain|getCodeLinesHtml|caption|getMatchesHtml|findMatches|figureOutLineNumbers|removeNestedMatches|getTitleHtml|brushNotHtmlScript|substring|createElement|Highlighter|load|HtmlScript|Brush|pre|expand|multiline|min|Can|ignoreCase|find|blur|extended|toLowerCase|aliases|addEventListener|innerText|textContent|wasn|select|createTextNode|removeChild|option|same|frame|xmlns|dtd|twice|1999|equiv|meta|htmlscript|transitional|1E3|expected|PUBLIC|DOCTYPE|on|W3C|XHTML|TR|EN|Transitional||configured|srcElement|Object|after|run|dblclick|matchChain|valueOf|constructor|default|switch|click|round|execAt|forHtmlScript|token|gimy|functions|getKeywords|1E6|escape|within|random|sgi|another|finally|supply|MSIE|ie|toUpperCase|catch|returnValue|definition|event|border|imsx|constructing|one|Infinity|from|when|Content|cellpadding|flags|cellspacing|try|xhtml|Type|spaces|2930402|hosted_button_id|lastIndexOf|donate|active|development|keep|to|xclick|_s|Xml|please|like|you|paypal|cgi|cmd|webscr|bin|highlighted|scrollbars|aspScriptTags|phpScriptTags|sort|max|scriptScriptTags|toolbar_item|_|command|command_|number|getElementById|doubleQuotedString|singleLinePerlComments|singleLineCComments|multiLineCComments|singleQuotedString|multiLineDoubleQuotedString|xmlComments|alt|multiLineSingleQuotedString|If|https|1em|000|fff|background|5em|xx|bottom|75em|Gorbatchev|large|serif|CDATA|continue|utf|charset|content|About|family|sans|Helvetica|Arial|Geneva|3em|nogutter|Copyright|syntax|close|write|2004|Alex|open|JavaScript|highlighter|July|02|replaceChild|offset|83'.split('|'),0,{})) 18 | -------------------------------------------------------------------------------- /examples/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 20 | 21 | 22 | 23 | 26 | 27 |

C3JS AngularJS Directives - Examples

28 |
29 | 30 |
31 | 32 | 33 | 34 | 35 | dashboard 36 |

Getting started

37 |
38 | 39 | settings 40 |

Generic configuration

41 |
42 | 43 | assessment 44 |

Bar examples

45 |
46 | 47 | timeline 48 |

Line examples

49 |
50 | 51 | timelapse 52 |

Pie examples

53 |
54 | 55 | donut_small 56 |

Donut examples

57 |
58 | 59 | redo 60 |

Gauge examples

61 |
62 | 63 | reply 64 |

Callback examples

65 |
66 | 67 | motorcycle 68 |

Dynamic examples

69 |
70 |
71 |
72 |
73 | 74 |
75 | 76 |
77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | -------------------------------------------------------------------------------- /license.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) {{{year}}} {{{fullname}}} 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 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "c3-angular", 3 | "version": "1.4.0", 4 | "description": "An angularjs directive to integrate c3.js within your angularjs project.", 5 | "main": "c3-angular.js", 6 | "directories": { 7 | "example": "examples" 8 | }, 9 | "scripts": { 10 | "test": "echo \"Error: no test specified\" && exit 1" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git://github.com/jettro/c3-angular-directive.git" 15 | }, 16 | "keywords": [ 17 | "c3js", 18 | "angularjs", 19 | "graph" 20 | ], 21 | "author": "Jettro Coenradie", 22 | "license": "MIT", 23 | "bugs": { 24 | "url": "https://github.com/jettro/c3-angular-directive/issues" 25 | }, 26 | "homepage": "https://github.com/jettro/c3-angular-directive", 27 | "devDependencies": { 28 | "angular-jsdoc": "^0.3.8", 29 | "canonical-path": "0.0.2", 30 | "grunt": "^0.4.5", 31 | "grunt-contrib-concat": "^0.5.0", 32 | "grunt-contrib-copy": "^0.7.0", 33 | "grunt-contrib-jshint": "^0.10.0", 34 | "grunt-contrib-uglify": "^0.7.0", 35 | "grunt-contrib-watch": "^0.6.1", 36 | "grunt-devserver": "^0.6.0", 37 | "grunt-jsdoc": "^0.6.7", 38 | "jsdoc": "^3.3.2" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/_main.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @ngdoc module 3 | * @name C3jsChartDirective 4 | * @description 5 | * AngularJS Directive for the c3js library. With this directive we make it easier 6 | * to work with the great c3js libary. We provide a number of directives that make 7 | * it possible to declaritively create some charts. 8 | * 9 | * This documentation can be found online at: {@link http://jettro.github.io/c3-angular-directive/api-docs/0.7/C3jsChartDirective.html} 10 | * 11 | * More information about the directive can be found here {@link http://jettro.github.io/c3-angular-directive/} 12 | * 13 | * The documentation is generated using jsdoc, and this plugin: {@link https://github.com/allenhwkim/angular-jsdoc} 14 | */ 15 | angular.module('gridshore.c3js.chart', []); -------------------------------------------------------------------------------- /src/axes-directive.js: -------------------------------------------------------------------------------- 1 | angular.module('gridshore.c3js.chart') 2 | .directive('chartAxes', ChartAxes); 3 | /** 4 | * @ngdoc directive 5 | * @name chartAxes 6 | * @description 7 | * `chart-axes` is used to customize the axes properties. Using this directive you can select the propertie(s) to use for the different categories or for the time field. You can also configure for the different columns to use y or y2. 8 | * 9 | * Restrict To: 10 | * Element 11 | * 12 | * Parent Element: 13 | * c3chart 14 | * 15 | * @param {String} valuesX Specify the key in the data object to use for the x value 16 | * 17 | * {@link http://c3js.org/reference.html#data-x} 18 | * @param {String} valuesXs Specify the different keys for different data columns in format 19 | * columnId:key,columnId:key 20 | * 21 | * {@link http://c3js.org/reference.html#data-xs} 22 | * @param {String} y Set the id(s) of columns to use the first y value (y). Format is comma separated. 23 | * 24 | * {@link http://c3js.org/reference.html#data-axes} 25 | * @param {String} y2 Set the id(s) of columns to use the second y value (y2) Format is comma separated. 26 | * 27 | * {@link http://c3js.org/reference.html#data-axes} 28 | * 29 | * @example 30 | * Usage: 31 | * 32 | * Example: 33 | * {@link http://jettro.github.io/c3-angular-directive/#examples} 34 | */ 35 | function ChartAxes () { 36 | var axesLinker = function (scope, element, attrs, chartCtrl) { 37 | var x = attrs.valuesX; 38 | if (x) { 39 | chartCtrl.addXAxisValues(x); 40 | } 41 | 42 | var xs = attrs.valuesXs; 43 | var xsValues = {}; 44 | if (xs) { 45 | xsItems = xs.split(","); 46 | for (var xsI in xsItems) { 47 | xsItem = xsItems[xsI].split(":"); 48 | xsValues[xsItem[0]] = xsItem[1]; 49 | } 50 | chartCtrl.addXSValues(xsValues); 51 | } 52 | 53 | var y = attrs.y; 54 | var y2 = attrs.y2; 55 | var yAxis = {}; 56 | if (y2) { 57 | var items = y2.split(","); 58 | for (var item in items) { 59 | yAxis[items[item]] = "y2"; 60 | } 61 | if (y) { 62 | var yItems = y.split(","); 63 | for (var yItem in yItems) { 64 | yAxis[yItems[yItem]] = "y"; 65 | } 66 | } 67 | chartCtrl.addYAxis(yAxis); 68 | } 69 | }; 70 | 71 | return { 72 | "require": "^c3chart", 73 | "restrict": "E", 74 | "scope": {}, 75 | "replace": true, 76 | "link": axesLinker 77 | }; 78 | }; 79 | -------------------------------------------------------------------------------- /src/axis-directive.js: -------------------------------------------------------------------------------- 1 | angular.module('gridshore.c3js.chart') 2 | .directive('chartAxis', ChartAxis); 3 | 4 | /** 5 | * @ngdoc directive 6 | * @name chartAxis 7 | * @description 8 | * `chart-axis` is used to customize the axis properties. Can be used to change the orientation of the axis. 9 | * 10 | * Restrict To: 11 | * Element 12 | * 13 | * Parent element: 14 | * c3chart 15 | * 16 | * @param {Boolean} axisRotate Configure to rotate the axis, javascript true means we rotate the axis. 17 | * 18 | * {@link http://c3js.org/reference.html#axis-rotated} 19 | * 20 | * @example 21 | * Usage: 22 | * 23 | * Example: 24 | * {@link http://jettro.github.io/c3-angular-directive/#examples} 25 | */ 26 | 27 | function ChartAxis () { 28 | var axisLinker = function (scope, element, attrs, chartCtrl) { 29 | var rotate = attrs.axisRotate; 30 | if (rotate) { 31 | chartCtrl.rotateAxis(); 32 | } 33 | }; 34 | 35 | return { 36 | "require": "^c3chart", 37 | "restrict": "E", 38 | "scope": {}, 39 | "transclude": true, 40 | "template": "
", 41 | "replace": true, 42 | "link": axisLinker 43 | }; 44 | }; 45 | -------------------------------------------------------------------------------- /src/axis-x-directive.js: -------------------------------------------------------------------------------- 1 | angular.module('gridshore.c3js.chart') 2 | .directive('chartAxisX', ChartAxisX); 3 | 4 | /** 5 | * @ngdoc directive 6 | * @name chartAxisX 7 | * @description 8 | * `chart-axis-x` is used to customize the x axis properties. Using this directive you can padding, size, visibility of the axis. 9 | * 10 | * Restrict To: 11 | * Element 12 | * 13 | * Parent Element: 14 | * chart-axis 15 | * 16 | * @param {String} axis-position Location of the label. Can have following values: 17 | * 18 | * - Horizontal: inner-right (default), inner-center, inner-left, outer-right, outer-center, outer-left 19 | * - Vertical: inner-top (default), inner-middle, inner-bottom, outer-top, outer-middle, outer-bottom 20 | * 21 | * {@link http://c3js.org/reference.html#data-x| c3js doc} 22 | * @param {String} axis-label Set the text for the label of the x axis. 23 | * 24 | * {@link http://c3js.org/reference.html#axis-x-label| c3js doc} 25 | * @param {Number} padding-left Set padding on the left side of the x axis. 26 | * 27 | * {@link http://c3js.org/reference.html#axis-x-padding| c3js doc} 28 | * @param {Number} padding-right Set padding on the right side of the x axis. 29 | * 30 | * {@link http://c3js.org/reference.html#axis-x-padding| c3js doc} 31 | * @param {Number} axis-height Set the overall height of the x axis, unit in pixels. 32 | * 33 | * {@link http://c3js.org/reference.html#axis-x-height| c3js doc} 34 | * @param {Boolean} show Show or hide the x axis. 35 | * 36 | * {@link http://c3js.org/reference.html#axis-x-show| c3js doc} 37 | * @param {String} axis-localtime Default is to use localtime, but can be set to false to use UTC. 38 | * 39 | * {@link http://c3js.org/reference.html#axis-x-localtime| c3js doc} 40 | * @param {String} axis-min Min value of the x axis. 41 | * 42 | * {@link http://c3js.org/reference.html#axis-x-min| c3js doc} 43 | * 44 | * @param {String} axis-max Max value of the x axis. 45 | * 46 | * {@link http://c3js.org/reference.html#axis-x-max | c3js doc} 47 | * 48 | * @param {String} axis-type The type of the x-axis can be one of the following three: timeseries, category or indexed (default). 49 | * 50 | * {@link http://c3js.org/reference.html#axis-x-type | c3js doc} 51 | * 52 | * @param {String} axis-x-format Specify format of x axis data, usefull when using timeseries. 53 | * 54 | * {@link http://c3js.org/reference.html#data-xFormat | c3js doc} 55 | * 56 | * @example 57 | * Usage: 58 | * 59 | * Example: 60 | * {@link http://jettro.github.io/c3-angular-directive/#examples} 61 | * 62 | * 63 | * 66 | * 67 | */ 68 | 69 | function ChartAxisX () { 70 | var axisLinker = function (scope, element, attrs, chartCtrl) { 71 | var position = attrs.axisPosition; 72 | var label = attrs.axisLabel; 73 | 74 | var axis = {"label": {"text": label, "position": position}}; 75 | 76 | var paddingLeft = attrs.paddingLeft; 77 | var paddingRight = attrs.paddingRight; 78 | if (paddingLeft || paddingRight) { 79 | paddingLeft = (paddingLeft) ? paddingLeft : 0; 80 | paddingRight = (paddingRight) ? paddingRight : 0; 81 | axis.padding = {"left": parseInt(paddingLeft), "right": parseInt(paddingRight)}; 82 | } 83 | var height=attrs.axisHeight; 84 | if (height) { 85 | axis.height = parseInt(height); 86 | } 87 | 88 | if (attrs.show === 'false') { 89 | axis.show = false; 90 | } 91 | if (attrs.axisLocaltime === 'true') { 92 | axis.localtime=true; 93 | } 94 | var max=attrs.axisMax; 95 | if (max) { 96 | axis.max=max; 97 | } 98 | var min=attrs.axisMin; 99 | if (min) { 100 | axis.min=min; 101 | } 102 | var type=attrs.axisType; 103 | if (type) { 104 | axis.type=type; 105 | } 106 | chartCtrl.addAxisProperties('x', axis); 107 | 108 | var xFormat = attrs.axisXFormat; 109 | if (xFormat) { 110 | chartCtrl.setXFormat(xFormat); 111 | } 112 | }; 113 | 114 | return { 115 | "require": "^c3chart", 116 | "restrict": "E", 117 | "scope": {}, 118 | "transclude": true, 119 | "template": "
", 120 | "replace": true, 121 | "link": axisLinker 122 | }; 123 | } -------------------------------------------------------------------------------- /src/axis-x-tick-directive.js: -------------------------------------------------------------------------------- 1 | angular.module('gridshore.c3js.chart') 2 | .directive('chartAxisXTick', ChartAxisXTick); 3 | 4 | /** 5 | * @ngdoc directive 6 | * @name chartAxisXTick 7 | * @description 8 | * `chart-axis-x-tick` is used to customize the x axis tick properties. You can change the amount of ticks, the format of the tick, culling, rotating. 9 | * 10 | * Restrict To: 11 | * Element 12 | * 13 | * Parent Element: 14 | * chart-axis-x 15 | * 16 | * @param {Number} tick-count Specify the number of ticks on the x axis. 17 | * 18 | * {@link http://c3js.org/reference.html#axis-x-tick-count| c3js doc} 19 | * @param {Boolean} tick-culling Culling means not all ticks will be shown, for category data this is by default false, for other data true. 20 | * 21 | * {@link http://c3js.org/reference.html#axis-x-tick-culling| c3js doc} 22 | * @param {Number} tick-culling-max Set the maximum number of ticks, if specified culling is by default true. 23 | * 24 | * {@link http://c3js.org/reference.html#axis-x-tick-culling-max| c3js doc} 25 | * @param {Boolean} tick-multiline Break the line if the tick length doesn't fit in space, default true. 26 | * 27 | * {@link http://c3js.org/reference.html#axis-x-tick-multiline| c3js doc} 28 | * @param {Boolean} tick-centered Centers the tick on the x axis 29 | * 30 | * {@link http://c3js.org/reference.html#axis-x-tick-centered| c3js doc} 31 | * @param {Number} tick-rotate Number of degrees to rotate the tick, can also be a negative number. 32 | * 33 | * {@link http://c3js.org/reference.html#axis-x-tick-rotate| c3js doc} 34 | * @param {Boolean} tick-fit Default is to make the tick fit the chart, if false it will be at the exact position of the x value. 35 | * 36 | * {@link http://c3js.org/reference.html#axis-x-tick-fit| c3js doc} 37 | * 38 | * @param {Boolean} tick-outer Default is not to show the outer tick, setting this to true will show the outer tick. 39 | * 40 | * {@link http://c3js.org/reference.html#axis-x-tick-outer| c3js doc} 41 | * 42 | * @param {Array} tick-values An array containing the exact values to present a tick for. 43 | * 44 | * {@link http://c3js.org/reference.html#axis-x-tick-values| c3js doc} 45 | * 46 | * @param {String} tick-format Provide a d3 based format for the tick value. 47 | * format: '$,' 48 | * 49 | * @param {String} tick-format-time Provide a d3 based format for the tick value in case of timeseries data. 50 | * format: '%Y-%m-%d %H:%M:%S' 51 | * 52 | * {@link http://c3js.org/reference.html#data-xFormat| c3js doc} 53 | * 54 | * @param {Function} tick-format-function Provide a function to format the tick value. 55 | * format: function (d) { return '$' + d; } 56 | * 57 | * {@link http://c3js.org/reference.html#axis-x-tick-format| c3js doc} 58 | * 59 | * @example 60 | * Usage: 61 | * 62 | * 63 | * Example: 64 | * {@link http://jettro.github.io/c3-angular-directive/#examples} 65 | * 66 | * 67 | * 69 | * 70 | * 71 | * 72 | */ 73 | function ChartAxisXTick() { 74 | var tickLinker = function (scope, element, attrs, chartCtrl) { 75 | var tick = {}; 76 | 77 | var count = attrs.tickCount; 78 | if (count) { 79 | tick.count = count; 80 | } 81 | 82 | var culling = attrs.tickCulling; 83 | if (culling) { 84 | culling = angular.lowercase(culling); 85 | if (culling === 'true') { 86 | tick.culling = true; 87 | } 88 | else if (culling === 'false') { 89 | tick.culling = false; 90 | } 91 | } 92 | 93 | var cullingMax = attrs.tickCullingMax; 94 | if (cullingMax) { 95 | tick.culling = { max: parseInt(cullingMax) } 96 | } 97 | 98 | var multiline = attrs.tickMultiline; 99 | if (multiline) { 100 | multiline = angular.lowercase(multiline); 101 | if (multiline === 'true') { 102 | tick.multiline = true; 103 | } 104 | else if (multiline === 'false') { 105 | tick.multiline = false; 106 | } 107 | } 108 | 109 | var centered = attrs.tickCentered; 110 | if (centered) { 111 | centered = angular.lowercase(centered); 112 | if (centered === 'true') { 113 | tick.centered = true; 114 | } 115 | else if (centered === 'false') { 116 | tick.centered = false; 117 | } 118 | } 119 | 120 | var rotate = attrs.tickRotate; 121 | if (rotate) { 122 | tick.rotate = rotate; 123 | } 124 | 125 | var fit = attrs.tickFit; 126 | if (fit) { 127 | fit = angular.lowercase(fit); 128 | if (fit === 'true') { 129 | tick.fit = true; 130 | } 131 | else if (fit === 'false') { 132 | tick.fit = false; 133 | } 134 | } 135 | 136 | var tickValues = attrs.tickValues; 137 | if (tickValues) { 138 | if (tickValues) { 139 | if (tickValues.indexOf(',') > -1) { 140 | tick.values = tickValues.split(','); 141 | } else { 142 | tick.values = tickValues; 143 | } 144 | } 145 | } 146 | 147 | var outer = attrs.tickOuter; 148 | if (outer) { 149 | outer = angular.lowercase(outer); 150 | if (outer === 'true') { 151 | tick.outer = true; 152 | } 153 | else if (outer === 'false') { 154 | tick.outer = false; 155 | } 156 | } 157 | 158 | var format = attrs.tickFormat; 159 | if (format) { 160 | tick.format = d3.format(format); 161 | } 162 | 163 | var formatTime = attrs.tickFormatTime; 164 | if (formatTime) { 165 | tick.format = d3.time.format(formatTime); 166 | } 167 | 168 | chartCtrl.addXTick(tick); 169 | 170 | if (attrs.tickFormatFunction) { 171 | chartCtrl.addXTickFormatFunction(scope.tickFormatFunction()); 172 | } 173 | 174 | }; 175 | 176 | return { 177 | "require": "^c3chart", 178 | "restrict": "E", 179 | "scope": { 180 | "tickFormatFunction": "&" 181 | }, 182 | "replace": true, 183 | "link": tickLinker 184 | }; 185 | } 186 | -------------------------------------------------------------------------------- /src/axis-y-directive.js: -------------------------------------------------------------------------------- 1 | angular.module('gridshore.c3js.chart') 2 | .directive('chartAxisY', ChartAxisY); 3 | 4 | /** 5 | * @ngdoc directive 6 | * @name chartAxisY 7 | * @description 8 | * `chart-axis-y` is used to customize the y and y2 axis properties. Using this directive you can padding, size, visibility of the axis. 9 | * 10 | * Restrict To: 11 | * Element 12 | * 13 | * Parent Element: 14 | * chart-axis 15 | * 16 | * @param {String} axis-id Default value is 'y' but you can also provide 'y2' 17 | * 18 | * @param {String} axis-position Location of the label. Can have following values: 19 | * 20 | * - Horizontal: inner-right (default), inner-center, inner-left, outer-right, outer-center, outer-left 21 | * - Vertical: inner-top (default), inner-middle, inner-bottom, outer-top, outer-middle, outer-bottom 22 | * 23 | * {@link http://c3js.org/reference.html#data-y| c3js doc} 24 | * @param {String} axis-label Set the text for the label of the y or y2 axis. 25 | * 26 | * {@link http://c3js.org/reference.html#axis-y-label| c3js doc} 27 | * @param {Number} padding-top Set padding on the top side of the y or y2 axis. 28 | * 29 | * {@link http://c3js.org/reference.html#axis-y-padding| c3js doc} 30 | * @param {Number} padding-bottom Set padding on the bottom side of the y or y2 axis. 31 | * 32 | * {@link http://c3js.org/reference.html#axis-y-padding| c3js doc} 33 | * @param {Boolean} show Configure if the y or y2 axis should be shown. 34 | * 35 | * {@link http://c3js.org/reference.html#axis-y-show| c3js doc} 36 | * @param {Number} axis-min Min value of the y our y2 axis in pixels. 37 | * 38 | * {@link http://c3js.org/reference.html#axis-y-min| c3js doc} 39 | * 40 | * @param {Number} axis-max Max value of the y or y2 axis in pixels. 41 | * 42 | * {@link http://c3js.org/reference.html#axis-y-max| c3js doc} 43 | * 44 | * @param {Boolean} axis-inner Position the y or y2 axis within the chart. 45 | * 46 | * {@link http://c3js.org/reference.html#axis-y-inner| c3js doc} 47 | * 48 | * @param {Boolean} axis-inverted Invert the y or y2 axis, the default is true, from top to bottom. 49 | * 50 | * {@link http://c3js.org/reference.html#axis-y-inverted| c3js doc} 51 | * 52 | * @param {Number} axis-center Set the center of the y or y2 axis, is a numeric value. 53 | * 54 | * {@link http://c3js.org/reference.html#axis-y-center| c3js doc} 55 | * 56 | * @example 57 | * Usage: 58 | * 59 | * Example: 60 | * {@link http://jettro.github.io/c3-angular-directive/#examples} 61 | * 62 | * 63 | * 69 | * 76 | * 77 | */ 78 | 79 | function ChartAxisY() { 80 | var axisLinker = function (scope, element, attrs, chartCtrl) { 81 | var id = attrs.axisId; 82 | var position = attrs.axisPosition; 83 | var label = attrs.axisLabel; 84 | 85 | id = ( id == undefined ? 'y' : id ); 86 | 87 | var axis = {"label": {"text": label, "position": position}}; 88 | if (attrs.show === 'false') { 89 | axis.show = false; 90 | } else if (id === 'y2') { 91 | axis.show = true; 92 | } 93 | var paddingTop = attrs.paddingTop; 94 | var paddingBottom = attrs.paddingBottom; 95 | if (paddingTop || paddingBottom) { 96 | paddingTop = (paddingTop) ? paddingTop : 0; 97 | paddingBottom = (paddingBottom) ? paddingBottom : 0; 98 | axis.padding = {"top": parseInt(paddingTop), "bottom": parseInt(paddingBottom)}; 99 | } 100 | var axisMax = attrs.axisMax; 101 | var axisMin = attrs.axisMin; 102 | if (axisMax) { 103 | axis.max = parseInt(axisMax); 104 | } 105 | if (axisMin) { 106 | axis.min = parseInt(axisMin); 107 | } 108 | if (attrs.axisInverted === 'true') { 109 | axis.inverted=true; 110 | } 111 | if (attrs.axisInner === 'true') { 112 | axis.inner=true; 113 | } 114 | var axisCenter = attrs.axisCenter; 115 | if (axisCenter) { 116 | axis.center = parseInt(axisCenter); 117 | } 118 | 119 | chartCtrl.addAxisProperties(id, axis); 120 | }; 121 | 122 | return { 123 | "require": "^c3chart", 124 | "restrict": "E", 125 | "scope": {}, 126 | "replace": true, 127 | "link": axisLinker 128 | }; 129 | } -------------------------------------------------------------------------------- /src/axis-y-tick-directive.js: -------------------------------------------------------------------------------- 1 | angular.module('gridshore.c3js.chart') 2 | .directive('chartAxisYTick', ChartAxisYTick); 3 | 4 | /** 5 | * @ngdoc directive 6 | * @name chartAxisYTick 7 | * @description 8 | * `chart-axis-y-tick` is used to customize the y or y2 axis tick properties. You can change the amount of ticks, the format of the tick, culling, rotating. 9 | * 10 | * Restrict To: 11 | * Element 12 | * 13 | * Parent Element: 14 | * chart-axis-y 15 | * 16 | * @param {Number} tick-count Specify the number of ticks on the x axis. 17 | * 18 | * {@link http://c3js.org/reference.html#axis-y-tick-count| c3js doc} 19 | * 20 | * @param {Boolean} tick-outer Default is not to show the outer tick, setting this to true will show the outer tick. 21 | * 22 | * {@link http://c3js.org/reference.html#axis-y-tick-outer| c3js doc} 23 | * 24 | * @param {Array} tick-values An array containing the exact values to present a tick for. 25 | * 26 | * {@link http://c3js.org/reference.html#axis-y-tick-values| c3js doc} 27 | * 28 | * @param {Function} tick-format Provide a d3 based format for the tick value. 29 | * format: '$,' 30 | * 31 | * {@link http://c3js.org/reference.html#axis-x-tick-format| c3js doc} 32 | * 33 | * @param {Function} tick-format-function Provide a function to format the tick value. 34 | * 35 | * {@link http://c3js.org/reference.html#axis-y-tick-format| c3js doc} 36 | * 37 | * @example 38 | * Usage: 39 | * 40 | * 41 | * Example: 42 | * {@link http://jettro.github.io/c3-angular-directive/#examples} 43 | * 44 | */ 45 | function ChartAxisYTick() { 46 | var tickLinker = function (scope, element, attrs, chartCtrl) { 47 | var tick = {}; 48 | 49 | var count = attrs.tickCount; 50 | if (count) { 51 | tick.count = count; 52 | } 53 | 54 | var outer = attrs.tickOuter; 55 | if (outer) { 56 | outer = angular.lowercase(outer); 57 | if (outer === 'true') { 58 | tick.outer = true; 59 | } 60 | else if (outer === 'false') { 61 | tick.outer = false; 62 | } 63 | } 64 | 65 | var tickValues = attrs.tickValues; 66 | if (tickValues) { 67 | if (tickValues.indexOf(',') > -1) { 68 | tick.values = tickValues.split(','); 69 | } else { 70 | tick.values = tickValues; 71 | } 72 | } 73 | 74 | var format = attrs.tickFormat; 75 | if (format) { 76 | tick.format = d3.format(format); 77 | } 78 | 79 | chartCtrl.addYTick(tick); 80 | 81 | if (attrs.tickFormatFunction) { 82 | chartCtrl.addYTickFormatFunction(scope.tickFormatFunction()); 83 | } 84 | }; 85 | 86 | return { 87 | "require": "^c3chart", 88 | "restrict": "E", 89 | "scope": { 90 | "tickFormatFunction": "&" 91 | }, 92 | "replace": true, 93 | "link": tickLinker 94 | }; 95 | } -------------------------------------------------------------------------------- /src/bar-directive.js: -------------------------------------------------------------------------------- 1 | angular.module('gridshore.c3js.chart') 2 | .directive('chartBar', ChartBar); 3 | /** 4 | * @ngdoc directive 5 | * @name chartBar 6 | * @description 7 | * `chart-bar` is used to customize the axes properties. Using this directive you can select the propertie(s) to use for the different categories or for the time field. You can also configure for the different columns to use y or y2. 8 | * 9 | * Restrict To: 10 | * Element 11 | * 12 | * Parent Element: 13 | * c3chart 14 | * 15 | * @param {Number} width Fixed with of the bars in pixels 16 | * 17 | * {@link http://c3js.org/reference.html#bar-width| c3js doc} 18 | * 19 | * @param {Number} ratio Change the width of the bar by ratio 20 | * 21 | * {@link http://c3js.org/reference.html#bar-width-ratio| c3js doc} 22 | * @param {Boolean} zerobased Set if we start from zero, default is true. 23 | * 24 | * {@link http://c3js.org/reference.html#bar-zerobased| c3js doc} 25 | * 26 | * @example 27 | * Usage: 28 | * 29 | * Example: 30 | * {@link http://jettro.github.io/c3-angular-directive/#examples} 31 | * 32 | */ 33 | 34 | function ChartBar() { 35 | var barLinker = function (scope, element, attrs, chartCtrl) { 36 | var bar = {}; 37 | if (attrs.width) { 38 | bar.width = parseInt(attrs.width); 39 | } 40 | if (attrs.ratio) { 41 | if (!bar.width) { 42 | bar.width = {}; 43 | } 44 | bar.width.ratio = parseFloat(attrs.ratio); 45 | } 46 | if (attrs.zerobased) { 47 | bar.zerobased = (attrs.zerobased === 'true'); 48 | } 49 | chartCtrl.addBar(bar); 50 | }; 51 | 52 | return { 53 | require: '^c3chart', 54 | restrict: 'E', 55 | scope: {}, 56 | replace: true, 57 | link: barLinker 58 | }; 59 | } -------------------------------------------------------------------------------- /src/c3chart-directive.js: -------------------------------------------------------------------------------- 1 | angular.module('gridshore.c3js.chart') 2 | .directive('c3chart', ['$timeout', function(timeout) { 3 | return C3Chart(timeout); 4 | }]); 5 | 6 | /** 7 | * @ngdoc directive 8 | * @name C3Chart 9 | * @description 10 | * `c3chart` is the main directive to create the chart. Use it to set the padding properties and include the other directives. You can also register the callback in this directive that receives the initialised chart object. 11 | * 12 | * When using multiple charts in the same page you need to provide unique bind-id parameters. 13 | * 14 | * Restrict To: 15 | * Element 16 | * 17 | * Parent Element: 18 | * - 19 | * 20 | * @param {Number} padding-top Set the top padding of the chart. 21 | * 22 | * {@link http://c3js.org/reference.html#padding-top| c3js doc} 23 | * 24 | * @param {Number} padding-bottom Set the bottom padding of the chart. 25 | * 26 | * {@link http://c3js.org/reference.html#padding-bottom| c3js doc} 27 | * 28 | * @param {Number} padding-right Set the right padding of the chart. 29 | * 30 | * {@link http://c3js.org/reference.html#padding-right| c3js doc} 31 | * 32 | * @param {Number} padding-left Set the left padding of the chart. 33 | * 34 | * {@link http://c3js.org/reference.html#padding-left| c3js doc} 35 | * 36 | * @param {String} empty-label Set text displayed when empty data. 37 | * 38 | * {@link http://c3js.org/reference.html#data-empty-label-text| c3js doc} 39 | * 40 | * @param {String} bind-id Id of the chart, needs to be unique when using multiple charts on one page. 41 | * 42 | * {@link http://c3js.org/reference.html#bindto| c3js doc} 43 | * 44 | * @param {String} sort-data You can enter three different versions: asc, desc, null. Using this sorting you can change the order of stacking and the order of the pieces of a pie or donut. 45 | * 46 | * {@link http://c3js.org/reference.html#data-order| c3js doc} 47 | * 48 | * @param {Boolean} show-labels Configure to show the labels 'true' or not, default is false. 49 | * 50 | * {@link http://c3js.org/reference.html#data-labels| c3js doc} 51 | * 52 | * @param {Function} labels-format-function Provide a function to format the labels. 53 | * 54 | * {@link http://c3js.org/reference.html#data-labels-format| c3js doc} 55 | * 56 | * @param {Boolean} show-subchart Configure to show the subchart or not (default). 57 | * 58 | * {@link http://c3js.org/reference.html#subchart-show| c3js doc} 59 | * 60 | * @param {Function} subchart-on-brush-function Use this if you want to do something after brush on subchart 61 | * 62 | * {@link http://c3js.org/reference.html#subchart-onbrush| c3js doc} 63 | * 64 | * @param {Boolean} enable-zoom Configure to enable zoom in the chart or not (defaut). 65 | * 66 | * {@link http://c3js.org/reference.html#zoom-enabled| c3js doc} 67 | * 68 | * @param {Boolean} rescale-zoom Use it to update the y domain according to the zoomed region. 69 | * 70 | * {@link http://c3js.org/reference.html#zoom-rescale| c3js doc} 71 | * 72 | * @param {Function} on-zoom-end-function Use this if you want to do something after zooming 73 | * 74 | * {@link http://c3js.org/reference.html#zoom-onzoomend| c3js doc} 75 | * 76 | * @param {Array} chart-data Provide a reference to a collection that can contain dynamic data. When providing this attrbiute you also need to provide the chart-columns attribute. 77 | * 78 | * Array consisting of objects with values for the different columns: [{"data1":10,"data2":20},{"data1":50,"data2":60}] 79 | * 80 | * @param {Array} chart-columns Provide a reference to a collection that contains the columns. When providing this attrbiute you also need to provide the chart-data attribute. 81 | * 82 | * Array consisting of objects with some properties for the different columns: [{"id": "data1", "type": "line"}, {"id": "data2", "type": "bar"}] 83 | * 84 | * @param {Object} chart-x Provide information about the x column. Used when adding dynamic data to specify the field that contains the x data value. 85 | * 86 | * Object containing reference to the id of the x data field: {"id": "x", "name": "My Data points"} 87 | * 88 | * @param {Function} callback-function Use this if you want to interact with the chart object using the api 89 | * 90 | * {@link http://c3js.org/reference.html#api-focus| c3js doc} 91 | * 92 | * @param {Number} transition-duration Duration of transition (in milliseconds) for chart animation. If you specify 0, transitions will be disabled which is good for large datasets. 93 | * 94 | * {@link http://c3js.org/reference.html#transition-duration| c3js doc} 95 | * 96 | * @param {Object} initial-config Provide the initial config object to start the graph with. 97 | * 98 | * @example 99 | * Usage: 100 | * 101 | * 102 | * 103 | * 104 | * Example: 105 | * 106 | * {@link http://jettro.github.io/c3-angular-directive/#examples} 107 | * 108 | * Shows how to use dynamic data points. 109 | * 110 | * 111 | * 112 | * $scope.piePoints = [{"data1": 70, "data2": 30, "data3": "100"}]; 113 | * $scope.pieColumns = [{"id": "data1", "type": "pie"}, {"id": "data2", "type": "pie"}, { 114 | * "id": "data3", 115 | * "type": "pie" 116 | * 117 | * Show how to register a callback function and use it. The screen contains a button to toggle the legend visibility. 118 | * 119 | * 121 | * 122 | * $scope.handleCallback = function (chartObj) { 123 | * $scope.theChart = chartObj; 124 | * }; 125 | * 126 | * $scope.legendIsShown = true; 127 | * $scope.toggleLegend = function() { 128 | * if ($scope.legendIsShown) { 129 | * $scope.theChart.legend.hide(); 130 | * } else { 131 | * $scope.theChart.legend.show(); 132 | * } 133 | * $scope.legendIsShown= !$scope.legendIsShown; 134 | * $scope.theChart.flush(); 135 | * }; 136 | */ 137 | function C3Chart ($timeout) { 138 | var chartLinker = function (scope, element, attrs, chartCtrl) { 139 | var paddingTop = attrs.paddingTop; 140 | var paddingRight = attrs.paddingRight; 141 | var paddingBottom = attrs.paddingBottom; 142 | var paddingLeft = attrs.paddingLeft; 143 | var sortData = attrs.sortData; 144 | var transitionDuration = attrs.transitionDuration; 145 | var initialConfig = attrs.initialConfig; 146 | 147 | if (attrs.interactionEnabled && attrs.interactionEnabled === 'false') { 148 | chartCtrl.addInteractionEnabled(false); 149 | } 150 | 151 | if (paddingTop) { 152 | chartCtrl.addPadding('top', paddingTop); 153 | } 154 | if (paddingRight) { 155 | chartCtrl.addPadding('right', paddingRight); 156 | } 157 | if (paddingBottom) { 158 | chartCtrl.addPadding('bottom', paddingBottom); 159 | } 160 | if (paddingLeft) { 161 | chartCtrl.addPadding('left', paddingLeft); 162 | } 163 | if (sortData) { 164 | chartCtrl.addSorting(sortData); 165 | } 166 | if (attrs.labelsFormatFunction) { 167 | chartCtrl.addDataLabelsFormatFunction(scope.labelsFormatFunction()); 168 | } 169 | if (attrs.onZoomEndFunction) { 170 | chartCtrl.addOnZoomEndFunction(scope.onZoomEndFunction()); 171 | } 172 | if (attrs.subchartOnBrushFunction){ 173 | chartCtrl.addSubchartOnBrushFunction(scope.subchartOnBrushFunction()); 174 | } 175 | if (attrs.callbackFunction) { 176 | chartCtrl.addChartCallbackFunction(scope.callbackFunction()); 177 | } 178 | if (transitionDuration) { 179 | chartCtrl.addTransitionDuration(transitionDuration); 180 | } 181 | if (initialConfig) { 182 | chartCtrl.addInitialConfig(initialConfig); 183 | } 184 | // Trick to wait for all rendering of the DOM to be finished. 185 | $timeout(function () { 186 | chartCtrl.showGraph(); 187 | }); 188 | }; 189 | 190 | return { 191 | "restrict": "E", 192 | "controller": "ChartController", 193 | "scope": { 194 | "bindto": "@bindtoId", 195 | "showLabels": "@showLabels", 196 | "labelsFormatFunction": "&", 197 | "onZoomEndFunction": "&", 198 | "showSubchart": "@showSubchart", 199 | "subchartOnBrushFunction": "&", 200 | "enableZoom": "@enableZoom", 201 | "rescaleZoom": "@rescaleZoom", 202 | "chartData": "=chartData", 203 | "chartColumns": "=chartColumns", 204 | "chartX": "=chartX", 205 | "callbackFunction": "&", 206 | "emptyLabel": "@emptyLabel" 207 | }, 208 | "template": "
", 209 | "replace": true, 210 | "transclude": true, 211 | "link": chartLinker 212 | }; 213 | } 214 | -------------------------------------------------------------------------------- /src/colors-directive.js: -------------------------------------------------------------------------------- 1 | angular.module('gridshore.c3js.chart') 2 | .directive('chartColors', ChartColors); 3 | 4 | /** 5 | * @ngdoc directive 6 | * @name chartColors 7 | * @description 8 | * `chart-colors` is used to specify the colors to use in the chart. You can provide the colors or a function to determine the colors. 9 | * 10 | * Restrict To: 11 | * Element 12 | * 13 | * Parent Element: 14 | * c3chart 15 | * 16 | * @param {String} color-pattern A string containing comma separated hex colors 17 | * @param {String} thresholds A string containing comma separated numeric values 18 | * 19 | * {@link http://c3js.org/reference.html#color-pattern| c3js docs} 20 | * @param {Function} color-function Provide a function that receives the value to determine a color for that value. 21 | * 22 | * {@link http://c3js.org/reference.html#data-color| c3js docs} 23 | * 24 | * @example 25 | * Usage: 26 | * 27 | * 28 | * Example: 29 | * {@link http://jettro.github.io/c3-angular-directive/#examples} 30 | * 31 | * 32 | */ 33 | function ChartColors () { 34 | var colorsLinker = function (scope, element, attrs, chartCtrl) { 35 | var pattern = attrs.colorPattern; 36 | if (pattern) { 37 | chartCtrl.addColorPatterns(pattern.split(",")); 38 | } 39 | 40 | var thresholds = attrs.thresholds; 41 | if(thresholds){ 42 | chartCtrl.addColorThresholds(thresholds.split(",")); 43 | } 44 | 45 | if (attrs.colorFunction) { 46 | chartCtrl.addColorFunction(scope.colorFunction()); 47 | } 48 | }; 49 | 50 | return { 51 | "require": "^c3chart", 52 | "restrict": "E", 53 | "scope": { 54 | "colorFunction": "&" 55 | }, 56 | "replace": true, 57 | "link": colorsLinker 58 | }; 59 | } 60 | -------------------------------------------------------------------------------- /src/column-directive.js: -------------------------------------------------------------------------------- 1 | angular.module('gridshore.c3js.chart') 2 | .directive('chartColumn', ChartColumn); 3 | 4 | /** 5 | * @ngdoc directive 6 | * @name chartColumn 7 | * @description 8 | * `chart-column` Used to provide data values for the chart as well as the name and some other config options. 9 | * 10 | * Restrict To: 11 | * Element 12 | * 13 | * Parent Element: 14 | * c3chart 15 | * 16 | * @param {String} column-id The id used to uniquely identify the column 17 | * 18 | * @param {String} column-values The values for this column to plot. 19 | * 20 | * @param {String} column-type The type of the column to show: line, spline, bar, step, area, area-spline, area-step, scatter, pie, donut, gauge 21 | * 22 | * {@link http://c3js.org/reference.html#data-type| c3js docs} 23 | * 24 | * @param {String} column-name The name of the column as used to print in the label. 25 | * 26 | * {@link http://c3js.org/reference.html#data-names| c3js docs} 27 | * 28 | * @param {String} column-color The color to use for this column. 29 | * 30 | * {@link http://c3js.org/reference.html#data-names| c3js docs} 31 | * 32 | * @example 33 | * Usage: 34 | * 35 | * 36 | * Example: 37 | * {@link http://jettro.github.io/c3-angular-directive/#examples} 38 | * 39 | * 44 | * 45 | */ 46 | function ChartColumn () { 47 | var columnLinker = function (scope, element, attrs, chartCtrl) { 48 | var column = attrs.columnValues.split(","); 49 | column.unshift(attrs.columnId); 50 | chartCtrl.addColumn(column, attrs.columnType, attrs.columnName, attrs.columnColor); 51 | }; 52 | 53 | return { 54 | "require": "^c3chart", 55 | "restrict": "E", 56 | "scope": {}, 57 | "replace": true, 58 | "link": columnLinker 59 | }; 60 | } 61 | -------------------------------------------------------------------------------- /src/donut-directive.js: -------------------------------------------------------------------------------- 1 | angular.module('gridshore.c3js.chart') 2 | .directive('chartDonut', ChartDonut); 3 | /** 4 | * @ngdoc directive 5 | * @name chartDonut 6 | * @description 7 | * `chart-donut` SPecific configuration options for creating a donut chart. 8 | * 9 | * Restrict To: 10 | * Element 11 | * 12 | * Parent Element: 13 | * c3chart 14 | * 15 | * @param {Boolean} show-label Show labels in the Donut. 16 | * 17 | * {@link http://c3js.org/reference.html#donut-label-show| c3js docs} 18 | * 19 | * @param {Number} threshold-label Set the threshold to show or hide labels. 20 | * 21 | * {@link http://c3js.org/reference.html#donut-label-threshold| c3js docs} 22 | * 23 | * @param {Boolean} expand Enable or disable whether to expand a pie part. True is the default. 24 | * 25 | * {@link http://c3js.org/reference.html#donut-expand| c3js docs} 26 | * 27 | * @param {Number} width The width of the donut. 28 | * 29 | * {@link http://c3js.org/reference.html#donut-width| c3js docs} 30 | * 31 | * @param {String} title The title for the donut chart. 32 | * 33 | * {@link http://c3js.org/reference.html#donut-title| c3js docs} 34 | * 35 | * @param {Function} label-format-function Function to format the labels. 36 | * 37 | * {@link http://c3js.org/reference.html#donut-label-format| c3js docs} 38 | * 39 | * @example 40 | * Usage: 41 | * 42 | * 43 | * Example: 44 | * {@link http://jettro.github.io/c3-angular-directive/#examples} 45 | * 46 | * 47 | * 50 | * 53 | * 56 | * 57 | * 58 | */ 59 | function ChartDonut() { 60 | var donutLinker = function (scope, element, attrs, chartCtrl) { 61 | var donut = {}; 62 | if (attrs.showLabel) { 63 | donut.label = {"show": (attrs.showLabel === 'true')}; 64 | } 65 | if (attrs.thresholdLabel) { 66 | if (!donut.label) { 67 | donut.label = {}; 68 | } 69 | donut.label.threshold = parseFloat(attrs.thresholdLabel); 70 | } 71 | if (attrs.expand) { 72 | donut.expand = (attrs.expand === 'true'); 73 | } 74 | if (attrs.width) { 75 | donut.width = parseInt(attrs.width); 76 | } 77 | if (attrs.title) { 78 | donut.title = attrs.title; 79 | } 80 | chartCtrl.addDonut(donut); 81 | if (attrs.labelFormatFunction) { 82 | chartCtrl.addDonutLabelFormatFunction(scope.labelFormatFunction()); 83 | } 84 | }; 85 | 86 | return { 87 | require: '^c3chart', 88 | restrict: 'E', 89 | scope: { 90 | "labelFormatFunction": "&" 91 | }, 92 | replace: true, 93 | link: donutLinker 94 | }; 95 | } 96 | -------------------------------------------------------------------------------- /src/events-directive.js: -------------------------------------------------------------------------------- 1 | angular.module('gridshore.c3js.chart') 2 | .directive('chartEvents', ChartEvents); 3 | 4 | /** 5 | * @ngdoc directive 6 | * @name chartEvents 7 | * @description 8 | * `chart-events` Used to provide callback functions to respond to events of the charts. 9 | * 10 | * Restrict To: 11 | * Element 12 | * 13 | * Parent Element: 14 | * c3chart 15 | * 16 | * @param {Function} on-init The on init callback function. 17 | * 18 | * {@link http://c3js.org/reference.html#oninit| c3js docs} 19 | * 20 | * @param {Function} on-rendered Provide the callback to respond to on-rendered. Basically, this callback will be called in each time when the chart is redrawed. 21 | * 22 | * {@link http://c3js.org/reference.html#onrendered| c3js docs} 23 | * 24 | * @param {Function} on-mouseover Provide callback to be called when you hoover the chart. 25 | * 26 | * {@link http://c3js.org/reference.html#onmouseover| c3js docs} 27 | * 28 | * @param {Function} on-mouseout Provide callback to be called when you hoover out of the chart. 29 | * 30 | * {@link http://c3js.org/reference.html#onmouseout| c3js docs} 31 | * 32 | * @param {Function} on-resize Provide callback to be called when the chart is resizing. 33 | * 34 | * {@link http://c3js.org/reference.html#onresize| c3js docs} 35 | * 36 | * @param {Function} on-resized Provide callback to be called when the chart is resized. 37 | * 38 | * {@link http://c3js.org/reference.html#onresized| c3js docs} 39 | * 40 | * @param {Function} on-click-data Provide callback to be called one of the data points, lines, bars, etc. is clicked. 41 | * 42 | * {@link http://c3js.org/reference.html#onclickdata| c3js docs} 43 | * 44 | * @param {Function} on-mouseover-data Provide callback to be called one of the data points, lines, bars, etc. is hoovered. 45 | * 46 | * {@link http://c3js.org/reference.html#onclickdata| c3js docs} 47 | * 48 | * @param {Function} on-mouseout-data Provide callback to be called one of the data points, lines, bars, etc. is hoovered out. 49 | * 50 | * {@link http://c3js.org/reference.html#onclickdata| c3js docs} 51 | * 52 | * @example 53 | * Usage: 54 | * 55 | * 56 | * Example: 57 | * {@link http://jettro.github.io/c3-angular-directive/#examples} 58 | * 59 | * 60 | * 63 | * 66 | * 69 | * 70 | * 71 | * 72 | * 73 | * graphApp.controller('GraphCtrl', function ($scope) { 74 | * $scope.clicked = {}; 75 | * $scope.showClick = function(data) { 76 | * $scope.clicked = data; 77 | * } 78 | */ 79 | function ChartEvents() { 80 | var eventsLinker = function (scope, element, attrs, chartCtrl) { 81 | if (attrs.onInit) { 82 | chartCtrl.addOnInitFunction(scope.onInit); 83 | } 84 | if (attrs.onMouseover) { 85 | chartCtrl.addOnMouseoverFunction(scope.onMouseover); 86 | } 87 | if (attrs.onMouseout) { 88 | chartCtrl.addOnMouseoutFunction(scope.onMouseout); 89 | } 90 | if (attrs.onResize) { 91 | chartCtrl.addOnResizeFunction(scope.onResize); 92 | } 93 | if (attrs.onResized) { 94 | chartCtrl.addOnResizedFunction(scope.onResized); 95 | } 96 | if (attrs.onRendered) { 97 | chartCtrl.addOnRenderedFunction(scope.onRendered); 98 | } 99 | if (attrs.onClickData) { 100 | chartCtrl.addDataOnClickFunction(scope.onClickData); 101 | } 102 | if (attrs.onMouseoverData) { 103 | chartCtrl.addDataOnMouseoverFunction(scope.onMouseoverData); 104 | } 105 | if (attrs.onMouseoutData) { 106 | chartCtrl.addDataOnMouseoutFunction(scope.onMouseoutData); 107 | } 108 | }; 109 | 110 | return { 111 | "require": "^c3chart", 112 | "restrict": "E", 113 | "scope": { 114 | "onInit": "&", 115 | "onMouseover": "&", 116 | "onMouseout": "&", 117 | "onResize": "&", 118 | "onResized": "&", 119 | "onRendered": "&", 120 | "onClickData": "&", 121 | "onMouseoverData": "&", 122 | "onMouseoutData": "&" 123 | }, 124 | "replace": true, 125 | "link": eventsLinker 126 | }; 127 | } 128 | -------------------------------------------------------------------------------- /src/gauge-directive.js: -------------------------------------------------------------------------------- 1 | angular.module('gridshore.c3js.chart') 2 | .directive('chartGauge', ChartGauge); 3 | /** 4 | * @ngdoc directive 5 | * @name chartGauge 6 | * @description 7 | * `chart-gauge` is used to specify specific properties when creating a guage chart. 8 | * 9 | * Restrict To: 10 | * Element 11 | * 12 | * Parent Element: 13 | * c3chart 14 | * 15 | * @param {Number} min The minimum value used in the Gauge. 16 | * 17 | * {@link http://c3js.org/reference.html#gauge-min| c3js docs} 18 | * 19 | * @param {Number} max The maximum value used in the Guage. 20 | * 21 | * {@link http://c3js.org/reference.html#gauge-max| c3js docs} 22 | * 23 | * @param {Number} width The width of the Guage. 24 | * 25 | * {@link http://c3js.org/reference.html#gauge-width| c3js docs} 26 | * 27 | * @param {String} units Set the units of the gauge, ' %' for instance. 28 | * 29 | * {@link http://c3js.org/reference.html#gauge-units| c3js docs} 30 | * 31 | * @param {Boolean} show-label Set to false to hide the labels, default is true. 32 | * 33 | * {@link http://c3js.org/reference.html#gauge-label-show| c3js docs} 34 | * 35 | * @param {Boolean} expand Set to false to prevent expanding the gauge, default is true. 36 | * 37 | * {@link http://c3js.org/reference.html#gauge-expand| c3js docs} 38 | * 39 | * @param {Function} label-format-function Function to format the labels. 40 | * 41 | * {@link http://c3js.org/reference.html#gauge-label-format| c3js docs} 42 | * 43 | * @example 44 | * Usage: 45 | * 46 | * 47 | * Example: 48 | * {@link http://jettro.github.io/c3-angular-directive/#examples} 49 | * 50 | * 51 | */ 52 | function ChartGauge () { 53 | var gaugeLinker = function (scope, element, attrs, chartCtrl) { 54 | var gauge = {}; 55 | if (attrs.min) { 56 | gauge.min = parseInt(attrs.min); 57 | } 58 | if (attrs.max) { 59 | gauge.max = parseInt(attrs.max); 60 | } 61 | if (attrs.width) { 62 | gauge.width = parseInt(attrs.width); 63 | } 64 | if (attrs.units) { 65 | gauge.units = attrs.units 66 | } 67 | if (attrs.showLabel) { 68 | gauge.label = {"show": (attrs.showLabel === 'true')}; 69 | } 70 | if (attrs.expand) { 71 | gauge.expand = (attrs.expand === 'true'); 72 | } 73 | chartCtrl.addGauge(gauge); 74 | if (attrs.labelFormatFunction) { 75 | chartCtrl.addGaugeLabelFormatFunction(scope.labelFormatFunction()); 76 | } 77 | }; 78 | 79 | return { 80 | require: '^c3chart', 81 | restrict: 'E', 82 | scope: { 83 | 'labelFormatFunction': "&" 84 | }, 85 | replace: true, 86 | link: gaugeLinker 87 | }; 88 | } 89 | -------------------------------------------------------------------------------- /src/grid-directive.js: -------------------------------------------------------------------------------- 1 | angular.module('gridshore.c3js.chart') 2 | .directive('chartGrid', ChartGrid); 3 | 4 | /** 5 | * @ngdoc directive 6 | * @name chartGrid 7 | * @description 8 | * `chart-grid` is used to specify properties to show a grid. 9 | * 10 | * Restrict To: 11 | * Element 12 | * 13 | * Parent Element: 14 | * c3chart 15 | * 16 | * @param {Boolean} showX Whether to show the x axis grid. 17 | * 18 | * {@link http://c3js.org/reference.html#grid-x-show| c3js docs} 19 | * 20 | * @param {Boolean} showY Whether to show the y axis grid. 21 | * 22 | * {@link http://c3js.org/reference.html#grid-y-show| c3js docs} 23 | * 24 | * @param {Boolean} showY2 Whether to show the y2 axis grid. 25 | * 26 | * {@link http://c3js.org/reference.html#grid-y-show| c3js docs} 27 | * 28 | * @param {Boolean} showFocus Whether to enable the focus grid. 29 | * 30 | * {@link http://c3js.org/reference.html#grid-focus-show| c3js docs} 31 | * 32 | * @example 33 | * Usage: 34 | * 35 | * 36 | * Example: 37 | * {@link http://jettro.github.io/c3-angular-directive/#examples} 38 | * 39 | * 40 | * 41 | * 42 | * 43 | * 44 | */ 45 | function ChartGrid () { 46 | var gridLinker = function (scope, element, attrs, chartCtrl) { 47 | var showX = attrs.showX; 48 | if (showX && showX === "true") { 49 | chartCtrl.addGrid("x"); 50 | } 51 | var showY = attrs.showY; 52 | if (showY && showY === "true") { 53 | chartCtrl.addGrid("y"); 54 | } 55 | var showY2 = attrs.showY2; 56 | if (showY2 && showY2 === "true") { 57 | chartCtrl.addGrid("y2"); 58 | } 59 | var showFocus = attrs.showFocus; 60 | if (showFocus && showFocus === "false") { 61 | chartCtrl.hideGridFocus(); 62 | } 63 | }; 64 | 65 | return { 66 | "require": "^c3chart", 67 | "restrict": "E", 68 | "scope": {}, 69 | "replace": true, 70 | "link": gridLinker, 71 | "transclude": true, 72 | "template": "
" 73 | }; 74 | } -------------------------------------------------------------------------------- /src/grid-optional-directive.js: -------------------------------------------------------------------------------- 1 | angular.module('gridshore.c3js.chart') 2 | .directive('chartGridOptional', ChartGridOptional); 3 | /** 4 | * @ngdoc directive 5 | * @name chartGridOptional 6 | * @description 7 | * `chart-grid-optional` is used to add optional grid lines to the chart. All attributes are mandatory 8 | * 9 | * Restrict To: 10 | * Element 11 | * 12 | * Parent Element: 13 | * gridDirective 14 | * 15 | * @param {String} axisId x, y or y2. 16 | * 17 | * {@link http://c3js.org/reference.html#grid-x-lines| c3js docs} 18 | * 19 | * @param {Number} value Value where to print the additional grid line. 20 | * 21 | * {@link http://c3js.org/reference.html#grid-x-lines| c3js docs} 22 | * 23 | * @param {String} text Label to print at the grid line. 24 | * 25 | * {@link http://c3js.org/reference.html#grid-x-lines| c3js docs} 26 | * 27 | * @param {String} gridClass Class to add to the grid line to be able to style them separately. 28 | * 29 | * {@link http://c3js.org/reference.html#grid-x-lines| c3js docs} 30 | * 31 | * @param {String} position Sets the position for the label, values are: start, middle, end. 32 | * 33 | * {@link http://c3js.org/reference.html#grid-x-lines| c3js docs} 34 | * 35 | * @example 36 | * Usage: 37 | * 38 | * 39 | * Example: 40 | * {@link http://jettro.github.io/c3-angular-directive/#examples} 41 | * 42 | * 43 | * 44 | * 45 | * 46 | * 47 | */ 48 | function ChartGridOptional() { 49 | var gridLinker = function (scope, element, attrs, chartCtrl) { 50 | var axisId = attrs.axisId; 51 | var value = attrs.gridValue; 52 | var text = attrs.gridText; 53 | var gridClass = attrs.gridClass; 54 | var position = attrs.position; 55 | 56 | chartCtrl.addGridLine(axisId, value, text, gridClass, position); 57 | }; 58 | 59 | return { 60 | "require": "^c3chart", 61 | "restrict": "E", 62 | "scope": {}, 63 | "replace": true, 64 | "link": gridLinker 65 | }; 66 | } 67 | -------------------------------------------------------------------------------- /src/group-directive.js: -------------------------------------------------------------------------------- 1 | angular.module('gridshore.c3js.chart') 2 | .directive('chartGroup', ChartGroup); 3 | 4 | /** 5 | * @ngdoc directive 6 | * @name chartGroup 7 | * @description 8 | * `chart-group` is used to group columns, for instance to add them to the 9 | * same column for the same x value. Input is a comma separated string with the 10 | * id's of the columns to group. 11 | * 12 | * Restrict To: 13 | * Element 14 | * 15 | * Parent Element: 16 | * c3chart 17 | * 18 | * @param {String} groupValues Comma separated column ids. 19 | * 20 | * {@link http://c3js.org/reference.html#data-groups| c3js docs} 21 | * 22 | * 23 | * @example 24 | * Usage: 25 | * 26 | * 27 | * Example: 28 | * {@link http://jettro.github.io/c3-angular-directive/#examples} 29 | * 30 | * 31 | * 36 | * 41 | * 42 | * 43 | */ 44 | function ChartGroup () { 45 | var groupLinker = function (scope, element, attrs, chartCtrl) { 46 | var group = attrs.groupValues.split(","); 47 | chartCtrl.addGroup(group); 48 | }; 49 | 50 | return { 51 | "require": "^c3chart", 52 | "restrict": "E", 53 | "scope": {}, 54 | "replace": true, 55 | "link": groupLinker 56 | }; 57 | } 58 | -------------------------------------------------------------------------------- /src/legend-directive.js: -------------------------------------------------------------------------------- 1 | angular.module('gridshore.c3js.chart') 2 | .directive('chartLegend', ChartLegend); 3 | 4 | /** 5 | * @ngdoc directive 6 | * @name chartLegend 7 | * @description 8 | * `chart-legend` is used configure the legend to add to the chart. You can also add function to handle events related 9 | * to the legend: onClick, onMouseOver and onMouseOut. 10 | * 11 | * Restrict To: 12 | * Element 13 | * 14 | * Parent Element: 15 | * c3chart 16 | * 17 | * @param {Boolean} showLegend Whether to show the legend or not, default is show. 18 | * 19 | * {@link http://c3js.org/reference.html#legend-show| c3js docs} 20 | * 21 | * @param {String} legendPosition One of the following values: bottom, right, inset. 22 | * 23 | * {@link http://c3js.org/reference.html#legend-position| c3js docs} 24 | * 25 | * @param {Function} onMouseover Provide callback to be called when you hoover the legend. 26 | * 27 | * {@link http://c3js.org/reference.html#legend-item-onmouseover| c3js docs} 28 | * 29 | * @param {Function} onMouseout Provide callback to be called when you hoover out of the legend. 30 | * 31 | * {@link http://c3js.org/reference.html#legend-item-onmouseout| c3js docs} 32 | * 33 | * @param {Function} onClick Provide callback to be called when you click the legend. 34 | * 35 | * {@link http://c3js.org/reference.html#legend-item-onmouseout| c3js docs} 36 | * 37 | * @param {String} legendInset Where to show an inset legend, valid values are: top-left, top-right, bottom-left, bottom-right 38 | * 39 | * {@link http://c3js.org/reference.html#legend-inset| c3js docs} 40 | * 41 | * @param {Number} legendInsetX X position for the inset. 42 | * 43 | * {@link http://c3js.org/reference.html#legend-inset| c3js docs} 44 | * 45 | * @param {Number} legendInsetY Y position for the inset. 46 | * 47 | * {@link http://c3js.org/reference.html#legend-inset| c3js docs} 48 | * 49 | * @param {Number} legendInsetStep Step for the inset. 50 | * 51 | * {@link http://c3js.org/reference.html#legend-inset| c3js docs} 52 | * 53 | * @example 54 | * Usage: 55 | * 56 | * 57 | * Example: 58 | * {@link http://jettro.github.io/c3-angular-directive/#examples} 59 | * 60 | * 61 | */ 62 | function ChartLegend () { 63 | var legendLinker = function (scope, element, attrs, chartCtrl) { 64 | var legend = null; 65 | var show = attrs.showLegend; 66 | if (show && show === "false") { 67 | legend = {"show": false}; 68 | } else { 69 | var position = attrs.legendPosition; 70 | if (position) { 71 | legend = {"position": position}; 72 | } 73 | var inset = attrs.legendInset; 74 | if (inset) { 75 | legend = {"position":"inset","inset":{"anchor":inset}}; 76 | 77 | var insetX = attrs.legendInsetX; 78 | if (insetX) { 79 | legend.inset.x = parseInt(insetX); 80 | } 81 | var insetY = attrs.legendInsetY; 82 | if (insetY) { 83 | legend.inset.y = parseInt(insetY); 84 | } 85 | var insetStep = attrs.legendInsetStep; 86 | if (insetStep) { 87 | legend.inset.step = parseInt(insetStep); 88 | } 89 | } 90 | } 91 | 92 | if (attrs.onMouseover) { 93 | legend = legend || {}; 94 | legend.item = legend.item || {}; 95 | legend.item.onmouseover = function (data) { 96 | scope.$apply(function () { 97 | scope.onMouseover({"data": data}); 98 | }); 99 | }; 100 | } 101 | if (attrs.onMouseout) { 102 | legend = legend || {}; 103 | legend.item = legend.item || {}; 104 | legend.item.onmouseout = function (data) { 105 | scope.$apply(function () { 106 | scope.onMouseout({"data": data}); 107 | }); 108 | }; 109 | } 110 | if (attrs.onClick) { 111 | legend = legend || {}; 112 | legend.item = legend.item || {}; 113 | 114 | legend.item.onclick = function (data) { 115 | scope.$apply(function () { 116 | scope.onClick({"data": data}); 117 | }); 118 | }; 119 | } 120 | 121 | if (legend != null) { 122 | chartCtrl.addLegend(legend); 123 | } 124 | }; 125 | 126 | return { 127 | "require": "^c3chart", 128 | "restrict": "E", 129 | "scope": { 130 | "onMouseover": "&", 131 | "onMouseout": "&", 132 | "onClick": "&" 133 | }, 134 | "replace": true, 135 | "link": legendLinker 136 | }; 137 | } -------------------------------------------------------------------------------- /src/line-directive.js: -------------------------------------------------------------------------------- 1 | angular.module('gridshore.c3js.chart') 2 | .directive('chartLine', ChartLine); 3 | /** 4 | * @ngdoc directive 5 | * @name chartLine 6 | * @description 7 | * `chart-line` is used to customize the line chart properties.. 8 | * 9 | * Restrict To: 10 | * Element 11 | * 12 | * Parent Element: 13 | * c3chart 14 | * 15 | * @param {String} stepType Step types for step chart: step, step-before and step-after. 16 | * 17 | * {@link http://c3js.org/reference.html#line-step_type| c3js doc} 18 | * 19 | * @param {Boolean} connectNull Should null data point be connected or not. 20 | * 21 | * {@link http://c3js.org/reference.html#bar-width-ratio| c3js doc} 22 | * 23 | * @example 24 | * Usage: 25 | * 26 | * Example: 27 | * {@link http://jettro.github.io/c3-angular-directive/#examples} 28 | * 29 | */ 30 | 31 | function ChartLine() { 32 | var lineLinker = function (scope, element, attrs, chartCtrl) { 33 | var line = {}; 34 | if (attrs.stepType) { 35 | line.step = line.step || {}; 36 | line.step.type = attrs.stepType; 37 | } 38 | if (attrs.connectNull) { 39 | line.connectNull = (attrs.connectNull === 'true'); 40 | } 41 | chartCtrl.addLine(line); 42 | }; 43 | 44 | return { 45 | require: '^c3chart', 46 | restrict: 'E', 47 | scope: {}, 48 | replace: true, 49 | link: lineLinker 50 | }; 51 | } 52 | 53 | -------------------------------------------------------------------------------- /src/pie-directive.js: -------------------------------------------------------------------------------- 1 | angular.module('gridshore.c3js.chart') 2 | .directive('chartPie', ChartPie); 3 | 4 | /** 5 | * @ngdoc directive 6 | * @name chartPie 7 | * @description 8 | * `chart-pie` is used configure additional properties for a pie chart. 9 | * 10 | * Restrict To: 11 | * Element 12 | * 13 | * Parent Element: 14 | * c3chart 15 | * 16 | * @param {Boolean} showLabel Whether to show a label for each pie part. 17 | * 18 | * {@link http://c3js.org/reference.html#pie-label-show| c3js docs} 19 | * 20 | * @param {Boolean} expand Whether to expand on mouse over. 21 | * 22 | * {@link http://c3js.org/reference.html#pie-expand| c3js docs} 23 | * 24 | * @param {Number} thresholdLabel Show label if value is higher than the provided value. 25 | * 26 | * {@link http://c3js.org/reference.html#pie-label-threshold| c3js docs} 27 | * 28 | * @param {Function} labelFormatFunction Present a function to format the label. 29 | * 30 | * {@link http://c3js.org/reference.html#pie-label-format| c3js docs} 31 | * 32 | * @example 33 | * Usage: 34 | * 35 | * 36 | * Example: 37 | * {@link http://jettro.github.io/c3-angular-directive/#examples} 38 | * 39 | * 40 | * 41 | * 42 | * 43 | * 44 | * 45 | */ 46 | function ChartPie () { 47 | var pieLinker = function (scope, element, attrs, chartCtrl) { 48 | var pie = {}; 49 | if (attrs.showLabel) { 50 | pie.label = {"show": (attrs.showLabel === 'true')}; 51 | } 52 | if (attrs.thresholdLabel) { 53 | if (!pie.label) { 54 | pie.label = {}; 55 | } 56 | pie.label.threshold = parseFloat(attrs.thresholdLabel); 57 | } 58 | if (attrs.expand) { 59 | pie.expand = (attrs.expand === 'true'); 60 | } 61 | chartCtrl.addPie(pie); 62 | if (attrs.labelFormatFunction) { 63 | chartCtrl.addPieLabelFormatFunction(scope.labelFormatFunction()); 64 | } 65 | }; 66 | 67 | return { 68 | require: '^c3chart', 69 | restrict: 'E', 70 | scope: { 71 | "labelFormatFunction": "&" 72 | }, 73 | replace: true, 74 | link: pieLinker 75 | }; 76 | } 77 | -------------------------------------------------------------------------------- /src/points-directive.js: -------------------------------------------------------------------------------- 1 | angular.module('gridshore.c3js.chart') 2 | .directive('chartPoints', ChartPoints); 3 | 4 | /** 5 | * @ngdoc directive 6 | * @name chartPoints 7 | * @description 8 | * `chart-points` is used configure the points in for example a line chart. You can 9 | * configure the radius of the point in normal as well as expand state. 10 | * 11 | * Restrict To: 12 | * Element 13 | * 14 | * Parent Element: 15 | * c3chart 16 | * 17 | * @param {Boolean} showPoint Whether to show points in the chart. 18 | * 19 | * {@link http://c3js.org/reference.html#point-show| c3js docs} 20 | * 21 | * @param {Boolean} pointExpandEnabled Whether to expand on mouse over. 22 | * 23 | * {@link http://c3js.org/reference.html#point-focus-expand-enabled| c3js docs} 24 | * 25 | * @param {Number} pointExpandRadius Radius of the point when expanded. Default is 1.75 times the 26 | * normal radius. 27 | * 28 | * {@link http://c3js.org/reference.html#point-focus-expand-r| c3js docs} 29 | * 30 | * @param {Number} pointRadius Radius of the point in normal mode. Default radius is 2.5 31 | * 32 | * {@link http://c3js.org/reference.html#point-r| c3js docs} 33 | * 34 | * @param {Number} pointSelectRadius Radius of the point when selected, default is 4 times the normal radius. 35 | * 36 | * {@link http://c3js.org/reference.html#point-select-r| c3js docs} 37 | * 38 | * @example 39 | * Usage: 40 | * 41 | * 42 | * Example: 43 | * {@link http://jettro.github.io/c3-angular-directive/#examples} 44 | * 45 | */ 46 | function ChartPoints () { 47 | var pointLinker = function (scope, element, attrs, chartCtrl) { 48 | var point = {}; 49 | if (attrs.showPoint) { 50 | point.show = (attrs.showPoint === 'true'); 51 | } 52 | if (attrs.pointExpandEnabled) { 53 | if (!point.focus) { 54 | point.focus = {"expand":{}}; 55 | } 56 | point.focus.expand.enabled = (attrs.pointsFocusEnabled !== 'false'); 57 | } 58 | if (attrs.pointExpandRadius) { 59 | if (!point.focus) { 60 | pie.focus = {"expand":{}}; 61 | } 62 | point.focus.expand.r = parseInt(attrs.pointFocusRadius); 63 | } 64 | if (attrs.pointRadius) { 65 | point.r = parseInt(attrs.pointRadius); 66 | } 67 | if (attrs.pointSelectRadius) { 68 | point.select = {"r":parseInt(attrs.pointSelectRadius)}; 69 | } 70 | chartCtrl.addPoint(point); 71 | }; 72 | 73 | return { 74 | require: '^c3chart', 75 | restrict: 'E', 76 | scope: {}, 77 | replace: true, 78 | link: pointLinker 79 | }; 80 | } -------------------------------------------------------------------------------- /src/region-directive.js: -------------------------------------------------------------------------------- 1 | angular.module('gridshore.c3js.chart') 2 | .directive('chartRegion', ChartRegion); 3 | /** 4 | * @ngdoc directive 5 | * @name chartRegion 6 | * @description 7 | * `chart-region` is used to set a region property on a chart. 8 | * 9 | * Restrict To: 10 | * Element 11 | * 12 | * Parent Element: 13 | * c3chart 14 | * 15 | * @param {String} region-id The id used to uniquely identify the column 16 | * 17 | * @param {String} region-style Style to identify the regions. 18 | * 19 | * {@link http://c3js.org/reference.html#data-regions| c3js doc} 20 | * 21 | * @param {String} region-starts The regions where the data starts. 22 | * 23 | * @param {String} region-ends The regions where the data starts. 24 | * 25 | * @example 26 | * Usage: 27 | * 28 | * Example: 29 | * {@link http://jettro.github.io/c3-angular-directive/#examples} 30 | * 31 | */ 32 | 33 | function ChartRegion() { 34 | var regionLinker = function (scope, element, attrs, chartCtrl) { 35 | var style = 'dashed', 36 | starts = [], 37 | ends = [], 38 | intervals = []; 39 | if (attrs.regionStyle) { 40 | style = attrs.regionStyle; 41 | } 42 | if (attrs.regionStarts){ 43 | starts = attrs.regionStarts.split(","); 44 | } 45 | if (attrs.regionEnds){ 46 | ends = attrs.regionEnds.split(","); 47 | } 48 | if (starts.length > ends.length) { 49 | intervals.push({'start': starts.pop(), 'style': style}); 50 | } 51 | if (starts.length < ends.length) { 52 | intervals.push({'end': ends.shift(), 'style': style}); 53 | } 54 | starts.forEach(function (value, i) { 55 | intervals.push({'start': starts[i], 'end': ends[i], 'style': style}); 56 | }); 57 | chartCtrl.addRegion(attrs.regionId, intervals); 58 | }; 59 | 60 | return { 61 | require: '^c3chart', 62 | restrict: 'E', 63 | scope: {}, 64 | replace: true, 65 | link: regionLinker 66 | }; 67 | } 68 | -------------------------------------------------------------------------------- /src/selection-directive.js: -------------------------------------------------------------------------------- 1 | angular.module('gridshore.c3js.chart') 2 | .directive('selection', Selection); 3 | /** 4 | * @ngdoc directive 5 | * @name selection 6 | * @description 7 | * `selection` is used to to configure whether it is possible to select elements and interact with the chart to find selected elements. 8 | * 9 | * Restrict To: 10 | * Element 11 | * 12 | * Parent Element: 13 | * c3chart 14 | * 15 | * @param {String} enabled Specify whether the selection should be enabled or not, default is true. 16 | * 17 | * {@link http://c3js.org/reference.html#data-selection-enabled} 18 | * 19 | * @param {String} grouped Enables the grouped selection. 20 | * 21 | * {@link http://c3js.org/reference.html#data-selection-grouped} 22 | * 23 | * @param {String} multiple Enables possibility to select multiple items. 24 | * 25 | * {@link http://c3js.org/reference.html#data-selection-multiple} 26 | * 27 | * @example 28 | * Usage: 29 | * 30 | * Example: 31 | * {@link http://jettro.github.io/c3-angular-directive/#examples} 32 | */ 33 | function Selection () { 34 | var selectionLinker = function (scope, element, attrs, chartCtrl) { 35 | var enabled = attrs.enabled; 36 | var grouped = attrs.grouped; 37 | var multiple = attrs.multiple; 38 | 39 | if (enabled && enabled === 'true') { 40 | var selection = {"enabled": true}; 41 | if (grouped && grouped === 'true') { 42 | selection.grouped = true; 43 | } 44 | if (multiple && multiple === 'true') { 45 | selection.multiple = true; 46 | } 47 | chartCtrl.addSelection(selection); 48 | } 49 | }; 50 | 51 | return { 52 | "require": "^c3chart", 53 | "restrict": "E", 54 | "scope": {}, 55 | "replace": true, 56 | "link": selectionLinker 57 | }; 58 | } 59 | -------------------------------------------------------------------------------- /src/size-directive.js: -------------------------------------------------------------------------------- 1 | angular.module('gridshore.c3js.chart') 2 | .directive('chartSize', ChartSize); 3 | 4 | /** 5 | * @ngdoc directive 6 | * @name chartSize 7 | * @description 8 | * `chart-size` is used to configure size properties of the chart. 9 | * 10 | * Restrict To: 11 | * Element 12 | * 13 | * Parent Element: 14 | * c3chart 15 | * 16 | * @param {Number} chartWidth Width of the chart element, by default it will be 17 | * calculated from the parent container. 18 | * 19 | * {@link http://c3js.org/reference.html#size-width| c3js docs} 20 | * 21 | * @param {Number} chartHeight Height of the chart element, by default it will be 22 | * calculated from the parent container. 23 | * 24 | * {@link http://c3js.org/reference.html#size-height| c3js docs} 25 | * 26 | * @example 27 | * Usage: 28 | * 29 | * 30 | * Example: 31 | * {@link http://jettro.github.io/c3-angular-directive/#examples} 32 | * 33 | * 34 | */ 35 | function ChartSize() { 36 | var sizeLinker = function (scope, element, attrs, chartCtrl) { 37 | var chartSize = null; 38 | var width = attrs.chartWidth; 39 | var height = attrs.chartHeight; 40 | if (width || height) { 41 | chartSize = {}; 42 | if (width) { 43 | chartSize.width = parseInt(width); 44 | } 45 | if (height) { 46 | chartSize.height = parseInt(height); 47 | } 48 | chartCtrl.addSize(chartSize); 49 | } 50 | }; 51 | 52 | return { 53 | "require": "^c3chart", 54 | "restrict": "E", 55 | "scope": {}, 56 | "replace": true, 57 | "link": sizeLinker 58 | }; 59 | } 60 | -------------------------------------------------------------------------------- /src/tooltip-directive.js: -------------------------------------------------------------------------------- 1 | angular.module('gridshore.c3js.chart') 2 | .directive('chartTooltip', ChartTooltip); 3 | 4 | /** 5 | * @ngdoc directive 6 | * @name chartTooltip 7 | * @description 8 | * `chart-tooltip` is used to configure the look and feel of the tooltip. You can 9 | * configure to show the tooltip or not and the formatting of labels, values, etc. 10 | * 11 | * Restrict To: 12 | * Element 13 | * 14 | * Parent Element: 15 | * c3chart 16 | * 17 | * @param {Boolean} showTooltip Whether to show the tooltip or not. 18 | * 19 | * {@link http://c3js.org/reference.html#tooltip-show| c3js docs} 20 | * 21 | * @param {Boolean} hideTooltipTitle Whether to show the tooltip title or not. 22 | * 23 | * @param {Boolean} groupTooltip Whether to group all tooltips of the different 24 | * columns in the chart. 25 | * 26 | * {@link http://c3js.org/reference.html#tooltip-grouped| c3js docs} 27 | * 28 | * @param {Function} titleFormatFunction Function to format the title of the tooltip. 29 | * 30 | * {@link http://c3js.org/reference.html#tooltip-format-title| c3js docs} 31 | * 32 | * @param {Function} nameFormatFunction Function to format the name of the tooltip. 33 | * 34 | * {@link http://c3js.org/reference.html#tooltip-format-name| c3js docs} 35 | * 36 | * @param {Function} valueFormatFunction Function to format the value of the tooltip. 37 | * 38 | * {@link http://c3js.org/reference.html#tooltip-format-value| c3js docs} 39 | * 40 | * @param {Function} contentFormatFunction Function to format the content of the tooltip. 41 | * 42 | * {@link http://c3js.org/reference.html#tooltip-contents| c3js docs} 43 | * 44 | * @example 45 | * Usage: 46 | * 47 | * 48 | * Example: 49 | * {@link http://jettro.github.io/c3-angular-directive/#examples} 50 | * 51 | * 52 | * 53 | * function Ctrl() { 54 | * var vm = this; 55 | * vm.formatTooltip = formatTooltip; 56 | * 57 | * function formatTooltip(value, ratio, id, index) { 58 | * return '$' + value; 59 | * } 60 | * } 61 | * 62 | */ 63 | function ChartTooltip () { 64 | var tooltipLinker = function (scope, element, attrs, chartCtrl) { 65 | var tooltip = null; 66 | var show = attrs.showTooltip; 67 | var hideTitle = attrs.hideTooltipTitle; 68 | var joined = attrs.joinedTooltip; 69 | 70 | if (show && show === "false") { 71 | tooltip = {"show": false}; 72 | } else { 73 | var grouped = attrs.groupTooltip; 74 | if (grouped && grouped === "false") { 75 | tooltip = {"grouped": false}; 76 | } 77 | } 78 | 79 | if (joined && joined === "true") { 80 | tooltip = tooltip || {}; 81 | tooltip.contents = function (d, defaultTitleFormat, defaultValueFormat, color) { 82 | var $$ = this, config = $$.config, 83 | titleFormat = config.tooltip_format_title || defaultTitleFormat, 84 | nameFormat = config.tooltip_format_name || function (name) { return name; }, 85 | valueFormat = config.tooltip_format_value || defaultValueFormat, 86 | text, i, title, value, name, bgcolor, CLASS; 87 | CLASS = { 88 | tooltipContainer: 'c3-tooltip-container', 89 | tooltip : 'c3-tooltip', 90 | tooltipName : 'c3-tooltip-name' 91 | }; 92 | for (i = d[0].x; i < (d[0].x + 1); i++) { 93 | if (! (d[i] && (d[i].value || d[i].value === 0))) { continue; } 94 | 95 | if (! text) { 96 | title = titleFormat ? titleFormat(d[i].x) : d[i].x; 97 | text = "" + (title || title === 0 ? "" : ""); 98 | } 99 | 100 | value = valueFormat(d[i].value, d[i].ratio, d[i].id, d[i].index); 101 | if (value !== undefined) { 102 | name = nameFormat(d[i].name, d[i].ratio, d[i].id, d[i].index); 103 | bgcolor = $$.levelColor ? $$.levelColor(d[i].value) : color(d[i].id); 104 | 105 | text += ""; 106 | text += ""; 107 | text += ""; 108 | text += ""; 109 | } 110 | } 111 | return text + "
" + title + "
" + name + "" + value + "
"; 112 | } 113 | } 114 | 115 | if (tooltip != null) { 116 | chartCtrl.addTooltip(tooltip); 117 | } 118 | if (attrs.titleFormatFunction) { 119 | chartCtrl.addTooltipTitleFormatFunction(scope.titleFormatFunction()); 120 | } 121 | if (attrs.nameFormatFunction) { 122 | chartCtrl.addTooltipNameFormatFunction(scope.nameFormatFunction()); 123 | } 124 | if (attrs.valueFormatFunction) { 125 | chartCtrl.addTooltipValueFormatFunction(scope.valueFormatFunction()); 126 | } 127 | if (attrs.contentFormatFunction) { 128 | chartCtrl.addTooltipContentFormatFunction(scope.contentFormatFunction()); 129 | } 130 | 131 | }; 132 | 133 | return { 134 | "require": "^c3chart", 135 | "restrict": "E", 136 | "scope": { 137 | "valueFormatFunction": "&", 138 | "nameFormatFunction": "&", 139 | "titleFormatFunction": "&", 140 | "contentFormatFunction": "&" 141 | }, 142 | "replace": true, 143 | "link": tooltipLinker 144 | }; 145 | } --------------------------------------------------------------------------------