├── .gitignore
├── samples
├── js
│ ├── VizGrammarSettings.js
│ └── topojson.js
├── css
│ ├── VizGrammar.css
│ ├── axes.css
│ └── custom.css
├── charts
│ ├── number
│ │ ├── number.css
│ │ └── index.html
│ ├── scatter
│ │ └── index.html
│ ├── table
│ │ └── index.html
│ ├── line
│ │ └── index.html
│ ├── map
│ │ └── index.html
│ ├── area
│ │ └── index.html
│ ├── arc
│ │ └── index.html
│ └── bar
│ │ └── index.html
└── jsonMapFiles
│ └── usaInfo.json
├── gh-deploy.bat
├── gh-deploy.sh
├── charts
├── chart.core.js
├── chart.number.js
├── custom.stack.js
├── chart.table.js
├── chart.line.js
├── chart.area.js
├── chart.scatter.js
├── chart.arc.js
├── chart.map.js
└── chart.bar.js
├── package.json
├── issue_template.md
├── GruntFile.js
├── pull_request_template.md
├── README.md
└── LICENSE
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea/
2 | node_modules/
3 |
--------------------------------------------------------------------------------
/samples/js/VizGrammarSettings.js:
--------------------------------------------------------------------------------
1 | var vizgSettings = {
2 | colorScale: ['#058DC7', '#50B432', '#DA524A', '#E08437']
3 | }
--------------------------------------------------------------------------------
/samples/css/VizGrammar.css:
--------------------------------------------------------------------------------
1 | .tooltipClass {
2 | background-color: #e5f2ff;
3 | padding: 4px 8px;
4 |
5 | }
6 | .tooltipClass p{
7 | margin: 0;
8 | padding: 0;
9 |
10 | }
--------------------------------------------------------------------------------
/samples/css/axes.css:
--------------------------------------------------------------------------------
1 | body svg.marks .mark-group .background {
2 | fill: #121822 !important;
3 | }
4 |
5 | body svg.marks .mark-group .mark-text text {
6 | fill: #7D8596 !important;
7 | }
8 |
9 | body svg.marks .mark-group .mark-rule line {
10 | stroke: #E3E5E6 !important;
11 | }
--------------------------------------------------------------------------------
/samples/charts/number/number.css:
--------------------------------------------------------------------------------
1 | p {
2 | margin: 0;
3 | display: block;
4 | text-align: center;
5 | font-weight: bold;
6 | }
7 |
8 | .titledChartNumberTorqueContent {
9 | color:steelblue;
10 | font-size:18px;
11 | font-weight: normal;
12 | padding: 10px 0;
13 | }
14 |
15 | .valdChartNumberTorqueContent {
16 | color:#438CAD;
17 | font-size:50px;
18 | font-weight: normal;
19 | }
20 |
21 |
22 | .diffdChartNumberTorqueContent {
23 | color:#438CAD;
24 | font-size:14px;
25 | }
26 |
27 | .diffPercentagedChartNumberTorqueContent {
28 | color:#ff944d;
29 | font-size:14px;
30 | }
--------------------------------------------------------------------------------
/gh-deploy.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 | title Deploy Samples to gh-pages
3 |
4 | echo "samples" folder contains will deploy to gh-pages branch
5 | echo =======================================================
6 | echo please commit all the changes before continue
7 | echo.
8 |
9 | SET /P ANSWER=Do you want to continue (Y/N)?
10 |
11 | if /i {%ANSWER%}=={y} (goto :yes)
12 | if /i {%ANSWER%}=={yes} (goto :yes)
13 | goto :no
14 |
15 | :yes
16 | echo.
17 | echo Deploying.....
18 | echo.
19 | git subtree push --prefix samples origin gh-pages
20 | echo.
21 | echo Finished!
22 | pause
23 | exit /b 0
24 |
25 | :no
26 | echo.
27 | pause
28 | exit /b 1
--------------------------------------------------------------------------------
/gh-deploy.sh:
--------------------------------------------------------------------------------
1 | #/bin/sh
2 | echo
3 | echo =========================================================
4 | echo "samples" folder contains will deploy to gh-pages branch
5 | echo please commit all the changes before continue
6 | echo =========================================================
7 | echo
8 | echo -n "Do you want to continue [Y/N]?"
9 | old_stty_cfg=$(stty -g)
10 | stty raw -echo
11 | answer=$( while ! head -c 1 | grep -i '[ny]' ;do true ;done )
12 | stty $old_stty_cfg
13 | if echo "$answer" | grep -iq "^y" ;then
14 | echo
15 | echo Deploying.....
16 | echo
17 | git pull
18 | git subtree push --prefix samples origin gh-pages
19 | echo
20 | echo Finished!
21 | sleep
22 | else
23 | sleep
24 | fi
25 | exit
--------------------------------------------------------------------------------
/charts/chart.core.js:
--------------------------------------------------------------------------------
1 | var vizg = function(dataTable, config) {
2 | dataTable = buildTable(dataTable);
3 | if (typeof config.charts !== "undefined" && config.charts.length == 1) {
4 | //Set chart config properties for main
5 | for (var property in config.charts[0]) {
6 | if (config.charts[0].hasOwnProperty(property)) {
7 | config[property] = config.charts[0][property];
8 | }
9 | }
10 |
11 | this.chart = new window[config.type]([dataTable], config);
12 | }
13 | };
14 |
15 | vizg.prototype.draw = function(div, callback) {
16 | this.chart.draw(div, callback);
17 | };
18 |
19 | vizg.prototype.insert = function(data) {
20 | this.chart.insert(buildData(data, this.chart.metadata));
21 | };
22 |
23 | vizg.prototype.getSpec = function() {
24 | return this.chart.getSpec();
25 | };
--------------------------------------------------------------------------------
/samples/jsonMapFiles/usaInfo.json:
--------------------------------------------------------------------------------
1 | {"Alabama":"01","Alaska":"02","Arizona":"04","Arkansas":"05","California":"06","Colorado":"08","Connecticut":"09","Delaware":"10","District of Columbia":"11","Florida":"12","Geogia":"13","Hawaii":"15","Idaho":"16","Illinois":"17","Indiana":"18","Iowa":"19","Kansas":"20","Kentucky":"21","Louisiana":"22","Maine":"23","Maryland":"24","Massachusetts":"25","Michigan":"26","Minnesota":"27","Mississippi":"28","Missouri":"29","Montana":"30","Nebraska":"31","Nevada":"32","New Hampshire":"33","New Jersey":"34","New Mexico":"35","New York":"36","North Carolina":"37","North Dakota":"38","Ohio":"39","Oklahoma":"40","Oregon":"41","Pennsylvania":"42","Rhode Island":"44","South Carolina":"45","South Dakota":"46","Tennessee":"47","Texas":"48","Utah":"49","Vermont":"50","Virginia":"51","Washington":"53","West Virginia":"54","Wisconsin":"55","Wyoming":"56"}
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "VizGrammar",
3 | "version": "2.0.0",
4 | "description": "Visualization library for Javascript that is based on d3",
5 | "keywords": [
6 | "vizg",
7 | "vizGrammar",
8 | "wso2",
9 | "visualization",
10 | "interaction",
11 | "grammar",
12 | "data",
13 | "d3"
14 | ],
15 | "author": {
16 | "name": "WSO2",
17 | "url": "http://wso2.com/"
18 | },
19 | "contributors": [
20 | {
21 | "name": "Tharik Kanaka",
22 | "url": "http://github.com/keizer619"
23 | }
24 | ],
25 | "license": "Apache-2.0",
26 | "repository": {
27 | "type": "git",
28 | "url": "http://github.com/wso2/VizGrammar/"
29 | },
30 | "devDependencies": {
31 | "grunt": "~0.4.5",
32 | "grunt-contrib-uglify": "~0.5.0",
33 | "grunt-contrib-concat": "~0.5.1",
34 | "grunt-contrib-copy":"~0.8.2"
35 | }
36 | }
--------------------------------------------------------------------------------
/issue_template.md:
--------------------------------------------------------------------------------
1 | **Description:**
2 |
3 |
4 | **Suggested Labels:**
5 |
6 |
7 | **Suggested Assignees:**
8 |
9 |
10 | **Affected Product Version:**
11 |
12 | **OS, DB, other environment details and versions:**
13 |
14 | **Steps to reproduce:**
15 |
16 |
17 | **Related Issues:**
18 |
--------------------------------------------------------------------------------
/GruntFile.js:
--------------------------------------------------------------------------------
1 | module.exports = function(grunt) {
2 |
3 | var wso2banner = '/*\n * Copyright (c) <%= grunt.template.today("yyyy") %>, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.\n *'
4 | +'\n * Licensed under the Apache License, Version 2.0 (the "License");\n'
5 | +' * you may not use this file except in compliance with the License./\n'
6 | +' * You may obtain a copy of the License at\n *\n *'
7 | +' http://www.apache.org/licenses/LICENSE-2.0\n *\n'
8 | +' * Unless required by applicable law or agreed to in writing, software\n'
9 | +' * distributed under the License is distributed on an "AS IS" BASIS,\n'
10 | +' * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n'
11 | +' * See the License for the specific language governing permissions and\n'
12 | +' * limitations under the License.\n */\n';
13 |
14 | grunt.initConfig({
15 | pkg: grunt.file.readJSON('package.json'),
16 | concat: {
17 | options: {
18 | banner: wso2banner,
19 | separator: ';'
20 | },
21 | dist: {
22 | src: ['charts/*.js'],
23 | dest: 'dist/<%= pkg.name %>.js'
24 | }
25 | },
26 | uglify: {
27 | options: {
28 | banner: wso2banner
29 | },
30 | dist: {
31 | files: {
32 | 'dist/<%= pkg.name %>.min.js': ['<%= concat.dist.dest %>']
33 | }
34 | }
35 | },
36 | copy: {
37 | main: {
38 | files: [
39 | { expand: true, cwd: 'dist', src: ['VizGrammar.min.js'], dest: 'samples/js/' }
40 | ],
41 | },
42 | }
43 | });
44 |
45 | grunt.loadNpmTasks('grunt-contrib-uglify');
46 | grunt.loadNpmTasks('grunt-contrib-concat');
47 | grunt.loadNpmTasks('grunt-contrib-copy');
48 | grunt.registerTask('default', ['concat', 'uglify', 'copy']);
49 |
50 | };
--------------------------------------------------------------------------------
/charts/chart.number.js:
--------------------------------------------------------------------------------
1 |
2 | var number = function(dataTable, config) {
3 | this.metadata = dataTable[0].metadata;
4 | this.data = dataTable[0].values
5 | var marks =[];
6 | this.spec = {};
7 |
8 | config = checkConfig(config, this.metadata);
9 | this.config = config;
10 | dataTable[0].name= config.title;
11 |
12 | };
13 |
14 | number.prototype.draw = function(div) {
15 | div = div.replace("#","");
16 | var contentId = div+"Content";
17 | var textContent = "";
18 |
19 | if (this.data != null && this.data.length != 0) {
20 | textContent = this.data[this.data.length - 1][this.metadata.names[this.config.x]];
21 | }
22 |
23 | var divContent = "
" + this.config.title+ "
"
24 | + "" + textContent + "
"
25 | + "0
"
26 | + "0%
";
27 |
28 | document.getElementById(div).innerHTML = divContent;
29 | this.view = contentId;
30 | };
31 |
32 | number.prototype.insert = function(data) {
33 | var current = data[data.length-1][this.metadata.names[this.config.x]];
34 | var previous = document.getElementById("val" + this.view).innerHTML;
35 | var difference = current - previous;
36 | var diffPercentage;
37 | var sign = "";
38 |
39 | if (previous != "" && previous != 0) {
40 | diffPercentage = (difference / previous).toFixed(2) * 100 + "%";
41 | } else {
42 | diffPercentage = "";
43 | }
44 |
45 | if (difference > 0) {
46 | sign = "+";
47 | }
48 |
49 | document.getElementById("diffPercentage" + this.view).innerHTML = sign + diffPercentage;
50 | document.getElementById("diff" + this.view).innerHTML = sign + difference;
51 | document.getElementById("val" + this.view).innerHTML = current;
52 |
53 | };
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/charts/custom.stack.js:
--------------------------------------------------------------------------------
1 |
2 | var stack = function(dataTable, config) {
3 | this.barChart = new bar(dataTable, config);
4 | this.metadata = this.barChart.metadata;
5 |
6 | var spec = this.barChart.getSpec();
7 |
8 | spec.axes = [spec.axes[0]];
9 | spec.axes[0].grid = false;
10 |
11 | spec.data.push(
12 | {
13 | "name": "selectedPoints",
14 | "modify": [
15 | {"type": "clear", "test": "!multi"},
16 | {"type": "toggle", "signal": "clickedPoint", "field": "id"}
17 | ]
18 | });
19 |
20 | spec.signals.push( {
21 | "name": "clickedPoint",
22 | "init": 0,
23 | "verbose": true,
24 | "streams": [{"type": "click", "expr": "datum._id"}]
25 | },
26 | {
27 | "name": "multi",
28 | "init": false,
29 | "verbose": true,
30 | "streams": [{"type": "click", "expr": "datum._id"}]
31 | });
32 |
33 | var textMark = JSON.parse(JSON.stringify(spec.marks[0]));
34 | textMark.type = "text";
35 | textMark.properties.update.text = {"field" :spec.marks[0].properties.update.fill.field};
36 | textMark.properties.update.x.offset = 10;
37 | textMark.properties.update.y.offset = -5;
38 | textMark.properties.update.fill = {"value": config.legendTitleColor};
39 | delete textMark.properties.update.y2;
40 | delete textMark.properties.hover;
41 | spec.marks.push(textMark);
42 |
43 | delete spec.marks[0].properties.hover;
44 | spec.marks[0].properties.update.fill = [
45 | {
46 | "test": "indata('selectedPoints', datum._id, 'id')",
47 | "value": config.selectionColor
48 | },spec.marks[0].properties.update.fill
49 | ];
50 |
51 | this.barChart.setSpec(spec);
52 |
53 | };
54 |
55 | stack.prototype.draw = function(div, callbacks) {
56 | this.barChart.draw(div, callbacks);
57 | };
58 |
59 | stack.prototype.insert = function(data) {
60 | this.barChart.insert(data);
61 | };
62 |
63 | stack.prototype.getSpec = function() {
64 | return this.barChart.getSpec();
65 | };
66 |
67 |
--------------------------------------------------------------------------------
/pull_request_template.md:
--------------------------------------------------------------------------------
1 | ## Purpose
2 | > Describe the problems, issues, or needs driving this feature/fix and include links to related issues in the following format: Resolves issue1, issue2, etc.
3 |
4 | ## Goals
5 | > Describe the solutions that this feature/fix will introduce to resolve the problems described above
6 |
7 | ## Approach
8 | > Describe how you are implementing the solutions. Include an animated GIF or screenshot if the change affects the UI (email documentation@wso2.com to review all UI text). Include a link to a Markdown file or Google doc if the feature write-up is too long to paste here.
9 |
10 | ## User stories
11 | > Summary of user stories addressed by this change>
12 |
13 | ## Release note
14 | > Brief description of the new feature or bug fix as it will appear in the release notes
15 |
16 | ## Documentation
17 | > Link(s) to product documentation that addresses the changes of this PR. If no doc impact, enter “N/A” plus brief explanation of why there’s no doc impact
18 |
19 | ## Training
20 | > Link to the PR for changes to the training content in https://github.com/wso2/WSO2-Training, if applicable
21 |
22 | ## Certification
23 | > Type “Sent” when you have provided new/updated certification questions, plus four answers for each question (correct answer highlighted in bold), based on this change. Certification questions/answers should be sent to certification@wso2.com and NOT pasted in this PR. If there is no impact on certification exams, type “N/A” and explain why.
24 |
25 | ## Marketing
26 | > Link to drafts of marketing content that will describe and promote this feature, including product page changes, technical articles, blog posts, videos, etc., if applicable
27 |
28 | ## Automation tests
29 | - Unit tests
30 | > Code coverage information
31 | - Integration tests
32 | > Details about the test cases and coverage
33 |
34 | ## Security checks
35 | - Followed secure coding standards in http://wso2.com/technical-reports/wso2-secure-engineering-guidelines? yes/no
36 | - Ran FindSecurityBugs plugin and verified report? yes/no
37 | - Confirmed that this PR doesn't commit any keys, passwords, tokens, usernames, or other secrets? yes/no
38 |
39 | ## Samples
40 | > Provide high-level details about the samples related to this feature
41 |
42 | ## Related PRs
43 | > List any other related PRs
44 |
45 | ## Migrations (if applicable)
46 | > Describe migration steps and platforms on which migration has been tested
47 |
48 | ## Test environment
49 | > List all JDK versions, operating systems, databases, and browser/versions on which this feature/fix was tested
50 |
51 | ## Learning
52 | > Describe the research phase and any blog posts, patterns, libraries, or add-ons you used to solve the problem.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ##Overview
2 | VizGrammar is a wrapper around powerful d3.js and vega.js library. It makes charting easy by adding required boilerplate code so that developers/designers can get started in few minutes.
3 |
4 | A chart can be drawn in a given location by simply calling
5 | ```javascript
6 | var chart = new vizg(data, configSingle);
7 | chart.draw("#chartDiv");
8 | ```
9 | where
10 |
11 | - canvas is the div element which contains the gadget,
12 | - config is the additional gadget configurations specified as a JSON object
13 | - dataTable is the JSON object that holds the dataset in a tabular format
14 |
15 | ## Build Process
16 |
17 | To manually build VizGrammar, you need to have [npm](https://www.npmjs.com/) and [grunt](http://gruntjs.com/) installed.
18 |
19 | 1. Run `npm install` in the VizGrammar directory to install dependencies.
20 | 2. Run `grunt`, this will combine JS files and do the minification.
21 |
22 | ##Getting Started
23 | Download [d3.js](http://d3js.org/ "d3js.org") and [vega.js](http://vega.github.io/ "vega.github.io").
24 | Download the latest vizg.js.
25 |
26 | ##Documentation
27 | [VizGrammar Documentation](https://github.com/wso2/VizGrammar/wiki)
28 |
29 | ##Data table
30 | VizGrammar required you to arrange your source dataset in a tabular way similar to follwing JSON format.
31 | ```javascript
32 | {
33 | "metadata":{
34 | "names":["Column1","Column2",...],
35 | "types":['ordinal', 'linear',]
36 | },
37 | "data": [
38 | ["value1",numericValue1,...],
39 | ["value2",numericValue2,...],
40 | ]
41 | }
42 | ```
43 |
44 | Sample data table would be like following:
45 | ```javascript
46 | var data = [
47 | {
48 | "metadata" : {
49 | "names" : ["rpm","torque","horsepower", "EngineType"],
50 | "types" : ["linear","linear", "ordinal","ordinal"]
51 | },
52 | "data": [
53 | [8000, 75, 120, "Piston"], [9000, 81, 130, "Rotary"]]
54 | }
55 | ];
56 | ```
57 |
58 |
59 | metadata.names is an array consists of column names/fields of the table where metadata.types records their types (ordinal (C) or linear).
60 | names and types are aligned together in a way that "Coulmn1" => 'ordinal' and "Coulmn2" => 'linear' and so on.
61 |
62 | data section is a collection of arrays of data rows. Single row is stored as an array and their element order follows the order of metadata.names.
63 |
64 |
65 | ##Chart Config
66 |
67 | Once the data structure is ready, igviz will try to draw a table out of it.
68 |
69 | Users can add additional parameters to the gadget using config object. It is a JSON object that has well known configuration properties. For example, default table implementation can be changed to a bar chart by setting chartType property in the config object.
70 |
71 | E.g Following is the bare minimum set of configurations require to draw a bar chart from above tabular data format.
72 | ```javascript
73 | var config = {
74 | x : "rpm",
75 | charts : [{type: "line", y : "torque", color: "EngineType"}],
76 | maxLength: 10,
77 | width: 400,
78 | height: 200
79 | }
80 | ```
81 |
82 | ##Chart Canvas
83 |
84 | This is the div element where chart will be renedered on. VizGrammar accepts the id attribute of a div element formatted as "#chartDiv"
85 | ```javascript
86 | var chart = new vizg(data, configSingle);
87 | chart.draw("#chartDiv");
88 | ```
89 |
90 | ##Plot Chart
91 |
92 | Drawring a chart means simply calling
93 | ```javascript
94 | chart.insert([[8000, 74, 120, "Rotary"]]);
95 | ```
96 | with parameters. VizGrammar currently supports six chart types including table, bar,line, scatter and map. Single number chart and an area chart is still in development. Drill down capabilities will be added to bar chart later.
97 |
98 | Visit [VizGrammar Samples Web Site](http://dunithd.github.io/igviz-site/samples/index.html) to see sample chart types and their documentation. Please note that the documentation is still in progress :)
99 |
100 | You can also follow the samples folder so that you'll get a better idea.
101 |
102 |
103 |
--------------------------------------------------------------------------------
/samples/css/custom.css:
--------------------------------------------------------------------------------
1 | body {
2 | background: #1E2531;
3 | color: #fff;
4 | padding-top: 80px;
5 | }
6 |
7 | body.widget {
8 | background: transparent;
9 | }
10 |
11 | .jumbotron{
12 | background-color: #131820 !important;
13 | color: #636C7C !important;
14 | }
15 |
16 |
17 | .col-1,
18 | .col-2,
19 | .col-3,
20 | .col-4,
21 | .col-5,
22 | .panel,
23 | .panel-heading,
24 | .col-8,
25 | .col-9,
26 | .col-10,
27 | .col-11,
28 | .col-12 {
29 | background-color: #1E2531 !important;
30 | color: #636C7C !important;
31 |
32 | }
33 |
34 | .col-1 {
35 | width: 8.33333333%;
36 | }
37 |
38 | .col-2 {
39 | width: 16.66666667%;
40 | }
41 |
42 | .col-3 {
43 | width: 25%;
44 | }
45 |
46 | .col-4 {
47 | width: 33.33333333%;
48 | }
49 |
50 | .col-5 {
51 | width: 41.66666667%;
52 | }
53 |
54 | .col-6 {
55 | width: 50%;
56 | }
57 |
58 | .col-7 {
59 | width: 58.33333333%;
60 | }
61 |
62 | .col-8 {
63 | width: 66.66666667%;
64 | }
65 |
66 | .col-9 {
67 | width: 75%;
68 | }
69 |
70 | .col-10 {
71 | width: 83.33333333%;
72 | }
73 |
74 | .col-11 {
75 | width: 91.66666667%;
76 | }
77 |
78 | .col-12 {
79 | width: 100%;
80 | }
81 |
82 | .status-message {
83 | display: block;
84 | height: 100%;
85 | width: 100%;
86 | }
87 |
88 | .status-message > .message-info,
89 | .status-message > .message-warning,
90 | .status-message > .message-danger,
91 | .status-message > .message-success {
92 | position: fixed;
93 | z-index: 2;
94 | width: 100%;
95 | height: 100%;
96 | top: 50%;
97 | left: 50%;
98 | margin: 0;
99 | -webkit-transform: translate(-50%, -50%);
100 | -moz-transform: translate(-50%, -50%);
101 | -ms-transform: translate(-50%, -50%);
102 | -o-transform: translate(-50%, -50%);
103 | transform: translate(-50%, -50%);
104 | }
105 |
106 | /* Dark Theme Styles */
107 | body.dark .tt-hint {
108 | background: transparent !important;
109 | }
110 |
111 | body.dark .tt-input {
112 | border: 1px solid #6B7992 !important;
113 | color: #E3E5E6;
114 | }
115 |
116 | body.dark .form-control-btn {
117 | color: #E3E5E6;
118 | }
119 |
120 | body.dark #date-select .btn-default {
121 | background: #636C7C;
122 | color: #fff;
123 | border-color: #353C48;
124 | }
125 |
126 | body.dark #date-select .btn-default:hover, body.dark #date-select .btn-default[aria-expanded=true] {
127 | background: #1E2531;
128 | }
129 |
130 | #date-select .btn-default[aria-expanded=true] {
131 | background: #e6e6e6;
132 | }
133 |
134 | body.dark #date-select .btn-default.active, body.dark #date-select .btn-default.active:hover {
135 | background: #438CAD;
136 | border-color: #353C48;
137 | }
138 |
139 | body.dark .stats {
140 | color: #E3E5E6 !important;
141 | }
142 |
143 | body.dark .message {
144 | background: #1E2531;
145 | color: #E3E5E6 !important;
146 | }
147 |
148 | .breadcrumb {
149 | background: #1E2531;
150 | }
151 |
152 | .breadcrumb a:visited {
153 | color: #E3E5E6;
154 | }
155 |
156 | #canvas-tooltip {
157 | background: #c4c4c4 !important;
158 | color: #000;
159 | opacity: 0.9;
160 | font-size: 12px;
161 | }
162 |
163 | body.dark #canvas-tooltip {
164 | background: #000 !important;
165 | color: #fff;
166 | }
167 |
168 | /* DataTables issue fixing */
169 | .table {
170 | font-size: 14px;
171 | }
172 |
173 | div.dataTables_length select {
174 | background: transparent;
175 | }
176 |
177 | body.dark div.dataTables_length select {
178 | color: #fff;
179 | border-color: #353C48;
180 | }
181 |
182 | .dataTables_filter input {
183 | margin: 0 0 0 14px !important;
184 | background: transparent;
185 | padding: 0 5px;
186 | border: 1px solid #747F8F;
187 | }
188 |
189 | div.dataTables_length select option {
190 | color: #31383e;
191 | }
192 |
193 | div.dataTables_processing {
194 | background: transparent !important;
195 | padding-top: 30px !important;
196 | }
197 |
198 | .dataTablesBottom {
199 | margin: 20px 0 0 0;
200 | }
201 |
202 | .pagination > .active > a,
203 | .pagination > .active > a:focus,
204 | .pagination > .active > a:hover,
205 | .pagination > .active > span, .pagination >
206 | .active > span:focus,
207 | .pagination > .active > span:hover {
208 | background: #438CAD;
209 | border-color: #438CAD;
210 | }
211 |
212 | .pagination > li > a,
213 | .pagination > li > span {
214 | background: transparent;
215 | color: #353C48;
216 | }
217 |
218 | body.dark .pagination > li > a,
219 | body.dark .pagination > li > a:focus,
220 | body.dark .pagination > li > span,
221 | body.dark .pagination > li.active > span:hover,
222 | body.dark .pagination > li.active > a:hover {
223 | color: #E3E5E6;
224 | border-color: #353C48;
225 | }
226 |
227 | .pagination > li > span:hover,
228 | .pagination > li > a:hover {
229 | color: #353C48;
230 | }
231 |
232 | body[media-screen=xs] .hidden-xs,
233 | body[media-screen=sm] .hidden-sm,
234 | body[media-screen=md] .hidden-md,
235 | body[media-screen=lg] .hidden-lg {
236 | display: none !important;
237 | }
238 |
239 | body[media-screen=xs] .visible-xs,
240 | body[media-screen=sm] .visible-sm,
241 | body[media-screen=md] .visible-md,
242 | body[media-screen=lg] .visible-lg {
243 | display: block !important;
244 | }
245 |
246 | body[media-screen=xs] .visible-inline-xs,
247 | body[media-screen=sm] .visible-inline-sm,
248 | body[media-screen=md] .visible-inline-md,
249 | body[media-screen=lg] .visible-inline-lg {
250 | display: inline !important;
251 | }
252 |
253 | body[media-screen=xs] .visible-inline-block-xs,
254 | body[media-screen=sm] .visible-inline-block-sm,
255 | body[media-screen=md] .visible-inline-block-md,
256 | body[media-screen=lg] .visible-inline-block-lg {
257 | display: inline-block !important;
258 | }
--------------------------------------------------------------------------------
/charts/chart.table.js:
--------------------------------------------------------------------------------
1 |
2 | var table = function(dataTable, config) {
3 | this.metadata = dataTable[0].metadata;
4 | this.data = dataTable[0].values
5 | var marks =[];
6 | this.spec = {};
7 | config = checkConfig(config, this.metadata);
8 | this.config = config;
9 | dataTable[0].name= config.title;
10 |
11 | if (this.config.columnTitles == null) {
12 | this.config.columnTitles = this.config.columns;
13 | }
14 |
15 | };
16 |
17 | table.prototype.draw = function(div) {
18 | var table = d3.select(div).append("table")
19 | .attr( "class", "table table-bordered")
20 | .attr("id", this.config.title);
21 |
22 | // set up the table header
23 | table.append('thead').attr("align", "center")
24 | .append('tr')
25 | .selectAll('th')
26 | .data(this.config.columnTitles)
27 | .enter()
28 | .append('th')
29 | .html(function (d) { return d });
30 |
31 | table.append('tbody').attr("id", "tableChart-"+this.config.title);
32 | this.setupData(this.data, this.config);
33 |
34 | table.selectAll("thead th")
35 | .html(function(column) {
36 | return column.charAt(0).toUpperCase() + column.substr(1);
37 | });
38 |
39 |
40 | };
41 |
42 | table.prototype.insert = function(data) {
43 | this.setupData(data, this.config);
44 | };
45 |
46 |
47 | table.prototype.setupData = function (dataset, config) {
48 | var data = [];
49 | var allColumns = this.metadata.names;
50 |
51 | //Select specified columns from dataset
52 | for (var i = 0; i < dataset.length; i++) {
53 | var row = {};
54 |
55 | for (var x = 0; x < config.columns.length; x++) {
56 | row[config.columns[x]] = dataset[i][config.columns[x]];
57 | }
58 | data.push(row);
59 | }
60 |
61 | //Select Rows by x Axis
62 | var rows = d3.select('#tableChart-'+config.title)
63 | .selectAll('tr')
64 | .data(data, function(d) { return d[config.key]})
65 |
66 | var entertd = rows.enter()
67 | .append('tr')
68 | .selectAll('td')
69 | .data(function(row) {
70 | return config.columns.map(function(column) {
71 | return {column: column, value: row[column]};
72 | });
73 | })
74 | .enter()
75 | .append('td')
76 |
77 | //Color cell background
78 | if (config.color != -1) {
79 | d3.select('#tableChart-'+config.title)
80 | .selectAll('td')
81 | .attr('bgcolor',
82 | function(d) {
83 | var column = d.key || d.column;
84 |
85 | var color;
86 | if (typeof config.colorScale == "string") {
87 | color = window["d3"]["scale"][config.colorScale]().range();
88 | } else {
89 | color = config.colorScale;
90 | }
91 |
92 | var colorIndex;
93 | for(var i = 0; i < allColumns.length; i += 1) {
94 | if(allColumns[i] === column) {
95 | colorIndex = i;
96 | }
97 | }
98 |
99 | if (typeof d.value == "string" && (config.color == "*" || column == allColumns[config.color])) {
100 |
101 | var colorDomain;
102 |
103 | if (config.colorDomain == -1) {
104 | colorDomain = [d3.min(d3.select('#tableChart-'+config.title) .selectAll('tr') .data(), function(d) { return d[column]; }),
105 | d3.max(d3.select('#tableChart-'+config.title) .selectAll('tr') .data(), function(d) { return d[column]; })]
106 |
107 | } else {
108 | colorDomain = config.colorDomain
109 | }
110 |
111 | var color;
112 | if (typeof config.colorScale == "string") {
113 | color = window["d3"]["scale"][config.colorScale]().range();
114 | } else {
115 | color = config.colorScale;
116 | }
117 |
118 | var colorScale = d3.scale.ordinal()
119 | .range(color)
120 | .domain(colorDomain);
121 | return colorScale(d.value);
122 |
123 | } else if (config.color == "*" || column == allColumns[config.color]){
124 |
125 | var colorScale = d3.scale.linear()
126 | .range(['#f2f2f2', color[colorIndex]])
127 | .domain([d3.min(d3.select('#tableChart-'+config.title) .selectAll('tr') .data(), function(d) { return d[column]; }),
128 | d3.max(d3.select('#tableChart-'+config.title) .selectAll('tr') .data(), function(d) { return d[column]; })]
129 | );
130 |
131 | return colorScale(d.value);
132 | }
133 |
134 | });
135 | }
136 |
137 |
138 |
139 | entertd.append('span')
140 | var td = rows.selectAll('td')
141 | .style({"padding": "0px 10px 0px 10px"})
142 |
143 | .data(function(d) { return d3.map(d).entries() })
144 | .attr('class', function (d) { return d.key })
145 |
146 |
147 |
148 |
149 | td.select('span')
150 | .html(function(d) {
151 | return d.value
152 | })
153 | //Remove data items when it hits maxLength
154 | if (config.maxLength != -1 && d3.select('tbody').selectAll('tr').data().length > config.maxLength) {
155 | var allowedDataset = d3.select('tbody').selectAll('tr').data().slice(d3.select('tbody').selectAll('tr').data().length- config.maxLength, config.maxLength);
156 | d3.select('tbody').selectAll('tr').data(allowedDataset,
157 | function(d) {
158 | return(d);
159 | })
160 | .remove();
161 | }
162 | }
--------------------------------------------------------------------------------
/charts/chart.line.js:
--------------------------------------------------------------------------------
1 |
2 | var line = function(dataTable, config) {
3 | this.metadata = dataTable[0].metadata;
4 | var marks =[];
5 | var signals = [];
6 | this.spec = {};
7 |
8 | config = checkConfig(config, this.metadata);
9 | this.config = config;
10 | dataTable[0].name= config.title;
11 |
12 | var scales = getXYScales(config, this.metadata);
13 |
14 | if (config.mode == "stack") {
15 | var aggregateData = {
16 | "name": "stack",
17 | "source": config.title,
18 | "transform": [
19 | {
20 | "type": "aggregate",
21 | "groupby": [this.metadata.names[config.x]],
22 | "summarize": [{"field": this.metadata.names[config.y], "ops": ["sum"]}]
23 | }
24 | ]
25 | };
26 |
27 | dataTable.push(aggregateData);
28 | yColumn = "sum_"+ this.metadata.names[config.y];
29 | yDomain = "stack";
30 |
31 | scales[1].domain = {"data": yDomain, "field": yColumn};
32 |
33 | }
34 |
35 |
36 |
37 | if (config.color != -1) {
38 |
39 | if (config.colorDomain == -1) {
40 | config.colorDomain = {"data": config.title, "field": this.metadata.names[config.color]};
41 | }
42 |
43 | var colorScale = {
44 | "name": "color",
45 | "type": "ordinal",
46 | "domain": config.colorDomain,
47 | "range": config.colorScale
48 | };
49 | scales.push(colorScale);
50 |
51 | var legendTitle = "Legend";
52 |
53 | if (config.title != "table") {
54 | legendTitle = config.title;
55 | }
56 |
57 | if (this.config.legend) {
58 | this.spec.legends = getLegend(this.config);
59 | }
60 | }
61 |
62 |
63 | var axes = getXYAxes(config, "x", "x", "y", "y");
64 |
65 |
66 | marks.push(getLineMark(config, this.metadata));
67 | config.fillOpacity = 0;
68 | config.markSize = 1000;
69 | marks.push(getSymbolMark(config, this.metadata));
70 | config.fillOpacity = 1;
71 | config.markSize = 15;
72 | marks.push(getSymbolMark(config, this.metadata));
73 |
74 | if (config.range) {
75 | signals = getRangeSignals(config, signals);
76 | marks = getRangeMark(config, marks);
77 | }
78 |
79 | this.spec.width = config.width;
80 | this.spec.height = config.height;
81 | this.spec.axes = axes;
82 | this.spec.data = dataTable;
83 | this.spec.scales = scales;
84 | this.spec.padding = config.padding;
85 | this.spec.marks = marks;
86 | this.spec.signals = signals;
87 | };
88 |
89 | line.prototype.draw = function(div, callbacks) {
90 |
91 | if(this.config.maxLength != -1){
92 | var dataset = this.spec.data[0].values;
93 | var maxValue = this.config.maxLength;
94 | if(dataset.length >= this.config.maxLength){
95 | var allowedDataSet = [];
96 | var startingPoint = dataset.length - maxValue;
97 | for(var i = startingPoint; i < dataset.length;i++){
98 | allowedDataSet.push(dataset[i]);
99 | }
100 | this.spec.data[0].values = allowedDataSet;
101 | }
102 | }
103 |
104 | drawChart(div, this, callbacks);
105 |
106 | };
107 |
108 | line.prototype.insert = function(data) {
109 | //Removing events when max value is enabled
110 | if (this.config.maxLength != -1 && this.config.maxLength < (this.view.data(this.config.title).values().length + data.length)) {
111 | var removeFunction = (function(d) {
112 | return d[this.metadata.names[this.config.x]] == oldData;
113 | }).bind(this);
114 |
115 | for (i = 0; i < data.length; i++) {
116 | var oldData = this.view.data(this.config.title).values()[i][this.metadata.names[this.config.x]];
117 | this.view.data(this.config.title).remove(removeFunction);
118 | }
119 | }
120 |
121 | this.view.data(this.config.title).insert(data);
122 | this.view.update();
123 | };
124 |
125 | line.prototype.getSpec = function() {
126 | return this.spec;
127 | };
128 |
129 |
130 | function getLineMark(config, metadata){
131 | interpolation = "linear";
132 | if (config.interpolation){
133 | interpolation = config.interpolation;
134 | }
135 |
136 | var mark;
137 | if (config.color != -1 && config.mode == "stack") {
138 | mark = {
139 | "type": "group",
140 | "from": {
141 | "data": config.title,
142 | "transform": [
143 | {"type": "stack", "groupby": [metadata.names[config.x]], "sortby": [metadata.names[config.color]], "field": metadata.names[config.y]},
144 | {"type": "facet", "groupby": [metadata.names[config.color]]}
145 | ]
146 | },
147 | "marks": [
148 | {
149 | "type": "line",
150 | "properties": {
151 | "update": {
152 | "x": {"scale": "x", "field": metadata.names[config.x]},
153 | "y": {"scale": "y", "field": "layout_start"},
154 | "y2": {"scale": "y", "field": "layout_end"},
155 | "stroke": {"scale": "color", "field": metadata.names[config.color]},
156 | "strokeWidth": {"value": 2},
157 | "interpolate": {"value": interpolation}
158 | },
159 | "hover": {
160 | "strokeOpacity": {"value": 0.5}
161 | }
162 | }
163 | }
164 | ]
165 | };
166 | } else if (config.color != -1) {
167 | mark = {
168 | "type": "group",
169 | "from": {
170 | "data": config.title,
171 | "transform": [{"type": "facet", "groupby": [metadata.names[config.color]]}]
172 | },
173 | "marks": [
174 | {
175 | "type": "line",
176 | "properties": {
177 | "update": {
178 | "x": {"scale": "x", "field": metadata.names[config.x]},
179 | "y": {"scale": "y", "field": metadata.names[config.y]},
180 | "stroke": {"scale": "color", "field": metadata.names[config.color]},
181 | "strokeWidth": {"value": 2},
182 | "interpolate": {"value": interpolation}
183 | },
184 | "hover": {
185 | "strokeOpacity": {"value": 0.5}
186 | }
187 | }
188 | }
189 | ]
190 | };
191 |
192 | } else{
193 | mark = {
194 | "type": "line",
195 | "from": {"data": config.title},
196 | "properties": {
197 | "update": {
198 |
199 | "x": {"scale": "x", "field": metadata.names[config.x]},
200 | "y": {"scale": "y", "field": metadata.names[config.y]},
201 | "stroke": { "value": config.markColor},
202 | "strokeWidth": {"value": 2},
203 | "interpolate": {"value": interpolation}
204 | },
205 | "hover": {
206 | "fillOpacity": {"value": 0.5}
207 | }
208 | }
209 | };
210 | }
211 |
212 |
213 | return mark;
214 | }
215 |
216 |
--------------------------------------------------------------------------------
/charts/chart.area.js:
--------------------------------------------------------------------------------
1 |
2 | var area = function(dataTable, config) {
3 | this.metadata = dataTable[0].metadata;
4 | var marks =[];
5 | var signals = [];
6 | this.spec = {};
7 |
8 | config = checkConfig(config, this.metadata);
9 | this.config = config;
10 | dataTable[0].name= config.title;
11 |
12 | var scales = getXYScales(config, this.metadata);
13 |
14 | if (config.mode == "stack") {
15 | var aggregateData = {
16 | "name": "stack",
17 | "source": config.title,
18 | "transform": [
19 | {
20 | "type": "aggregate",
21 | "groupby": [this.metadata.names[config.x]],
22 | "summarize": [{"field": this.metadata.names[config.y], "ops": ["sum"]}]
23 | }
24 | ]
25 | };
26 |
27 | dataTable.push(aggregateData);
28 | yColumn = "sum_"+ this.metadata.names[config.y];
29 | yDomain = "stack";
30 |
31 | scales[1].domain = {"data": yDomain, "field": yColumn};
32 |
33 | }
34 |
35 |
36 | //Make Y scale zero false as area should filled to minimum value
37 | delete scales[1].zero;
38 |
39 | if (config.color != -1) {
40 |
41 | if (config.colorDomain == -1) {
42 | config.colorDomain = {"data": config.title, "field": this.metadata.names[config.color]};
43 | }
44 |
45 | var colorScale = {
46 | "name": "color",
47 | "type": "ordinal",
48 | "domain": config.colorDomain,
49 | "range": config.colorScale
50 | };
51 | scales.push(colorScale);
52 |
53 | var legendTitle = "Legend";
54 |
55 | if (config.title != "table") {
56 | legendTitle = config.title;
57 | }
58 |
59 | if (this.config.legend) {
60 | this.spec.legends = getLegend(this.config);
61 | }
62 | }
63 |
64 |
65 | var axes = getXYAxes(config, "x", "x", "y", "y");
66 |
67 |
68 | marks.push(getLineMark(config, this.metadata));
69 |
70 | config.fillOpacity = 0.7;
71 | marks.push(getAreaMark(config, this.metadata));
72 | config.fillOpacity = 0;
73 | config.markSize = 1000;
74 | marks.push(getSymbolMark(config, this.metadata));
75 | config.fillOpacity = 1;
76 | config.markSize = 15;
77 | marks.push(getSymbolMark(config, this.metadata));
78 |
79 | if (config.range) {
80 | signals = getRangeSignals(config, signals);
81 | marks = getRangeMark(config, marks);
82 | }
83 |
84 | this.spec.width = config.width;
85 | this.spec.height = config.height;
86 | this.spec.axes = axes;
87 | this.spec.data = dataTable;
88 | this.spec.scales = scales;
89 | this.spec.padding = config.padding;
90 | this.spec.marks = marks;
91 | this.spec.signals = signals;
92 | };
93 |
94 | area.prototype.draw = function(div, callbacks) {
95 |
96 | if(this.config.maxLength != -1){
97 | var dataset = this.spec.data[0].values;
98 | var maxValue = this.config.maxLength;
99 | if(dataset.length >= this.config.maxLength){
100 | var allowedDataSet = [];
101 | var startingPoint = dataset.length - maxValue;
102 | for(var i = startingPoint; i < dataset.length;i++){
103 | allowedDataSet.push(dataset[i]);
104 | }
105 | this.spec.data[0].values = allowedDataSet;
106 | }
107 | }
108 |
109 | drawChart(div, this, callbacks);
110 |
111 | };
112 |
113 | area.prototype.insert = function(data) {
114 | //Removing events when max value is enabled
115 | if (this.config.maxLength != -1 && this.config.maxLength < (this.view.data(this.config.title).values().length + data.length)) {
116 | var removeFunction = (function(d) {
117 | return d[this.metadata.names[this.config.x]] == oldData;
118 | }).bind(this);
119 |
120 | for (i = 0; i < data.length; i++) {
121 | var oldData = this.view.data(this.config.title).values()[i][this.metadata.names[this.config.x]];
122 | this.view.data(this.config.title).remove(removeFunction);
123 | }
124 | }
125 |
126 | this.view.data(this.config.title).insert(data);
127 | this.view.update();
128 | };
129 |
130 | area.prototype.getSpec = function() {
131 | return this.spec;
132 | };
133 |
134 |
135 | function getAreaMark(config, metadata){
136 | interpolation = "linear";
137 | if (config.interpolation){
138 | interpolation = config.interpolation;
139 | }
140 |
141 | var mark;
142 | if (config.color != -1 && config.mode == "stack") {
143 | mark = {
144 | "type": "group",
145 | "from": {
146 | "data": config.title,
147 | "transform": [
148 | {"type": "stack", "groupby": [metadata.names[config.x]], "sortby": [metadata.names[config.color]], "field": metadata.names[config.y]},
149 | {"type": "facet", "groupby": [metadata.names[config.color]]}
150 | ]
151 | },
152 | "marks": [
153 | {
154 | "type": "area",
155 | "properties": {
156 | "update": {
157 | "x": {"scale": "x", "field": metadata.names[config.x]},
158 | "y": {"scale": "y", "field": "layout_start"},
159 | "y2": {"scale": "y", "field": "layout_end"},
160 | "fill": {"scale": "color", "field": metadata.names[config.color]},
161 | "strokeWidth": {"value": 2},
162 | "fillOpacity": {"value": config.fillOpacity},
163 | "interpolate": {"value": interpolation}
164 | },
165 | "hover": {
166 | "strokeOpacity": {"value": 0.5}
167 | }
168 | }
169 | }
170 | ]
171 | };
172 | } else if (config.color != -1) {
173 | mark = {
174 | "type": "group",
175 | "from": {
176 | "data": config.title,
177 | "transform": [{"type": "facet", "groupby": [metadata.names[config.color]]}]
178 | },
179 | "marks": [
180 | {
181 | "type": "area",
182 | "properties": {
183 | "update": {
184 | "x": {"scale": "x", "field": metadata.names[config.x]},
185 | "y": {"scale": "y", "field": metadata.names[config.y]},
186 | "y2": {"scale": "y", "value": 0},
187 | "fill": {"scale": "color", "field": metadata.names[config.color]},
188 | "strokeWidth": {"value": 2},
189 | "fillOpacity": {"value": config.fillOpacity},
190 | "interpolate": {"value": interpolation}
191 | },
192 | "hover": {
193 | "strokeOpacity": {"value": 0.5}
194 | }
195 | }
196 | }
197 | ]
198 | };
199 |
200 | } else{
201 | mark = {
202 | "type": "area",
203 | "from": {"data": config.title},
204 | "properties": {
205 | "update": {
206 |
207 | "x": {"scale": "x", "field": metadata.names[config.x]},
208 | "y": {"scale": "y", "field": metadata.names[config.y]},
209 | "y2": {"scale": "y", "value": 0},
210 | "fill": { "value": config.markColor},
211 | "strokeWidth": {"value": 2},
212 | "fillOpacity": {"value": config.fillOpacity},
213 | "interpolate": {"value": interpolation}
214 | },
215 | "hover": {
216 | "fillOpacity": {"value": 0.5}
217 | }
218 | }
219 | };
220 | }
221 |
222 |
223 | return mark;
224 | }
225 |
226 |
--------------------------------------------------------------------------------
/samples/charts/number/index.html:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | VizGrammar.js - Number Chart Sample
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 | Number Chart Sample
74 |
75 |
76 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 | Data Collection
88 |
89 |
90 |
91 |
92 |
93 | {
94 | "metadata" : {
95 | "names" : ["rpm","torque","horsepower", "EngineType"],
96 | "types" : ["linear","linear", "ordinal","ordinal"]
97 | },
98 | "data": [
99 | [0, 10, 1, "Piston"]]
100 | };
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 | Configurations
117 |
118 |
119 |
120 |
121 | {
122 | x : "rpm",
123 | title :"Torque of Engine",
124 | charts : [{type: "number"}],
125 | width: 400,
126 | height: 200
127 | }
128 |
129 |
130 |
131 |
132 |
133 | Property
134 | Value
135 | Description
136 |
137 |
138 |
139 |
140 | title
141 | String
142 | Title of the table
143 |
144 |
145 | x
146 | String
147 | cAttribute name for X-axis
148 |
149 |
150 | height
151 | px
152 | height of the chart
153 |
154 |
155 |
156 |
157 | charts
158 | object
159 | Collection of charts
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 | Property
169 | Value
170 | Description
171 |
172 |
173 |
174 |
175 | type
176 | String
177 | Title of the table
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
221 |
222 |
223 |
224 |
225 |
226 |
231 |
232 |
233 |
--------------------------------------------------------------------------------
/samples/charts/scatter/index.html:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | VizGrammar.js - Scatter Plot Chart Sample
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 | Scatter Plot Chart Sample
73 |
74 |
75 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 | Data Collection
87 |
88 |
89 |
90 |
91 |
92 | {
93 | "metadata" : {
94 | "names" : ["rpm","torque","horsepower", "weight", "EngineType"],
95 | "types" : ["linear","linear", "linear","linear", "ordinal"]
96 | },
97 | "data": [
98 | [1,41600,3.5,79.91,0.8,0.03,"Piston"],
99 | [2,37800,3.5,79.65,1.3,0.06,"Piston"]
100 | };
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 | Configurations
117 |
118 |
119 |
120 |
121 | {
122 | type: "scatter",
123 | charts : [
124 | {type: "scatter",
125 | x : "rpm",
126 | y : "torque",
127 | color: "horsepower",
128 | size : "weight",
129 | maxLength: 30}],
130 |
131 | width: 400,
132 | height: 200
133 | }
134 |
135 |
136 |
137 |
138 |
139 | Property
140 | Value
141 | Description
142 |
143 |
144 |
145 |
146 | title
147 | String
148 | Title of the table
149 |
150 |
151 | x
152 | String
153 | cAttribute name for X-axis
154 |
155 |
156 | maxLength
157 | int
158 | Maximum length of chart datatable
159 |
160 |
161 |
162 |
163 | height
164 | px
165 | height of the chart
166 |
167 |
168 |
169 |
170 | charts
171 | object
172 | Collection of charts
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 | Property
182 | Value
183 | Description
184 |
185 |
186 |
187 |
188 | type
189 | String
190 | Title of the table
191 |
192 |
193 | y
194 | String
195 | Attribute name for Y-axis
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
253 |
254 |
255 |
256 |
257 |
258 |
263 |
264 |
265 |
--------------------------------------------------------------------------------
/charts/chart.scatter.js:
--------------------------------------------------------------------------------
1 | var scatter = function(dataTable, config) {
2 |
3 | this.metadata = dataTable[0].metadata;
4 | var marks = [];
5 | var signals ;
6 | this.spec = {};
7 |
8 | config = checkConfig(config, this.metadata);
9 | this.config = config;
10 | dataTable[0].name = config.title;
11 |
12 | var rScale = {
13 | "name": "size",
14 | "type": "linear",
15 | "range": [0,576],
16 | "domain": {"data": config.title, "field": this.metadata.names[config.size]}
17 | };
18 |
19 | var cScale = {
20 | "name": "color",
21 | "type": this.metadata.types[config.color],
22 | "range": config.colorScale,
23 | "domain": {"data": config.title, "field": this.metadata.names[config.color]}
24 | };
25 |
26 | var scales = getXYScales(config, this.metadata);
27 | scales.push(rScale);
28 | scales.push(cScale);
29 |
30 | var axes = getXYAxes(config, "x", "x", "y", "y");
31 |
32 | marks.push(getScatterMark(config, this.metadata));
33 |
34 | if (this.config.legend
35 | && this.metadata.types[config.color] != "linear") {
36 | this.spec.legends = getLegend(this.config);
37 | }
38 |
39 | this.spec.width = config.width;
40 | this.spec.height = config.height;
41 | this.spec.axes = axes;
42 | this.spec.data = dataTable;
43 | this.spec.scales = scales;
44 | this.spec.padding = config.padding;
45 | this.spec.marks = marks;
46 |
47 | };
48 |
49 | scatter.prototype.draw = function(div, callbacks) {
50 | var viewUpdateFunction = (function(chart) {
51 | if(this.config.tooltip.enabled){
52 | createTooltip(div);
53 | this.view = chart({el:div}).renderer(this.config.renderer).update();
54 | bindTooltip(div,this.view,this.config,this.metadata);
55 | } else {
56 | this.view = chart({el:div}).renderer(this.config.renderer).update();
57 | }
58 | if (callbacks != null) {
59 | for (var i = 0; i= this.config.maxLength){
70 | var allowedDataSet = [];
71 | var startingPoint = dataset.length - maxValue;
72 | for(var i = startingPoint; i < dataset.length;i++){
73 | allowedDataSet.push(dataset[i]);
74 | }
75 | this.spec.data[0].values = allowedDataSet;
76 | }
77 | }
78 |
79 | vg.parse.spec(this.spec, viewUpdateFunction);
80 | };
81 |
82 | scatter.prototype.insert = function(data) {
83 |
84 | var xAxis = this.metadata.names[this.config.x];
85 | var yAxis = this.metadata.names[this.config.y];
86 | var size = this.metadata.names[this.config.size];
87 | var color = this.metadata.names[this.config.color];
88 |
89 | if (this.config.maxLength != -1 && this.config.maxLength < (this.view.data(this.config.title).values().length + data.length)) {
90 |
91 | var allDataSet = this.view.data(this.config.title).values().concat(data);
92 | var allowedRemovableDataSet = [];
93 | for (i = 0; i < allDataSet.length - this.config.maxLength; i++) {
94 | allowedRemovableDataSet.push(this.view.data(this.config.title).values()[i][xAxis]);
95 | }
96 |
97 | for (i = 0; i < data.length; i++) {
98 | var isValueMatched = false;
99 | this.view.data(this.config.title).update(function(d) {
100 | return d[xAxis] == data[i][xAxis]; },
101 | yAxis,
102 | function(d) {
103 | isValueMatched = true;
104 | return data[i][yAxis];
105 | });
106 |
107 | this.view.data(this.config.title).update(function(d) {
108 | return d[xAxis] == data[i][xAxis]; },
109 | color,
110 | function(d) {
111 | isValueMatched = true;
112 | return data[i][color];
113 | });
114 |
115 | this.view.data(this.config.title).update(function(d) {
116 | return d[xAxis] == data[i][xAxis]; },
117 | size,
118 | function(d) {
119 | isValueMatched = true;
120 | return data[i][size];
121 | });
122 |
123 | if(isValueMatched){
124 | var isIndexRemoved = false;
125 |
126 | var index = allowedRemovableDataSet.indexOf(data[i][xAxis]);
127 | if (index > -1) {
128 | // updated value matched in allowed removable values
129 | isIndexRemoved = true;
130 | allowedRemovableDataSet.splice(index, 1);
131 | }
132 |
133 | if(!isIndexRemoved){
134 | // updated value NOT matched in allowed removable values
135 | allowedRemovableDataSet.splice((allowedRemovableDataSet.length - 1), 1);
136 | }
137 |
138 | } else {
139 | //insert the new data
140 | this.view.data(this.config.title).insert([data[i]]);
141 | this.view.update();
142 | }
143 | }
144 |
145 | var oldData;
146 | var removeFunction = function(d) {
147 | return d[xAxis] == oldData;
148 | };
149 |
150 | for (i = 0; i < allowedRemovableDataSet.length; i++) {
151 | oldData = allowedRemovableDataSet[i];
152 | this.view.data(this.config.title).remove(removeFunction);
153 | }
154 | } else{
155 | for (i = 0; i < data.length; i++) {
156 | var isValueMatched = false;
157 | this.view.data(this.config.title).update(function(d) {
158 | return d[xAxis] == data[i][xAxis]; },
159 | yAxis,
160 | function(d) {
161 | isValueMatched = true;
162 | return data[i][yAxis];
163 | });
164 |
165 | this.view.data(this.config.title).update(function(d) {
166 | return d[xAxis] == data[i][xAxis]; },
167 | color,
168 | function(d) {
169 | isValueMatched = true;
170 | return data[i][color];
171 | });
172 |
173 | this.view.data(this.config.title).update(function(d) {
174 | return d[xAxis] == data[i][xAxis]; },
175 | size,
176 | function(d) {
177 | isValueMatched = true;
178 | return data[i][size];
179 | });
180 |
181 | if(!isValueMatched){
182 | this.view.data(this.config.title).insert([data[i]]);
183 | }
184 | }
185 | }
186 | this.view.update({duration: 200});
187 | };
188 |
189 | scatter.prototype.getSpec = function() {
190 | return this.spec;
191 | };
192 |
193 |
194 | function getScatterMark(config, metadata){
195 | var fill;
196 | var size;
197 |
198 | if (config.color == -1) {
199 | fill = {"value": config.markColor};
200 | } else {
201 | fill = {"scale": "color", "field": metadata.names[config.color]};
202 | }
203 |
204 | if (config.size == -1) {
205 | size = {"value": config.markSize * 50};
206 | } else {
207 | size = {"scale":"size","field":metadata.names[config.size]};
208 | }
209 |
210 | var mark = {
211 |
212 | "type": "symbol",
213 | "from": {"data": config.title},
214 | "properties": {
215 | "update": {
216 | "x": {"scale": "x", "field": metadata.names[config.x]},
217 | "y": {"scale": "y", "field": metadata.names[config.y]},
218 | "fill": fill,
219 | "size": size,
220 | "fillOpacity": {"value": 1}
221 | },
222 | "hover": {
223 | "fillOpacity": {"value": 0.5},
224 | "cursor": {"value": config.hoverCursor}
225 | }
226 | }
227 |
228 | }
229 | ;
230 |
231 |
232 | return mark;
233 | }
234 |
235 | function getScatterToolTipMark(config, metadata) {
236 | config.toolTip.height = 50;
237 | config.toolTip.y = -50;
238 |
239 | var mark = getToolTipMark(config, metadata);
240 | var sizeText = {
241 | "type": "text",
242 | "properties": {
243 | "update": {
244 | "x": {"value": 6},
245 | "y": {"value": 44},
246 | "text": {"template": "Size \t (" + metadata.names[config.size] + ") \t {{hover." + metadata.names[config.size] + "}}"},
247 | "fill": {"value": "black"}
248 | }
249 | }
250 | };
251 | mark.marks.push(sizeText);
252 | return mark;
253 | }
254 |
--------------------------------------------------------------------------------
/charts/chart.arc.js:
--------------------------------------------------------------------------------
1 |
2 | var arc = function(dataTable, config) {
3 | this.metadata = dataTable[0].metadata;
4 | var marks =[];
5 | this.spec = {};
6 |
7 | config = checkConfig(config, this.metadata);
8 | this.config = config;
9 | dataTable[0].name= config.title;
10 |
11 | var summarize = {};
12 | summarize[this.metadata.names[config.x]] = "sum";
13 |
14 | dataTable.push({
15 | "name": "summary",
16 | "source": config.title,
17 | "transform": [
18 | {
19 | "type": "aggregate",
20 | "summarize": summarize
21 | }
22 | ]
23 | });
24 |
25 | dataTable.push( {
26 | "name": "layout",
27 | "source": "table",
28 | "transform": [
29 | {"type": "cross", "with": "summary"},
30 | {"type": "pie","field": "a." + this.metadata.names[config.x]},
31 | {
32 | "type": "formula",
33 | "field": "percentage",
34 | "expr": "datum.a."+this.metadata.names[config.x]
35 | +" / datum.b.sum_"+this.metadata.names[config.x]+" * 100"
36 | }
37 | ]
38 | });
39 |
40 | var scales = [];
41 |
42 | if (config.colorDomain == -1) {
43 | config.colorDomain = {"data": config.title, "field": this.metadata.names[config.color]};
44 | }
45 |
46 |
47 | var colorScale = {
48 | "name": "color",
49 | "type": "ordinal",
50 | "domain": config.colorDomain,
51 | "range": config.colorScale
52 | };
53 | scales.push(colorScale);
54 |
55 |
56 | if (config.percentage &&
57 | (config.mode == "pie" || config.mode == "donut")) {
58 | marks.push(getPieText(config, this.metadata));
59 | } else if (config.percentage) {
60 | //Push complimentary value to fill the arc
61 | dataTable.push(
62 | {
63 | "name": "arc",
64 | "values": [{"type": "YES"}]
65 | });
66 | marks.push(getPieMidText(config, this.metadata));
67 | }
68 |
69 | marks.push(getPieMark(config, this.metadata));
70 |
71 | var legendTitle = "Legend";
72 |
73 | if (config.title != "table") {
74 | legendTitle = config.title;
75 | }
76 |
77 | if (this.config.legend) {
78 | this.spec.legends = getLegend(this.config);
79 | }
80 |
81 | this.spec.width = config.width;
82 | this.spec.height = config.height;
83 | this.spec.data = dataTable;
84 | this.spec.scales = scales;
85 | this.spec.padding = config.padding;
86 | this.spec.marks = marks;
87 | };
88 |
89 | arc.prototype.draw = function(div, callbacks) {
90 |
91 | var viewUpdateFunction = (function(chart) {
92 | if(this.config.tooltip.enabled){
93 | this.config.tooltip.type = "arc";
94 | createTooltip(div);
95 | this.view = chart({el:div}).renderer(this.config.renderer).update();
96 | bindTooltip(div,this.view,this.config,this.metadata);
97 | } else {
98 | this.view = chart({el:div}).renderer(this.config.renderer).update();
99 | }
100 |
101 | if (callbacks != null) {
102 | for (var i = 0; i= this.config.maxLength){
113 | var allowedDataSet = [];
114 | var startingPoint = dataset.length - maxValue;
115 | for(var i = startingPoint; i < dataset.length;i++){
116 | allowedDataSet.push(dataset[i]);
117 | }
118 | this.spec.data[0].values = allowedDataSet;
119 | }
120 | }
121 |
122 | vg.parse.spec(this.spec, viewUpdateFunction);
123 | };
124 |
125 | arc.prototype.insert = function(data) {
126 |
127 | var color = this.metadata.names[this.config.color];
128 | var x = this.metadata.names[this.config.x];
129 | var view =this.view;
130 |
131 |
132 |
133 | var updated = false;
134 |
135 | for (i = 0; i < data.length; i++) {
136 | this.view.data(this.config.title)
137 | .update(
138 | function(d) {
139 | return d[color] == data[i][color];
140 | },
141 | x,
142 | function(d) {
143 | updated = true;
144 | return data[i][x];
145 | });
146 | }
147 |
148 | if (updated == false) {
149 | view.data(this.config.title).insert(data);
150 | }
151 |
152 | this.view.update({duration: 500});
153 | };
154 |
155 | arc.prototype.getSpec = function() {
156 | return this.spec;
157 | };
158 |
159 |
160 | function getPieMark(config, metadata){
161 | var innerRadius;
162 | if (config.mode == "donut") {
163 | var innerRadius = config.height / 5 * ( 1 + config.innerRadius);
164 | } else if (config.mode == "pie") {
165 | var innerRadius = 0;
166 | } else {
167 | config.innerRadius += 0.5;
168 | var innerRadius = config.height / 5 * ( 1 + config.innerRadius);
169 | }
170 |
171 | var title = config.title;
172 | var fieldAlias = ""
173 |
174 | if (config.type != null) {
175 | title = "layout";
176 | fieldAlias = "a.";
177 | }
178 |
179 | var mark = {
180 | "type": "arc",
181 | "from": {"data": title},
182 | "properties": {
183 | "update": {
184 | "x": {"field": {"group": "width"}, "mult": 0.5},
185 | "y": {"field": {"group": "height"}, "mult": 0.5},
186 | "startAngle": {"field": "layout_start"},
187 | "endAngle": {"field": "layout_end"},
188 | "innerRadius": {"value": innerRadius},
189 | "outerRadius": {"value": config.height * 0.4},
190 | "fill": {"scale": "color", "field": fieldAlias + metadata.names[config.color]},
191 | "fillOpacity": {"value": 1}
192 | },
193 |
194 | "hover": {
195 | "fillOpacity": {"value": 0.8},
196 | "cursor": {"value": config.hoverCursor}
197 | }
198 | }
199 | };
200 |
201 | return mark;
202 | };
203 | function getPieMidText(config, metadata){
204 | var mark = {
205 | "type": "text",
206 | "from": {"data": "layout"},
207 | "properties": {
208 | "update": {
209 | "x": {"field": {"group": "width"}, "mult": 0.5},
210 | "y": {"field": {"group": "height"}, "mult": 0.5},
211 | "radius": { "value": 0},
212 | "theta": {"field": "layout_mid"},
213 | "fill": [
214 | {
215 | "test": "indata('arc', datum.a."+metadata.names[config.color]+", 'type')",
216 | "scale": "color", "field": metadata.names[config.color]
217 | },
218 | {}
219 | ],
220 | "align": {"value": "center"},
221 | "baseline": {"value": "middle"},
222 | "fontSize":{"value": config.height/9},
223 | "text": {"template": "{{datum.percentage | number:'.2f'}}%"}
224 |
225 | }
226 | }
227 | };
228 | return mark;
229 | };
230 |
231 |
232 | function getPieText(config, metadata){
233 | var mark = {
234 | "type": "text",
235 | "from": {"data": "layout"},
236 | "properties": {
237 | "update": {
238 | "x": {"field": {"group": "width"}, "mult": 0.5},
239 | "y": {"field": {"group": "height"}, "mult": 0.5},
240 | "radius": { "value": config.height * 0.5},
241 | "theta": {"field": "layout_mid"},
242 | "fill": {"value": "#000"},
243 | "align": {"value": "center"},
244 | "baseline": {"value": "middle"},
245 | "text": {"template": "{{datum.percentage | number:'.2f'}}%"}
246 |
247 | }
248 | }
249 | };
250 |
251 | return mark;
252 | };
253 |
--------------------------------------------------------------------------------
/samples/charts/table/index.html:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | VizGrammar.js - Table Chart Sample
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 | Number Chart Sample
72 |
73 |
74 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 | Data Collection
86 |
87 |
88 |
89 |
90 |
91 | {
92 | "metadata" : {
93 | "names" : ["rpm","torque","horsepower", "EngineType"],
94 | "types" : ["linear","linear", "ordinal","ordinal"]
95 | },
96 | "data": [
97 | [1, 10, 1, "Piston"]]
98 | };
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 | Configurations
115 |
116 |
117 |
118 |
119 | {
120 | key : "rpm",
121 | charts : [{type: "table", y : "torque"}],
122 | maxLength: 7,
123 | columns:["EngineType", "torque", "rpm"],
124 | width: 400,
125 | height: 200
126 | }
127 |
128 |
129 |
130 |
131 |
132 | Property
133 | Value
134 | Description
135 |
136 |
137 |
138 |
139 | title
140 | String
141 | Title of the table
142 |
143 |
144 | x
145 | String
146 | cAttribute name for X-axis
147 |
148 |
149 | maxLength
150 | int
151 | Maximum length of chart datatable
152 |
153 |
154 |
155 |
156 | height
157 | px
158 | height of the chart
159 |
160 |
161 |
162 |
163 | charts
164 | object
165 | Collection of charts
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 | Property
175 | Value
176 | Description
177 |
178 |
179 |
180 |
181 | type
182 | String
183 | Title of the table
184 |
185 |
186 | y
187 | String
188 | Attribute name for Y-axis
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
252 |
253 |
254 |
255 |
256 |
257 |
262 |
263 |
264 |
--------------------------------------------------------------------------------
/samples/charts/line/index.html:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | VizGrammar.js - Bar Chart Sample
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 | Group Multi Line Chart Sample
73 |
74 |
75 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 | Single Line Chart Sample
88 |
89 |
90 |
93 |
94 |
95 |
96 |
97 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 | Data Collection
164 |
165 |
166 |
167 |
168 |
169 | {
170 | "metadata" : {
171 | "names" : ["rpm","torque","horsepower", "EngineType"],
172 | "types" : ["linear","linear", "ordinal","ordinal"]
173 | },
174 | "data": [
175 | [1, 10, 1, "Piston"]]
176 | };
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 | Configurations
192 |
193 |
194 |
195 |
196 |
197 |
198 | {
199 | x : "rpm",
200 | charts : [{type: "line", y : "torque", color: "EngineType"}],
201 | maxLength: 10,
202 | width: 400,
203 | height: 200
204 | }
205 |
206 |
207 |
208 |
209 |
210 | Property
211 | Value
212 | Description
213 |
214 |
215 |
216 |
217 | title
218 | String
219 | Title of the table
220 |
221 |
222 | x
223 | String
224 | cAttribute name for X-axis
225 |
226 |
227 | maxLength
228 | int
229 | Maximum length of chart datatable
230 |
231 |
232 |
233 |
234 | height
235 | px
236 | height of the chart
237 |
238 |
239 |
240 |
241 | charts
242 | object
243 | Collection of charts
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 | Property
253 | Value
254 | Description
255 |
256 |
257 |
258 |
259 | type
260 | String
261 | Title of the table
262 |
263 |
264 | y
265 | String
266 | Attribute name for Y-axis
267 |
268 |
269 |
270 | color
271 | String
272 | Attribute name for color dimension
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
293 |
294 |
295 |
--------------------------------------------------------------------------------
/samples/charts/map/index.html:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | VizGrammar.js - Map Chart Sample
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 | World Map Chart Sample
72 |
73 |
74 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 | US Map Chart Sample
86 |
87 |
88 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 | Europe Map Chart Sample
100 |
101 |
102 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 | Data Collection
114 |
115 |
116 |
117 |
118 |
119 | {
120 | "metadata" : {
121 | "names" : ["Country","Inflation"],
122 | "types" : ["ordinal","linear"]
123 | },
124 | "data": [
125 | ["Afghanistan",4.23],
126 | ["EGY",1.23],
127 | ["Afghanistan",2.23],
128 | ["United States",8.23],
129 | };
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 | Configurations
146 |
147 |
148 |
149 |
150 | {
151 | x : "Country",
152 | charts : [{type: "map", y : "Inflation"}],
153 | width: 400,
154 | height: 200
155 | }
156 |
157 |
158 |
159 |
160 |
161 | Property
162 | Value
163 | Description
164 |
165 |
166 |
167 |
168 | title
169 | String
170 | Title of the table
171 |
172 |
173 | x
174 | String
175 | cAttribute name for X-axis
176 |
177 |
178 | maxLength
179 | int
180 | Maximum length of chart datatable
181 |
182 |
183 |
184 |
185 | height
186 | px
187 | height of the chart
188 |
189 |
190 |
191 |
192 | charts
193 | object
194 | Collection of charts
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 | Property
204 | Value
205 | Description
206 |
207 |
208 |
209 |
210 | type
211 | String
212 | Title of the table
213 |
214 |
215 | y
216 | String
217 | Attribute name for Y-axis
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
347 |
348 |
349 |
350 |
351 |
352 |
357 |
358 |
359 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
203 |
--------------------------------------------------------------------------------
/samples/charts/area/index.html:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | VizGrammar.js - Area Chart Sample
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 | Area Chart Sample
73 |
74 |
75 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 | Group Area Chart Sample
88 |
89 |
90 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 | Stack Area Chart Sample
102 |
103 |
104 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 | Data Collection
116 |
117 |
118 |
119 |
120 |
121 | {
122 | "metadata" : {
123 | "names" : ["rpm","torque","horsepower", "EngineType"],
124 | "types" : ["linear","linear", "ordinal","ordinal"]
125 | },
126 | "data": [
127 | [1, 10, 1, "Piston"]]
128 | };
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 | Configurations
145 |
146 |
147 |
148 |
149 | {
150 |
151 | charts : [{type: "area", x : "rpm", y : "torque"}],
152 | maxLength: 10,
153 | width: 400,
154 | height: 200
155 | }
156 |
157 |
158 |
159 |
160 |
161 | Property
162 | Value
163 | Description
164 |
165 |
166 |
167 |
168 | title
169 | String
170 | Title of the table
171 |
172 |
173 | x
174 | String
175 | cAttribute name for X-axis
176 |
177 |
178 | maxLength
179 | int
180 | Maximum length of chart datatable
181 |
182 |
183 |
184 |
185 | height
186 | px
187 | height of the chart
188 |
189 |
190 |
191 |
192 | charts
193 | object
194 | Collection of charts
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 | Property
204 | Value
205 | Description
206 |
207 |
208 |
209 |
210 | type
211 | String
212 | Title of the table
213 |
214 |
215 | y
216 | String
217 | Attribute name for Y-axis
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
316 |
317 |
318 |
319 |
320 |
321 |
326 |
327 |
328 |
--------------------------------------------------------------------------------
/charts/chart.map.js:
--------------------------------------------------------------------------------
1 | var map = function(dataTable, config) {
2 |
3 | this.metadata = dataTable[0].metadata;
4 | var marks ;
5 | var signals ;
6 | var predicates = [];
7 | var legends = [];
8 | this.spec = {};
9 | var geoInfoJson ;
10 |
11 | geoInfoJson = loadGeoMapCodes(config.helperUrl);
12 | config = checkConfig(config, this.metadata);
13 | this.config = config;
14 | this.config.geoInfoJson = geoInfoJson;
15 |
16 | for (i = 0; i < dataTable[0].values.length; i++) {
17 | for (var key in dataTable[0].values[i]) {
18 | if(key == dataTable[0].metadata.names[config.x]){
19 | if (dataTable[0].values[i].hasOwnProperty(key)) {
20 | dataTable[0].values[i].unitName = dataTable[0].values[i][key];
21 | dataTable[0].values[i][key] = getMapCode(dataTable[0].values[i][key], config.mapType,geoInfoJson);
22 | break;
23 | }
24 | }
25 | }
26 | };
27 |
28 | dataTable[0].name = config.title;
29 | dataTable[0].transform = [
30 | {
31 | "type": "formula",
32 | "field": "v",
33 | "expr": "datum."+this.metadata.names[config.y]
34 | }
35 | ];
36 |
37 | if (config.tooltip.enabled) {
38 | marks = getMapMark(config, this.metadata);
39 | signals = getMapSignals();
40 | this.spec.signals = signals;
41 | }
42 |
43 | dataTable.push(getTopoJson(config,this.metadata));
44 | predicates.push(getMapPredicates());
45 |
46 | if (config.legend) {
47 | legends.push(getMapLegends(config,this.metadata));
48 | }
49 |
50 | var cScale = {
51 | "name": "color",
52 | "type": "linear",
53 | "domain": {"data": "geoData","field": "zipped.v"},
54 | "domainMin": 0.0,
55 | "zero": false,
56 | "range": config.colorScale
57 | };
58 |
59 | if (config.highlight == "single" || config.highlight == "multi") {
60 |
61 | var multiTest;
62 |
63 | if (config.highlight == "multi") {
64 | multiTest = "!multi";
65 | } else {
66 | multiTest = "multi";
67 | }
68 |
69 |
70 | dataTable.push(
71 | {
72 | "name": "selectedPoints",
73 | "modify": [
74 | {"type": "clear", "test": multiTest},
75 | {"type": "toggle", "signal": "clickedPoint", "field": "id"}
76 | ]
77 | });
78 |
79 | signals.push( {
80 | "name": "clickedPoint",
81 | "init": 0,
82 | "verbose": true,
83 | "streams": [{"type": "click", "expr": "datum._id"}]
84 | },
85 | {
86 | "name": "multi",
87 | "init": false,
88 | "verbose": true,
89 | "streams": [{"type": "click", "expr": "datum._id"}]
90 | });
91 |
92 | marks[0].properties.update.fillOpacity = [
93 | {
94 | "test": "indata('selectedPoints', datum._id, 'id')",
95 | "value": 1
96 | },{"value":config.selectionOpacity}
97 | ];
98 |
99 | }
100 |
101 | var scales = [cScale];
102 |
103 | this.spec.width = config.width;
104 | this.spec.height = config.height;
105 | this.spec.data = dataTable;
106 | this.spec.scales = scales;
107 | this.spec.padding = config.padding;
108 | this.spec.marks = marks;
109 | this.spec.predicates = predicates;
110 | this.spec.legends = legends;
111 | this.spec.signals = signals;
112 |
113 | };
114 |
115 | map.prototype.draw = function(div, callbacks) {
116 | var viewUpdateFunction = (function(chart) {
117 | this.view = chart({el:div}).renderer(this.config.renderer).update();
118 |
119 | if (callbacks != null) {
120 | for (var i = 0; i
2 |
3 |
4 |
5 |
6 |
7 | VizGrammar.js - Arc Chart Sample
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 | Donut Chart Sample
53 |
54 |
55 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 | Pie Chart Sample
67 |
68 |
69 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 | Arc Chart Sample
86 |
87 |
88 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 | Arc Chart Sample
100 |
101 |
102 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 | Data Collection
120 |
121 |
122 |
123 |
124 |
125 | {
126 | "metadata" : {
127 | "names" : ["rpm","torque","horsepower", "EngineType"],
128 | "types" : ["linear","linear", "ordinal","ordinal"]
129 | },
130 | "data": [
131 | [1, 10, 1, "Piston"]]
132 | };
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 | Configurations
147 |
148 |
149 |
150 |
151 | {
152 | charts : [{type:"arc", x:"torque", color:"EngineType", mode:"donut"}],
153 | width: 300,
154 | height: 250
155 | }
156 |
157 |
158 |
159 |
160 |
161 | Property
162 | Value
163 | Description
164 |
165 |
166 |
167 |
168 | title
169 | String
170 | Title of the table
171 |
172 |
173 | x
174 | String
175 | cAttribute name for X-axis
176 |
177 |
178 | maxLength
179 | int
180 | Maximum length of chart datatable
181 |
182 |
183 |
184 |
185 | height
186 | px
187 | height of the chart
188 |
189 |
190 |
191 |
192 | charts
193 | object
194 | Collection of charts
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 | Property
204 | Value
205 | Description
206 |
207 |
208 |
209 |
210 | type
211 | String
212 | Title of the table
213 |
214 |
215 | y
216 | String
217 | Attribute name for Y-axis
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
371 |
372 |
373 |
374 |
375 |
380 |
381 |