Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Float-bar support. The logic is to use array values [bottomY, topY] i… #5262

Closed
wants to merge 82 commits into from
Closed
Show file tree
Hide file tree
Changes from 59 commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
a31d179
Float-bar support. The logic is to use array values [bottomY, topY] i…
gwyneblaidd Feb 11, 2018
ceafcaf
formatting
gwyneblaidd Feb 11, 2018
f2e7310
formatting&fix
gwyneblaidd Feb 11, 2018
d07f183
formatting
gwyneblaidd Feb 11, 2018
4ae0988
formatting
gwyneblaidd Feb 11, 2018
5b5bd25
formatting&docs
gwyneblaidd Feb 11, 2018
88aa1a5
logarithmic scale is added
gwyneblaidd Feb 11, 2018
fc478a6
Update bar.md
gwyneblaidd Feb 12, 2018
6075e6f
core scale hardcoding for getRightBarValue(). Float bar support (arra…
gwyneblaidd Feb 14, 2018
85ea4da
Merge remote-tracking branch 'origin/master'
gwyneblaidd Feb 22, 2018
b4c2994
CHanges as requested simonbrunel
gwyneblaidd Feb 22, 2018
87e6e38
latest changes with stacked bar linera/log scale and float0bar support
gwyneblaidd Feb 23, 2018
0e55557
formatting
gwyneblaidd Feb 23, 2018
0dd7666
tests
gwyneblaidd Feb 24, 2018
8e44c5e
formatting
gwyneblaidd Feb 24, 2018
70a11e5
formatting
gwyneblaidd Feb 24, 2018
362d5f9
formatting
gwyneblaidd Feb 24, 2018
12525ce
formatting
gwyneblaidd Feb 24, 2018
4a366a2
formatting
gwyneblaidd Feb 24, 2018
69b8ab0
D stacking implementation for float-bar support
gwyneblaidd Apr 28, 2018
256729c
Merge branch 'master' into master
gwyneblaidd Apr 28, 2018
42add1c
conflict resolve
gwyneblaidd Apr 28, 2018
0aad0c8
chars -> charts
gwyneblaidd May 7, 2018
e414eb7
removing comment, because this section was reverted back to fit D sta…
gwyneblaidd May 7, 2018
2161fc3
lowercased variable name
gwyneblaidd May 8, 2018
84e89aa
element code formatting change
gwyneblaidd May 8, 2018
8bfa7e1
reverted scale.js
gwyneblaidd May 11, 2018
b12e2fe
latest fixes
gwyneblaidd May 11, 2018
786c5c4
1. new method in core.scales to handle arrays (float-bars), getRightV…
gwyneblaidd May 15, 2018
861ed13
ode reformatting. Methods for extracting value, high and top separately
gwyneblaidd May 16, 2018
df32e68
refactoring
gwyneblaidd May 17, 2018
10c3831
refactoring
gwyneblaidd May 17, 2018
614275d
refactoring
gwyneblaidd May 17, 2018
cf6fd4b
formatting
gwyneblaidd May 17, 2018
d5ef434
formatting
gwyneblaidd May 18, 2018
a75e3ac
CHanges to float-bar support.
gwyneblaidd May 21, 2018
aaaac73
formatting
gwyneblaidd May 21, 2018
5e877aa
fixes
gwyneblaidd May 21, 2018
823160e
formatting
gwyneblaidd May 22, 2018
11bb986
fixes
gwyneblaidd May 23, 2018
1c526e3
fixes
gwyneblaidd May 23, 2018
a59a602
fixes
gwyneblaidd May 23, 2018
a4efcf0
fix
gwyneblaidd May 23, 2018
25ff4ea
formatting
gwyneblaidd May 23, 2018
7e75bef
fixes
gwyneblaidd May 23, 2018
03b8167
Reformatting parseScale function
gwyneblaidd May 24, 2018
659235b
last changes
gwyneblaidd May 29, 2018
fe0772c
formatting
gwyneblaidd Jun 4, 2018
730e468
fix
gwyneblaidd Jun 5, 2018
122167c
formatting
gwyneblaidd Jun 8, 2018
3e42297
fix
gwyneblaidd Jun 11, 2018
9b95637
fix
gwyneblaidd Jun 18, 2018
2af134b
fix to pass tests. Omit 0 when building scales when value min is 0.
gwyneblaidd Jun 19, 2018
a0e1231
tooltip fix for tests
gwyneblaidd Jun 20, 2018
a65aa3c
beginAtZero for float-val tests
gwyneblaidd Jun 27, 2018
901c96f
formatting
gwyneblaidd Jun 27, 2018
7a42562
formatting
gwyneblaidd Jun 27, 2018
4f5332e
formatting
gwyneblaidd Jun 27, 2018
63ce9e9
formatting
gwyneblaidd Jun 27, 2018
b626b57
rebase
gwyneblaidd Jan 16, 2019
b25db90
Merge branch 'master' into master_up
gwyneblaidd Jan 16, 2019
8f06bc5
Merge pull request #1 from gwyneblaidd/master_up
gwyneblaidd Jan 16, 2019
2a07aaa
Update controller.bar.js
gwyneblaidd Jan 17, 2019
d165e24
Update core.scale.js
gwyneblaidd Jan 17, 2019
c4148e9
Update core.tooltip.js
gwyneblaidd Jan 17, 2019
a48b8ce
Update element.rectangle.js
gwyneblaidd Jan 17, 2019
e1095fa
Update scale.linear.js
gwyneblaidd Jan 17, 2019
14bccfe
Update scale.logarithmic.js
gwyneblaidd Jan 17, 2019
f4d7413
Back changes after rebase
gwyneblaidd Jan 18, 2019
5590350
formatting
gwyneblaidd Jan 19, 2019
9f88e05
formatting
gwyneblaidd Jan 19, 2019
76e9ceb
fixes
gwyneblaidd Feb 5, 2019
f957e64
Merge branch 'master' into master
gwyneblaidd Feb 5, 2019
2d06063
formatting
gwyneblaidd Feb 5, 2019
a786cd1
Merge branch 'master' of https://github.com/gwyneblaidd/Chart.js
gwyneblaidd Feb 5, 2019
74dc634
fallback to test units
gwyneblaidd Feb 7, 2019
dba5bdb
border skipped added
gwyneblaidd Feb 7, 2019
0e58967
_parseValue added. Scales updated
gwyneblaidd Feb 8, 2019
124688c
format
gwyneblaidd Feb 8, 2019
84dae3d
+
gwyneblaidd Feb 8, 2019
19a400c
controller bar update
gwyneblaidd Feb 8, 2019
87b0d91
format
gwyneblaidd Feb 8, 2019
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
11 changes: 6 additions & 5 deletions docs/charts/bar.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ A bar chart provides a way of showing data values represented as vertical bars.
],
"datasets": [{
"label": "My First Dataset",
"data": [65, 59, 80, 81, 56, 55, 40],
"data": [65, 59, 80, 81, 56, 55, 40, [10, 20]],
"fill": false,
"backgroundColor": [
"rgba(255, 99, 132, 0.2)",
Expand Down Expand Up @@ -86,6 +86,7 @@ Options are:
* 'left'
* 'top'
* 'right'
* false - in the case of floating bar chart we need to have all borders, so you can set var to false to draw all borders

## Configuration Options

Expand Down Expand Up @@ -146,10 +147,10 @@ Sample: |==============|

## Data Structure

The `data` property of a dataset for a bar chart is specified as a an array of numbers. Each point in the data array corresponds to the label at the same index on the x axis.

The `data` property of a dataset for a bar chart is specified as a an array of numbers or arrays. Each point in the data array corresponds to the label at the same index on the x axis.
For floating bar chart you can use array for a specific Y value passing two numbers. First one will be used as min value and second one as max value for a bar.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would change this to something like
For floating bar char you can use array of [start, end] for a point, where both start and end are values accepted by the scale used

```javascript
data: [20, 10]
data: [20, 10, [10, 20]]
```

You can also specify the dataset as x/y coordinates when using the [time scale](../axes/cartesian/time.md#time-cartesian-axis).
Expand Down Expand Up @@ -196,7 +197,7 @@ A horizontal bar chart is a variation on a vertical bar chart. It is sometimes u
"labels": ["January", "February", "March", "April", "May", "June", "July"],
"datasets": [{
"label": "My First Dataset",
"data": [65, 59, 80, 81, 56, 55, 40],
"data": [65, 59, 80, 81, 56, 55, 40, [10, 20]],
"fill": false,
"backgroundColor": [
"rgba(255, 99, 132, 0.2)",
Expand Down
25 changes: 17 additions & 8 deletions src/controllers/controller.bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@ module.exports = function(Chart) {
var custom = rectangle.custom || {};
var rectangleOptions = chart.options.elements.rectangle;

// float-bar support, if y arguments are array lets override rectangles styles, assigning no skippingBorder
if (helpers.isArray(dataset.data[index])) {
custom.borderSkipped = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So does that means we will enforce borderSkipped in case of float-bar? I'm not sure that's a good idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, in fact we enforce this, cause float-bar will have all 4 sides required to be drawn, now sure if need to add smth else there. Or your idea to check the stacking here and make border skipped when 2 float-bars are stacked and one border should be eliminated. In my opinion in this case we will have 2 borders between 2 float-bars while stacking but thats better for vizualization purpose.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would consider changing this to

cutom.borderSkipped = custom.borderSkipped !== undefined ? custom.borderSkipped : null;

ie, if for whatever reason a bar has a custom skipped border setting, it will be kept otherwise there is no way for a user to draw partial borders on a floating bar

}

rectangle._xScale = me.getScaleForId(meta.xAxisID);
rectangle._yScale = me.getScaleForId(meta.yAxisID);
rectangle._datasetIndex = me.index;
Expand All @@ -227,7 +232,7 @@ module.exports = function(Chart) {
rectangle._model = {
datasetLabel: dataset.label,
label: chart.data.labels[index],
borderSkipped: custom.borderSkipped ? custom.borderSkipped : rectangleOptions.borderSkipped,
borderSkipped: helpers.valueOrDefault(custom.borderSkipped, rectangleOptions.borderSkipped),
backgroundColor: custom.backgroundColor ? custom.backgroundColor : helpers.valueAtIndexOrDefault(dataset.backgroundColor, index, rectangleOptions.backgroundColor),
borderColor: custom.borderColor ? custom.borderColor : helpers.valueAtIndexOrDefault(dataset.borderColor, index, rectangleOptions.borderColor),
borderWidth: custom.borderWidth ? custom.borderWidth : helpers.valueAtIndexOrDefault(dataset.borderWidth, index, rectangleOptions.borderWidth)
Expand Down Expand Up @@ -383,11 +388,12 @@ module.exports = function(Chart) {
var meta = me.getMeta();
var scale = me.getValueScale();
var datasets = chart.data.datasets;
var value = scale.getRightValue(datasets[datasetIndex].data[index]);
var value = scale._parseValue(datasets[datasetIndex].data[index]);
kurkle marked this conversation as resolved.
Show resolved Hide resolved
var stacked = scale.options.stacked;
var stack = meta.stack;
var start = 0;
var i, imeta, ivalue, base, head, size;
var i, imeta, ivalue, base, head, size, yStackValue;
kurkle marked this conversation as resolved.
Show resolved Hide resolved
var start = value.max >= 0 && value.min >= 0 ? value.min : value.max;
var yValue = value.max >= 0 && value.min >= 0 ? value.max - value.min : value.min - value.max;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use the size variable for this, as its what this is essentially about (its not Y for horizontalBar)

(size instead of yValue in the following)
Does everything work correctly for axis crossing or negative floats?

[-2, 1] => start = 1, size = -3
[-2, -1] => start = -1, size = 1

Another thing to consider is category axis for values. Say you have categories 'one', 'two', 'three', you should be able to draw bars with data [['two', 'three'], 'one'], right?

I think using start = value.start, size = value.end - value.start should work always (should be pixels to support category axis).

[-2, 1] => start = -2, size = 3
[-2, -1] => start = -2, size = 1
[1, 2] => start = 1, size = 1
[1, -2] => start = 1, size = -3


benmccann marked this conversation as resolved.
Show resolved Hide resolved
if (stacked || (stacked === undefined && stack !== undefined)) {
for (i = 0; i < datasetIndex; ++i) {
Expand All @@ -397,17 +403,18 @@ module.exports = function(Chart) {
imeta.stack === stack &&
imeta.controller.getValueScaleId() === scale.id &&
chart.isDatasetVisible(i)) {
yStackValue = scale._parseValue(datasets[i].data[index]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how the stacking should work here.

But, lets consider some scenarios:

data = [[5, 6], 2, 3]

  • stack should start at 5 and contain 3 bars sized 1, 2 and 3
  • or stack from 0 sized 2, 3 and a float at 5 sized 1

data = [1, [5, 7], 3]

  • stack should start from zero and contain 3 bars sized 1, 2 and 3
  • or one bar from 0 sized 1 and stack from 5 with bars sized 2 and 3
  • or stack from 0 sized 1 and 3 and a float at 5 sized 2

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kurkle there was a discussion on the stacking behavior back in March. It was decided to go with option D as Simon described here: #5262 (comment)

Hope that clarifies it!

ivalue = yStackValue.min >= 0 && yStackValue.max >= 0 ? yStackValue.max : yStackValue.min;

benmccann marked this conversation as resolved.
Show resolved Hide resolved
ivalue = scale.getRightValue(datasets[i].data[index]);
if ((value < 0 && ivalue < 0) || (value >= 0 && ivalue > 0)) {
if ((yValue < 0 && ivalue < 0) || (yValue >= 0 && ivalue >= 0)) {
start += ivalue;
}
}
}
}

base = scale.getPixelForValue(start);
head = scale.getPixelForValue(start + value);
head = scale.getPixelForValue(start + yValue);
size = (head - base) / 2;

return {
Expand Down Expand Up @@ -453,8 +460,10 @@ module.exports = function(Chart) {

helpers.canvas.clipArea(chart.ctx, chart.chartArea);

// float-bar support, if y arguments are array function will use bottom value as bar start point
for (; i < ilen; ++i) {
if (!isNaN(scale.getRightValue(dataset.data[i]))) {
var val = scale._parseValue(dataset.data[i]);
if (!isNaN(val.start) && !isNaN(val.end)) {
rects[i].draw();
}
}
Expand Down
36 changes: 31 additions & 5 deletions src/core/core.scale.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,14 +514,16 @@ module.exports = Element.extend({

// Get the correct value. NaN bad inputs, If the value type is object get the x or y based on whether we are horizontal or not
getRightValue: function(rawValue) {
// Null and undefined values first
if (helpers.isNullOrUndef(rawValue)) {
// Null and undefined values first. isNaN(object) returns true, so make sure NaN is checking for a number; Discard Infinite values
if (helpers.isNullOrUndef(rawValue) || (typeof rawValue === 'number' && !isFinite(rawValue))) {
return NaN;
}
// isNaN(object) returns true, so make sure NaN is checking for a number; Discard Infinite values
if (typeof rawValue === 'number' && !isFinite(rawValue)) {
return NaN;

// Float-bar support. Handling arrays
if (helpers.isArray(rawValue)) {
return [this.getRightValue(rawValue[0]), this.getRightValue(rawValue[1])];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also allows data like [[{x: 1, y: 1}, {x: 2, y: 2}], [1, 2], 3], but I guess its ok (and maybe usable in another chart type)

}

// If it is in fact an object, dive in one more level
if (rawValue) {
if (this.isHorizontal()) {
Expand All @@ -537,6 +539,30 @@ module.exports = Element.extend({
return rawValue;
},

/**
* @private
* Parse array and generic values into object
*/
_parseValue: function(raw) {
var value = this.getRightValue(raw);
var start, end;

if (helpers.isArray(value)) {
start = value[0];
end = value[1];
} else {
start = 0;
end = value;
}

return {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would consider calculating size (in pixels?) already here

min: Math.min(start, end),
max: Math.max(start, end),
start: start,
end: end
};
},

/**
* Used to get the value to display in the tooltip for the data at the given index
* @param index
Expand Down
1 change: 1 addition & 0 deletions src/core/core.tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ defaults._set('global', {
if (label) {
label += ': ';
}

label += tooltipItem.yLabel;
return label;
},
Expand Down
10 changes: 7 additions & 3 deletions src/elements/element.rectangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var defaults = require('../core/core.defaults');
var Element = require('../core/core.element');
var helpers = require('../helpers/index');

defaults._set('global', {
elements: {
Expand Down Expand Up @@ -67,7 +68,8 @@ module.exports = Element.extend({
bottom = vm.base;
signX = 1;
signY = bottom > top ? 1 : -1;
borderSkipped = vm.borderSkipped || 'bottom';
// no border support
borderSkipped = helpers.valueOrDefault(vm.borderSkipped, 'bottom');
} else {
// horizontal bar
left = vm.base;
Expand All @@ -76,7 +78,8 @@ module.exports = Element.extend({
bottom = vm.y + vm.height / 2;
signX = right > left ? 1 : -1;
signY = 1;
borderSkipped = vm.borderSkipped || 'left';
// no border support
borderSkipped = helpers.valueOrDefault(vm.borderSkipped, 'left');
}

// Canvas doesn't allow us to stroke inside the width so we can
Expand Down Expand Up @@ -132,8 +135,9 @@ module.exports = Element.extend({
// Draw rectangle from 'startCorner'
var corner = cornerAt(0);
ctx.moveTo(corner[0], corner[1]);
var cornersCount = borderSkipped === null ? 4 : 3;

for (var i = 1; i < 4; i++) {
for (var i = 1; i <= cornersCount; i++) {
corner = cornerAt(i);
ctx.lineTo(corner[0], corner[1]);
}
Expand Down
43 changes: 29 additions & 14 deletions src/scales/scale.linear.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,27 @@ module.exports = function(Chart) {

if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
helpers.each(dataset.data, function(rawValue, index) {
var value = +me.getRightValue(rawValue);
if (isNaN(value) || meta.data[index].hidden) {
var value = me._parseValue(rawValue);

if (isNaN(value.min) || isNaN(value.max) || meta.data[index].hidden) {
return;
}

positiveValues[index] = positiveValues[index] || 0;
negativeValues[index] = negativeValues[index] || 0;

if (value.min === 0) {
value.min = value.max;
} else if (value.max === 0) {
value.max = value.min;
}

if (opts.relativePoints) {
positiveValues[index] = 100;
} else if (value < 0) {
negativeValues[index] += value;
} else if (value.min < 0) {
negativeValues[index] += value.min;
} else {
positiveValues[index] += value;
positiveValues[index] += value.max;
}
});
}
Expand All @@ -106,21 +113,28 @@ module.exports = function(Chart) {
var meta = chart.getDatasetMeta(datasetIndex);
if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
helpers.each(dataset.data, function(rawValue, index) {
var value = +me.getRightValue(rawValue);
if (isNaN(value) || meta.data[index].hidden) {
var value = me._parseValue(rawValue);

if (isNaN(value.min) || isNaN(value.max) || meta.data[index].hidden) {
return;
}

if (value.min === 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this block will cause a problem if the user draws a floating bar with [0, 10] the scale will only consider 10

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @etimberg! We had to force to this check in order to keep the logic of scale building, its ok that 0 will not pass to scale values. Without this check some unit tests were not passed cause generally scale should not take account of 0 as start point. [0, 10] is not actually a float-bar, it has standartized representation as array but in fact its another view of 10. So, if we pass 10 this will be treated as [0,10]. So, scale should only take 10 and not zero. The reason why we should omit this 0 - for example we will use for bulding bars two values - 1 and 2. The new logic will treat them as [0,1] and [0,2]. WE have three uniq values here - 0, 1, 2. If scale will take all of them it will build scale from 0 to 2. According to general logic (without treating as arrays) it will build scale only from 1 to 2. We will have pixels difference in case of standart as integers or new logic (as arrays) values for graphs. SO this check is checking if the zero is actually a new value that should be passed to scale or its just for compability of old and new methods.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gwyneblaidd sounds good. I wanted to make sure this was expected since the case I highlighted might cause some confusion. If you haven't already, would it be possible to include this in the documentation of the float bar feature? That way other users would know to simply pass the value they expect

value.min = value.max;
} else if (value.max === 0) {
value.max = value.min;
}

if (me.min === null) {
me.min = value;
} else if (value < me.min) {
me.min = value;
me.min = value.min;
} else if (value.min < me.min) {
me.min = value.min;
}

if (me.max === null) {
me.max = value;
} else if (value > me.max) {
me.max = value;
me.max = value.max;
} else if (value.max > me.max) {
me.max = value.max;
}
});
}
Expand Down Expand Up @@ -156,7 +170,8 @@ module.exports = function(Chart) {
}
},
getLabelForIndex: function(index, datasetIndex) {
Copy link
Contributor

@benmccann benmccann May 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method is the same in both the linear and logarithmic scales. perhaps we should move it to core.scale.js or scale.linearbase. that seems like a better solution than introducing a new method getScaleLabel since we generally try to avoid introducing new public APIs except when required

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
var v = this._parseValue(this.chart.data.datasets[datasetIndex].data[index]);
return v.start === 0 ? v.end : v.start + ' ; ' + v.end;
gwyneblaidd marked this conversation as resolved.
Show resolved Hide resolved
},
// Utils
getPixelForValue: function(value) {
Expand Down
36 changes: 21 additions & 15 deletions src/scales/scale.logarithmic.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ module.exports = function(Chart) {
}
};

var LogarithmicScale = Scale.extend({
var LogarithmicScale = Chart.Scale.extend({
determineDataLimits: function() {
var me = this;
var opts = me.options;
Expand Down Expand Up @@ -119,13 +119,14 @@ module.exports = function(Chart) {

helpers.each(dataset.data, function(rawValue, index) {
var values = valuesPerStack[key];
var value = +me.getRightValue(rawValue);
var value = me._parseValue(rawValue);

// invalid, hidden and negative values are ignored
if (isNaN(value) || meta.data[index].hidden || value < 0) {
if (isNaN(value.max) || meta.data[index].hidden || value.max < 0) {
return;
}
values[index] = values[index] || 0;
values[index] += value;
values[index] += value.max;
});
}
});
Expand All @@ -144,26 +145,30 @@ module.exports = function(Chart) {
var meta = chart.getDatasetMeta(datasetIndex);
if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) {
helpers.each(dataset.data, function(rawValue, index) {
var value = +me.getRightValue(rawValue);
var value = me._parseValue(rawValue);
// invalid, hidden and negative values are ignored
if (isNaN(value) || meta.data[index].hidden || value < 0) {
if (isNaN(value.min) || isNaN(value.max) || meta.data[index].hidden || value.min < 0 || value.max < 0) {
return;
}

if (value.min === 0) {
value.min = value.max;
}

if (me.min === null) {
me.min = value;
} else if (value < me.min) {
me.min = value;
me.min = value.min;
} else if (value.min < me.min) {
me.min = value.min;
}

if (me.max === null) {
me.max = value;
} else if (value > me.max) {
me.max = value;
me.max = value.max;
} else if (value.max > me.max) {
me.max = value.max;
}

benmccann marked this conversation as resolved.
Show resolved Hide resolved
if (value !== 0 && (me.minNotZero === null || value < me.minNotZero)) {
me.minNotZero = value;
if (value.min !== 0 && (me.minNotZero === null || value.min < me.minNotZero)) {
me.minNotZero = value.min;
}
});
}
Expand Down Expand Up @@ -247,7 +252,8 @@ module.exports = function(Chart) {
},
// Get the correct tooltip label
getLabelForIndex: function(index, datasetIndex) {
return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]);
var v = this._parseValue(this.chart.data.datasets[datasetIndex].data[index]);
return v.start === 0 ? v.end : v.start + ' ; ' + v.end;
},
getPixelForTick: function(index) {
return this.getPixelForValue(this.tickValues[index]);
Expand Down