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
Changes from 26 commits
a31d179
ceafcaf
f2e7310
d07f183
4ae0988
5b5bd25
88aa1a5
fc478a6
6075e6f
85ea4da
b4c2994
87e6e38
0e55557
0dd7666
8e44c5e
70a11e5
362d5f9
12525ce
4a366a2
69b8ab0
256729c
42add1c
0aad0c8
e414eb7
2161fc3
84e89aa
8bfa7e1
b12e2fe
786c5c4
861ed13
df32e68
10c3831
614275d
cf6fd4b
d5ef434
a75e3ac
aaaac73
5e877aa
823160e
11bb986
1c526e3
a59a602
a4efcf0
25ff4ea
7e75bef
03b8167
659235b
fe0772c
730e468
122167c
3e42297
9b95637
2af134b
a0e1231
a65aa3c
901c96f
7a42562
4f5332e
63ce9e9
b626b57
b25db90
8f06bc5
2a07aaa
d165e24
c4148e9
a48b8ce
e1095fa
14bccfe
f4d7413
5590350
9f88e05
76e9ceb
f957e64
2d06063
a786cd1
74dc634
dba5bdb
0e58967
124688c
84dae3d
19a400c
87b0d91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,7 +87,14 @@ defaults._set('horizontalBar', { | |
|
||
label: function(item, data) { | ||
var datasetLabel = data.datasets[item.datasetIndex].label || ''; | ||
return datasetLabel + ': ' + item.xLabel; | ||
// float-bar support, if y arguments are array tooltip will show bottom and up values | ||
var yValue = data.datasets[item.datasetIndex].data[item.index]; | ||
if (helpers.isArray(yValue)) { | ||
benmccann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
datasetLabel += ': ' + yValue[0] + ' - ' + yValue[1]; | ||
} else { | ||
datasetLabel += ': ' + item.xLabel; | ||
} | ||
return datasetLabel; | ||
} | ||
}, | ||
mode: 'index', | ||
|
@@ -219,6 +226,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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So does that means we will enforce There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
@@ -227,7 +239,7 @@ module.exports = function(Chart) { | |
rectangle._model = { | ||
datasetLabel: dataset.label, | ||
label: chart.data.labels[index], | ||
borderSkipped: custom.borderSkipped ? custom.borderSkipped : rectangleOptions.borderSkipped, | ||
borderSkipped: custom.borderSkipped || custom.borderSkipped === null ? custom.borderSkipped : rectangleOptions.borderSkipped, | ||
benmccann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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) | ||
|
@@ -383,12 +395,14 @@ 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]); | ||
// float-bar support, if y arguments are array function will use top - bottom value to calculate bar height | ||
var yValue = datasets[datasetIndex].data[index]; | ||
var value = helpers.isArray(yValue) ? (scale.getRightValue(yValue[1]) - scale.getRightValue(yValue[0])) : scale.getRightValue(yValue); | ||
benmccann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
var stacked = scale.options.stacked; | ||
var stack = meta.stack; | ||
var start = 0; | ||
// float-bar support, if y arguments are array function will use bottom value as bar start point | ||
var start = helpers.isArray(yValue) ? yValue[0] : 0; | ||
var i, imeta, ivalue, base, head, size; | ||
|
||
benmccann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (stacked || (stacked === undefined && stack !== undefined)) { | ||
for (i = 0; i < datasetIndex; ++i) { | ||
imeta = chart.getDatasetMeta(i); | ||
|
@@ -397,7 +411,6 @@ module.exports = function(Chart) { | |
imeta.stack === stack && | ||
imeta.controller.getValueScaleId() === scale.id && | ||
chart.isDatasetVisible(i)) { | ||
|
||
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)) { | ||
start += ivalue; | ||
|
@@ -453,8 +466,14 @@ 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 yValue = dataset.data[i]; | ||
if (helpers.isArray(yValue)) { | ||
benmccann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (!isNaN(scale.getRightValue(yValue[1])) && !isNaN(scale.getRightValue(yValue[0]))) { | ||
rects[i].draw(); | ||
} | ||
} else if (!isNaN(scale.getRightValue(yValue))) { | ||
rects[i].draw(); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
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