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 1 commit
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 30 additions & 10 deletions src/controllers/controller.bar.js
Expand Up @@ -87,7 +87,13 @@ defaults._set('horizontalBar', {

label: function(item, data) {
var datasetLabel = data.datasets[item.datasetIndex].label || '';
return datasetLabel + ': ' + item.xLabel;

benmccann marked this conversation as resolved.
Show resolved Hide resolved
//float-bar support, if y arguments are array tooltip will show bottom and up values
if(!helpers.isArray(data.datasets[item.datasetIndex].data[item.index])) {
benmccann marked this conversation as resolved.
Show resolved Hide resolved
return datasetLabel + ': ' + item.xLabel;
} else {
return datasetLabel + ': ' + data.datasets[item.datasetIndex].data[item.index][0] + ' - ' + data.datasets[item.datasetIndex].data[item.index][1];
}
}
},
mode: 'index',
Expand Down Expand Up @@ -219,6 +225,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])) {
rectangleOptions.borderSkipped = 'none';
}

rectangle._xScale = me.getScaleForId(meta.xAxisID);
rectangle._yScale = me.getScaleForId(meta.yAxisID);
rectangle._datasetIndex = me.index;
Expand Down Expand Up @@ -383,11 +394,13 @@ 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 stacked = scale.options.stacked;
//float-bar support, if y arguments are array function will use top - bottom value to calculate bar height
var value = helpers.isArray(datasets[datasetIndex].data[index]) ? (scale.getRightValue(datasets[datasetIndex].data[index][1]) - scale.getRightValue(datasets[datasetIndex].data[index][0])) : scale.getRightValue(datasets[datasetIndex].data[index]);
var stacked = scale.options.stacked;
var stack = meta.stack;
var start = 0;
var i, imeta, ivalue, base, head, size;
//float-bar support, if y arguments are array function will use bottom value as bar start point
var start = helpers.isArray(datasets[datasetIndex].data[index]) ? datasets[datasetIndex].data[index][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) {
Expand Down Expand Up @@ -453,11 +466,18 @@ module.exports = function(Chart) {

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

for (; i < ilen; ++i) {
if (!isNaN(scale.getRightValue(dataset.data[i]))) {
rects[i].draw();
}
}
//float-bar support, if y arguments are array function will use bottom value as bar start point
for (; i < ilen; ++i) {
if(!helpers.isArray(dataset.data[i])) {
if (!isNaN(scale.getRightValue(dataset.data[i]))) {
rects[i].draw();
}
} else {
if (!isNaN(scale.getRightValue(dataset.data[i][1])) && !isNaN(scale.getRightValue(dataset.data[i][0]))) {
rects[i].draw();
}
}
}

helpers.canvas.unclipArea(chart.ctx);
},
Expand Down
8 changes: 2 additions & 6 deletions src/core/core.scale.js
Expand Up @@ -857,15 +857,11 @@ module.exports = function(Chart) {

var label = itemToDraw.label;
if (helpers.isArray(label)) {
var lineCount = label.length;
benmccann marked this conversation as resolved.
Show resolved Hide resolved
var lineHeight = tickFont.size * 1.5;
var y = me.isHorizontal() ? 0 : -lineHeight * (lineCount - 1) / 2;

for (var i = 0; i < lineCount; ++i) {
for (var i = 0, y = 0; i < label.length; ++i) {
// We just make sure the multiline element is a string here..
context.fillText('' + label[i], 0, y);
// apply same lineSpacing as calculated @ L#320
y += lineHeight;
y += (tickFont.size * 1.5);
}
} else {
context.fillText(label, 0, 0);
Expand Down
9 changes: 8 additions & 1 deletion src/core/core.tooltip.js
Expand Up @@ -68,7 +68,14 @@ defaults._set('global', {
if (label) {
label += ': ';
}
label += tooltipItem.yLabel;

//float-bar support, if y arguments are array tooltip will show bottom and up values
if(!helpers.isArray(data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index])) {
label += tooltipItem.yLabel;
} else {
label += data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index][0] + ' - ' + data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index][1];
}

return label;
},
labelColor: function(tooltipItem, chart) {
Expand Down
15 changes: 11 additions & 4 deletions src/elements/element.rectangle.js
Expand Up @@ -133,10 +133,17 @@ module.exports = Element.extend({
var corner = cornerAt(0);
ctx.moveTo(corner[0], corner[1]);

for (var i = 1; i < 4; i++) {
corner = cornerAt(i);
ctx.lineTo(corner[0], corner[1]);
}
//float-bar support, let's rectangle allow to have all borders, assign corners_count to 5 instead of 4, so we are allowing to fill all sides.
if(borderSkipped == 'none') {
var corners_count = 5;
} else {
var corners_count = 4;
}

for (var i = 1; i < corners_count; i++) {
corner = cornerAt(i);
ctx.lineTo(corner[0], corner[1]);
}

ctx.fill();
if (borderWidth) {
Expand Down
8 changes: 7 additions & 1 deletion src/scales/scale.linear.js
Expand Up @@ -105,7 +105,13 @@ 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);
//float-bar support, if y arguments are array scales will check Y value for min&max values
if(!helpers.isArray(rawValue)) {
var value = +me.getRightValue(rawValue);
} else {
var value = +me.getRightValue(rawValue[1]);
}

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