From: Tanner Linsley Date: Mon, 15 Jun 2015 01:42:39 +0000 (-0600) Subject: Controller function organization X-Git-Tag: 2.0.0-alpha3~10^2~16^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aaa2484e1b5b7bc3d7fa328fa803c154647f7087;p=thirdparty%2FChart.js.git Controller function organization --- diff --git a/gulpfile.js b/gulpfile.js index 9ce3dc3f4..70d58c008 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -32,7 +32,7 @@ gulp.task('build', function() { './src/controllers/**', './src/scales/**', './src/elements/**', - './src/charts/**', + './src/charts/chart.bar.js', './node_modules/color/dist/color.min.js' ], isCustom = !!(util.env.types), diff --git a/samples/bar.html b/samples/bar.html index 5e0018d8d..812b2e0d7 100644 --- a/samples/bar.html +++ b/samples/bar.html @@ -40,6 +40,7 @@ window.onload = function() { var ctx = document.getElementById("canvas").getContext("2d"); window.myBar = new Chart(ctx, { + type: 'bar', data: barChartData, options: { responsive: true, diff --git a/src/_charts/chart.bar.js b/src/charts/chart.bar.js similarity index 100% rename from src/_charts/chart.bar.js rename to src/charts/chart.bar.js diff --git a/src/_charts/chart.doughnut.js b/src/charts/chart.doughnut.js similarity index 100% rename from src/_charts/chart.doughnut.js rename to src/charts/chart.doughnut.js diff --git a/src/_charts/chart.line.js b/src/charts/chart.line.js similarity index 100% rename from src/_charts/chart.line.js rename to src/charts/chart.line.js diff --git a/src/_charts/chart.polarArea.js b/src/charts/chart.polarArea.js similarity index 100% rename from src/_charts/chart.polarArea.js rename to src/charts/chart.polarArea.js diff --git a/src/_charts/chart.radar.js b/src/charts/chart.radar.js similarity index 100% rename from src/_charts/chart.radar.js rename to src/charts/chart.radar.js diff --git a/src/_charts/chart.scatter.js b/src/charts/chart.scatter.js similarity index 100% rename from src/_charts/chart.scatter.js rename to src/charts/chart.scatter.js diff --git a/src/core/core.controller.js b/src/core/core.controller.js index 74e73d9f4..dd2a02340 100644 --- a/src/core/core.controller.js +++ b/src/core/core.controller.js @@ -46,13 +46,8 @@ this.bindEvents(); this.buildScales(); - - Chart.scaleService.fitScalesForChart(this, this.chart.width, this.chart.height); - this.resetElements(); - this.initToolTip(); - this.update(); return this; @@ -112,6 +107,8 @@ this.scales[scale.id] = scale; }, this); + + Chart.scaleService.fitScalesForChart(this, this.chart.width, this.chart.height); }, resetElements: function resetElements() { @@ -119,7 +116,8 @@ }, update: function update(animationDuration) { // This will loop through any data and do the appropriate element update for the type - //this.render(animationDuration); + Chart.scaleService.fitScalesForChart(this, this.chart.width, this.chart.height); + this.render(animationDuration); }, render: function render(duration) { @@ -205,6 +203,26 @@ return elementsArray.length ? elementsArray : []; }, + getDatasetAtEvent: function getDatasetAtEvent(e) { + + var elementsArray = [], + eventPosition = helpers.getRelativePosition(e), + datasetIterator = function(dataset) { + elementsArray.push(dataset.metaData[elementIndex]); + }, + elementIndex; + + for (var datasetIndex = 0; datasetIndex < this.data.datasets.length; datasetIndex++) { + for (elementIndex = 0; elementIndex < this.data.datasets[datasetIndex].metaData.length; elementIndex++) { + if (this.data.datasets[datasetIndex].metaData[elementIndex].inGroupRange(eventPosition.x, eventPosition.y)) { + helpers.each(this.data.datasets, datasetIterator); + } + } + } + + return elementsArray.length ? elementsArray : []; + }, + generateLegend: function generateLegend() { return template(this.options.legendTemplate, this); }, @@ -233,13 +251,20 @@ toBase64Image: function toBase64Image() { return this.chart.canvas.toDataURL.apply(this.chart.canvas, arguments); }, + + initToolTip: function initToolTip() { + this.tooltip = new Chart.Tooltip({ + _chart: this.chart, + _data: this.data, + _options: this.options, + }, this); + }, + bindEvents: function bindEvents() { helpers.bindEvents(this, this.options.events, function(evt) { - // this will be the chart instance - this.canvasController.eventHandler(evt); + this.eventHandler(evt); }); }, - eventHandler: function eventHandler(e) { this.lastActive = this.lastActive || []; @@ -358,20 +383,6 @@ this.lastActive = this.active; return this; }, - - initToolTip: function initToolTip() { - this.tooltip = new Chart.Tooltip({ - _chart: this.chart, - _data: this.data, - _options: this.options, - }, this); - }, - - - update: function update() { - Chart.scaleService.fitScalesForChart(this, this.chart.width, this.chart.height); - this.elementController.updateElements(); - } }); }).call(this);