]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Create interfaces similar to the old interfaces. Ensure that scales always have IDs... 1220/head
authorEvert Timberg <evert.timberg@gmail.com>
Tue, 16 Jun 2015 23:20:26 +0000 (19:20 -0400)
committerEvert Timberg <evert.timberg@gmail.com>
Tue, 16 Jun 2015 23:20:26 +0000 (19:20 -0400)
16 files changed:
gulpfile.js
samples/bar-multi-axis.html
samples/line-multi-axis.html
samples/polar-area.html
samples/scatter-multi-axis.html
samples/scatter.html
src/charts/Chart.Bar.js [new file with mode: 0644]
src/charts/Chart.Doughnut.js [new file with mode: 0644]
src/charts/Chart.Line.js [new file with mode: 0644]
src/charts/Chart.PolarArea.js [new file with mode: 0644]
src/charts/Chart.Radar.js [new file with mode: 0644]
src/charts/Chart.Scatter.js [moved from src/controllers/controller.scatter.js with 75% similarity]
src/controllers/controller.line.js
src/core/core.controller.js
src/scales/scale.category.js
src/scales/scale.linear.js

index 70d58c0083cec641787e5d76513683eefb35d18d..9ce3dc3f4bb2535dccd589ae39ed1b98f18efc10 100644 (file)
@@ -32,7 +32,7 @@ gulp.task('build', function() {
             './src/controllers/**',
             './src/scales/**',
             './src/elements/**',
-            './src/charts/chart.bar.js',
+            './src/charts/**',
             './node_modules/color/dist/color.min.js'
         ],
         isCustom = !!(util.env.types),
index ff5c360fa9f18bb4d6c2c2229d100327e1ab1562..b1ed3abf0f715b15586d6610af07a678cb2273c2 100644 (file)
@@ -45,8 +45,7 @@
     };
     window.onload = function() {
         var ctx = document.getElementById("canvas").getContext("2d");
-        window.myBar = new Chart(ctx, {
-            type: 'bar',
+        window.myBar = Chart.Bar(ctx, {
             data: barChartData, 
             options: {
                 responsive: true,
index 729cf3731b2e5a904fbb53ed2d17a79391aadb12..e2f0d873b63fd9a1cce0fe6852895112943eefb4 100644 (file)
@@ -45,7 +45,7 @@
 
     window.onload = function() {
         var ctx = document.getElementById("canvas").getContext("2d");
-        window.myLine = new Chart(ctx).Line({
+        window.myLine = Chart.Line(ctx, {
             data: lineChartData,
             options: {
                 responsive: true,
index 4388a73cad01e98f79e3e3260eb116e708729691..73d5c604972938a908fa6e32e88f435a5092eb9e 100644 (file)
@@ -21,7 +21,6 @@
     };
 
     var config = {
-        type: 'polarArea',
         data: {
             datasets: [{
                 data: [
@@ -54,7 +53,7 @@
 
     window.onload = function() {
         var ctx = document.getElementById("chart-area");
-        window.myPolarArea = new Chart(ctx, config);
+        window.myPolarArea = Chart.PolarArea(ctx, config);
     };
 
     $('#randomizeData').click(function() {
index ab08e0d264891d82d7a7b624cc00556048ea86b0..a25c5f1b12a40eced05943f96a8585ccdc69122b 100644 (file)
@@ -90,7 +90,7 @@
 
     window.onload = function() {
         var ctx = document.getElementById("canvas").getContext("2d");
-        window.myScatter = new Chart(ctx).Scatter({
+        window.myScatter = Chart.Scatter(ctx, {
                data: scatterChartData,
                options: {
                    responsive: true,
index b27743762c15a8c6e42e64e8f46028e0ae0297d0..c4c96fbf8dc379b87eb1f936b454fe9cf64fd8be 100644 (file)
 
     window.onload = function() {
         var ctx = document.getElementById("canvas").getContext("2d");
-        window.myScatter = new Chart(ctx).Scatter({
+        window.myScatter = Chart.Scatter(ctx, {
                data: scatterChartData,
                options: {
-                   responsive: true,
-                   hoverMode: 'single', // should always use single for a scatter chart
                    scales: {
                        xAxes: [{
+                               position: 'top',
                                gridLines: {
-                                       zeroLineColor: "rgba(0,0,0,1)"
+                                       zeroLineColor: "rgba(0,255,0,1)"
                                }
                        }]
                    }
diff --git a/src/charts/Chart.Bar.js b/src/charts/Chart.Bar.js
new file mode 100644 (file)
index 0000000..26db4ad
--- /dev/null
@@ -0,0 +1,14 @@
+(function() {
+       "use strict";
+
+       var root = this;
+       var Chart = root.Chart;
+       var helpers = Chart.helpers;
+
+       Chart.Bar = function(context, config) {
+               config.type = 'bar';
+
+               return new Chart(context, config);
+       }
+       
+}).call(this);
diff --git a/src/charts/Chart.Doughnut.js b/src/charts/Chart.Doughnut.js
new file mode 100644 (file)
index 0000000..d01959d
--- /dev/null
@@ -0,0 +1,14 @@
+(function() {
+       "use strict";
+
+       var root = this;
+       var Chart = root.Chart;
+       var helpers = Chart.helpers;
+
+       Chart.Doughnut = function(context, config) {
+               config.type = 'doughnut';
+
+               return new Chart(context, config);
+       }
+       
+}).call(this);
diff --git a/src/charts/Chart.Line.js b/src/charts/Chart.Line.js
new file mode 100644 (file)
index 0000000..d5e7cf7
--- /dev/null
@@ -0,0 +1,14 @@
+(function() {
+       "use strict";
+
+       var root = this;
+       var Chart = root.Chart;
+       var helpers = Chart.helpers;
+
+       Chart.Line = function(context, config) {
+               config.type = 'line';
+
+               return new Chart(context, config);
+       }
+       
+}).call(this);
diff --git a/src/charts/Chart.PolarArea.js b/src/charts/Chart.PolarArea.js
new file mode 100644 (file)
index 0000000..e798f74
--- /dev/null
@@ -0,0 +1,14 @@
+(function() {
+       "use strict";
+
+       var root = this;
+       var Chart = root.Chart;
+       var helpers = Chart.helpers;
+
+       Chart.PolarArea = function(context, config) {
+               config.type = 'polarArea';
+
+               return new Chart(context, config);
+       }
+       
+}).call(this);
diff --git a/src/charts/Chart.Radar.js b/src/charts/Chart.Radar.js
new file mode 100644 (file)
index 0000000..f558078
--- /dev/null
@@ -0,0 +1,14 @@
+(function() {
+       "use strict";
+
+       var root = this;
+       var Chart = root.Chart;
+       var helpers = Chart.helpers;
+
+       Chart.Radar = function(context, config) {
+               config.type = 'radar';
+
+               return new Chart(context, config);
+       }
+       
+}).call(this);
similarity index 75%
rename from src/controllers/controller.scatter.js
rename to src/charts/Chart.Scatter.js
index 7048897b9ea6313e771340a66c8e8fa5da3925ae..3c784ff3212ac023f6dbc94e95b22229c430242b 100644 (file)
@@ -1,11 +1,9 @@
 (function() {
        "use strict";
 
-       return;
-
-       var root = this,
-               Chart = root.Chart,
-               helpers = Chart.helpers;
+       var root = this;
+       var Chart = root.Chart;
+       var helpers = Chart.helpers;
 
        var defaultConfig = {
                hover: {
 
        };
 
-
-       Chart.types.Line.extend({
-               name: "Scatter",
-               defaults: defaultConfig,
-       });
-}).call(this);
+       Chart.Scatter = function(context, config) {
+               config.options = helpers.configMerge(defaultConfig, config.options);
+               config.type = 'line';
+               return new Chart(context, config);
+       }
+       
+}).call(this);
\ No newline at end of file
index 79bc1c7822eb2ecad33de43d872dde57939576ab..19c9d6f53542a8f6b6bf0771d98b10d1ab37b188 100644 (file)
                scales: {
                        xAxes: [{
                                type: "category",
+                               id: 'x-axis-0'
                        }],
                        yAxes: [{
                                type: "linear",
+                               id: 'y-axis-0'
                        }],
                },
        };
index 77a08bbdf15ce3c3488f1f586f52f57b99897938..ac081a748bc9bea39960270b8e068c5b1e35ae56 100644 (file)
@@ -51,6 +51,7 @@
 
                        // Make sure controllers are built first so that each dataset is bound to an axis before the scales
                        // are built
+                       this.ensureScalesHaveIDs();
                        this.buildControllers();
                        this.buildScales();
                        this.resetElements();
 
                        return this;
                },
+               ensureScalesHaveIDs: function ensureScalesHaveIDs() {
+                       var defaultXAxisID = 'x-axis-';
+                       var defaultYAxisID = 'y-axis-';
 
+                       if (this.options.scales) {
+                               if (this.options.scales.xAxes && this.options.scales.xAxes.length) {
+                                       helpers.each(this.options.scales.xAxes, function(xAxisOptions, index) {
+                                               xAxisOptions.id = xAxisOptions.id || (defaultXAxisID + index);
+                                       }, this);
+                               }
+
+                               if (this.options.scales.yAxes && this.options.scales.yAxes.length) {
+                                       // Build the y axes
+                                       helpers.each(this.options.scales.yAxes, function(yAxisOptions, index) {
+                                               yAxisOptions.id = yAxisOptions.id || (defaultYAxisID + index);
+                                       }, this);
+                               }
+                       }
+               },
                buildScales: function buildScales() {
                        // Map of scale ID to scale object so we can lookup later 
                        this.scales = {};
                        // Build the x axes
                        if (this.options.scales) {
                                if (this.options.scales.xAxes && this.options.scales.xAxes.length) {
-                                       helpers.each(this.options.scales.xAxes, function(xAxisOptions) {
+                                       helpers.each(this.options.scales.xAxes, function(xAxisOptions, index) {
                                                var ScaleClass = Chart.scaleService.getScaleConstructor(xAxisOptions.type);
                                                var scale = new ScaleClass({
                                                        ctx: this.chart.ctx,
 
                                if (this.options.scales.yAxes && this.options.scales.yAxes.length) {
                                        // Build the y axes
-                                       helpers.each(this.options.scales.yAxes, function(yAxisOptions) {
+                                       helpers.each(this.options.scales.yAxes, function(yAxisOptions, index) {
                                                var ScaleClass = Chart.scaleService.getScaleConstructor(yAxisOptions.type);
                                                var scale = new ScaleClass({
                                                        ctx: this.chart.ctx,
index 3577315784012e64335441b1a4cb5673553a506c..ffac6fe21000e4189cdfcb39c987bc197e6ae642 100644 (file)
@@ -9,7 +9,6 @@
        var defaultConfig = {
                display: true,
                position: "bottom",
-               id: "x-axis-1", // need an ID so datasets can reference the scale
 
                // grid line settings
                gridLines: {
index 2f2c781fa4fce2c310a65e7c869c126d2bae7452..ce2fa8eb19db2fdb8c5e176c4fe4bd86aedd0005 100644 (file)
@@ -8,7 +8,6 @@
        var defaultConfig = {
                display: true,
                position: "left",
-               id: "y-axis-1",
 
                // grid line settings
                gridLines: {