Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ custom/*

docs/index.md
bower_components

.idea
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Chart.StackedBar.js",
"version": "1.0.3",
"version": "1.2.1",
"description": "StackedBar implementation for Chart.js",
"homepage": "https://github.com/nnnick/Chart.js",
"author": "Regaddi",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
"homepage": "http://www.chartjs.org",
"description": "StackedBar implementation for Chart.js",
"private": true,
"version": "1.0.3",
"version": "1.2.1",
"repository": {
"type": "git",
"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": {
Expand Down
50 changes: 42 additions & 8 deletions src/Chart.StackedBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,37 @@
}(function (Chart) {
"use strict";

var helpers = Chart.helpers;
var helpers = Chart.helpers;

function drawLine(ctx, scale, annotation) {
ctx.beginPath();
ctx.moveTo(scale.calculateBarX(annotation.value), scale.startPoint);
ctx.strokeStyle = annotation.lineColor;
ctx.lineTo(scale.calculateBarX(annotation.value), scale.endPoint);
ctx.stroke();
}

function drawLabel(ctx, scale, annotation) {
ctx.textAlign = 'left';
ctx.fillStyle = annotation.labelColor;
ctx.fillText(annotation.labelText, scale.calculateBarX(annotation.value), 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) {
drawLine(ctx, scale, annotation);
drawLabel(ctx, scale, annotation);
});
});
}

var defaultConfig = {
scaleBeginAtZero : true,
Expand Down Expand Up @@ -279,12 +309,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);

Expand Down Expand Up @@ -531,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){
Expand Down