From e6b0e6b85d933f68d6b05169c4cec1a3620aac40 Mon Sep 17 00:00:00 2001 From: Adrian Lawrence Date: Wed, 6 Jan 2016 10:38:58 +0000 Subject: [PATCH 1/5] updated chart.js version and .gitignore --- .gitignore | 2 ++ package.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 25a1ef4..3af0387 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ custom/* docs/index.md bower_components + +.idea diff --git a/package.json b/package.json index 8dae174..d31807c 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "url": "https://github.com/Regaddi/Chart.StackedBar.js.git" }, "dependences": { - "Chart.js": ">= 1.0.0-beta" + "Chart.js": ">= 1.0.2" }, "main": "src/Chart.StackedBar.js", "devDependencies": { From 07b4c2ebef390ead0d0ae0f47aca954f9001f0b3 Mon Sep 17 00:00:00 2001 From: Adrian Lawrence Date: Tue, 12 Jan 2016 19:10:29 +0000 Subject: [PATCH 2/5] Don't display element with a zero value --- src/Chart.StackedBar.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Chart.StackedBar.js b/src/Chart.StackedBar.js index a452f04..1f80d75 100644 --- a/src/Chart.StackedBar.js +++ b/src/Chart.StackedBar.js @@ -279,12 +279,14 @@ total.value += element.value; - //Include any colour information about the element - tooltipLabels.push(helpers.template(this.options.multiTooltipTemplate, element)); - tooltipColors.push({ - fill: element._saved.fillColor || element.fillColor, - stroke: element._saved.strokeColor || element.strokeColor - }); + //Include any colour information about the element(s) + if (element.value !== 0) { + tooltipLabels.push(helpers.template(this.options.multiTooltipTemplate, element)); + tooltipColors.push({ + fill: element._saved.fillColor || element.fillColor, + stroke: element._saved.strokeColor || element.strokeColor + }); + } }, this); From e0cd3b09664f9b98e1d87ce9aee7e5d5722932dc Mon Sep 17 00:00:00 2001 From: fetz Date: Tue, 23 Aug 2016 12:24:31 +0100 Subject: [PATCH 3/5] add annotations to stackedBar, related https://github.com/tes/H2O/issues/317 --- src/Chart.StackedBar.js | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/Chart.StackedBar.js b/src/Chart.StackedBar.js index 1f80d75..0f3b535 100644 --- a/src/Chart.StackedBar.js +++ b/src/Chart.StackedBar.js @@ -13,7 +13,37 @@ }(function (Chart) { "use strict"; - var helpers = Chart.helpers; + var helpers = Chart.helpers; + + function drawLine(ctx, point, scale, annotation) { + ctx.beginPath(); + ctx.moveTo(point.x, scale.startPoint); + ctx.strokeStyle = annotation.lineColor; + ctx.lineTo(point.x, scale.endPoint); + ctx.stroke(); + } + + function drawLabel(ctx, point, scale, annotation) { + ctx.textAlign = 'left'; + ctx.fillStyle = annotation.labelColor; + ctx.fillText(annotation.labelText, point.x, scale.startPoint - 5); + } + + function drawAnnotations(chartType) { + var annotations = chartType.options.annotation ? chartType.options.annotation.annotations : []; + var datasets = chartType.datasets; + var scale = chartType.scale; + var ctx = chartType.chart.ctx; + helpers.each(annotations, function (annotation) { + if (annotation.type !== 'line') return; + + helpers.each(datasets, function (dataset) { + var point = dataset.bars[annotation.value]; + drawLine(ctx, point, scale, annotation); + drawLabel(ctx, point, scale, annotation); + }); + }); + } var defaultConfig = { scaleBeginAtZero : true, @@ -533,7 +563,9 @@ var ctx = this.chart.ctx; - this.scale.draw(easingDecimal); + this.scale.draw(easingDecimal); + + drawAnnotations(this); //Draw all the bars for each dataset helpers.each(this.datasets,function(dataset,datasetIndex){ From f3da2e23ecdd7d73c0482a9ee526427930c326af Mon Sep 17 00:00:00 2001 From: fetz Date: Tue, 23 Aug 2016 12:40:56 +0100 Subject: [PATCH 4/5] bump --- bower.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bower.json b/bower.json index b7b5182..33104a2 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "Chart.StackedBar.js", - "version": "1.0.3", + "version": "1.2.0", "description": "StackedBar implementation for Chart.js", "homepage": "https://github.com/nnnick/Chart.js", "author": "Regaddi", diff --git a/package.json b/package.json index d31807c..ac41a97 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "homepage": "http://www.chartjs.org", "description": "StackedBar implementation for Chart.js", "private": true, - "version": "1.0.3", + "version": "1.2.0", "repository": { "type": "git", "url": "https://github.com/Regaddi/Chart.StackedBar.js.git" From 20398aee41af729361fc459527f006215992e3ac Mon Sep 17 00:00:00 2001 From: fetz Date: Tue, 23 Aug 2016 17:40:17 +0100 Subject: [PATCH 5/5] fix bar line, to be handle to draw the annotation even when there is no bar --- bower.json | 2 +- package.json | 2 +- src/Chart.StackedBar.js | 16 ++++++++-------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/bower.json b/bower.json index 33104a2..55005b6 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "Chart.StackedBar.js", - "version": "1.2.0", + "version": "1.2.1", "description": "StackedBar implementation for Chart.js", "homepage": "https://github.com/nnnick/Chart.js", "author": "Regaddi", diff --git a/package.json b/package.json index ac41a97..fe09c36 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "homepage": "http://www.chartjs.org", "description": "StackedBar implementation for Chart.js", "private": true, - "version": "1.2.0", + "version": "1.2.1", "repository": { "type": "git", "url": "https://github.com/Regaddi/Chart.StackedBar.js.git" diff --git a/src/Chart.StackedBar.js b/src/Chart.StackedBar.js index 0f3b535..2c02145 100644 --- a/src/Chart.StackedBar.js +++ b/src/Chart.StackedBar.js @@ -15,18 +15,18 @@ var helpers = Chart.helpers; - function drawLine(ctx, point, scale, annotation) { + function drawLine(ctx, scale, annotation) { ctx.beginPath(); - ctx.moveTo(point.x, scale.startPoint); + ctx.moveTo(scale.calculateBarX(annotation.value), scale.startPoint); ctx.strokeStyle = annotation.lineColor; - ctx.lineTo(point.x, scale.endPoint); + ctx.lineTo(scale.calculateBarX(annotation.value), scale.endPoint); ctx.stroke(); } - function drawLabel(ctx, point, scale, annotation) { + function drawLabel(ctx, scale, annotation) { ctx.textAlign = 'left'; ctx.fillStyle = annotation.labelColor; - ctx.fillText(annotation.labelText, point.x, scale.startPoint - 5); + ctx.fillText(annotation.labelText, scale.calculateBarX(annotation.value), scale.startPoint - 5); } function drawAnnotations(chartType) { @@ -34,13 +34,13 @@ var datasets = chartType.datasets; var scale = chartType.scale; var ctx = chartType.chart.ctx; + helpers.each(annotations, function (annotation) { if (annotation.type !== 'line') return; helpers.each(datasets, function (dataset) { - var point = dataset.bars[annotation.value]; - drawLine(ctx, point, scale, annotation); - drawLabel(ctx, point, scale, annotation); + drawLine(ctx, scale, annotation); + drawLabel(ctx, scale, annotation); }); }); }