From a31d1795d1066816189488d4e631ea17536e865c Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Sun, 11 Feb 2018 04:47:59 +0200 Subject: [PATCH 01/76] Float-bar support. The logic is to use array values [bottomY, topY] instead of regular vals. SO if you use regular numbers char will be not floated and bottomY will be 0 by default. If you use array for value current update allowing to track this and use bottomY value from array instead of 0.) --- src/controllers/controller.bar.js | 40 +++++++++++++++++++++++-------- src/core/core.scale.js | 8 ++----- src/core/core.tooltip.js | 9 ++++++- src/elements/element.rectangle.js | 15 ++++++++---- src/scales/scale.linear.js | 8 ++++++- 5 files changed, 58 insertions(+), 22 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index ff2b56ae5a0..96ff508d248 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -87,7 +87,13 @@ 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 + if(!helpers.isArray(data.datasets[item.datasetIndex].data[item.index])) { + 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', @@ -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; @@ -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; if (stacked || (stacked === undefined && stack !== undefined)) { for (i = 0; i < datasetIndex; ++i) { @@ -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); }, diff --git a/src/core/core.scale.js b/src/core/core.scale.js index 1996c6c894d..f79dbee8009 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -857,15 +857,11 @@ module.exports = function(Chart) { var label = itemToDraw.label; if (helpers.isArray(label)) { - var lineCount = label.length; - 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); diff --git a/src/core/core.tooltip.js b/src/core/core.tooltip.js index 9b09d760443..59829caf588 100644 --- a/src/core/core.tooltip.js +++ b/src/core/core.tooltip.js @@ -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) { diff --git a/src/elements/element.rectangle.js b/src/elements/element.rectangle.js index ef59ac0dd62..b06dc0d7eda 100644 --- a/src/elements/element.rectangle.js +++ b/src/elements/element.rectangle.js @@ -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) { diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index aa723004fb7..ea80bfe63ba 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -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; } From ceafcaf8638425624fc96a22b50911dad94778dc Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Sun, 11 Feb 2018 05:18:12 +0200 Subject: [PATCH 02/76] formatting --- src/controllers/controller.bar.js | 20 ++++++++++---------- src/core/core.tooltip.js | 4 ++-- src/elements/element.rectangle.js | 4 ++-- src/scales/scale.linear.js | 9 +++++---- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 96ff508d248..1e2b497122e 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -87,13 +87,13 @@ defaults._set('horizontalBar', { label: function(item, data) { var datasetLabel = data.datasets[item.datasetIndex].label || ''; - - //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])) { - return datasetLabel + ': ' + item.xLabel; + // 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])) { + datasetLabel + ': ' + item.xLabel; } else { - return datasetLabel + ': ' + data.datasets[item.datasetIndex].data[item.index][0] + ' - ' + data.datasets[item.datasetIndex].data[item.index][1]; + datasetLabel + ': ' + data.datasets[item.datasetIndex].data[item.index][0] + ' - ' + data.datasets[item.datasetIndex].data[item.index][1]; } + return datasetLabel; } }, mode: 'index', @@ -225,8 +225,8 @@ 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])) { + // float-bar support, if y arguments are array lets override rectangles styles, assigning no skippingBorder + if (helpers.isArray(dataset.data[index])) { rectangleOptions.borderSkipped = 'none'; } @@ -394,11 +394,11 @@ module.exports = function(Chart) { var meta = me.getMeta(); var scale = me.getValueScale(); var datasets = chart.data.datasets; - //float-bar support, if y arguments are array function will use top - bottom value to calculate bar height + // 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; - //float-bar support, if y arguments are array function will use bottom value as bar start point + // 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; @@ -466,7 +466,7 @@ 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 + // 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]))) { diff --git a/src/core/core.tooltip.js b/src/core/core.tooltip.js index 59829caf588..f861f5408c3 100644 --- a/src/core/core.tooltip.js +++ b/src/core/core.tooltip.js @@ -69,8 +69,8 @@ defaults._set('global', { label += ': '; } - //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])) { + // 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]; diff --git a/src/elements/element.rectangle.js b/src/elements/element.rectangle.js index b06dc0d7eda..b693551b512 100644 --- a/src/elements/element.rectangle.js +++ b/src/elements/element.rectangle.js @@ -133,8 +133,8 @@ module.exports = Element.extend({ var corner = cornerAt(0); ctx.moveTo(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') { + // 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; diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index ea80bfe63ba..128ed347a38 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -105,11 +105,12 @@ module.exports = function(Chart) { var meta = chart.getDatasetMeta(datasetIndex); if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) { helpers.each(dataset.data, function(rawValue, index) { - //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); + // float-bar support, if y arguments are array scales will check Y value for min&max values + var value = 0; + if (!helpers.isArray(rawValue)) { + value = +me.getRightValue(rawValue); } else { - var value = +me.getRightValue(rawValue[1]); + value = +me.getRightValue(rawValue[1]); } if (isNaN(value) || meta.data[index].hidden) { From f2e7310a61013b5a89b935e685ee645865e52624 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Sun, 11 Feb 2018 16:50:25 +0200 Subject: [PATCH 03/76] formatting&fix --- src/controllers/controller.bar.js | 58 ++++++++++++++++--------------- src/core/core.scale.js | 8 +++-- src/core/core.tooltip.js | 13 ++++--- src/elements/element.rectangle.js | 11 +++--- src/scales/scale.linear.js | 14 ++++---- 5 files changed, 54 insertions(+), 50 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 1e2b497122e..c6e5419bb9e 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -88,12 +88,13 @@ defaults._set('horizontalBar', { label: function(item, data) { var datasetLabel = data.datasets[item.datasetIndex].label || ''; // 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])) { - datasetLabel + ': ' + item.xLabel; - } else { - datasetLabel + ': ' + data.datasets[item.datasetIndex].data[item.index][0] + ' - ' + data.datasets[item.datasetIndex].data[item.index][1]; - } - return datasetLabel; + var Yvalue = data.datasets[item.datasetIndex].data[item.index]; + if (helpers.isArray(Yvalue)) { + datasetLabel + ': ' + Yvalue[0] + ' - ' + Yvalue[1]; + } else { + datasetLabel + ': ' + item.xLabel; + } + return datasetLabel; } }, mode: 'index', @@ -226,9 +227,9 @@ module.exports = function(Chart) { 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'; - } + if (helpers.isArray(dataset.data[index])) { + rectangleOptions.borderSkipped = 'none'; + } rectangle._xScale = me.getScaleForId(meta.xAxisID); rectangle._yScale = me.getScaleForId(meta.yAxisID); @@ -394,14 +395,14 @@ module.exports = function(Chart) { var meta = me.getMeta(); var scale = me.getValueScale(); var datasets = chart.data.datasets; - // 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; + // 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); + var stacked = scale.options.stacked; var stack = meta.stack; - // 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; - + // 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; if (stacked || (stacked === undefined && stack !== undefined)) { for (i = 0; i < datasetIndex; ++i) { imeta = chart.getDatasetMeta(i); @@ -466,18 +467,19 @@ 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(!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(); - } - } - } + // float-bar support, if y arguments are array function will use bottom value as bar start point + for (; i < ilen; ++i) { + var Yvalue = dataset.data[i]; + if(helpers.isArray(Yvalue)) { + if (!isNaN(scale.getRightValue(Yvalue[1])) && !isNaN(scale.getRightValue(Yvalue[0]))) { + rects[i].draw(); + } + } else { + if (!isNaN(scale.getRightValue(Yvalue))) { + rects[i].draw(); + } + } + } helpers.canvas.unclipArea(chart.ctx); }, diff --git a/src/core/core.scale.js b/src/core/core.scale.js index f79dbee8009..1996c6c894d 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -857,11 +857,15 @@ module.exports = function(Chart) { var label = itemToDraw.label; if (helpers.isArray(label)) { - for (var i = 0, y = 0; i < label.length; ++i) { + var lineCount = label.length; + var lineHeight = tickFont.size * 1.5; + var y = me.isHorizontal() ? 0 : -lineHeight * (lineCount - 1) / 2; + + for (var i = 0; i < lineCount; ++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 += (tickFont.size * 1.5); + y += lineHeight; } } else { context.fillText(label, 0, 0); diff --git a/src/core/core.tooltip.js b/src/core/core.tooltip.js index f861f5408c3..6a47b137feb 100644 --- a/src/core/core.tooltip.js +++ b/src/core/core.tooltip.js @@ -68,14 +68,13 @@ defaults._set('global', { if (label) { label += ': '; } - // 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]; - } - + var Yvalue = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index]; + if (helpers.isArray(Yvalue)) { + label += Yvalue[0] + ' - ' + Yvalue[1]; + } else { + label += tooltipItem.yLabel; + } return label; }, labelColor: function(tooltipItem, chart) { diff --git a/src/elements/element.rectangle.js b/src/elements/element.rectangle.js index b693551b512..0546e0de463 100644 --- a/src/elements/element.rectangle.js +++ b/src/elements/element.rectangle.js @@ -132,13 +132,12 @@ module.exports = Element.extend({ // Draw rectangle from 'startCorner' var corner = cornerAt(0); ctx.moveTo(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. + var corners_count = 4; - // 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; - } + if (borderSkipped === 'none') { + corners_count = 5; + } for (var i = 1; i < corners_count; i++) { corner = cornerAt(i); diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index 128ed347a38..882f3b99fb8 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -105,13 +105,13 @@ module.exports = function(Chart) { var meta = chart.getDatasetMeta(datasetIndex); if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) { helpers.each(dataset.data, function(rawValue, index) { - // float-bar support, if y arguments are array scales will check Y value for min&max values - var value = 0; - if (!helpers.isArray(rawValue)) { - value = +me.getRightValue(rawValue); - } else { - value = +me.getRightValue(rawValue[1]); - } + // float-bar support, if y arguments are array scales will check Y value for min&max values + var value = 0; + if (helpers.isArray(rawValue)) { + value = +me.getRightValue(rawValue[1]); + } else { + value = +me.getRightValue(rawValue); + } if (isNaN(value) || meta.data[index].hidden) { return; From d07f18376cb797a3b9dfcea7d14a36083104efcc Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Sun, 11 Feb 2018 17:14:32 +0200 Subject: [PATCH 04/76] formatting --- src/controllers/controller.bar.js | 8 ++++---- src/elements/element.rectangle.js | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index c6e5419bb9e..04e430c3c3a 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -90,9 +90,9 @@ defaults._set('horizontalBar', { // 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)) { - datasetLabel + ': ' + Yvalue[0] + ' - ' + Yvalue[1]; + datasetLabel += ': ' + Yvalue[0] + ' - ' + Yvalue[1]; } else { - datasetLabel + ': ' + item.xLabel; + datasetLabel += ': ' + item.xLabel; } return datasetLabel; } @@ -469,8 +469,8 @@ module.exports = function(Chart) { // float-bar support, if y arguments are array function will use bottom value as bar start point for (; i < ilen; ++i) { - var Yvalue = dataset.data[i]; - if(helpers.isArray(Yvalue)) { + var Yvalue = dataset.data[i]; + if (helpers.isArray(Yvalue)) { if (!isNaN(scale.getRightValue(Yvalue[1])) && !isNaN(scale.getRightValue(Yvalue[0]))) { rects[i].draw(); } diff --git a/src/elements/element.rectangle.js b/src/elements/element.rectangle.js index 0546e0de463..3710d5ac4a0 100644 --- a/src/elements/element.rectangle.js +++ b/src/elements/element.rectangle.js @@ -133,16 +133,16 @@ module.exports = Element.extend({ var corner = cornerAt(0); ctx.moveTo(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. - var corners_count = 4; + var cornersCount = 4; if (borderSkipped === 'none') { - corners_count = 5; + cornersCount = 5; } - for (var i = 1; i < corners_count; i++) { - corner = cornerAt(i); - ctx.lineTo(corner[0], corner[1]); - } + for (var i = 1; i < cornersCount; i++) { + corner = cornerAt(i); + ctx.lineTo(corner[0], corner[1]); + } ctx.fill(); if (borderWidth) { From 4ae0988c086278b38ba7536336817e957d43234e Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Sun, 11 Feb 2018 17:25:14 +0200 Subject: [PATCH 05/76] formatting --- src/controllers/controller.bar.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 04e430c3c3a..d93e3223bbe 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -474,10 +474,8 @@ module.exports = function(Chart) { if (!isNaN(scale.getRightValue(Yvalue[1])) && !isNaN(scale.getRightValue(Yvalue[0]))) { rects[i].draw(); } - } else { - if (!isNaN(scale.getRightValue(Yvalue))) { + } else if (!isNaN(scale.getRightValue(Yvalue))) { rects[i].draw(); - } } } From 5b5bd25a448068ae8a838f983bd4f789aba83ac7 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Sun, 11 Feb 2018 17:38:30 +0200 Subject: [PATCH 06/76] formatting&docs --- docs/charts/bar.md | 23 ++++++++++++----------- src/controllers/controller.bar.js | 2 +- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/docs/charts/bar.md b/docs/charts/bar.md index 84704ba941b..e0d2b6b0e52 100644 --- a/docs/charts/bar.md +++ b/docs/charts/bar.md @@ -6,17 +6,17 @@ A bar chart provides a way of showing data values represented as vertical bars. "type": "bar", "data": { "labels": [ - "January", - "February", - "March", - "April", - "May", - "June", + "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)", @@ -86,6 +86,7 @@ Options are: * 'left' * 'top' * 'right' +* 'none' - in the case of floating bar chart we need to have all borders, so you can pass 'none' to draw all borders ## Configuration Options @@ -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 lowY and second one as highY. ```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). @@ -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)", diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index d93e3223bbe..2d23bc7d8e8 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -475,7 +475,7 @@ module.exports = function(Chart) { rects[i].draw(); } } else if (!isNaN(scale.getRightValue(Yvalue))) { - rects[i].draw(); + rects[i].draw(); } } From 88aa1a56bbfd042ac932447403ba958629554cf0 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Sun, 11 Feb 2018 19:38:00 +0200 Subject: [PATCH 07/76] logarithmic scale is added --- src/scales/scale.linear.js | 2 +- src/scales/scale.logarithmic.js | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index 882f3b99fb8..1fd629107da 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -106,7 +106,7 @@ module.exports = function(Chart) { if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) { helpers.each(dataset.data, function(rawValue, index) { // float-bar support, if y arguments are array scales will check Y value for min&max values - var value = 0; + var value; if (helpers.isArray(rawValue)) { value = +me.getRightValue(rawValue[1]); } else { diff --git a/src/scales/scale.logarithmic.js b/src/scales/scale.logarithmic.js index 74a210e4473..a99d8aad73c 100644 --- a/src/scales/scale.logarithmic.js +++ b/src/scales/scale.logarithmic.js @@ -142,7 +142,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 + var value; + if (helpers.isArray(rawValue)) { + value = +me.getRightValue(rawValue[1]); + } else { + value = +me.getRightValue(rawValue); + } // invalid, hidden and negative values are ignored if (isNaN(value) || meta.data[index].hidden || value < 0) { return; @@ -159,7 +165,6 @@ module.exports = function(Chart) { } else if (value > me.max) { me.max = value; } - if (value !== 0 && (me.minNotZero === null || value < me.minNotZero)) { me.minNotZero = value; } From fc478a635b930a29f4a2ad680384c86f1047af2d Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Mon, 12 Feb 2018 03:53:16 +0200 Subject: [PATCH 08/76] Update bar.md --- docs/charts/bar.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/charts/bar.md b/docs/charts/bar.md index e0d2b6b0e52..dcf8fa916d9 100644 --- a/docs/charts/bar.md +++ b/docs/charts/bar.md @@ -6,12 +6,12 @@ A bar chart provides a way of showing data values represented as vertical bars. "type": "bar", "data": { "labels": [ - "January", - "February", - "March", - "April", - "May", - "June", + "January", + "February", + "March", + "April", + "May", + "June", "July" ], "datasets": [{ From 6075e6fb88b5f61fbf8eedeb8784e8e3767ad87a Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Wed, 14 Feb 2018 14:03:00 +0200 Subject: [PATCH 09/76] core scale hardcoding for getRightBarValue(). Float bar support (arrays for Y val) --- src/core/core.scale.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/core/core.scale.js b/src/core/core.scale.js index 1996c6c894d..c50ee1debbf 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -515,6 +515,10 @@ module.exports = function(Chart) { // 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) { + // Float-bar support. Check if array so be aware of min/max Y values. + if (helpers.isArray(rawValue)) { + rawValue = rawValue[0]; + } // Null and undefined values first if (helpers.isNullOrUndef(rawValue)) { return NaN; From b4c2994918a97dba2a6905bcef5111dfe6802d9c Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Thu, 22 Feb 2018 14:45:51 +0200 Subject: [PATCH 10/76] CHanges as requested simonbrunel A few early feedback: instead of duplicating the logic to pick the "right" value in each scale, it may be better to move it directly in getRightValue()? Though, that would need some investigation to be sure it doesn't break anything. I would not introduce the new borderSkipped: 'none' value, but instead support borderSkipped: false|null. I would not call it lowY or highY but low/hight or min/max --- docs/charts/bar.md | 4 ++-- src/controllers/controller.bar.js | 2 +- src/elements/element.rectangle.js | 2 +- src/scales/scale.linear.js | 9 +-------- src/scales/scale.logarithmic.js | 8 +------- 5 files changed, 6 insertions(+), 19 deletions(-) diff --git a/docs/charts/bar.md b/docs/charts/bar.md index dcf8fa916d9..85177e97210 100644 --- a/docs/charts/bar.md +++ b/docs/charts/bar.md @@ -86,7 +86,7 @@ Options are: * 'left' * 'top' * 'right' -* 'none' - in the case of floating bar chart we need to have all borders, so you can pass 'none' to draw all borders +* 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 @@ -148,7 +148,7 @@ Sample: |==============| ## Data Structure 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 lowY and second one as highY. +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. ```javascript data: [20, 10, [10, 20]] ``` diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 2d23bc7d8e8..70aaa6544d9 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -228,7 +228,7 @@ module.exports = function(Chart) { // float-bar support, if y arguments are array lets override rectangles styles, assigning no skippingBorder if (helpers.isArray(dataset.data[index])) { - rectangleOptions.borderSkipped = 'none'; + rectangleOptions.borderSkipped = false; } rectangle._xScale = me.getScaleForId(meta.xAxisID); diff --git a/src/elements/element.rectangle.js b/src/elements/element.rectangle.js index 3710d5ac4a0..f4bd1fd6cea 100644 --- a/src/elements/element.rectangle.js +++ b/src/elements/element.rectangle.js @@ -135,7 +135,7 @@ module.exports = Element.extend({ // 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. var cornersCount = 4; - if (borderSkipped === 'none') { + if (borderSkipped === false) { cornersCount = 5; } diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index 1fd629107da..aa723004fb7 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -105,14 +105,7 @@ module.exports = function(Chart) { var meta = chart.getDatasetMeta(datasetIndex); if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) { helpers.each(dataset.data, function(rawValue, index) { - // float-bar support, if y arguments are array scales will check Y value for min&max values - var value; - if (helpers.isArray(rawValue)) { - value = +me.getRightValue(rawValue[1]); - } else { - value = +me.getRightValue(rawValue); - } - + var value = +me.getRightValue(rawValue); if (isNaN(value) || meta.data[index].hidden) { return; } diff --git a/src/scales/scale.logarithmic.js b/src/scales/scale.logarithmic.js index a99d8aad73c..9214d1a15d8 100644 --- a/src/scales/scale.logarithmic.js +++ b/src/scales/scale.logarithmic.js @@ -142,13 +142,7 @@ module.exports = function(Chart) { var meta = chart.getDatasetMeta(datasetIndex); if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) { helpers.each(dataset.data, function(rawValue, index) { - // float-bar support, if y arguments are array scales will check Y value for min&max values - var value; - if (helpers.isArray(rawValue)) { - value = +me.getRightValue(rawValue[1]); - } else { - value = +me.getRightValue(rawValue); - } + var value = +me.getRightValue(rawValue); // invalid, hidden and negative values are ignored if (isNaN(value) || meta.data[index].hidden || value < 0) { return; From 87e6e380ecc0e5f2f583347870f2c1e0586701bc Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Fri, 23 Feb 2018 12:22:43 +0200 Subject: [PATCH 11/76] latest changes with stacked bar linera/log scale and float0bar support --- src/controllers/controller.bar.js | 13 ++++++++----- src/core/core.scale.js | 8 ++++++-- src/elements/element.rectangle.js | 6 +++--- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 70aaa6544d9..68d297d830a 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -228,7 +228,7 @@ module.exports = function(Chart) { // float-bar support, if y arguments are array lets override rectangles styles, assigning no skippingBorder if (helpers.isArray(dataset.data[index])) { - rectangleOptions.borderSkipped = false; + rectangleOptions.borderSkipped = null; } rectangle._xScale = me.getScaleForId(meta.xAxisID); @@ -411,10 +411,13 @@ module.exports = function(Chart) { imeta.stack === stack && imeta.controller.getValueScaleId() === scale.id && chart.isDatasetVisible(i)) { - - ivalue = scale.getRightValue(datasets[i].data[index]); - if ((value < 0 && ivalue < 0) || (value >= 0 && ivalue > 0)) { - start += ivalue; + // float-bar support for stacked chars, if y arguments are array we don''t need to omit this here. Start for next char value in some point should include value of prev point + min Y value + var Yvalue = datasets[i].data[index]; + ivalue = scale.getRightValue(Yvalue); + if (helpers.isArray(Yvalue)) { + start += 0; + } else if ((value < 0 && ivalue < 0) || (value >= 0 && ivalue > 0)) { + start += ivalue; } } } diff --git a/src/core/core.scale.js b/src/core/core.scale.js index c50ee1debbf..2c60f2ae8b1 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -515,9 +515,13 @@ module.exports = function(Chart) { // 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) { - // Float-bar support. Check if array so be aware of min/max Y values. + // Float-bar support. Check if array so be aware of min/max Y values. Return min for stacked chars and max for general char if (helpers.isArray(rawValue)) { - rawValue = rawValue[0]; + if ((this.chart.options.scales.yAxes[0].stacked || this.chart.options.scales.xAxes[0].stacked) && !isNaN(rawValue[0])) { + rawValue = rawValue[0]; + } else if (!isNaN(rawValue[1])) { + rawValue = rawValue[1]; + } } // Null and undefined values first if (helpers.isNullOrUndef(rawValue)) { diff --git a/src/elements/element.rectangle.js b/src/elements/element.rectangle.js index f4bd1fd6cea..454d3cc775e 100644 --- a/src/elements/element.rectangle.js +++ b/src/elements/element.rectangle.js @@ -67,7 +67,7 @@ module.exports = Element.extend({ bottom = vm.base; signX = 1; signY = bottom > top ? 1 : -1; - borderSkipped = vm.borderSkipped || 'bottom'; + borderSkipped = vm.borderSkipped === null ? null : 'bottom'; } else { // horizontal bar left = vm.base; @@ -76,7 +76,7 @@ module.exports = Element.extend({ bottom = vm.y + vm.height / 2; signX = right > left ? 1 : -1; signY = 1; - borderSkipped = vm.borderSkipped || 'left'; + borderSkipped = vm.borderSkipped === null ? null : 'left'; } // Canvas doesn't allow us to stroke inside the width so we can @@ -135,7 +135,7 @@ module.exports = Element.extend({ // 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. var cornersCount = 4; - if (borderSkipped === false) { + if (borderSkipped === null) { cornersCount = 5; } From 0e55557d275932acc63e94c2ba361ef6ac1254a4 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Fri, 23 Feb 2018 12:42:26 +0200 Subject: [PATCH 12/76] formatting --- src/controllers/controller.bar.js | 12 ++++++------ src/core/core.scale.js | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 68d297d830a..3042902e4e4 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -411,13 +411,13 @@ module.exports = function(Chart) { imeta.stack === stack && imeta.controller.getValueScaleId() === scale.id && chart.isDatasetVisible(i)) { - // float-bar support for stacked chars, if y arguments are array we don''t need to omit this here. Start for next char value in some point should include value of prev point + min Y value - var Yvalue = datasets[i].data[index]; - ivalue = scale.getRightValue(Yvalue); - if (helpers.isArray(Yvalue)) { - start += 0; + // float-bar support for stacked chars, if y arguments are array we don't need to omit this here. Start for next char value in some point should include value of prev point + min Y value + var Yvalue1 = datasets[i].data[index]; + ivalue = scale.getRightValue(Yvalue1); + if (helpers.isArray(Yvalue1)) { + start += 0; } else if ((value < 0 && ivalue < 0) || (value >= 0 && ivalue > 0)) { - start += ivalue; + start += ivalue; } } } diff --git a/src/core/core.scale.js b/src/core/core.scale.js index 2c60f2ae8b1..31ac2b75697 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -521,7 +521,7 @@ module.exports = function(Chart) { rawValue = rawValue[0]; } else if (!isNaN(rawValue[1])) { rawValue = rawValue[1]; - } + } } // Null and undefined values first if (helpers.isNullOrUndef(rawValue)) { From 0dd76662e81f769ff3b2386b25aac91498d70688 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Sat, 24 Feb 2018 21:39:10 +0200 Subject: [PATCH 13/76] tests --- src/controllers/controller.bar.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 3042902e4e4..95f83b9bb4b 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -228,7 +228,7 @@ module.exports = function(Chart) { // float-bar support, if y arguments are array lets override rectangles styles, assigning no skippingBorder if (helpers.isArray(dataset.data[index])) { - rectangleOptions.borderSkipped = null; + custom.borderSkipped = null; } rectangle._xScale = me.getScaleForId(meta.xAxisID); @@ -239,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, 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) From 8e44c5ee2fc978f5b0f461ecc7d148040ccd2b1f Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Sat, 24 Feb 2018 21:48:52 +0200 Subject: [PATCH 14/76] formatting --- src/controllers/controller.bar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 95f83b9bb4b..0619185102c 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -239,7 +239,7 @@ module.exports = function(Chart) { rectangle._model = { datasetLabel: dataset.label, label: chart.data.labels[index], - borderSkipped: custom.borderSkipped || custom.borderSkipped === null ? custom.borderSkipped : rectangleOptions.borderSkipped, + borderSkipped: custom.borderSkipped || custom.borderSkipped === null ? 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) From 70a11e5ce251ebfb2b7b1046ada67b57bc3000f9 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Sat, 24 Feb 2018 22:12:53 +0200 Subject: [PATCH 15/76] formatting --- src/elements/element.rectangle.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/elements/element.rectangle.js b/src/elements/element.rectangle.js index 454d3cc775e..9f2c43d8b34 100644 --- a/src/elements/element.rectangle.js +++ b/src/elements/element.rectangle.js @@ -67,7 +67,7 @@ module.exports = Element.extend({ bottom = vm.base; signX = 1; signY = bottom > top ? 1 : -1; - borderSkipped = vm.borderSkipped === null ? null : 'bottom'; + borderSkipped = vm.borderSkipped || 'bottom'; } else { // horizontal bar left = vm.base; @@ -76,7 +76,7 @@ module.exports = Element.extend({ bottom = vm.y + vm.height / 2; signX = right > left ? 1 : -1; signY = 1; - borderSkipped = vm.borderSkipped === null ? null : 'left'; + borderSkipped = vm.borderSkipped || 'left'; } // Canvas doesn't allow us to stroke inside the width so we can From 362d5f942a55f2e4d691204da8855386a038c8f2 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Sat, 24 Feb 2018 23:52:22 +0200 Subject: [PATCH 16/76] formatting --- src/elements/element.rectangle.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/elements/element.rectangle.js b/src/elements/element.rectangle.js index 9f2c43d8b34..5f8659265be 100644 --- a/src/elements/element.rectangle.js +++ b/src/elements/element.rectangle.js @@ -67,7 +67,7 @@ module.exports = Element.extend({ bottom = vm.base; signX = 1; signY = bottom > top ? 1 : -1; - borderSkipped = vm.borderSkipped || 'bottom'; + borderSkipped = vm.borderSkipped === null ? null : 'bottom'; } else { // horizontal bar left = vm.base; @@ -76,7 +76,7 @@ module.exports = Element.extend({ bottom = vm.y + vm.height / 2; signX = right > left ? 1 : -1; signY = 1; - borderSkipped = vm.borderSkipped || 'left'; + borderSkipped = vm.borderSkipped === null ? null : 'left'; } // Canvas doesn't allow us to stroke inside the width so we can @@ -120,9 +120,15 @@ module.exports = Element.extend({ // Find first (starting) corner with fallback to 'bottom' var borders = ['bottom', 'left', 'top', 'right']; - var startCorner = borders.indexOf(borderSkipped, 0); - if (startCorner === -1) { + var startCorner; + // float-bar support, no border support + if (borderSkipped === null) { startCorner = 0; + } else { + startCorner = borders.indexOf(borderSkipped, 0); + if (startCorner === -1) { + startCorner = 0; + } } function cornerAt(index) { From 12525ce9af134b48f131f1ef8ded497f87ce80fb Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Sun, 25 Feb 2018 01:18:57 +0200 Subject: [PATCH 17/76] formatting --- src/elements/element.rectangle.js | 34 +++++++++++++++++-------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/elements/element.rectangle.js b/src/elements/element.rectangle.js index 5f8659265be..da9b695bc01 100644 --- a/src/elements/element.rectangle.js +++ b/src/elements/element.rectangle.js @@ -67,16 +67,26 @@ module.exports = Element.extend({ bottom = vm.base; signX = 1; signY = bottom > top ? 1 : -1; - borderSkipped = vm.borderSkipped === null ? null : 'bottom'; - } else { - // horizontal bar - left = vm.base; - right = vm.x; - top = vm.y - vm.height / 2; + // no border support + if (vm.borderSkipped === null) { + borderSkipped = null; + } else { + borderSkipped = vm.borderSkipped || 'bottom'; + } + } else { + // horizontal bar + left = vm.base; + right = vm.x; + top = vm.y - vm.height / 2; bottom = vm.y + vm.height / 2; signX = right > left ? 1 : -1; signY = 1; - borderSkipped = vm.borderSkipped === null ? null : 'left'; + // no border support + if (vm.borderSkipped === null) { + borderSkipped = null; + } else { + borderSkipped = vm.borderSkipped || 'left'; + } } // Canvas doesn't allow us to stroke inside the width so we can @@ -120,15 +130,9 @@ module.exports = Element.extend({ // Find first (starting) corner with fallback to 'bottom' var borders = ['bottom', 'left', 'top', 'right']; - var startCorner; - // float-bar support, no border support - if (borderSkipped === null) { + var startCorner = borders.indexOf(borderSkipped, 0); + if (startCorner === -1) { startCorner = 0; - } else { - startCorner = borders.indexOf(borderSkipped, 0); - if (startCorner === -1) { - startCorner = 0; - } } function cornerAt(index) { From 4a366a229b8d3cfbc4a13e03a3173f01c2699528 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Sun, 25 Feb 2018 01:40:44 +0200 Subject: [PATCH 18/76] formatting --- src/elements/element.rectangle.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/elements/element.rectangle.js b/src/elements/element.rectangle.js index da9b695bc01..d04e538b8a9 100644 --- a/src/elements/element.rectangle.js +++ b/src/elements/element.rectangle.js @@ -73,11 +73,11 @@ module.exports = Element.extend({ } else { borderSkipped = vm.borderSkipped || 'bottom'; } - } else { - // horizontal bar - left = vm.base; - right = vm.x; - top = vm.y - vm.height / 2; + } else { + // horizontal bar + left = vm.base; + right = vm.x; + top = vm.y - vm.height / 2; bottom = vm.y + vm.height / 2; signX = right > left ? 1 : -1; signY = 1; From 69b8ab002a1f6a91abc8317751a52c04ef612802 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Sat, 28 Apr 2018 22:23:04 +0300 Subject: [PATCH 19/76] D stacking implementation for float-bar support --- src/controllers/controller.bar.js | 27 ++++++++++++--------------- src/core/core.scale.js | 8 ++------ 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 0619185102c..4f096304f96 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -88,9 +88,9 @@ defaults._set('horizontalBar', { label: function(item, data) { var datasetLabel = data.datasets[item.datasetIndex].label || ''; // 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)) { - datasetLabel += ': ' + Yvalue[0] + ' - ' + Yvalue[1]; + var yValue = data.datasets[item.datasetIndex].data[item.index]; + if (helpers.isArray(yValue)) { + datasetLabel += ': ' + yValue[0] + ' - ' + yValue[1]; } else { datasetLabel += ': ' + item.xLabel; } @@ -396,12 +396,12 @@ module.exports = function(Chart) { var scale = me.getValueScale(); var datasets = chart.data.datasets; // 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); + var yValue = datasets[datasetIndex].data[index]; + var value = helpers.isArray(yValue) ? (scale.getRightValue(yValue[1]) - scale.getRightValue(yValue[0])) : scale.getRightValue(yValue); var stacked = scale.options.stacked; var stack = meta.stack; // 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 start = helpers.isArray(yValue) ? yValue[0] : 0; var i, imeta, ivalue, base, head, size; if (stacked || (stacked === undefined && stack !== undefined)) { for (i = 0; i < datasetIndex; ++i) { @@ -412,11 +412,8 @@ module.exports = function(Chart) { imeta.controller.getValueScaleId() === scale.id && chart.isDatasetVisible(i)) { // float-bar support for stacked chars, if y arguments are array we don't need to omit this here. Start for next char value in some point should include value of prev point + min Y value - var Yvalue1 = datasets[i].data[index]; - ivalue = scale.getRightValue(Yvalue1); - if (helpers.isArray(Yvalue1)) { - start += 0; - } else if ((value < 0 && ivalue < 0) || (value >= 0 && ivalue > 0)) { + ivalue = scale.getRightValue(datasets[i].data[index]); + if ((value < 0 && ivalue < 0) || (value >= 0 && ivalue > 0)) { start += ivalue; } } @@ -472,12 +469,12 @@ module.exports = function(Chart) { // float-bar support, if y arguments are array function will use bottom value as bar start point for (; i < ilen; ++i) { - var Yvalue = dataset.data[i]; - if (helpers.isArray(Yvalue)) { - if (!isNaN(scale.getRightValue(Yvalue[1])) && !isNaN(scale.getRightValue(Yvalue[0]))) { + var yValue = dataset.data[i]; + if (helpers.isArray(yValue)) { + if (!isNaN(scale.getRightValue(yValue[1])) && !isNaN(scale.getRightValue(yValue[0]))) { rects[i].draw(); } - } else if (!isNaN(scale.getRightValue(Yvalue))) { + } else if (!isNaN(scale.getRightValue(yValue))) { rects[i].draw(); } } diff --git a/src/core/core.scale.js b/src/core/core.scale.js index 31ac2b75697..6028d4962df 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -515,13 +515,9 @@ module.exports = function(Chart) { // 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) { - // Float-bar support. Check if array so be aware of min/max Y values. Return min for stacked chars and max for general char + // Float-bar support. Check if array so be aware of min/max Y values. if (helpers.isArray(rawValue)) { - if ((this.chart.options.scales.yAxes[0].stacked || this.chart.options.scales.xAxes[0].stacked) && !isNaN(rawValue[0])) { - rawValue = rawValue[0]; - } else if (!isNaN(rawValue[1])) { - rawValue = rawValue[1]; - } + rawValue = rawValue[1]; } // Null and undefined values first if (helpers.isNullOrUndef(rawValue)) { From 42add1ccf3491f2e881b5a7f25076b933678272e Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Sat, 28 Apr 2018 23:27:50 +0300 Subject: [PATCH 20/76] conflict resolve --- src/core/core.scale.js | 62 ++++++------------------------------------ 1 file changed, 8 insertions(+), 54 deletions(-) diff --git a/src/core/core.scale.js b/src/core/core.scale.js index 7f45d7aeade..bcde2ef5b3c 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -480,60 +480,10 @@ module.exports = Element.extend({ } } - me.handleMargins(); - - me.width = minSize.width; - me.height = minSize.height; - }, - - /** - * Handle margins and padding interactions - * @private - */ - handleMargins: function() { - var me = this; - if (me.margins) { - me.paddingLeft = Math.max(me.paddingLeft - me.margins.left, 0); - me.paddingTop = Math.max(me.paddingTop - me.margins.top, 0); - me.paddingRight = Math.max(me.paddingRight - me.margins.right, 0); - me.paddingBottom = Math.max(me.paddingBottom - me.margins.bottom, 0); - } - }, - - afterFit: function() { - helpers.callback(this.options.afterFit, [this]); - }, - - // Shared Methods - isHorizontal: function() { - return this.options.position === 'top' || this.options.position === 'bottom'; - }, - isFullWidth: function() { - return (this.options.fullWidth); - }, - - // 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) { - // Float-bar support. Check if array so be aware of min/max Y values. - if (helpers.isArray(rawValue)) { - rawValue = rawValue[1]; - } - // Null and undefined values first - if (helpers.isNullOrUndef(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; - } - // If it is in fact an object, dive in one more level - if (rawValue) { - if (this.isHorizontal()) { - if (rawValue.x !== undefined) { - return this.getRightValue(rawValue.x); - } - } else if (rawValue.y !== undefined) { - return this.getRightValue(rawValue.y); + me.handleMargins(); + + me.width = minSize.width; + me.height = minSize.height; }, /** @@ -564,6 +514,10 @@ 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) { + // Float-bar support. Check if array so be aware of min/max Y values. + if (helpers.isArray(rawValue)) { + rawValue = rawValue[1]; + } // Null and undefined values first if (helpers.isNullOrUndef(rawValue)) { return NaN; From 0aad0c88e3c99e05e34ef329d9d1cfbea583029e Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Mon, 7 May 2018 18:14:19 +0300 Subject: [PATCH 21/76] chars -> charts --- src/controllers/controller.bar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 4f096304f96..fc0ada6f4e4 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -411,7 +411,7 @@ module.exports = function(Chart) { imeta.stack === stack && imeta.controller.getValueScaleId() === scale.id && chart.isDatasetVisible(i)) { - // float-bar support for stacked chars, if y arguments are array we don't need to omit this here. Start for next char value in some point should include value of prev point + min Y value + // float-bar support for stacked charts, if y arguments are array we don't need to omit this here. Start for next char value in some point should include value of prev point + min Y value ivalue = scale.getRightValue(datasets[i].data[index]); if ((value < 0 && ivalue < 0) || (value >= 0 && ivalue > 0)) { start += ivalue; From e414eb7dd473cb69d82fb9842dc1c0aa52b7decd Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Mon, 7 May 2018 20:29:40 +0300 Subject: [PATCH 22/76] removing comment, because this section was reverted back to fit D stacking solution --- src/controllers/controller.bar.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index fc0ada6f4e4..38bd4429f36 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -411,7 +411,6 @@ module.exports = function(Chart) { imeta.stack === stack && imeta.controller.getValueScaleId() === scale.id && chart.isDatasetVisible(i)) { - // float-bar support for stacked charts, if y arguments are array we don't need to omit this here. Start for next char value in some point should include value of prev point + min Y value ivalue = scale.getRightValue(datasets[i].data[index]); if ((value < 0 && ivalue < 0) || (value >= 0 && ivalue > 0)) { start += ivalue; From 2161fc399312852a359d222338f2e6330c42f02f Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Tue, 8 May 2018 17:51:17 +0300 Subject: [PATCH 23/76] lowercased variable name --- src/core/core.tooltip.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/core.tooltip.js b/src/core/core.tooltip.js index d28cfedc489..1099d56e572 100644 --- a/src/core/core.tooltip.js +++ b/src/core/core.tooltip.js @@ -69,9 +69,9 @@ defaults._set('global', { label += ': '; } // float-bar support, if y arguments are array tooltip will show bottom and up values - var Yvalue = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index]; - if (helpers.isArray(Yvalue)) { - label += Yvalue[0] + ' - ' + Yvalue[1]; + var yValue = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index]; + if (helpers.isArray(yValue)) { + label += yValue[0] + ' - ' + yValue[1]; } else { label += tooltipItem.yLabel; } From 84e89aaab7db784b217c0b5ad275f4f3efc660b9 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Tue, 8 May 2018 23:18:18 +0300 Subject: [PATCH 24/76] element code formatting change corners from 5 to 4 if borderskipped is null, cycle from < to <= --- src/elements/element.rectangle.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/elements/element.rectangle.js b/src/elements/element.rectangle.js index d04e538b8a9..99ad5b05c99 100644 --- a/src/elements/element.rectangle.js +++ b/src/elements/element.rectangle.js @@ -143,13 +143,9 @@ module.exports = Element.extend({ var corner = cornerAt(0); ctx.moveTo(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. - var cornersCount = 4; + var cornersCount = borderSkipped === null ? 4 : 3; - if (borderSkipped === null) { - cornersCount = 5; - } - - for (var i = 1; i < cornersCount; i++) { + for (var i = 1; i <= cornersCount; i++) { corner = cornerAt(i); ctx.lineTo(corner[0], corner[1]); } From 8bfa7e11fb00757c43ca173a8f9dd22b751c3874 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Fri, 11 May 2018 15:37:58 +0300 Subject: [PATCH 25/76] reverted scale.js optimized code for bar.js and rectangle js as per Simon Brunel request --- src/controllers/controller.bar.js | 8 +++++--- src/elements/element.rectangle.js | 13 ++----------- src/scales/scale.logarithmic.js | 1 + 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 38bd4429f36..c03606c5309 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -90,8 +90,8 @@ defaults._set('horizontalBar', { // 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)) { - datasetLabel += ': ' + yValue[0] + ' - ' + yValue[1]; - } else { + datasetLabel += ': ' + yValue.join(' ; '); + } else { datasetLabel += ': ' + item.xLabel; } return datasetLabel; @@ -239,7 +239,7 @@ module.exports = function(Chart) { rectangle._model = { datasetLabel: dataset.label, label: chart.data.labels[index], - borderSkipped: custom.borderSkipped || custom.borderSkipped === null ? 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) @@ -403,6 +403,7 @@ module.exports = function(Chart) { // 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; + if (stacked || (stacked === undefined && stack !== undefined)) { for (i = 0; i < datasetIndex; ++i) { imeta = chart.getDatasetMeta(i); @@ -411,6 +412,7 @@ module.exports = function(Chart) { imeta.stack === stack && imeta.controller.getValueScaleId() === scale.id && chart.isDatasetVisible(i)) { + ivalue = scale.getRightValue(datasets[i].data[index]); if ((value < 0 && ivalue < 0) || (value >= 0 && ivalue > 0)) { start += ivalue; diff --git a/src/elements/element.rectangle.js b/src/elements/element.rectangle.js index 99ad5b05c99..d17ddaea12e 100644 --- a/src/elements/element.rectangle.js +++ b/src/elements/element.rectangle.js @@ -68,11 +68,7 @@ module.exports = Element.extend({ signX = 1; signY = bottom > top ? 1 : -1; // no border support - if (vm.borderSkipped === null) { - borderSkipped = null; - } else { - borderSkipped = vm.borderSkipped || 'bottom'; - } + borderSkipped = helpers.valueOrDefault(vm.borderSkipped, 'bottom'); } else { // horizontal bar left = vm.base; @@ -82,11 +78,7 @@ module.exports = Element.extend({ signX = right > left ? 1 : -1; signY = 1; // no border support - if (vm.borderSkipped === null) { - borderSkipped = null; - } else { - borderSkipped = vm.borderSkipped || 'left'; - } + borderSkipped = helpers.valueOrDefault(vm.borderSkipped, 'left'); } // Canvas doesn't allow us to stroke inside the width so we can @@ -142,7 +134,6 @@ module.exports = Element.extend({ // Draw rectangle from 'startCorner' var corner = cornerAt(0); ctx.moveTo(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. var cornersCount = borderSkipped === null ? 4 : 3; for (var i = 1; i <= cornersCount; i++) { diff --git a/src/scales/scale.logarithmic.js b/src/scales/scale.logarithmic.js index b55ae508421..0365568e772 100644 --- a/src/scales/scale.logarithmic.js +++ b/src/scales/scale.logarithmic.js @@ -161,6 +161,7 @@ module.exports = function(Chart) { } else if (value > me.max) { me.max = value; } + if (value !== 0 && (me.minNotZero === null || value < me.minNotZero)) { me.minNotZero = value; } From b12e2fe483bfc9c1b5f3ce435d4fd46d7e821f90 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Fri, 11 May 2018 16:42:43 +0300 Subject: [PATCH 26/76] latest fixes --- src/core/core.tooltip.js | 2 +- src/elements/element.rectangle.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/core.tooltip.js b/src/core/core.tooltip.js index 1099d56e572..b179b848be5 100644 --- a/src/core/core.tooltip.js +++ b/src/core/core.tooltip.js @@ -71,7 +71,7 @@ defaults._set('global', { // float-bar support, if y arguments are array tooltip will show bottom and up values var yValue = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index]; if (helpers.isArray(yValue)) { - label += yValue[0] + ' - ' + yValue[1]; + label += yValue.join(' ; '); } else { label += tooltipItem.yLabel; } diff --git a/src/elements/element.rectangle.js b/src/elements/element.rectangle.js index d17ddaea12e..54706d2fae2 100644 --- a/src/elements/element.rectangle.js +++ b/src/elements/element.rectangle.js @@ -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: { From 786c5c4ff6d782b9546ac386f28f058ff827a5d0 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Tue, 15 May 2018 18:05:48 +0300 Subject: [PATCH 27/76] 1. new method in core.scales to handle arrays (float-bars), getRightValueLowHigh() - it returns lowY, highY and actual Y value; Method is called from original getRightValue when incoming data is actuall array. 2. Label updates, so now it returns data in format join(' ; ') values (lowY and high Y). Labels are generated from proper scale code for float-bars 3. Proper scale build. Now for negative or positive values scale are getting correct value from a pait of Y values (lowY and highY) link for testing - http://pravopys.net/chartjs/samples/charts/bar/stacked-vertical-simon.html --- src/controllers/controller.bar.js | 30 +++++++++++++++-------- src/core/core.scale.js | 40 +++++++++++++++++++++++++++---- src/core/core.tooltip.js | 9 ++----- src/scales/scale.linear.js | 39 +++++++++++++++++++++++++++--- src/scales/scale.logarithmic.js | 39 +++++++++++++++++++++++++++--- 5 files changed, 129 insertions(+), 28 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index c03606c5309..85815b3f0d7 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -87,13 +87,9 @@ defaults._set('horizontalBar', { label: function(item, data) { var datasetLabel = data.datasets[item.datasetIndex].label || ''; - // 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)) { - datasetLabel += ': ' + yValue.join(' ; '); - } else { - datasetLabel += ': ' + item.xLabel; - } + + datasetLabel += ': ' + item.xLabel; + return datasetLabel; } }, @@ -397,11 +393,18 @@ module.exports = function(Chart) { var datasets = chart.data.datasets; // 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); + var rValue = scale.getRightValue(yValue); + var value = helpers.isArray(rValue) ? rValue[2] : rValue; var stacked = scale.options.stacked; var stack = meta.stack; - // 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; + // float-bar support, if y arguments are array function will use proper value as bar start point + var start = 0; + if (helpers.isArray(rValue) && rValue[2] <= 0 ) { + start = rValue[1]; + } else if (helpers.isArray(rValue) && rValue[2] > 0) { + start = rValue[0]; + } + var i, imeta, ivalue, base, head, size; if (stacked || (stacked === undefined && stack !== undefined)) { @@ -414,6 +417,13 @@ module.exports = function(Chart) { chart.isDatasetVisible(i)) { ivalue = scale.getRightValue(datasets[i].data[index]); + // float-bar support + if (helpers.isArray(ivalue) && ivalue[2] <= 0 ) { + ivalue = ivalue[0]; + } else if (helpers.isArray(ivalue) && ivalue[2] > 0) { + ivalue = ivalue[1]; + } + if ((value < 0 && ivalue < 0) || (value >= 0 && ivalue > 0)) { start += ivalue; } diff --git a/src/core/core.scale.js b/src/core/core.scale.js index bcde2ef5b3c..a657107023a 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -514,10 +514,7 @@ 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) { - // Float-bar support. Check if array so be aware of min/max Y values. - if (helpers.isArray(rawValue)) { - rawValue = rawValue[1]; - } + // Null and undefined values first if (helpers.isNullOrUndef(rawValue)) { return NaN; @@ -526,6 +523,12 @@ module.exports = Element.extend({ if (typeof rawValue === 'number' && !isFinite(rawValue)) { return NaN; } + + // Float-bar support. Handling arrays + if (helpers.isArray(rawValue)) { + return this.getRightValueLowHigh(rawValue); + } + // If it is in fact an object, dive in one more level if (rawValue) { if (this.isHorizontal()) { @@ -541,7 +544,34 @@ module.exports = Element.extend({ return rawValue; }, - /** + // Get the correct Y low and high values. NaN bad inputs. Returns 3 values, lowY as first element, highY as second and actual Yvalue as third. + getRightValueLowHigh: function(rawValue) { + if (!helpers.isArray(rawValue)) { + return this.getRightValue(rawValue); + } + // Null and undefined values first + if (typeof rawValue[0] === 'number' && !isFinite(rawValue[0])) { + return NaN; + } + // Null and undefined values first + if (typeof rawValue[1] === 'number' && !isFinite(rawValue[1])) { + return NaN; + } + + var lowY = rawValue[0] <= rawValue[1] ? rawValue[0] : rawValue[1]; + var highY = rawValue[0] > rawValue[1] ? rawValue[0] : rawValue[1]; + var valueY = 0; + + //calculate the proper Y value depending on negative or positive values of the highY and lowY + if (lowY >= 0 && highY > 0) { + valueY = highY - lowY; + } else if (lowY <= 0 && highY <= 0) { + valueY = lowY - highY; + } + // Value is good, return it + return [this.getRightValue(lowY), this.getRightValue(highY), this.getRightValue(valueY)]; + }, +/** * Used to get the value to display in the tooltip for the data at the given index * @param index * @param datasetIndex diff --git a/src/core/core.tooltip.js b/src/core/core.tooltip.js index b179b848be5..0a1be38387f 100644 --- a/src/core/core.tooltip.js +++ b/src/core/core.tooltip.js @@ -68,13 +68,8 @@ defaults._set('global', { if (label) { label += ': '; } - // float-bar support, if y arguments are array tooltip will show bottom and up values - var yValue = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index]; - if (helpers.isArray(yValue)) { - label += yValue.join(' ; '); - } else { - label += tooltipItem.yLabel; - } + + label += tooltipItem.yLabel; return label; }, labelColor: function(tooltipItem, chart) { diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index a980615c5d1..dab2390e4bf 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -74,7 +74,19 @@ module.exports = function(Chart) { if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) { helpers.each(dataset.data, function(rawValue, index) { - var value = +me.getRightValue(rawValue); + var value, valueR; + valueR = me.getRightValue(rawValue); + + if (helpers.isArray(valueR)) { + if (valueR[2] <= 0) { + value = +me.getRightValue(valueR[0]); + } else if (valueR[2] > 0) { + value = +me.getRightValue(valueR[1]); + } + } else { + value = +me.getRightValue(valueR); + } + if (isNaN(value) || meta.data[index].hidden) { return; } @@ -106,7 +118,23 @@ 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, valueR; + valueR = me.getRightValue(rawValue); + + if (helpers.isArray(valueR)) { + if (valueR[2] <= 0) { + value = +me.getRightValue(valueR[0]); + } else if (valueR[2] > 0) { + value = +me.getRightValue(valueR[1]); + } + } else { + value = +me.getRightValue(valueR); + } + + if (isNaN(value) || meta.data[index].hidden) { + return; + } + if (isNaN(value) || meta.data[index].hidden) { return; } @@ -156,7 +184,12 @@ module.exports = function(Chart) { } }, getLabelForIndex: function(index, datasetIndex) { - return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]); + var yValue = this.chart.data.datasets[datasetIndex].data[index]; + if (helpers.isArray(yValue)) { + return yValue.join(' ; '); + } else { + return +this.getRightValue(yValue); + } }, // Utils getPixelForValue: function(value) { diff --git a/src/scales/scale.logarithmic.js b/src/scales/scale.logarithmic.js index 0365568e772..fbc8889d489 100644 --- a/src/scales/scale.logarithmic.js +++ b/src/scales/scale.logarithmic.js @@ -119,7 +119,19 @@ module.exports = function(Chart) { helpers.each(dataset.data, function(rawValue, index) { var values = valuesPerStack[key]; - var value = +me.getRightValue(rawValue); + var value, valueR; + valueR = me.getRightValue(rawValue); + + if (helpers.isArray(valueR)) { + if (valueR[2] < 0) { + return; + } else if (valueR[2] >= 0) { + value = +me.getRightValue(valueR[1]); + } + } else { + value = +me.getRightValue(valueR); + } + // invalid, hidden and negative values are ignored if (isNaN(value) || meta.data[index].hidden || value < 0) { return; @@ -144,7 +156,23 @@ 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, valueR; + valueR = +me.getRightValue(rawValue); + + if (helpers.isArray(valueR)) { + if (valueR[2] < 0) { + return; + } else if (valueR[2] >= 0) { + value = +me.getRightValue(valueR[1]); + } + } else { + value = +me.getRightValue(valueR); + } + + if (isNaN(value) || meta.data[index].hidden) { + return; + } + // invalid, hidden and negative values are ignored if (isNaN(value) || meta.data[index].hidden || value < 0) { return; @@ -247,7 +275,12 @@ module.exports = function(Chart) { }, // Get the correct tooltip label getLabelForIndex: function(index, datasetIndex) { - return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]); + var yValue = this.chart.data.datasets[datasetIndex].data[index]; + if (helpers.isArray(yValue)) { + return yValue.join(' ; '); + } else { + return +this.getRightValue(yValue); + } }, getPixelForTick: function(index) { return this.getPixelForValue(this.tickValues[index]); From 861ed13924b97008d5ef9053404895ba742e6466 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Thu, 17 May 2018 01:36:41 +0300 Subject: [PATCH 28/76] ode reformatting. Methods for extracting value, high and top separately --- src/controllers/controller.bar.js | 30 +++++++++++++--------- src/core/core.scale.js | 41 ++++++++++++++++++++++++++++++- src/scales/scale.linear.js | 28 +++++++++------------ src/scales/scale.logarithmic.js | 38 +++++++++++++--------------- 4 files changed, 87 insertions(+), 50 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 85815b3f0d7..30d18aedc39 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -393,19 +393,22 @@ module.exports = function(Chart) { var datasets = chart.data.datasets; // 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 rValue = scale.getRightValue(yValue); - var value = helpers.isArray(rValue) ? rValue[2] : rValue; + var value = scale.getRightValue(yValue); var stacked = scale.options.stacked; var stack = meta.stack; // float-bar support, if y arguments are array function will use proper value as bar start point var start = 0; - if (helpers.isArray(rValue) && rValue[2] <= 0 ) { - start = rValue[1]; - } else if (helpers.isArray(rValue) && rValue[2] > 0) { - start = rValue[0]; + + if (helpers.isArray(yValue)) { + if (value <= 0 ) { + start = scale.getRightValueHigh(yValue); + } else if (value > 0) { + start = scale.getRightValueLow(yValue); + } } - var i, imeta, ivalue, base, head, size; + + var i, imeta, ivalue, base, head, size, yStackValue; if (stacked || (stacked === undefined && stack !== undefined)) { for (i = 0; i < datasetIndex; ++i) { @@ -416,12 +419,15 @@ module.exports = function(Chart) { imeta.controller.getValueScaleId() === scale.id && chart.isDatasetVisible(i)) { - ivalue = scale.getRightValue(datasets[i].data[index]); + yStackValue = datasets[i].data[index]; + ivalue = scale.getRightValue(yStackValue); // float-bar support - if (helpers.isArray(ivalue) && ivalue[2] <= 0 ) { - ivalue = ivalue[0]; - } else if (helpers.isArray(ivalue) && ivalue[2] > 0) { - ivalue = ivalue[1]; + if (helpers.isArray(yStackValue)) { + if (ivalue <= 0 ) { + ivalue = scale.getRightValueLow(ivalue); + } else if (ivalue > 0) { + ivalue = scale.getRightValueHigh(ivalue); + } } if ((value < 0 && ivalue < 0) || (value >= 0 && ivalue > 0)) { diff --git a/src/core/core.scale.js b/src/core/core.scale.js index a657107023a..4c7ef50c46e 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -568,8 +568,47 @@ module.exports = Element.extend({ } else if (lowY <= 0 && highY <= 0) { valueY = lowY - highY; } + + // Value is good, return it + return valueY; + }, + + getRightValueLow: function(rawValue) { + if (!helpers.isArray(rawValue)) { + return this.getRightValue(rawValue); + } + // Null and undefined values first + if (typeof rawValue[0] === 'number' && !isFinite(rawValue[0])) { + return NaN; + } + // Null and undefined values first + if (typeof rawValue[1] === 'number' && !isFinite(rawValue[1])) { + return NaN; + } + + var lowY = rawValue[0] <= rawValue[1] ? rawValue[0] : rawValue[1]; + + // Value is good, return it + return lowY; + }, + + getRightValueHigh: function(rawValue) { + if (!helpers.isArray(rawValue)) { + return this.getRightValue(rawValue); + } + // Null and undefined values first + if (typeof rawValue[0] === 'number' && !isFinite(rawValue[0])) { + return NaN; + } + // Null and undefined values first + if (typeof rawValue[1] === 'number' && !isFinite(rawValue[1])) { + return NaN; + } + + var highY = rawValue[0] > rawValue[1] ? rawValue[0] : rawValue[1]; + // Value is good, return it - return [this.getRightValue(lowY), this.getRightValue(highY), this.getRightValue(valueY)]; + return highY; }, /** * Used to get the value to display in the tooltip for the data at the given index diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index dab2390e4bf..6c66d36f073 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -77,14 +77,14 @@ module.exports = function(Chart) { var value, valueR; valueR = me.getRightValue(rawValue); - if (helpers.isArray(valueR)) { - if (valueR[2] <= 0) { - value = +me.getRightValue(valueR[0]); - } else if (valueR[2] > 0) { - value = +me.getRightValue(valueR[1]); + if (helpers.isArray(rawValue)) { + if (valueR <= 0 ) { + value = +me.getRightValueLow(rawValue); + } else if (valueR > 0) { + value = +me.getRightValueHigh(rawValue); } } else { - value = +me.getRightValue(valueR); + value = +valueR; } if (isNaN(value) || meta.data[index].hidden) { @@ -121,18 +121,14 @@ module.exports = function(Chart) { var value, valueR; valueR = me.getRightValue(rawValue); - if (helpers.isArray(valueR)) { - if (valueR[2] <= 0) { - value = +me.getRightValue(valueR[0]); - } else if (valueR[2] > 0) { - value = +me.getRightValue(valueR[1]); + if (helpers.isArray(rawValue)) { + if (valueR <= 0 ) { + value = +me.getRightValueLow(rawValue); + } else if (valueR > 0) { + value = +me.getRightValueHigh(rawValue); } } else { - value = +me.getRightValue(valueR); - } - - if (isNaN(value) || meta.data[index].hidden) { - return; + value = +valueR; } if (isNaN(value) || meta.data[index].hidden) { diff --git a/src/scales/scale.logarithmic.js b/src/scales/scale.logarithmic.js index fbc8889d489..02017f7748f 100644 --- a/src/scales/scale.logarithmic.js +++ b/src/scales/scale.logarithmic.js @@ -122,14 +122,14 @@ module.exports = function(Chart) { var value, valueR; valueR = me.getRightValue(rawValue); - if (helpers.isArray(valueR)) { - if (valueR[2] < 0) { + if (helpers.isArray(rawValue)) { + if (valueR <= 0 ) { return; - } else if (valueR[2] >= 0) { - value = +me.getRightValue(valueR[1]); + } else if (valueR > 0) { + value = +me.getRightValueHigh(rawValue); } } else { - value = +me.getRightValue(valueR); + value = +valueR; } // invalid, hidden and negative values are ignored @@ -156,22 +156,18 @@ module.exports = function(Chart) { var meta = chart.getDatasetMeta(datasetIndex); if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) { helpers.each(dataset.data, function(rawValue, index) { - var value, valueR; - valueR = +me.getRightValue(rawValue); - - if (helpers.isArray(valueR)) { - if (valueR[2] < 0) { - return; - } else if (valueR[2] >= 0) { - value = +me.getRightValue(valueR[1]); - } - } else { - value = +me.getRightValue(valueR); - } - - if (isNaN(value) || meta.data[index].hidden) { - return; - } + var value, valueR; + valueR = me.getRightValue(rawValue); + + if (helpers.isArray(rawValue)) { + if (valueR <= 0 ) { + return; + } else if (valueR > 0) { + value = +me.getRightValueHigh(rawValue); + } + } else { + value = +valueR; + } // invalid, hidden and negative values are ignored if (isNaN(value) || meta.data[index].hidden || value < 0) { From df32e68c3b47d658bfd510cd51e323bf58fbad11 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Thu, 17 May 2018 03:15:11 +0300 Subject: [PATCH 29/76] refactoring --- src/controllers/controller.bar.js | 24 +++--------------- src/core/core.scale.js | 41 +++++++++++++++++++++++-------- src/scales/scale.linear.js | 30 ++++++---------------- src/scales/scale.logarithmic.js | 20 ++------------- 4 files changed, 44 insertions(+), 71 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 30d18aedc39..354dc4924d9 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -397,18 +397,8 @@ module.exports = function(Chart) { var stacked = scale.options.stacked; var stack = meta.stack; // float-bar support, if y arguments are array function will use proper value as bar start point - var start = 0; - - if (helpers.isArray(yValue)) { - if (value <= 0 ) { - start = scale.getRightValueHigh(yValue); - } else if (value > 0) { - start = scale.getRightValueLow(yValue); - } - } - - - var i, imeta, ivalue, base, head, size, yStackValue; + var start = scale.getRightStartPoint(yValue, value); + var i, imeta, ivalue, base, head, size, yStackValue, yStackValueR; if (stacked || (stacked === undefined && stack !== undefined)) { for (i = 0; i < datasetIndex; ++i) { @@ -420,15 +410,9 @@ module.exports = function(Chart) { chart.isDatasetVisible(i)) { yStackValue = datasets[i].data[index]; - ivalue = scale.getRightValue(yStackValue); + yStackValueR = scale.getRightValue(yStackValue); // float-bar support - if (helpers.isArray(yStackValue)) { - if (ivalue <= 0 ) { - ivalue = scale.getRightValueLow(ivalue); - } else if (ivalue > 0) { - ivalue = scale.getRightValueHigh(ivalue); - } - } + ivalue = scale.getRightGapPoint(yStackValue, yStackValueR); if ((value < 0 && ivalue < 0) || (value >= 0 && ivalue > 0)) { start += ivalue; diff --git a/src/core/core.scale.js b/src/core/core.scale.js index 4c7ef50c46e..f287caa0dc5 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -546,9 +546,6 @@ module.exports = Element.extend({ // Get the correct Y low and high values. NaN bad inputs. Returns 3 values, lowY as first element, highY as second and actual Yvalue as third. getRightValueLowHigh: function(rawValue) { - if (!helpers.isArray(rawValue)) { - return this.getRightValue(rawValue); - } // Null and undefined values first if (typeof rawValue[0] === 'number' && !isFinite(rawValue[0])) { return NaN; @@ -574,9 +571,6 @@ module.exports = Element.extend({ }, getRightValueLow: function(rawValue) { - if (!helpers.isArray(rawValue)) { - return this.getRightValue(rawValue); - } // Null and undefined values first if (typeof rawValue[0] === 'number' && !isFinite(rawValue[0])) { return NaN; @@ -593,10 +587,7 @@ module.exports = Element.extend({ }, getRightValueHigh: function(rawValue) { - if (!helpers.isArray(rawValue)) { - return this.getRightValue(rawValue); - } - // Null and undefined values first + // Null and undefined values first if (typeof rawValue[0] === 'number' && !isFinite(rawValue[0])) { return NaN; } @@ -610,6 +601,36 @@ module.exports = Element.extend({ // Value is good, return it return highY; }, + + getRightStartPoint: function(rawValue, value) { + + var start = 0; + + if (helpers.isArray(rawValue)) { + if (value <= 0 ) { + start = this.getRightValueHigh(rawValue); + } else if (value > 0) { + start = this.getRightValueLow(rawValue); + } + } + + return start; + }, + + getRightGapPoint: function(rawValue, value) { + + var gap = rawValue; + + if (helpers.isArray(rawValue)) { + if (value <= 0 ) { + gap = this.getRightValueLow(rawValue); + } else if (value > 0) { + gap = this.getRightValueHigh(rawValue); + } + } + + return gap; + }, /** * Used to get the value to display in the tooltip for the data at the given index * @param index diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index 6c66d36f073..5c15a46627c 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -77,15 +77,7 @@ module.exports = function(Chart) { var value, valueR; valueR = me.getRightValue(rawValue); - if (helpers.isArray(rawValue)) { - if (valueR <= 0 ) { - value = +me.getRightValueLow(rawValue); - } else if (valueR > 0) { - value = +me.getRightValueHigh(rawValue); - } - } else { - value = +valueR; - } + value = me.getRightGapPoint(rawValue, valueR); if (isNaN(value) || meta.data[index].hidden) { return; @@ -119,17 +111,9 @@ module.exports = function(Chart) { if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) { helpers.each(dataset.data, function(rawValue, index) { var value, valueR; - valueR = me.getRightValue(rawValue); + valueR = me.getRightValue(rawValue); - if (helpers.isArray(rawValue)) { - if (valueR <= 0 ) { - value = +me.getRightValueLow(rawValue); - } else if (valueR > 0) { - value = +me.getRightValueHigh(rawValue); - } - } else { - value = +valueR; - } + value = me.getRightGapPoint(rawValue, valueR); if (isNaN(value) || meta.data[index].hidden) { return; @@ -180,11 +164,11 @@ module.exports = function(Chart) { } }, getLabelForIndex: function(index, datasetIndex) { - var yValue = this.chart.data.datasets[datasetIndex].data[index]; - if (helpers.isArray(yValue)) { - return yValue.join(' ; '); + var lyValue = this.chart.data.datasets[datasetIndex].data[index]; + if (helpers.isArray(lyValue)) { + return lyValue.join(' ; '); } else { - return +this.getRightValue(yValue); + return +this.getRightValue(lyValue); } }, // Utils diff --git a/src/scales/scale.logarithmic.js b/src/scales/scale.logarithmic.js index 02017f7748f..dec756dc17e 100644 --- a/src/scales/scale.logarithmic.js +++ b/src/scales/scale.logarithmic.js @@ -122,15 +122,7 @@ module.exports = function(Chart) { var value, valueR; valueR = me.getRightValue(rawValue); - if (helpers.isArray(rawValue)) { - if (valueR <= 0 ) { - return; - } else if (valueR > 0) { - value = +me.getRightValueHigh(rawValue); - } - } else { - value = +valueR; - } + value = me.getRightGapPoint(rawValue, valueR); // invalid, hidden and negative values are ignored if (isNaN(value) || meta.data[index].hidden || value < 0) { @@ -159,15 +151,7 @@ module.exports = function(Chart) { var value, valueR; valueR = me.getRightValue(rawValue); - if (helpers.isArray(rawValue)) { - if (valueR <= 0 ) { - return; - } else if (valueR > 0) { - value = +me.getRightValueHigh(rawValue); - } - } else { - value = +valueR; - } + value = me.getRightGapPoint(rawValue, valueR); // invalid, hidden and negative values are ignored if (isNaN(value) || meta.data[index].hidden || value < 0) { From 10c3831f8ec67b20d8689475beb0125cd31c7750 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Thu, 17 May 2018 12:02:40 +0300 Subject: [PATCH 30/76] refactoring --- src/core/core.scale.js | 78 +++++++++++++++------------------ src/scales/scale.linear.js | 8 +--- src/scales/scale.logarithmic.js | 8 +--- 3 files changed, 39 insertions(+), 55 deletions(-) diff --git a/src/core/core.scale.js b/src/core/core.scale.js index f287caa0dc5..3c19c945967 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -515,12 +515,8 @@ 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)) { - return NaN; - } - // isNaN(object) returns true, so make sure NaN is checking for a number; Discard Infinite values - if (typeof rawValue === 'number' && !isFinite(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; } @@ -546,15 +542,6 @@ module.exports = Element.extend({ // Get the correct Y low and high values. NaN bad inputs. Returns 3 values, lowY as first element, highY as second and actual Yvalue as third. getRightValueLowHigh: function(rawValue) { - // Null and undefined values first - if (typeof rawValue[0] === 'number' && !isFinite(rawValue[0])) { - return NaN; - } - // Null and undefined values first - if (typeof rawValue[1] === 'number' && !isFinite(rawValue[1])) { - return NaN; - } - var lowY = rawValue[0] <= rawValue[1] ? rawValue[0] : rawValue[1]; var highY = rawValue[0] > rawValue[1] ? rawValue[0] : rawValue[1]; var valueY = 0; @@ -571,14 +558,10 @@ module.exports = Element.extend({ }, getRightValueLow: function(rawValue) { - // Null and undefined values first - if (typeof rawValue[0] === 'number' && !isFinite(rawValue[0])) { - return NaN; - } - // Null and undefined values first - if (typeof rawValue[1] === 'number' && !isFinite(rawValue[1])) { - return NaN; - } + + if (!getArrayYvaluesCheck(rawValue)) { + return; + } var lowY = rawValue[0] <= rawValue[1] ? rawValue[0] : rawValue[1]; @@ -587,14 +570,10 @@ module.exports = Element.extend({ }, getRightValueHigh: function(rawValue) { - // Null and undefined values first - if (typeof rawValue[0] === 'number' && !isFinite(rawValue[0])) { - return NaN; - } - // Null and undefined values first - if (typeof rawValue[1] === 'number' && !isFinite(rawValue[1])) { - return NaN; - } + + if (!getArrayYvaluesCheck(rawValue)) { + return; + } var highY = rawValue[0] > rawValue[1] ? rawValue[0] : rawValue[1]; @@ -607,11 +586,7 @@ module.exports = Element.extend({ var start = 0; if (helpers.isArray(rawValue)) { - if (value <= 0 ) { - start = this.getRightValueHigh(rawValue); - } else if (value > 0) { - start = this.getRightValueLow(rawValue); - } + start = value > 0 ? this.getRightValueLow(rawValue) : this.getRightValueHigh(rawValue); } return start; @@ -621,16 +596,33 @@ module.exports = Element.extend({ var gap = rawValue; - if (helpers.isArray(rawValue)) { - if (value <= 0 ) { - gap = this.getRightValueLow(rawValue); - } else if (value > 0) { - gap = this.getRightValueHigh(rawValue); - } - } + if (helpers.isArray(rawValue)) { + gap = value <= 0 ? this.getRightValueLow(rawValue) : this.getRightValueHigh(rawValue); + } return gap; }, + + getArrayYvaluesCheck: function(rawValue) { + // Null and undefined values first + if (typeof rawValue[0] === 'number' && !isFinite(rawValue[0])) { + return false; + } + // Null and undefined values first + if (typeof rawValue[1] === 'number' && !isFinite(rawValue[1])) { + return false; + } + + return true; + }, + + getScaleLabel: function() { + if (helpers.isArray(lyValue)) { + return lyValue.join(' ; '); + } else { + return +this.getRightValue(lyValue); + } + }, /** * Used to get the value to display in the tooltip for the data at the given index * @param index diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index 5c15a46627c..369ae6a4386 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -164,12 +164,8 @@ module.exports = function(Chart) { } }, getLabelForIndex: function(index, datasetIndex) { - var lyValue = this.chart.data.datasets[datasetIndex].data[index]; - if (helpers.isArray(lyValue)) { - return lyValue.join(' ; '); - } else { - return +this.getRightValue(lyValue); - } + var value = getScaleLabel( this.chart.data.datasets[datasetIndex].data[index]); + return +this.getRightValue(value); }, // Utils getPixelForValue: function(value) { diff --git a/src/scales/scale.logarithmic.js b/src/scales/scale.logarithmic.js index dec756dc17e..4a8725d01c0 100644 --- a/src/scales/scale.logarithmic.js +++ b/src/scales/scale.logarithmic.js @@ -255,12 +255,8 @@ module.exports = function(Chart) { }, // Get the correct tooltip label getLabelForIndex: function(index, datasetIndex) { - var yValue = this.chart.data.datasets[datasetIndex].data[index]; - if (helpers.isArray(yValue)) { - return yValue.join(' ; '); - } else { - return +this.getRightValue(yValue); - } + var value = getScaleLabel( this.chart.data.datasets[datasetIndex].data[index]); + return +this.getRightValue(value); }, getPixelForTick: function(index) { return this.getPixelForValue(this.tickValues[index]); From 614275de00ab5890c4e24e62ed479261adfb756a Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Thu, 17 May 2018 17:48:41 +0300 Subject: [PATCH 31/76] refactoring --- src/controllers/controller.bar.js | 1 - src/core/core.scale.js | 25 ++----------------------- src/scales/scale.linear.js | 5 +---- src/scales/scale.logarithmic.js | 6 +----- 4 files changed, 4 insertions(+), 33 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 354dc4924d9..2c3041f46c6 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -408,7 +408,6 @@ module.exports = function(Chart) { imeta.stack === stack && imeta.controller.getValueScaleId() === scale.id && chart.isDatasetVisible(i)) { - yStackValue = datasets[i].data[index]; yStackValueR = scale.getRightValue(yStackValue); // float-bar support diff --git a/src/core/core.scale.js b/src/core/core.scale.js index 3c19c945967..e57a88b6e42 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -545,61 +545,41 @@ module.exports = Element.extend({ var lowY = rawValue[0] <= rawValue[1] ? rawValue[0] : rawValue[1]; var highY = rawValue[0] > rawValue[1] ? rawValue[0] : rawValue[1]; var valueY = 0; - //calculate the proper Y value depending on negative or positive values of the highY and lowY if (lowY >= 0 && highY > 0) { valueY = highY - lowY; } else if (lowY <= 0 && highY <= 0) { valueY = lowY - highY; } - // Value is good, return it return valueY; }, getRightValueLow: function(rawValue) { - - if (!getArrayYvaluesCheck(rawValue)) { - return; - } - var lowY = rawValue[0] <= rawValue[1] ? rawValue[0] : rawValue[1]; - // Value is good, return it return lowY; }, getRightValueHigh: function(rawValue) { - - if (!getArrayYvaluesCheck(rawValue)) { - return; - } - var highY = rawValue[0] > rawValue[1] ? rawValue[0] : rawValue[1]; - // Value is good, return it return highY; }, getRightStartPoint: function(rawValue, value) { - var start = 0; - if (helpers.isArray(rawValue)) { start = value > 0 ? this.getRightValueLow(rawValue) : this.getRightValueHigh(rawValue); } - return start; }, getRightGapPoint: function(rawValue, value) { - var gap = rawValue; - - if (helpers.isArray(rawValue)) { - gap = value <= 0 ? this.getRightValueLow(rawValue) : this.getRightValueHigh(rawValue); + if (this.getArrayYvaluesCheck(rawValue)) { + gap = value <= 0 ? rawValue : this.getRightValueHigh(rawValue); } - return gap; }, @@ -612,7 +592,6 @@ module.exports = Element.extend({ if (typeof rawValue[1] === 'number' && !isFinite(rawValue[1])) { return false; } - return true; }, diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index 369ae6a4386..b47de1f8192 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -76,7 +76,6 @@ module.exports = function(Chart) { helpers.each(dataset.data, function(rawValue, index) { var value, valueR; valueR = me.getRightValue(rawValue); - value = me.getRightGapPoint(rawValue, valueR); if (isNaN(value) || meta.data[index].hidden) { @@ -112,7 +111,6 @@ module.exports = function(Chart) { helpers.each(dataset.data, function(rawValue, index) { var value, valueR; valueR = me.getRightValue(rawValue); - value = me.getRightGapPoint(rawValue, valueR); if (isNaN(value) || meta.data[index].hidden) { @@ -164,8 +162,7 @@ module.exports = function(Chart) { } }, getLabelForIndex: function(index, datasetIndex) { - var value = getScaleLabel( this.chart.data.datasets[datasetIndex].data[index]); - return +this.getRightValue(value); + return +this.getRightValue(this.getScaleLabel(this.chart.data.datasets[datasetIndex].data[index])); }, // Utils getPixelForValue: function(value) { diff --git a/src/scales/scale.logarithmic.js b/src/scales/scale.logarithmic.js index 4a8725d01c0..1ae0065c5a7 100644 --- a/src/scales/scale.logarithmic.js +++ b/src/scales/scale.logarithmic.js @@ -121,7 +121,6 @@ module.exports = function(Chart) { var values = valuesPerStack[key]; var value, valueR; valueR = me.getRightValue(rawValue); - value = me.getRightGapPoint(rawValue, valueR); // invalid, hidden and negative values are ignored @@ -150,9 +149,7 @@ module.exports = function(Chart) { helpers.each(dataset.data, function(rawValue, index) { var value, valueR; valueR = me.getRightValue(rawValue); - value = me.getRightGapPoint(rawValue, valueR); - // invalid, hidden and negative values are ignored if (isNaN(value) || meta.data[index].hidden || value < 0) { return; @@ -255,8 +252,7 @@ module.exports = function(Chart) { }, // Get the correct tooltip label getLabelForIndex: function(index, datasetIndex) { - var value = getScaleLabel( this.chart.data.datasets[datasetIndex].data[index]); - return +this.getRightValue(value); + return +this.getRightValue(this.getScaleLabel(this.chart.data.datasets[datasetIndex].data[index])); }, getPixelForTick: function(index) { return this.getPixelForValue(this.tickValues[index]); From cf6fd4b9e4718df7bc8f6d9fb35bf859232bdd5c Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Thu, 17 May 2018 18:20:43 +0300 Subject: [PATCH 32/76] formatting --- src/core/core.scale.js | 48 ++++++++++++++++----------------- src/scales/scale.linear.js | 9 ++++--- src/scales/scale.logarithmic.js | 6 ++--- 3 files changed, 31 insertions(+), 32 deletions(-) diff --git a/src/core/core.scale.js b/src/core/core.scale.js index e57a88b6e42..6eaabc8d02b 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -514,7 +514,6 @@ 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. 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; @@ -542,10 +541,10 @@ module.exports = Element.extend({ // Get the correct Y low and high values. NaN bad inputs. Returns 3 values, lowY as first element, highY as second and actual Yvalue as third. getRightValueLowHigh: function(rawValue) { - var lowY = rawValue[0] <= rawValue[1] ? rawValue[0] : rawValue[1]; + var lowY = rawValue[0] <= rawValue[1] ? rawValue[0] : rawValue[1]; var highY = rawValue[0] > rawValue[1] ? rawValue[0] : rawValue[1]; var valueY = 0; - //calculate the proper Y value depending on negative or positive values of the highY and lowY + // calculate the proper Y value depending on negative or positive values of the highY and lowY if (lowY >= 0 && highY > 0) { valueY = highY - lowY; } else if (lowY <= 0 && highY <= 0) { @@ -556,8 +555,8 @@ module.exports = Element.extend({ }, getRightValueLow: function(rawValue) { - var lowY = rawValue[0] <= rawValue[1] ? rawValue[0] : rawValue[1]; - // Value is good, return it + var lowY = rawValue[0] <= rawValue[1] ? rawValue[0] : rawValue[1]; + // Value is good, return it return lowY; }, @@ -577,30 +576,29 @@ module.exports = Element.extend({ getRightGapPoint: function(rawValue, value) { var gap = rawValue; - if (this.getArrayYvaluesCheck(rawValue)) { - gap = value <= 0 ? rawValue : this.getRightValueHigh(rawValue); - } + if (helpers.isArray(rawValue) && this.getArrayYvaluesCheck(rawValue)) { + gap = value <= 0 ? rawValue : this.getRightValueHigh(rawValue); + } return gap; }, - getArrayYvaluesCheck: function(rawValue) { - // Null and undefined values first - if (typeof rawValue[0] === 'number' && !isFinite(rawValue[0])) { - return false; - } - // Null and undefined values first - if (typeof rawValue[1] === 'number' && !isFinite(rawValue[1])) { - return false; - } - return true; - }, + getArrayYvaluesCheck: function(rawValue) { + // Null and undefined values first + if (typeof rawValue[0] === 'number' && !isFinite(rawValue[0])) { + return false; + } + // Null and undefined values first + if (typeof rawValue[1] === 'number' && !isFinite(rawValue[1])) { + return false; + } + return true; + }, - getScaleLabel: function() { - if (helpers.isArray(lyValue)) { - return lyValue.join(' ; '); - } else { - return +this.getRightValue(lyValue); - } + getScaleLabel: function(value) { + if (helpers.isArray(value)) { + return lyValue.join(' ; '); + } + return +this.getRightValue(value); }, /** * Used to get the value to display in the tooltip for the data at the given index diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index b47de1f8192..be32e6377aa 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -76,7 +76,7 @@ module.exports = function(Chart) { helpers.each(dataset.data, function(rawValue, index) { var value, valueR; valueR = me.getRightValue(rawValue); - value = me.getRightGapPoint(rawValue, valueR); + value = me.getRightGapPoint(rawValue, valueR); if (isNaN(value) || meta.data[index].hidden) { return; @@ -110,8 +110,8 @@ module.exports = function(Chart) { if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) { helpers.each(dataset.data, function(rawValue, index) { var value, valueR; - valueR = me.getRightValue(rawValue); - value = me.getRightGapPoint(rawValue, valueR); + valueR = me.getRightValue(rawValue); + value = me.getRightGapPoint(rawValue, valueR); if (isNaN(value) || meta.data[index].hidden) { return; @@ -162,7 +162,8 @@ module.exports = function(Chart) { } }, getLabelForIndex: function(index, datasetIndex) { - return +this.getRightValue(this.getScaleLabel(this.chart.data.datasets[datasetIndex].data[index])); + var value = this.chart.data.datasets[datasetIndex].data[index]; + return +this.getRightValue(this.getScaleLabel(value)); }, // Utils getPixelForValue: function(value) { diff --git a/src/scales/scale.logarithmic.js b/src/scales/scale.logarithmic.js index 1ae0065c5a7..eb7d524873b 100644 --- a/src/scales/scale.logarithmic.js +++ b/src/scales/scale.logarithmic.js @@ -121,7 +121,7 @@ module.exports = function(Chart) { var values = valuesPerStack[key]; var value, valueR; valueR = me.getRightValue(rawValue); - value = me.getRightGapPoint(rawValue, valueR); + value = me.getRightGapPoint(rawValue, valueR); // invalid, hidden and negative values are ignored if (isNaN(value) || meta.data[index].hidden || value < 0) { @@ -149,7 +149,7 @@ module.exports = function(Chart) { helpers.each(dataset.data, function(rawValue, index) { var value, valueR; valueR = me.getRightValue(rawValue); - value = me.getRightGapPoint(rawValue, valueR); + value = me.getRightGapPoint(rawValue, valueR); // invalid, hidden and negative values are ignored if (isNaN(value) || meta.data[index].hidden || value < 0) { return; @@ -252,7 +252,7 @@ module.exports = function(Chart) { }, // Get the correct tooltip label getLabelForIndex: function(index, datasetIndex) { - return +this.getRightValue(this.getScaleLabel(this.chart.data.datasets[datasetIndex].data[index])); + return +this.getRightValue(this.getScaleLabel(this.chart.data.datasets[datasetIndex].data[index])); }, getPixelForTick: function(index) { return this.getPixelForValue(this.tickValues[index]); From d5ef4345c9468764b9cb7b9ee91a4ffdadfd4032 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Fri, 18 May 2018 16:38:07 +0300 Subject: [PATCH 33/76] formatting --- src/core/core.scale.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/core.scale.js b/src/core/core.scale.js index 6eaabc8d02b..948d0a5a5e8 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -572,7 +572,7 @@ module.exports = Element.extend({ start = value > 0 ? this.getRightValueLow(rawValue) : this.getRightValueHigh(rawValue); } return start; - }, + }, getRightGapPoint: function(rawValue, value) { var gap = rawValue; @@ -596,11 +596,11 @@ module.exports = Element.extend({ getScaleLabel: function(value) { if (helpers.isArray(value)) { - return lyValue.join(' ; '); + return value.join(' ; '); } return +this.getRightValue(value); }, -/** + /** * Used to get the value to display in the tooltip for the data at the given index * @param index * @param datasetIndex From a75e3ac28299b89480957d13da153b8d74edf6e1 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Mon, 21 May 2018 17:52:28 +0300 Subject: [PATCH 34/76] CHanges to float-bar support. parseValue is in scale.js, returns data as object with min, max and val. This functions is used in controller.bar.js to calculate start point and gap for floating-bar. Also this functiotn is used in scale.linearjs and scale.logarithmic.js to calculate scale min and max values and label texts. --- src/controllers/controller.bar.js | 22 ++++++++++++------- src/core/core.scale.js | 35 +++++++++++++++++++++++++------ src/scales/scale.linear.js | 28 +++++++++++-------------- src/scales/scale.logarithmic.js | 34 +++++++++++++----------------- 4 files changed, 70 insertions(+), 49 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 2c3041f46c6..0e55dd2dc04 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -392,13 +392,16 @@ module.exports = function(Chart) { var scale = me.getValueScale(); var datasets = chart.data.datasets; // 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 = scale.getRightValue(yValue); + var value = scale.parseValue(datasets[datasetIndex].data[index]); var stacked = scale.options.stacked; var stack = meta.stack; // float-bar support, if y arguments are array function will use proper value as bar start point - var start = scale.getRightStartPoint(yValue, value); - var i, imeta, ivalue, base, head, size, yStackValue, yStackValueR; + var start = 0; + if (value.min != value.max) { + start = value.val > 0 ? value.min : value.max; + } + + var i, imeta, ivalue, base, head, size, yStackValue; if (stacked || (stacked === undefined && stack !== undefined)) { for (i = 0; i < datasetIndex; ++i) { @@ -408,10 +411,13 @@ module.exports = function(Chart) { imeta.stack === stack && imeta.controller.getValueScaleId() === scale.id && chart.isDatasetVisible(i)) { - yStackValue = datasets[i].data[index]; - yStackValueR = scale.getRightValue(yStackValue); - // float-bar support - ivalue = scale.getRightGapPoint(yStackValue, yStackValueR); + yStackValue = scale.parseValue(datasets[i].data[index]); + + if (yStackValue.min == yStackValue.max) { + ivalue = yStackValue.val; + } else { + ivalue = yStackValue.val <= 0 ? yStackValue.min : yStackValue.max; + } if ((value < 0 && ivalue < 0) || (value >= 0 && ivalue > 0)) { start += ivalue; diff --git a/src/core/core.scale.js b/src/core/core.scale.js index 948d0a5a5e8..2d9984837e9 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -521,7 +521,7 @@ module.exports = Element.extend({ // Float-bar support. Handling arrays if (helpers.isArray(rawValue)) { - return this.getRightValueLowHigh(rawValue); + return [this.getRightValue(rawValue[0]), this.getRightValue(rawValue[1])]; } // If it is in fact an object, dive in one more level @@ -539,6 +539,31 @@ module.exports = Element.extend({ return rawValue; }, + parseValue: function(rawValue) { + var value = this.getRightValue(rawValue); + var min, max; + + if (helpers.isArray(value)) { + min = value[0] <= value[1] ? value[0] : value[1]; + max = value[0] > value[1] ? value[0] : value[1]; + + if (min >= 0 && max > 0) { + value = max - min; + } else if (min <= 0 && max <= 0) { + value = min - max; + } + } else { + min = value; + max = value; + } + + return { + min: min, + max: max, + val: value + } + }, + // Get the correct Y low and high values. NaN bad inputs. Returns 3 values, lowY as first element, highY as second and actual Yvalue as third. getRightValueLowHigh: function(rawValue) { var lowY = rawValue[0] <= rawValue[1] ? rawValue[0] : rawValue[1]; @@ -594,11 +619,9 @@ module.exports = Element.extend({ return true; }, - getScaleLabel: function(value) { - if (helpers.isArray(value)) { - return value.join(' ; '); - } - return +this.getRightValue(value); + getScaleLabel: function(rawValue) { + var v = scale.parseValue(rawValue); + return v.min == v.max ? v.min : v.min + " ; " v.max; }, /** * Used to get the value to display in the tooltip for the data at the given index diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index be32e6377aa..ba430fb3101 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -74,11 +74,9 @@ module.exports = function(Chart) { if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) { helpers.each(dataset.data, function(rawValue, index) { - var value, valueR; - valueR = me.getRightValue(rawValue); - value = me.getRightGapPoint(rawValue, valueR); + var value = me.parseValue(rawValue); - if (isNaN(value) || meta.data[index].hidden) { + if (isNaN(value.val) || meta.data[index].hidden) { return; } @@ -87,10 +85,10 @@ module.exports = function(Chart) { if (opts.relativePoints) { positiveValues[index] = 100; - } else if (value < 0) { - negativeValues[index] += value; + } else if (value.val < 0) { + negativeValues[index] += value.min; } else { - positiveValues[index] += value; + positiveValues[index] += value.max; } }); } @@ -109,24 +107,22 @@ module.exports = function(Chart) { var meta = chart.getDatasetMeta(datasetIndex); if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) { helpers.each(dataset.data, function(rawValue, index) { - var value, valueR; - valueR = me.getRightValue(rawValue); - value = me.getRightGapPoint(rawValue, valueR); + var value = me.parseValue(rawValue); - if (isNaN(value) || meta.data[index].hidden) { + if (isNaN(value.val) || meta.data[index].hidden) { return; } if (me.min === null) { - me.min = value; + me.min = value.min; } else if (value < me.min) { - me.min = value; + me.min = value.min; } if (me.max === null) { - me.max = value; + me.max = value.max; } else if (value > me.max) { - me.max = value; + me.max = value.max; } }); } @@ -163,7 +159,7 @@ module.exports = function(Chart) { }, getLabelForIndex: function(index, datasetIndex) { var value = this.chart.data.datasets[datasetIndex].data[index]; - return +this.getRightValue(this.getScaleLabel(value)); + return this.getScaleLabel(value); }, // Utils getPixelForValue: function(value) { diff --git a/src/scales/scale.logarithmic.js b/src/scales/scale.logarithmic.js index eb7d524873b..6e9bae7ad63 100644 --- a/src/scales/scale.logarithmic.js +++ b/src/scales/scale.logarithmic.js @@ -118,17 +118,14 @@ module.exports = function(Chart) { } helpers.each(dataset.data, function(rawValue, index) { - var values = valuesPerStack[key]; - var value, valueR; - valueR = me.getRightValue(rawValue); - value = me.getRightGapPoint(rawValue, valueR); + var value = me.parseValue(rawValue); // invalid, hidden and negative values are ignored - if (isNaN(value) || meta.data[index].hidden || value < 0) { + if (isNaN(value.val) || meta.data[index].hidden || value.val < 0) { return; } values[index] = values[index] || 0; - values[index] += value; + values[index] += value.max; }); } }); @@ -147,28 +144,26 @@ module.exports = function(Chart) { var meta = chart.getDatasetMeta(datasetIndex); if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) { helpers.each(dataset.data, function(rawValue, index) { - var value, valueR; - valueR = me.getRightValue(rawValue); - value = me.getRightGapPoint(rawValue, valueR); + var value = me.parseValue(rawValue); // invalid, hidden and negative values are ignored - if (isNaN(value) || meta.data[index].hidden || value < 0) { + if (isNaN(value.val) || meta.data[index].hidden || value.val < 0) { return; } 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; } - 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; } }); } @@ -252,7 +247,8 @@ module.exports = function(Chart) { }, // Get the correct tooltip label getLabelForIndex: function(index, datasetIndex) { - return +this.getRightValue(this.getScaleLabel(this.chart.data.datasets[datasetIndex].data[index])); + var value = this.chart.data.datasets[datasetIndex].data[index]; + return this.getScaleLabel(value); }, getPixelForTick: function(index) { return this.getPixelForValue(this.tickValues[index]); From aaaac7357fbc9438838768d343c579d0416df84e Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Mon, 21 May 2018 18:07:56 +0300 Subject: [PATCH 35/76] formatting --- src/core/core.scale.js | 55 ------------------------------------------ 1 file changed, 55 deletions(-) diff --git a/src/core/core.scale.js b/src/core/core.scale.js index 2d9984837e9..4cd09a60430 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -564,61 +564,6 @@ module.exports = Element.extend({ } }, - // Get the correct Y low and high values. NaN bad inputs. Returns 3 values, lowY as first element, highY as second and actual Yvalue as third. - getRightValueLowHigh: function(rawValue) { - var lowY = rawValue[0] <= rawValue[1] ? rawValue[0] : rawValue[1]; - var highY = rawValue[0] > rawValue[1] ? rawValue[0] : rawValue[1]; - var valueY = 0; - // calculate the proper Y value depending on negative or positive values of the highY and lowY - if (lowY >= 0 && highY > 0) { - valueY = highY - lowY; - } else if (lowY <= 0 && highY <= 0) { - valueY = lowY - highY; - } - // Value is good, return it - return valueY; - }, - - getRightValueLow: function(rawValue) { - var lowY = rawValue[0] <= rawValue[1] ? rawValue[0] : rawValue[1]; - // Value is good, return it - return lowY; - }, - - getRightValueHigh: function(rawValue) { - var highY = rawValue[0] > rawValue[1] ? rawValue[0] : rawValue[1]; - // Value is good, return it - return highY; - }, - - getRightStartPoint: function(rawValue, value) { - var start = 0; - if (helpers.isArray(rawValue)) { - start = value > 0 ? this.getRightValueLow(rawValue) : this.getRightValueHigh(rawValue); - } - return start; - }, - - getRightGapPoint: function(rawValue, value) { - var gap = rawValue; - if (helpers.isArray(rawValue) && this.getArrayYvaluesCheck(rawValue)) { - gap = value <= 0 ? rawValue : this.getRightValueHigh(rawValue); - } - return gap; - }, - - getArrayYvaluesCheck: function(rawValue) { - // Null and undefined values first - if (typeof rawValue[0] === 'number' && !isFinite(rawValue[0])) { - return false; - } - // Null and undefined values first - if (typeof rawValue[1] === 'number' && !isFinite(rawValue[1])) { - return false; - } - return true; - }, - getScaleLabel: function(rawValue) { var v = scale.parseValue(rawValue); return v.min == v.max ? v.min : v.min + " ; " v.max; From 5e877aa247e41e351a13ae979faa6f30886f4945 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Mon, 21 May 2018 21:45:12 +0300 Subject: [PATCH 36/76] fixes --- src/controllers/controller.bar.js | 16 ++++++++-------- src/core/core.scale.js | 4 ++-- src/scales/scale.linear.js | 4 ++-- src/scales/scale.logarithmic.js | 9 +++++---- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 0e55dd2dc04..e1f802ef5fd 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -396,10 +396,10 @@ module.exports = function(Chart) { var stacked = scale.options.stacked; var stack = meta.stack; // float-bar support, if y arguments are array function will use proper value as bar start point - var start = 0; - if (value.min != value.max) { - start = value.val > 0 ? value.min : value.max; - } + var start = 0; + if (value.min !== value.max) { + start = value.val > 0 ? value.min : value.max; + } var i, imeta, ivalue, base, head, size, yStackValue; @@ -413,10 +413,10 @@ module.exports = function(Chart) { chart.isDatasetVisible(i)) { yStackValue = scale.parseValue(datasets[i].data[index]); - if (yStackValue.min == yStackValue.max) { - ivalue = yStackValue.val; - } else { - ivalue = yStackValue.val <= 0 ? yStackValue.min : yStackValue.max; + if (yStackValue.min === yStackValue.max) { + ivalue = yStackValue.val; + } else { + ivalue = yStackValue.val <= 0 ? yStackValue.min : yStackValue.max; } if ((value < 0 && ivalue < 0) || (value >= 0 && ivalue > 0)) { diff --git a/src/core/core.scale.js b/src/core/core.scale.js index 4cd09a60430..d2d873c66ea 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -565,8 +565,8 @@ module.exports = Element.extend({ }, getScaleLabel: function(rawValue) { - var v = scale.parseValue(rawValue); - return v.min == v.max ? v.min : v.min + " ; " v.max; + var v = this.parseValue(rawValue); + return v.min == v.max ? v.min : v.min + " ; " + v.max; }, /** * Used to get the value to display in the tooltip for the data at the given index diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index ba430fb3101..f31431be715 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -74,7 +74,7 @@ module.exports = function(Chart) { if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) { helpers.each(dataset.data, function(rawValue, index) { - var value = me.parseValue(rawValue); + var value = me.parseValue(rawValue); if (isNaN(value.val) || meta.data[index].hidden) { return; @@ -107,7 +107,7 @@ 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.parseValue(rawValue); + var value = me.parseValue(rawValue); if (isNaN(value.val) || meta.data[index].hidden) { return; diff --git a/src/scales/scale.logarithmic.js b/src/scales/scale.logarithmic.js index 6e9bae7ad63..2777a0db96d 100644 --- a/src/scales/scale.logarithmic.js +++ b/src/scales/scale.logarithmic.js @@ -118,7 +118,8 @@ module.exports = function(Chart) { } helpers.each(dataset.data, function(rawValue, index) { - var value = me.parseValue(rawValue); + var values = valuesPerStack[key]; + var value = me.parseValue(rawValue); // invalid, hidden and negative values are ignored if (isNaN(value.val) || meta.data[index].hidden || value.val < 0) { @@ -144,7 +145,7 @@ 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.parseValue(rawValue); + var value = me.parseValue(rawValue); // invalid, hidden and negative values are ignored if (isNaN(value.val) || meta.data[index].hidden || value.val < 0) { return; @@ -247,8 +248,8 @@ module.exports = function(Chart) { }, // Get the correct tooltip label getLabelForIndex: function(index, datasetIndex) { - var value = this.chart.data.datasets[datasetIndex].data[index]; - return this.getScaleLabel(value); + var value = this.chart.data.datasets[datasetIndex].data[index]; + return this.getScaleLabel(value); }, getPixelForTick: function(index) { return this.getPixelForValue(this.tickValues[index]); From 823160ea6d84f775d50bf1aaf1a31e3058f56add Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Wed, 23 May 2018 01:45:01 +0300 Subject: [PATCH 37/76] formatting --- src/controllers/controller.bar.js | 8 ++------ src/scales/scale.linear.js | 13 ++++++------- src/scales/scale.logarithmic.js | 5 ++--- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index e1f802ef5fd..6d3514a5247 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -87,10 +87,7 @@ defaults._set('horizontalBar', { label: function(item, data) { var datasetLabel = data.datasets[item.datasetIndex].label || ''; - - datasetLabel += ': ' + item.xLabel; - - return datasetLabel; + return datasetLabel + ': ' + item.xLabel; } }, mode: 'index', @@ -397,12 +394,11 @@ module.exports = function(Chart) { var stack = meta.stack; // float-bar support, if y arguments are array function will use proper value as bar start point var start = 0; + var i, imeta, ivalue, base, head, size, yStackValue; if (value.min !== value.max) { start = value.val > 0 ? value.min : value.max; } - var i, imeta, ivalue, base, head, size, yStackValue; - if (stacked || (stacked === undefined && stack !== undefined)) { for (i = 0; i < datasetIndex; ++i) { imeta = chart.getDatasetMeta(i); diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index f31431be715..0d5ecabe121 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -76,7 +76,7 @@ module.exports = function(Chart) { helpers.each(dataset.data, function(rawValue, index) { var value = me.parseValue(rawValue); - if (isNaN(value.val) || meta.data[index].hidden) { + if (isNaN(value.min) || isNaN(value.max) || meta.data[index].hidden) { return; } @@ -85,7 +85,7 @@ module.exports = function(Chart) { if (opts.relativePoints) { positiveValues[index] = 100; - } else if (value.val < 0) { + } else if (value.min < 0 || value.max < 0 ) { negativeValues[index] += value.min; } else { positiveValues[index] += value.max; @@ -109,19 +109,19 @@ module.exports = function(Chart) { helpers.each(dataset.data, function(rawValue, index) { var value = me.parseValue(rawValue); - if (isNaN(value.val) || meta.data[index].hidden) { + if (isNaN(value.min) || isNaN(value.max) || meta.data[index].hidden) { return; } if (me.min === null) { me.min = value.min; - } else if (value < me.min) { + } else if (value.min < me.min) { me.min = value.min; } if (me.max === null) { me.max = value.max; - } else if (value > me.max) { + } else if (value.max > me.max) { me.max = value.max; } }); @@ -158,8 +158,7 @@ module.exports = function(Chart) { } }, getLabelForIndex: function(index, datasetIndex) { - var value = this.chart.data.datasets[datasetIndex].data[index]; - return this.getScaleLabel(value); + return this.getScaleLabel(this.chart.data.datasets[datasetIndex].data[index]); }, // Utils getPixelForValue: function(value) { diff --git a/src/scales/scale.logarithmic.js b/src/scales/scale.logarithmic.js index 2777a0db96d..5de27250af0 100644 --- a/src/scales/scale.logarithmic.js +++ b/src/scales/scale.logarithmic.js @@ -122,7 +122,7 @@ module.exports = function(Chart) { var value = me.parseValue(rawValue); // invalid, hidden and negative values are ignored - if (isNaN(value.val) || meta.data[index].hidden || value.val < 0) { + if (isNaN(value.max) || meta.data[index].hidden || value.max < 0) { return; } values[index] = values[index] || 0; @@ -248,8 +248,7 @@ module.exports = function(Chart) { }, // Get the correct tooltip label getLabelForIndex: function(index, datasetIndex) { - var value = this.chart.data.datasets[datasetIndex].data[index]; - return this.getScaleLabel(value); + return this.getScaleLabel(this.chart.data.datasets[datasetIndex].data[index]); }, getPixelForTick: function(index) { return this.getPixelForValue(this.tickValues[index]); From 11bb986426a4463c07a7f3a6080660757df49ddd Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Wed, 23 May 2018 04:46:15 +0300 Subject: [PATCH 38/76] fixes --- src/controllers/controller.bar.js | 4 ++-- src/scales/scale.logarithmic.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 6d3514a5247..ceec575bcb4 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -415,7 +415,7 @@ module.exports = function(Chart) { ivalue = yStackValue.val <= 0 ? yStackValue.min : yStackValue.max; } - if ((value < 0 && ivalue < 0) || (value >= 0 && ivalue > 0)) { + if ((value.min < 0 && ivalue < 0) || (value.max >= 0 && ivalue > 0)) { start += ivalue; } } @@ -423,7 +423,7 @@ module.exports = function(Chart) { } base = scale.getPixelForValue(start); - head = scale.getPixelForValue(start + value); + head = scale.getPixelForValue(start + value.val); size = (head - base) / 2; return { diff --git a/src/scales/scale.logarithmic.js b/src/scales/scale.logarithmic.js index 5de27250af0..01206c8d158 100644 --- a/src/scales/scale.logarithmic.js +++ b/src/scales/scale.logarithmic.js @@ -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; From 1c526e30d7eba3b30c31d8f10566cc3b462b38cf Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Wed, 23 May 2018 05:04:11 +0300 Subject: [PATCH 39/76] fixes --- src/core/core.scale.js | 51 ++++++++++++++++----------------- src/scales/scale.linear.js | 2 +- src/scales/scale.logarithmic.js | 2 +- 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/src/core/core.scale.js b/src/core/core.scale.js index d2d873c66ea..2cba5a70e18 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -539,34 +539,33 @@ module.exports = Element.extend({ return rawValue; }, - parseValue: function(rawValue) { - var value = this.getRightValue(rawValue); - var min, max; - - if (helpers.isArray(value)) { - min = value[0] <= value[1] ? value[0] : value[1]; - max = value[0] > value[1] ? value[0] : value[1]; - - if (min >= 0 && max > 0) { - value = max - min; - } else if (min <= 0 && max <= 0) { - value = min - max; - } - } else { - min = value; - max = value; - } - - return { - min: min, - max: max, - val: value - } - }, + parseValue: function(rawValue) { + var value = this.getRightValue(rawValue); + var min, max; + if (helpers.isArray(value)) { + min = value[0] <= value[1] ? value[0] : value[1]; + max = value[0] > value[1] ? value[0] : value[1]; + + if (min >= 0 && max > 0) { + value = max - min; + } else if (min <= 0 && max <= 0) { + value = min - max; + } + } else { + min = value; + max = value; + } + + return { + min: min, + max: max, + val: value + }; + }, getScaleLabel: function(rawValue) { - var v = this.parseValue(rawValue); - return v.min == v.max ? v.min : v.min + " ; " + v.max; + var v = this.parseValue(rawValue); + return v.min === v.max ? v.min : v.min + ' ; ' + v.max; }, /** * Used to get the value to display in the tooltip for the data at the given index diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index 0d5ecabe121..009f0beb96c 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -85,7 +85,7 @@ module.exports = function(Chart) { if (opts.relativePoints) { positiveValues[index] = 100; - } else if (value.min < 0 || value.max < 0 ) { + } else if (value.min < 0 || value.max < 0) { negativeValues[index] += value.min; } else { positiveValues[index] += value.max; diff --git a/src/scales/scale.logarithmic.js b/src/scales/scale.logarithmic.js index 01206c8d158..0274c595875 100644 --- a/src/scales/scale.logarithmic.js +++ b/src/scales/scale.logarithmic.js @@ -248,7 +248,7 @@ module.exports = function(Chart) { }, // Get the correct tooltip label getLabelForIndex: function(index, datasetIndex) { - return this.getScaleLabel(this.chart.data.datasets[datasetIndex].data[index]); + return this.getScaleLabel(this.chart.data.datasets[datasetIndex].data[index]); }, getPixelForTick: function(index) { return this.getPixelForValue(this.tickValues[index]); From a59a602dd5743300a902574476105ba18d05c554 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Wed, 23 May 2018 05:30:46 +0300 Subject: [PATCH 40/76] fixes --- src/core/core.scale.js | 2 +- src/scales/scale.logarithmic.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/core.scale.js b/src/core/core.scale.js index 2cba5a70e18..17e209e431b 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -540,7 +540,7 @@ module.exports = Element.extend({ }, parseValue: function(rawValue) { - var value = this.getRightValue(rawValue); + var value = +this.getRightValue(rawValue); var min, max; if (helpers.isArray(value)) { min = value[0] <= value[1] ? value[0] : value[1]; diff --git a/src/scales/scale.logarithmic.js b/src/scales/scale.logarithmic.js index 0274c595875..9c1e29fce61 100644 --- a/src/scales/scale.logarithmic.js +++ b/src/scales/scale.logarithmic.js @@ -147,7 +147,7 @@ module.exports = function(Chart) { helpers.each(dataset.data, function(rawValue, index) { var value = me.parseValue(rawValue); // invalid, hidden and negative values are ignored - if (isNaN(value.val) || meta.data[index].hidden || value.val < 0) { + if (isNaN(value.min) || isNaN(value.max) || meta.data[index].hidden || value.min < 0 || value.max < 0) { return; } From a4efcf08bafb6840c87d6aeea54b94a6ba3241c3 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Wed, 23 May 2018 10:12:50 +0300 Subject: [PATCH 41/76] fix --- src/controllers/controller.bar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index ceec575bcb4..2e38a404baf 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -396,7 +396,7 @@ module.exports = function(Chart) { var start = 0; var i, imeta, ivalue, base, head, size, yStackValue; if (value.min !== value.max) { - start = value.val > 0 ? value.min : value.max; + start = value.val >= 0 ? value.min : value.max; } if (stacked || (stacked === undefined && stack !== undefined)) { From 25ff4ea3d99eec8fd02346b1bb1571f0d9f16c35 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Wed, 23 May 2018 21:35:48 +0300 Subject: [PATCH 42/76] formatting --- src/controllers/controller.bar.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 2e38a404baf..137e866253a 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -408,10 +408,9 @@ module.exports = function(Chart) { imeta.controller.getValueScaleId() === scale.id && chart.isDatasetVisible(i)) { yStackValue = scale.parseValue(datasets[i].data[index]); + var ivalue = yStackValue.val; - if (yStackValue.min === yStackValue.max) { - ivalue = yStackValue.val; - } else { + if (yStackValue.min !== yStackValue.max) { ivalue = yStackValue.val <= 0 ? yStackValue.min : yStackValue.max; } From 7e75beff9a691a1e061759d55fa672d02a81e5c3 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Thu, 24 May 2018 00:01:37 +0300 Subject: [PATCH 43/76] fixes --- src/controllers/controller.bar.js | 2 +- src/core/core.scale.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 137e866253a..80f01febcb9 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -408,7 +408,7 @@ module.exports = function(Chart) { imeta.controller.getValueScaleId() === scale.id && chart.isDatasetVisible(i)) { yStackValue = scale.parseValue(datasets[i].data[index]); - var ivalue = yStackValue.val; + ivalue = yStackValue.val; if (yStackValue.min !== yStackValue.max) { ivalue = yStackValue.val <= 0 ? yStackValue.min : yStackValue.max; diff --git a/src/core/core.scale.js b/src/core/core.scale.js index 17e209e431b..8db73691f7c 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -543,8 +543,8 @@ module.exports = Element.extend({ var value = +this.getRightValue(rawValue); var min, max; if (helpers.isArray(value)) { - min = value[0] <= value[1] ? value[0] : value[1]; - max = value[0] > value[1] ? value[0] : value[1]; + min = Math.min(value[0], value[1]); + max = Math.max(value[0], value[1]); if (min >= 0 && max > 0) { value = max - min; From 03b816790e42e7fa204ca1d3272918bec16e740d Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Thu, 24 May 2018 14:19:25 +0300 Subject: [PATCH 44/76] Reformatting parseScale function --- src/controllers/controller.bar.js | 23 ++++++++------------- src/core/core.scale.js | 33 +++++++++++++++---------------- src/scales/scale.linear.js | 4 ++-- src/scales/scale.logarithmic.js | 4 ++-- 4 files changed, 28 insertions(+), 36 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 80f01febcb9..a16339700e7 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -388,16 +388,13 @@ module.exports = function(Chart) { var meta = me.getMeta(); var scale = me.getValueScale(); var datasets = chart.data.datasets; - // float-bar support, if y arguments are array function will use top - bottom value to calculate bar height - var value = scale.parseValue(datasets[datasetIndex].data[index]); + var value = scale._parseValue(datasets[datasetIndex].data[index]); var stacked = scale.options.stacked; var stack = meta.stack; - // float-bar support, if y arguments are array function will use proper value as bar start point - var start = 0; var i, imeta, ivalue, base, head, size, yStackValue; - if (value.min !== value.max) { - start = value.val >= 0 ? value.min : value.max; - } + var start = value.max >= 0 && value.min >= 0 ? value.min : value.max; + + value.value = value.max >= 0 && value.min >= 0 ? value.max - value.min : value.min - value.max; if (stacked || (stacked === undefined && stack !== undefined)) { for (i = 0; i < datasetIndex; ++i) { @@ -407,14 +404,10 @@ module.exports = function(Chart) { imeta.stack === stack && imeta.controller.getValueScaleId() === scale.id && chart.isDatasetVisible(i)) { - yStackValue = scale.parseValue(datasets[i].data[index]); - ivalue = yStackValue.val; - - if (yStackValue.min !== yStackValue.max) { - ivalue = yStackValue.val <= 0 ? yStackValue.min : yStackValue.max; - } + yStackValue = scale._parseValue(datasets[i].data[index]); + ivalue = yStackValue.min >= 0 && yStackValue.max >= 0 ? yStackValue.max : yStackValue.min; - if ((value.min < 0 && ivalue < 0) || (value.max >= 0 && ivalue > 0)) { + if ((value.min <= 0 && ivalue < 0) || (value.max >= 0 && ivalue > 0)) { start += ivalue; } } @@ -422,7 +415,7 @@ module.exports = function(Chart) { } base = scale.getPixelForValue(start); - head = scale.getPixelForValue(start + value.val); + head = scale.getPixelForValue(start + value.value); size = (head - base) / 2; return { diff --git a/src/core/core.scale.js b/src/core/core.scale.js index 8db73691f7c..a6eee4ebf15 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -539,32 +539,31 @@ module.exports = Element.extend({ return rawValue; }, - parseValue: function(rawValue) { - var value = +this.getRightValue(rawValue); - var min, max; - if (helpers.isArray(value)) { - min = Math.min(value[0], value[1]); - max = Math.max(value[0], value[1]); + /** + * @private + */ + _parseValue: function(raw) { + var value = this.getRightValue(raw); + var start, end; - if (min >= 0 && max > 0) { - value = max - min; - } else if (min <= 0 && max <= 0) { - value = min - max; - } + if (helpers.isArray(value)) { + start = value[0]; + end = value[1]; } else { - min = value; - max = value; + start = 0; + end = value; } return { - min: min, - max: max, - val: value + min: Math.min(start, end), + max: Math.max(start, end), + start: start, + end: end }; }, getScaleLabel: function(rawValue) { - var v = this.parseValue(rawValue); + var v = this._parseValue(rawValue); return v.min === v.max ? v.min : v.min + ' ; ' + v.max; }, /** diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index 009f0beb96c..68a2efeba0f 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -74,7 +74,7 @@ module.exports = function(Chart) { if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) { helpers.each(dataset.data, function(rawValue, index) { - var value = me.parseValue(rawValue); + var value = me._parseValue(rawValue); if (isNaN(value.min) || isNaN(value.max) || meta.data[index].hidden) { return; @@ -107,7 +107,7 @@ 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.parseValue(rawValue); + var value = me._parseValue(rawValue); if (isNaN(value.min) || isNaN(value.max) || meta.data[index].hidden) { return; diff --git a/src/scales/scale.logarithmic.js b/src/scales/scale.logarithmic.js index 9c1e29fce61..cb92acc8bb5 100644 --- a/src/scales/scale.logarithmic.js +++ b/src/scales/scale.logarithmic.js @@ -119,7 +119,7 @@ module.exports = function(Chart) { helpers.each(dataset.data, function(rawValue, index) { var values = valuesPerStack[key]; - var value = me.parseValue(rawValue); + var value = me._parseValue(rawValue); // invalid, hidden and negative values are ignored if (isNaN(value.max) || meta.data[index].hidden || value.max < 0) { @@ -145,7 +145,7 @@ 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.parseValue(rawValue); + var value = me._parseValue(rawValue); // invalid, hidden and negative values are ignored if (isNaN(value.min) || isNaN(value.max) || meta.data[index].hidden || value.min < 0 || value.max < 0) { return; From 659235bba980d06c4e103e09a7e3dd78a1bb8166 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Wed, 30 May 2018 02:23:59 +0300 Subject: [PATCH 45/76] last changes --- src/controllers/controller.bar.js | 21 ++++++++------------- src/core/core.scale.js | 9 +++------ src/scales/scale.linear.js | 5 +++-- src/scales/scale.logarithmic.js | 3 ++- 4 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index a16339700e7..d9775c6090a 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -392,9 +392,8 @@ module.exports = function(Chart) { var stacked = scale.options.stacked; var stack = meta.stack; var i, imeta, ivalue, base, head, size, yStackValue; - var start = value.max >= 0 && value.min >= 0 ? value.min : value.max; - - value.value = value.max >= 0 && value.min >= 0 ? value.max - value.min : value.min - value.max; + var value.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; if (stacked || (stacked === undefined && stack !== undefined)) { for (i = 0; i < datasetIndex; ++i) { @@ -407,15 +406,15 @@ module.exports = function(Chart) { yStackValue = scale._parseValue(datasets[i].data[index]); ivalue = yStackValue.min >= 0 && yStackValue.max >= 0 ? yStackValue.max : yStackValue.min; - if ((value.min <= 0 && ivalue < 0) || (value.max >= 0 && ivalue > 0)) { - start += ivalue; + if ((value.min < 0 && ivalue < 0) || (value.max >= 0 && ivalue > 0)) { + value.start += ivalue; } } } } - base = scale.getPixelForValue(start); - head = scale.getPixelForValue(start + value.value); + base = scale.getPixelForValue(value.start); + head = scale.getPixelForValue(value.start + yValue); size = (head - base) / 2; return { @@ -463,12 +462,8 @@ module.exports = function(Chart) { // float-bar support, if y arguments are array function will use bottom value as bar start point for (; i < ilen; ++i) { - var yValue = dataset.data[i]; - if (helpers.isArray(yValue)) { - if (!isNaN(scale.getRightValue(yValue[1])) && !isNaN(scale.getRightValue(yValue[0]))) { - rects[i].draw(); - } - } else if (!isNaN(scale.getRightValue(yValue))) { + var val = scale._parseValue(dataset.data[i]); + if (!helpers.isNaN(val.start) && !helpers.isNaN(val.end)) { rects[i].draw(); } } diff --git a/src/core/core.scale.js b/src/core/core.scale.js index a6eee4ebf15..73921eeced9 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -540,8 +540,9 @@ module.exports = Element.extend({ }, /** - * @private - */ + * @private + * Parse array and generic values into object + */ _parseValue: function(raw) { var value = this.getRightValue(raw); var start, end; @@ -562,10 +563,6 @@ module.exports = Element.extend({ }; }, - getScaleLabel: function(rawValue) { - var v = this._parseValue(rawValue); - return v.min === v.max ? v.min : v.min + ' ; ' + v.max; - }, /** * Used to get the value to display in the tooltip for the data at the given index * @param index diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index 68a2efeba0f..0ec55c9d7b2 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -85,7 +85,7 @@ module.exports = function(Chart) { if (opts.relativePoints) { positiveValues[index] = 100; - } else if (value.min < 0 || value.max < 0) { + } else if (value.min < 0) { negativeValues[index] += value.min; } else { positiveValues[index] += value.max; @@ -158,7 +158,8 @@ module.exports = function(Chart) { } }, getLabelForIndex: function(index, datasetIndex) { - return this.getScaleLabel(this.chart.data.datasets[datasetIndex].data[index]); + var v = this._parseValue(rawValue); + return v.start !== 0 ? v.end : v.start + ' ; ' + v.end; }, // Utils getPixelForValue: function(value) { diff --git a/src/scales/scale.logarithmic.js b/src/scales/scale.logarithmic.js index cb92acc8bb5..14284a4ea65 100644 --- a/src/scales/scale.logarithmic.js +++ b/src/scales/scale.logarithmic.js @@ -248,7 +248,8 @@ module.exports = function(Chart) { }, // Get the correct tooltip label getLabelForIndex: function(index, datasetIndex) { - return this.getScaleLabel(this.chart.data.datasets[datasetIndex].data[index]); + var v = this._parseValue(rawValue); + return v.start !== 0 ? v.end : v.start + ' ; ' + v.end; }, getPixelForTick: function(index) { return this.getPixelForValue(this.tickValues[index]); From fe0772cd707b27b5131115a95430484f7ca1c0eb Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Mon, 4 Jun 2018 12:35:05 +0300 Subject: [PATCH 46/76] formatting --- src/controllers/controller.bar.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index d9775c6090a..8455b1be0a7 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -392,7 +392,7 @@ module.exports = function(Chart) { var stacked = scale.options.stacked; var stack = meta.stack; var i, imeta, ivalue, base, head, size, yStackValue; - var value.start = value.max >= 0 && value.min >= 0 ? value.min : value.max; + 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; if (stacked || (stacked === undefined && stack !== undefined)) { @@ -407,14 +407,14 @@ module.exports = function(Chart) { ivalue = yStackValue.min >= 0 && yStackValue.max >= 0 ? yStackValue.max : yStackValue.min; if ((value.min < 0 && ivalue < 0) || (value.max >= 0 && ivalue > 0)) { - value.start += ivalue; + start += ivalue; } } } } - base = scale.getPixelForValue(value.start); - head = scale.getPixelForValue(value.start + yValue); + base = scale.getPixelForValue(start); + head = scale.getPixelForValue(start + yValue); size = (head - base) / 2; return { From 730e468401708f091db2346abf232c980abf3e61 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Tue, 5 Jun 2018 09:46:41 +0300 Subject: [PATCH 47/76] fix --- src/controllers/controller.bar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 8455b1be0a7..6801117bd7f 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -463,7 +463,7 @@ module.exports = function(Chart) { // float-bar support, if y arguments are array function will use bottom value as bar start point for (; i < ilen; ++i) { var val = scale._parseValue(dataset.data[i]); - if (!helpers.isNaN(val.start) && !helpers.isNaN(val.end)) { + if (!isNaN(val.start) && !isNaN(val.end)) { rects[i].draw(); } } From 122167c86165981ecafe11c54fb060844b428efe Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Fri, 8 Jun 2018 20:40:46 +0300 Subject: [PATCH 48/76] formatting --- src/scales/scale.linear.js | 2 +- src/scales/scale.logarithmic.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index 0ec55c9d7b2..7ab4dee8cb6 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -158,7 +158,7 @@ module.exports = function(Chart) { } }, getLabelForIndex: function(index, datasetIndex) { - var v = this._parseValue(rawValue); + var v = this._parseValue(this.chart.data.datasets[datasetIndex].data[index]); return v.start !== 0 ? v.end : v.start + ' ; ' + v.end; }, // Utils diff --git a/src/scales/scale.logarithmic.js b/src/scales/scale.logarithmic.js index 14284a4ea65..fab7dd40ed5 100644 --- a/src/scales/scale.logarithmic.js +++ b/src/scales/scale.logarithmic.js @@ -248,7 +248,7 @@ module.exports = function(Chart) { }, // Get the correct tooltip label getLabelForIndex: function(index, datasetIndex) { - var v = this._parseValue(rawValue); + var v = this._parseValue(this.chart.data.datasets[datasetIndex].data[index]); return v.start !== 0 ? v.end : v.start + ' ; ' + v.end; }, getPixelForTick: function(index) { From 3e42297424ed95e02ef3dec6124ca66284d6c532 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Mon, 11 Jun 2018 22:29:11 +0300 Subject: [PATCH 49/76] fix --- src/controllers/controller.bar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 6801117bd7f..a780efee76b 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -406,7 +406,7 @@ module.exports = function(Chart) { yStackValue = scale._parseValue(datasets[i].data[index]); ivalue = yStackValue.min >= 0 && yStackValue.max >= 0 ? yStackValue.max : yStackValue.min; - if ((value.min < 0 && ivalue < 0) || (value.max >= 0 && ivalue > 0)) { + if ((yValue < 0 && ivalue < 0) || (yValue > 0 && ivalue > 0)) { start += ivalue; } } From 9b956373160f9efc306a2633baa345c88058bab0 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Mon, 18 Jun 2018 15:20:40 +0300 Subject: [PATCH 50/76] fix --- src/controllers/controller.bar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index a780efee76b..b46fc4a2e05 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -406,7 +406,7 @@ module.exports = function(Chart) { yStackValue = scale._parseValue(datasets[i].data[index]); ivalue = yStackValue.min >= 0 && yStackValue.max >= 0 ? yStackValue.max : yStackValue.min; - if ((yValue < 0 && ivalue < 0) || (yValue > 0 && ivalue > 0)) { + if ((yValue < 0 && ivalue < 0) || (yValue >= 0 && ivalue >= 0)) { start += ivalue; } } From 2af134b25a46ebacfe7a660231e4d60ea52ac127 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Tue, 19 Jun 2018 13:16:20 +0300 Subject: [PATCH 51/76] fix to pass tests. Omit 0 when building scales when value min is 0. --- src/scales/scale.linear.js | 8 ++++++++ src/scales/scale.logarithmic.js | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index 7ab4dee8cb6..e5af41c96ef 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -83,6 +83,10 @@ module.exports = function(Chart) { positiveValues[index] = positiveValues[index] || 0; negativeValues[index] = negativeValues[index] || 0; + if (value.min === 0) { + value.min = value.max; + } + if (opts.relativePoints) { positiveValues[index] = 100; } else if (value.min < 0) { @@ -113,6 +117,10 @@ module.exports = function(Chart) { return; } + if (value.min === 0) { + value.min = value.max; + } + if (me.min === null) { me.min = value.min; } else if (value.min < me.min) { diff --git a/src/scales/scale.logarithmic.js b/src/scales/scale.logarithmic.js index fab7dd40ed5..8ee5c0624a2 100644 --- a/src/scales/scale.logarithmic.js +++ b/src/scales/scale.logarithmic.js @@ -151,6 +151,10 @@ module.exports = function(Chart) { return; } + if (value.min === 0) { + value.min = value.max; + } + if (me.min === null) { me.min = value.min; } else if (value.min < me.min) { From a0e12310ab6bcd2c3f3aee86906596ef9d1b6802 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Wed, 20 Jun 2018 15:58:34 +0300 Subject: [PATCH 52/76] tooltip fix for tests --- src/scales/scale.linear.js | 2 +- src/scales/scale.logarithmic.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index e5af41c96ef..4795d8e0867 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -167,7 +167,7 @@ module.exports = function(Chart) { }, getLabelForIndex: function(index, datasetIndex) { var v = this._parseValue(this.chart.data.datasets[datasetIndex].data[index]); - return v.start !== 0 ? v.end : v.start + ' ; ' + v.end; + return v.start === 0 ? v.end : v.start + ' ; ' + v.end; }, // Utils getPixelForValue: function(value) { diff --git a/src/scales/scale.logarithmic.js b/src/scales/scale.logarithmic.js index 8ee5c0624a2..de3e7d62606 100644 --- a/src/scales/scale.logarithmic.js +++ b/src/scales/scale.logarithmic.js @@ -253,7 +253,7 @@ module.exports = function(Chart) { // Get the correct tooltip label getLabelForIndex: function(index, datasetIndex) { var v = this._parseValue(this.chart.data.datasets[datasetIndex].data[index]); - return v.start !== 0 ? v.end : v.start + ' ; ' + v.end; + return v.start === 0 ? v.end : v.start + ' ; ' + v.end; }, getPixelForTick: function(index) { return this.getPixelForValue(this.tickValues[index]); From a65aa3c0fb6cfaf8e4aa9ac040e982cbb1fd95ea Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Wed, 27 Jun 2018 14:02:09 +0300 Subject: [PATCH 53/76] beginAtZero for float-val tests --- src/scales/scale.linear.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index 4795d8e0867..4b7054a93bc 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -117,6 +117,8 @@ module.exports = function(Chart) { return; } + console.log(optionTicks); + if (value.min === 0) { value.min = value.max; } From 901c96f51a0e89f3f9a02748d8ce6f7144444362 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Wed, 27 Jun 2018 14:11:52 +0300 Subject: [PATCH 54/76] formatting --- src/scales/scale.linear.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index 4b7054a93bc..1ba5c18a596 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -83,7 +83,7 @@ module.exports = function(Chart) { positiveValues[index] = positiveValues[index] || 0; negativeValues[index] = negativeValues[index] || 0; - if (value.min === 0) { + if (value.min === 0 && !opts.ticks.beginAtZero) { value.min = value.max; } @@ -117,9 +117,7 @@ module.exports = function(Chart) { return; } - console.log(optionTicks); - - if (value.min === 0) { + if (value.min === 0 && !opts.ticks.beginAtZero) { value.min = value.max; } From 7a425629c0edc48439c2d266255451109dc0d048 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Wed, 27 Jun 2018 14:38:01 +0300 Subject: [PATCH 55/76] formatting --- src/scales/scale.linear.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index 1ba5c18a596..a9b291cf0ae 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -86,6 +86,7 @@ module.exports = function(Chart) { if (value.min === 0 && !opts.ticks.beginAtZero) { value.min = value.max; } + if (opts.relativePoints) { positiveValues[index] = 100; From 4f5332eefb23d9fbe2e63ee4e83e24b8f12379ec Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Wed, 27 Jun 2018 15:40:09 +0300 Subject: [PATCH 56/76] formatting --- src/scales/scale.linear.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index a9b291cf0ae..d385f9f29f2 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -83,12 +83,13 @@ module.exports = function(Chart) { positiveValues[index] = positiveValues[index] || 0; negativeValues[index] = negativeValues[index] || 0; - if (value.min === 0 && !opts.ticks.beginAtZero) { + if (value.min === 0) { value.min = value.max; + } else if (value.max === 0) { + value.max = value.min; } - - if (opts.relativePoints) { + if (opts.relativePoints) { positiveValues[index] = 100; } else if (value.min < 0) { negativeValues[index] += value.min; @@ -118,8 +119,10 @@ module.exports = function(Chart) { return; } - if (value.min === 0 && !opts.ticks.beginAtZero) { + if (value.min === 0) { value.min = value.max; + } else if (value.max === 0) { + value.max = value.min; } if (me.min === null) { From 63ce9e9fbd0f47df60fc4fa851d6404bacf2d033 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Wed, 27 Jun 2018 16:47:34 +0300 Subject: [PATCH 57/76] formatting --- src/scales/scale.linear.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index d385f9f29f2..f0f9dc602e6 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -89,7 +89,7 @@ module.exports = function(Chart) { value.max = value.min; } - if (opts.relativePoints) { + if (opts.relativePoints) { positiveValues[index] = 100; } else if (value.min < 0) { negativeValues[index] += value.min; From b626b570c4a16f15e68798b77a431d2e35cdb301 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Wed, 16 Jan 2019 20:47:05 +0200 Subject: [PATCH 58/76] rebase --- src/elements/element.rectangle.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/elements/element.rectangle.js b/src/elements/element.rectangle.js index 54706d2fae2..fcdb868c20a 100644 --- a/src/elements/element.rectangle.js +++ b/src/elements/element.rectangle.js @@ -4,11 +4,13 @@ var defaults = require('../core/core.defaults'); var Element = require('../core/core.element'); var helpers = require('../helpers/index'); +var defaultColor = defaults.global.defaultColor; + defaults._set('global', { elements: { rectangle: { - backgroundColor: defaults.global.defaultColor, - borderColor: defaults.global.defaultColor, + backgroundColor: defaultColor, + borderColor: defaultColor, borderSkipped: 'bottom', borderWidth: 0 } From 2a07aaa41d8405af66c9755edef97e17a45666c6 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Thu, 17 Jan 2019 12:51:51 +0200 Subject: [PATCH 59/76] Update controller.bar.js --- src/controllers/controller.bar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 45f34e54d13..cd611657275 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -441,4 +441,4 @@ module.exports = DatasetController.extend({ return values; } -}); \ No newline at end of file +}); From d165e2454103b63a483da54da18dc4b5ea12eb42 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Thu, 17 Jan 2019 12:53:21 +0200 Subject: [PATCH 60/76] Update core.scale.js --- src/core/core.scale.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/core.scale.js b/src/core/core.scale.js index cbac6f0c637..ff73d98115f 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -993,4 +993,4 @@ module.exports = Element.extend({ context.stroke(); } } -}); \ No newline at end of file +}); From c4148e952af6d13fe77912327cb4974dc9a8042d Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Thu, 17 Jan 2019 12:54:11 +0200 Subject: [PATCH 61/76] Update core.tooltip.js --- src/core/core.tooltip.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/core/core.tooltip.js b/src/core/core.tooltip.js index b5d18eb5864..a04bec3fb6d 100644 --- a/src/core/core.tooltip.js +++ b/src/core/core.tooltip.js @@ -70,7 +70,6 @@ defaults._set('global', { if (label) { label += ': '; } - label += tooltipItem.yLabel; return label; }, From a48b8ce030381c880dbc678b1b0d175127b12f7d Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Thu, 17 Jan 2019 12:56:14 +0200 Subject: [PATCH 62/76] Update element.rectangle.js --- src/elements/element.rectangle.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/elements/element.rectangle.js b/src/elements/element.rectangle.js index 5ce205772a7..1cb6fbb534f 100644 --- a/src/elements/element.rectangle.js +++ b/src/elements/element.rectangle.js @@ -2,9 +2,6 @@ var defaults = require('../core/core.defaults'); var Element = require('../core/core.element'); -var helpers = require('../helpers/index'); - -var defaultColor = defaults.global.defaultColor; var defaultColor = defaults.global.defaultColor; @@ -72,8 +69,7 @@ module.exports = Element.extend({ bottom = vm.base; signX = 1; signY = bottom > top ? 1 : -1; - // no border support - borderSkipped = helpers.valueOrDefault(vm.borderSkipped, 'bottom'); + borderSkipped = vm.borderSkipped || 'bottom'; } else { // horizontal bar left = vm.base; @@ -82,8 +78,7 @@ module.exports = Element.extend({ bottom = vm.y + vm.height / 2; signX = right > left ? 1 : -1; signY = 1; - // no border support - borderSkipped = helpers.valueOrDefault(vm.borderSkipped, 'left'); + borderSkipped = vm.borderSkipped || 'left'; } // Canvas doesn't allow us to stroke inside the width so we can @@ -139,9 +134,8 @@ 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 <= cornersCount; i++) { + for (var i = 1; i < 4; i++) { corner = cornerAt(i); ctx.lineTo(corner[0], corner[1]); } From e1095fa14ec15b453b6f0889d92f5544cd8d2e6d Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Thu, 17 Jan 2019 12:57:37 +0200 Subject: [PATCH 63/76] Update scale.linear.js --- src/scales/scale.linear.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index 68177d86bc5..41a4e4168a3 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -187,4 +187,4 @@ module.exports = LinearScaleBase.extend({ }); // INTERNAL: static default options, registered in src/chart.js -module.exports._defaults = defaultConfig; \ No newline at end of file +module.exports._defaults = defaultConfig; From 14bccfebb4d4207d51701abe159a2c0ba05e67c9 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Thu, 17 Jan 2019 12:58:01 +0200 Subject: [PATCH 64/76] Update scale.logarithmic.js --- src/scales/scale.logarithmic.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scales/scale.logarithmic.js b/src/scales/scale.logarithmic.js index 2b734f72e0e..91f90845da3 100644 --- a/src/scales/scale.logarithmic.js +++ b/src/scales/scale.logarithmic.js @@ -341,4 +341,4 @@ module.exports = Scale.extend({ }); // INTERNAL: static default options, registered in src/chart.js -module.exports._defaults = defaultConfig; \ No newline at end of file +module.exports._defaults = defaultConfig; From f4d741388db74540a5b4f29bdd28f8af45cc14e0 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Sat, 19 Jan 2019 00:51:56 +0200 Subject: [PATCH 65/76] Back changes after rebase --- src/controllers/controller.bar.js | 24 +++++++++++++------ src/core/core.scale.js | 31 ++++++++++++++++++++++++ src/elements/element.rectangle.js | 12 +++++++--- src/scales/scale.linear.js | 39 ++++++++++++++++++++----------- src/scales/scale.logarithmic.js | 28 +++++++++++----------- 5 files changed, 96 insertions(+), 38 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index cd611657275..6a1aaa548db 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -149,6 +149,11 @@ module.exports = DatasetController.extend({ var dataset = me.getDataset(); var options = me._resolveElementOptions(rectangle, index); + //float-bar support, if y arguments are array lets override rectangles styles, assigning no skippingBorder + if (helpers.isArray(dataset.data[index])) { + options.borderSkipped = null; + } + rectangle._xScale = me.getScaleForId(meta.xAxisID); rectangle._yScale = me.getScaleForId(meta.yAxisID); rectangle._datasetIndex = me.index; @@ -313,12 +318,13 @@ module.exports = DatasetController.extend({ var scale = me.getValueScale(); var isHorizontal = scale.isHorizontal(); var datasets = chart.data.datasets; - var value = +scale.getRightValue(datasets[datasetIndex].data[index]); + var value = scale._parseValue(datasets[datasetIndex].data[index]); var minBarLength = scale.options.minBarLength; var stacked = scale.options.stacked; var stack = meta.stack; - var start = 0; - var i, imeta, ivalue, base, head, size; + 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; + var i, imeta, ivalue, base, head, size, yStackValue; if (stacked || (stacked === undefined && stack !== undefined)) { for (i = 0; i < datasetIndex; ++i) { @@ -329,8 +335,10 @@ module.exports = DatasetController.extend({ imeta.controller.getValueScaleId() === scale.id && chart.isDatasetVisible(i)) { - ivalue = +scale.getRightValue(datasets[i].data[index]); - if ((value < 0 && ivalue < 0) || (value >= 0 && ivalue > 0)) { + yStackValue = scale._parseValue(datasets[i].data[index]); + ivalue = yStackValue.min >= 0 && yStackValue.max >= 0 ? yStackValue.max : yStackValue.min; + + if ((value.min < 0 && ivalue < 0) || (value.max >= 0 && ivalue > 0)) { start += ivalue; } } @@ -338,7 +346,7 @@ module.exports = DatasetController.extend({ } base = scale.getPixelForValue(start); - head = scale.getPixelForValue(start + value); + head = scale.getPixelForValue(start + yValue); size = head - base; if (minBarLength !== undefined && Math.abs(size) < minBarLength) { @@ -393,8 +401,10 @@ module.exports = DatasetController.extend({ 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(); } } diff --git a/src/core/core.scale.js b/src/core/core.scale.js index ff73d98115f..f1c3f001dd7 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -522,6 +522,12 @@ module.exports = Element.extend({ if ((typeof rawValue === 'number' || rawValue instanceof Number) && !isFinite(rawValue)) { return NaN; } + + //Float-bar support. Handling arrays + if (helpers.isArray(rawValue)) { + return [this.getRightValue(rawValue[0]), this.getRightValue(rawValue[1])]; + } + // If it is in fact an object, dive in one more level if (rawValue) { if (this.isHorizontal()) { @@ -537,6 +543,31 @@ module.exports = Element.extend({ return rawValue; }, + _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 { + min: Math.min(start, end), + max: Math.max(start, end), + start: start, + end: end + }; + }, + + getScaleLabel: function(rawValue) { + var v = this._parseValue(rawValue); + return v.min == v.max ? v.min : v.min + " ; " + v.max; + }, + /** * Used to get the value to display in the tooltip for the data at the given index * @param index diff --git a/src/elements/element.rectangle.js b/src/elements/element.rectangle.js index 1cb6fbb534f..fcf21e4dd00 100644 --- a/src/elements/element.rectangle.js +++ b/src/elements/element.rectangle.js @@ -123,8 +123,13 @@ module.exports = Element.extend({ // Find first (starting) corner with fallback to 'bottom' var borders = ['bottom', 'left', 'top', 'right']; var startCorner = borders.indexOf(borderSkipped, 0); - if (startCorner === -1) { + if (borderSkipped === null) { startCorner = 0; + } else { + startCorner = borders.indexOf(borderSkipped, 0); + if (startCorner === -1) { + startCorner = 0; + } } function cornerAt(index) { @@ -135,8 +140,9 @@ module.exports = Element.extend({ var corner = cornerAt(0); ctx.moveTo(corner[0], corner[1]); - for (var i = 1; i < 4; i++) { - corner = cornerAt(i); + var cornersCount = borderSkipped === null ? 4 : 3; + + for (var i = 1; i <= cornersCount; i++) { ctx.lineTo(corner[0], corner[1]); } diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index 41a4e4168a3..2c35667d377 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -70,20 +70,25 @@ module.exports = LinearScaleBase.extend({ 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 && !opts.ticks.beginAtZero) { + value.min = value.max; + } + if (opts.relativePoints) { positiveValues[index] = 100; - } else if (value < 0) { - negativeValues[index] += value; + } else if (value.min < 0 || value.max < 0 ) { + negativeValues[index] += value.min; } else { - positiveValues[index] += value; + positiveValues[index] += value.max; } }); } @@ -102,21 +107,27 @@ module.exports = LinearScaleBase.extend({ 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 && !opts.ticks.beginAtZero) { + 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; } }); } @@ -151,7 +162,7 @@ module.exports = LinearScaleBase.extend({ }, getLabelForIndex: function(index, datasetIndex) { - return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]); + return this.getScaleLabel(this.chart.data.datasets[datasetIndex].data[index]); }, // Utils diff --git a/src/scales/scale.logarithmic.js b/src/scales/scale.logarithmic.js index 91f90845da3..5941b1a2025 100644 --- a/src/scales/scale.logarithmic.js +++ b/src/scales/scale.logarithmic.js @@ -113,13 +113,13 @@ module.exports = Scale.extend({ 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; }); } }); @@ -138,26 +138,26 @@ module.exports = Scale.extend({ 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.val) || meta.data[index].hidden || value.val < 0) { return; } 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; } - 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; } }); } @@ -242,7 +242,7 @@ module.exports = Scale.extend({ // Get the correct tooltip label getLabelForIndex: function(index, datasetIndex) { - return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]); + return this.getScaleLabel(this.chart.data.datasets[datasetIndex].data[index]); }, getPixelForTick: function(index) { From 5590350130573485859afe728040b2c33e94c31a Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Sat, 19 Jan 2019 03:04:07 +0200 Subject: [PATCH 66/76] formatting --- src/controllers/controller.bar.js | 4 ++-- src/core/core.scale.js | 4 ++-- src/scales/scale.linear.js | 4 ++-- src/scales/scale.logarithmic.js | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 6a1aaa548db..ed079c38b27 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -149,7 +149,7 @@ module.exports = DatasetController.extend({ var dataset = me.getDataset(); var options = me._resolveElementOptions(rectangle, index); - //float-bar support, if y arguments are array lets override rectangles styles, assigning no skippingBorder + // float-bar support, if y arguments are array lets override rectangles styles, assigning no skippingBorder if (helpers.isArray(dataset.data[index])) { options.borderSkipped = null; } @@ -401,7 +401,7 @@ module.exports = DatasetController.extend({ helpers.canvas.clipArea(chart.ctx, chart.chartArea); - //float-bar support, if y arguments are array function will use bottom value as bar start point + // float-bar support, if y arguments are array function will use bottom value as bar start point for (; i < ilen; ++i) { var val = scale._parseValue(dataset.data[i]); if (!isNaN(val.start) && !isNaN(val.end)) { diff --git a/src/core/core.scale.js b/src/core/core.scale.js index f1c3f001dd7..f98b2716ca1 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -523,7 +523,7 @@ module.exports = Element.extend({ return NaN; } - //Float-bar support. Handling arrays + // Float-bar support. Handling arrays if (helpers.isArray(rawValue)) { return [this.getRightValue(rawValue[0]), this.getRightValue(rawValue[1])]; } @@ -565,7 +565,7 @@ module.exports = Element.extend({ getScaleLabel: function(rawValue) { var v = this._parseValue(rawValue); - return v.min == v.max ? v.min : v.min + " ; " + v.max; + return v.min === v.max ? v.min : v.min + ' ; ' + v.max; }, /** diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index 2c35667d377..c2acf41bd13 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -85,7 +85,7 @@ module.exports = LinearScaleBase.extend({ if (opts.relativePoints) { positiveValues[index] = 100; - } else if (value.min < 0 || value.max < 0 ) { + } else if (value.min < 0 || value.max < 0) { negativeValues[index] += value.min; } else { positiveValues[index] += value.max; @@ -162,7 +162,7 @@ module.exports = LinearScaleBase.extend({ }, getLabelForIndex: function(index, datasetIndex) { - return this.getScaleLabel(this.chart.data.datasets[datasetIndex].data[index]); + return this.getScaleLabel(this.chart.data.datasets[datasetIndex].data[index]); }, // Utils diff --git a/src/scales/scale.logarithmic.js b/src/scales/scale.logarithmic.js index 5941b1a2025..de3a6525924 100644 --- a/src/scales/scale.logarithmic.js +++ b/src/scales/scale.logarithmic.js @@ -242,7 +242,7 @@ module.exports = Scale.extend({ // Get the correct tooltip label getLabelForIndex: function(index, datasetIndex) { - return this.getScaleLabel(this.chart.data.datasets[datasetIndex].data[index]); + return this.getScaleLabel(this.chart.data.datasets[datasetIndex].data[index]); }, getPixelForTick: function(index) { From 9f88e0542a15ca9aa43525962dbbf65b85d611a8 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Sat, 19 Jan 2019 03:16:57 +0200 Subject: [PATCH 67/76] formatting --- src/scales/scale.logarithmic.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scales/scale.logarithmic.js b/src/scales/scale.logarithmic.js index de3a6525924..b178b60b9c9 100644 --- a/src/scales/scale.logarithmic.js +++ b/src/scales/scale.logarithmic.js @@ -140,7 +140,7 @@ module.exports = Scale.extend({ helpers.each(dataset.data, function(rawValue, index) { var value = me._parseValue(rawValue); // invalid, hidden and negative values are ignored - if (isNaN(value.val) || meta.data[index].hidden || value.val < 0) { + if (isNaN(value.max) || meta.data[index].hidden || value.max < 0) { return; } From 76e9ceb199b0cf72696e5d636188ec7084fc409b Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Tue, 5 Feb 2019 13:08:44 +0200 Subject: [PATCH 68/76] fixes --- src/controllers/controller.bar.js | 2 +- src/core/core.scale.js | 13 ++++++++++--- src/scales/scale.linear.js | 5 +++-- src/scales/scale.logarithmic.js | 9 +++++++-- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index ed079c38b27..f7726f2f607 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -338,7 +338,7 @@ module.exports = DatasetController.extend({ yStackValue = scale._parseValue(datasets[i].data[index]); ivalue = yStackValue.min >= 0 && yStackValue.max >= 0 ? yStackValue.max : yStackValue.min; - if ((value.min < 0 && ivalue < 0) || (value.max >= 0 && ivalue > 0)) { + if ((value.min < 0 && ivalue < 0) || (value.max >= 0 && ivalue >= 0)) { start += ivalue; } } diff --git a/src/core/core.scale.js b/src/core/core.scale.js index f98b2716ca1..13eb0ffc9c6 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -545,27 +545,34 @@ module.exports = Element.extend({ _parseValue: function(raw) { var value = this.getRightValue(raw); - var start, end; + var start, end, isarr; if (helpers.isArray(value)) { start = value[0]; end = value[1]; + isarr = true; } else { start = 0; end = value; + isarr = false; } return { min: Math.min(start, end), max: Math.max(start, end), start: start, - end: end + end: end, + isarr: isarr }; }, getScaleLabel: function(rawValue) { var v = this._parseValue(rawValue); - return v.min === v.max ? v.min : v.min + ' ; ' + v.max; + if(v.issar === true) { + return v.min === v.max ? v.min : v.min + ' ; ' + v.max; + } + + return +this.getRightValue(rawValue); }, /** diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index c2acf41bd13..de80eb81bc3 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -113,8 +113,9 @@ module.exports = LinearScaleBase.extend({ return; } - if (value.min === 0 && !opts.ticks.beginAtZero) { - value.min = value.max; + if (value.isarr === false) { + value.min = value.end; + value.max = value.end; } diff --git a/src/scales/scale.logarithmic.js b/src/scales/scale.logarithmic.js index b178b60b9c9..6023445c789 100644 --- a/src/scales/scale.logarithmic.js +++ b/src/scales/scale.logarithmic.js @@ -115,7 +115,7 @@ module.exports = Scale.extend({ var values = valuesPerStack[key]; var value = me._parseValue(rawValue); // invalid, hidden and negative values are ignored - if (isNaN(value.max) || meta.data[index].hidden || value.max < 0) { + if (isNaN(value.min) || isNaN(value.max) || meta.data[index].hidden || value.max < 0 || value.max < 0) { return; } values[index] = values[index] || 0; @@ -140,10 +140,15 @@ module.exports = Scale.extend({ helpers.each(dataset.data, function(rawValue, index) { var value = me._parseValue(rawValue); // invalid, hidden and negative values are ignored - if (isNaN(value.max) || meta.data[index].hidden || value.max < 0) { + if (isNaN(value.min) || isNaN(value.max) || meta.data[index].hidden || value.min < 0 || value.max < 0) { return; } + if (value.isarr === false) { + value.min = value.end; + value.max = value.end; + } + if (me.min === null) { me.min = value.min; } else if (value.min < me.min) { From 2d0606371ab6023db2a7f157bab3a3d6035223f3 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Tue, 5 Feb 2019 13:29:23 +0200 Subject: [PATCH 69/76] formatting --- src/core/core.scale.js | 2 +- src/scales/scale.linear.js | 2 +- src/scales/scale.logarithmic.js | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/core/core.scale.js b/src/core/core.scale.js index 13eb0ffc9c6..0ff2b41b737 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -568,7 +568,7 @@ module.exports = Element.extend({ getScaleLabel: function(rawValue) { var v = this._parseValue(rawValue); - if(v.issar === true) { + if (v.issar === true) { return v.min === v.max ? v.min : v.min + ' ; ' + v.max; } diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index de80eb81bc3..df7b828e471 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -115,7 +115,7 @@ module.exports = LinearScaleBase.extend({ if (value.isarr === false) { value.min = value.end; - value.max = value.end; + value.max = value.end; } diff --git a/src/scales/scale.logarithmic.js b/src/scales/scale.logarithmic.js index 6023445c789..7e5b1cbe750 100644 --- a/src/scales/scale.logarithmic.js +++ b/src/scales/scale.logarithmic.js @@ -144,10 +144,10 @@ module.exports = Scale.extend({ return; } - if (value.isarr === false) { - value.min = value.end; - value.max = value.end; - } + if (value.isarr === false) { + value.min = value.end; + value.max = value.end; + } if (me.min === null) { me.min = value.min; From 74dc634e2b2e5f1fe2441d7fb4db9dd4a367a749 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Fri, 8 Feb 2019 01:40:21 +0200 Subject: [PATCH 70/76] fallback to test units --- src/controllers/controller.bar.js | 24 ++++++------------- src/core/core.scale.js | 38 ----------------------------- src/elements/element.rectangle.js | 12 +++------- src/platforms/platform.dom.js | 20 ++++++++-------- src/scales/scale.linear.js | 40 +++++++++++-------------------- src/scales/scale.logarithmic.js | 33 +++++++++++-------------- 6 files changed, 48 insertions(+), 119 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index e96f6b92919..aef53b68afe 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -149,11 +149,6 @@ module.exports = DatasetController.extend({ var dataset = me.getDataset(); var options = me._resolveElementOptions(rectangle, index); - // float-bar support, if y arguments are array lets override rectangles styles, assigning no skippingBorder - if (helpers.isArray(dataset.data[index])) { - options.borderSkipped = null; - } - rectangle._xScale = me.getScaleForId(meta.xAxisID); rectangle._yScale = me.getScaleForId(meta.yAxisID); rectangle._datasetIndex = me.index; @@ -290,13 +285,12 @@ module.exports = DatasetController.extend({ var scale = me._getValueScale(); var isHorizontal = scale.isHorizontal(); var datasets = chart.data.datasets; - var value = scale._parseValue(datasets[datasetIndex].data[index]); + var value = +scale.getRightValue(datasets[datasetIndex].data[index]); var minBarLength = scale.options.minBarLength; var stacked = scale.options.stacked; var stack = meta.stack; - 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; - var i, imeta, ivalue, base, head, size, yStackValue; + var start = 0; + var i, imeta, ivalue, base, head, size; if (stacked || (stacked === undefined && stack !== undefined)) { for (i = 0; i < datasetIndex; ++i) { @@ -307,10 +301,8 @@ module.exports = DatasetController.extend({ imeta.controller._getValueScaleId() === scale.id && chart.isDatasetVisible(i)) { - yStackValue = scale._parseValue(datasets[i].data[index]); - ivalue = yStackValue.min >= 0 && yStackValue.max >= 0 ? yStackValue.max : yStackValue.min; - - if ((value.min < 0 && ivalue < 0) || (value.max >= 0 && ivalue >= 0)) { + ivalue = +scale.getRightValue(datasets[i].data[index]); + if ((value < 0 && ivalue < 0) || (value >= 0 && ivalue > 0)) { start += ivalue; } } @@ -318,7 +310,7 @@ module.exports = DatasetController.extend({ } base = scale.getPixelForValue(start); - head = scale.getPixelForValue(start + yValue); + head = scale.getPixelForValue(start + value); size = head - base; if (minBarLength !== undefined && Math.abs(size) < minBarLength) { @@ -373,10 +365,8 @@ module.exports = DatasetController.extend({ 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) { - var val = scale._parseValue(dataset.data[i]); - if (!isNaN(val.start) && !isNaN(val.end)) { + if (!isNaN(scale.getRightValue(dataset.data[i]))) { rects[i].draw(); } } diff --git a/src/core/core.scale.js b/src/core/core.scale.js index 0ff2b41b737..ff73d98115f 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -522,12 +522,6 @@ module.exports = Element.extend({ if ((typeof rawValue === 'number' || rawValue instanceof Number) && !isFinite(rawValue)) { return NaN; } - - // Float-bar support. Handling arrays - if (helpers.isArray(rawValue)) { - return [this.getRightValue(rawValue[0]), this.getRightValue(rawValue[1])]; - } - // If it is in fact an object, dive in one more level if (rawValue) { if (this.isHorizontal()) { @@ -543,38 +537,6 @@ module.exports = Element.extend({ return rawValue; }, - _parseValue: function(raw) { - var value = this.getRightValue(raw); - var start, end, isarr; - - if (helpers.isArray(value)) { - start = value[0]; - end = value[1]; - isarr = true; - } else { - start = 0; - end = value; - isarr = false; - } - - return { - min: Math.min(start, end), - max: Math.max(start, end), - start: start, - end: end, - isarr: isarr - }; - }, - - getScaleLabel: function(rawValue) { - var v = this._parseValue(rawValue); - if (v.issar === true) { - return v.min === v.max ? v.min : v.min + ' ; ' + v.max; - } - - return +this.getRightValue(rawValue); - }, - /** * Used to get the value to display in the tooltip for the data at the given index * @param index diff --git a/src/elements/element.rectangle.js b/src/elements/element.rectangle.js index 067dbc58aad..fe3702cda4e 100644 --- a/src/elements/element.rectangle.js +++ b/src/elements/element.rectangle.js @@ -123,13 +123,8 @@ module.exports = Element.extend({ // Find first (starting) corner with fallback to 'bottom' var borders = ['bottom', 'left', 'top', 'right']; var startCorner = borders.indexOf(borderSkipped, 0); - if (borderSkipped === null) { + if (startCorner === -1) { startCorner = 0; - } else { - startCorner = borders.indexOf(borderSkipped, 0); - if (startCorner === -1) { - startCorner = 0; - } } function cornerAt(index) { @@ -140,9 +135,8 @@ module.exports = Element.extend({ var corner = cornerAt(0); ctx.moveTo(corner[0], corner[1]); - var cornersCount = borderSkipped === null ? 4 : 3; - - for (var i = 1; i <= cornersCount; i++) { + for (var i = 1; i < 4; i++) { + corner = cornerAt(i); ctx.lineTo(corner[0], corner[1]); } diff --git a/src/platforms/platform.dom.js b/src/platforms/platform.dom.js index 01a46174d7f..053db20d2e2 100644 --- a/src/platforms/platform.dom.js +++ b/src/platforms/platform.dom.js @@ -124,11 +124,11 @@ var supportsEventListenerOptions = (function() { // https://github.com/chartjs/Chart.js/issues/4287 var eventListenerOptions = supportsEventListenerOptions ? {passive: true} : false; -function addEventListener(node, type, listener) { +function addListener(node, type, listener) { node.addEventListener(type, listener, eventListenerOptions); } -function removeEventListener(node, type, listener) { +function removeListener(node, type, listener) { node.removeEventListener(type, listener, eventListenerOptions); } @@ -223,8 +223,8 @@ function createResizer(handler) { handler(); }; - addEventListener(expand, 'scroll', onScroll.bind(expand, 'expand')); - addEventListener(shrink, 'scroll', onScroll.bind(shrink, 'shrink')); + addListener(expand, 'scroll', onScroll.bind(expand, 'expand')); + addListener(shrink, 'scroll', onScroll.bind(shrink, 'shrink')); return resizer; } @@ -239,7 +239,7 @@ function watchForRender(node, handler) { }; helpers.each(ANIMATION_START_EVENTS, function(type) { - addEventListener(node, type, proxy); + addListener(node, type, proxy); }); // #4737: Chrome might skip the CSS animation when the CSS_RENDER_MONITOR class @@ -258,7 +258,7 @@ function unwatchForRender(node) { if (proxy) { helpers.each(ANIMATION_START_EVENTS, function(type) { - removeEventListener(node, type, proxy); + removeListener(node, type, proxy); }); delete expando.renderProxy; @@ -429,7 +429,7 @@ module.exports = { listener(fromNativeEvent(event, chart)); }; - addEventListener(canvas, type, proxy); + addListener(canvas, type, proxy); }, removeEventListener: function(chart, type, listener) { @@ -447,7 +447,7 @@ module.exports = { return; } - removeEventListener(canvas, type, proxy); + removeListener(canvas, type, proxy); } }; @@ -462,7 +462,7 @@ module.exports = { * @todo remove at version 3 * @private */ -helpers.addEvent = addEventListener; +helpers.addEvent = addListener; /** * Provided for backward compatibility, use EventTarget.removeEventListener instead. @@ -473,4 +473,4 @@ helpers.addEvent = addEventListener; * @todo remove at version 3 * @private */ -helpers.removeEvent = removeEventListener; +helpers.removeEvent = removeListener; diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index df7b828e471..41a4e4168a3 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -70,25 +70,20 @@ module.exports = LinearScaleBase.extend({ if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) { helpers.each(dataset.data, function(rawValue, index) { - var value = me._parseValue(rawValue); - - if (isNaN(value.min) || isNaN(value.max) || meta.data[index].hidden) { + var value = +me.getRightValue(rawValue); + if (isNaN(value) || meta.data[index].hidden) { return; } positiveValues[index] = positiveValues[index] || 0; negativeValues[index] = negativeValues[index] || 0; - if (value.min === 0 && !opts.ticks.beginAtZero) { - value.min = value.max; - } - if (opts.relativePoints) { positiveValues[index] = 100; - } else if (value.min < 0 || value.max < 0) { - negativeValues[index] += value.min; + } else if (value < 0) { + negativeValues[index] += value; } else { - positiveValues[index] += value.max; + positiveValues[index] += value; } }); } @@ -107,28 +102,21 @@ module.exports = LinearScaleBase.extend({ var meta = chart.getDatasetMeta(datasetIndex); if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) { helpers.each(dataset.data, function(rawValue, index) { - var value = me._parseValue(rawValue); - - if (isNaN(value.min) || isNaN(value.max) || meta.data[index].hidden) { + var value = +me.getRightValue(rawValue); + if (isNaN(value) || meta.data[index].hidden) { return; } - if (value.isarr === false) { - value.min = value.end; - value.max = value.end; - } - - if (me.min === null) { - me.min = value.min; - } else if (value.min < me.min) { - me.min = value.min; + me.min = value; + } else if (value < me.min) { + me.min = value; } if (me.max === null) { - me.max = value.max; - } else if (value.max > me.max) { - me.max = value.max; + me.max = value; + } else if (value > me.max) { + me.max = value; } }); } @@ -163,7 +151,7 @@ module.exports = LinearScaleBase.extend({ }, getLabelForIndex: function(index, datasetIndex) { - return this.getScaleLabel(this.chart.data.datasets[datasetIndex].data[index]); + return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]); }, // Utils diff --git a/src/scales/scale.logarithmic.js b/src/scales/scale.logarithmic.js index 7e5b1cbe750..91f90845da3 100644 --- a/src/scales/scale.logarithmic.js +++ b/src/scales/scale.logarithmic.js @@ -113,13 +113,13 @@ module.exports = Scale.extend({ helpers.each(dataset.data, function(rawValue, index) { var values = valuesPerStack[key]; - var value = me._parseValue(rawValue); + var value = +me.getRightValue(rawValue); // invalid, hidden and negative values are ignored - if (isNaN(value.min) || isNaN(value.max) || meta.data[index].hidden || value.max < 0 || value.max < 0) { + if (isNaN(value) || meta.data[index].hidden || value < 0) { return; } values[index] = values[index] || 0; - values[index] += value.max; + values[index] += value; }); } }); @@ -138,31 +138,26 @@ module.exports = Scale.extend({ var meta = chart.getDatasetMeta(datasetIndex); if (chart.isDatasetVisible(datasetIndex) && IDMatches(meta)) { helpers.each(dataset.data, function(rawValue, index) { - var value = me._parseValue(rawValue); + var value = +me.getRightValue(rawValue); // invalid, hidden and negative values are ignored - if (isNaN(value.min) || isNaN(value.max) || meta.data[index].hidden || value.min < 0 || value.max < 0) { + if (isNaN(value) || meta.data[index].hidden || value < 0) { return; } - if (value.isarr === false) { - value.min = value.end; - value.max = value.end; - } - if (me.min === null) { - me.min = value.min; - } else if (value.min < me.min) { - me.min = value.min; + me.min = value; + } else if (value < me.min) { + me.min = value; } if (me.max === null) { - me.max = value.max; - } else if (value.max > me.max) { - me.max = value.max; + me.max = value; + } else if (value > me.max) { + me.max = value; } - if (value.min !== 0 && (me.minNotZero === null || value.min < me.minNotZero)) { - me.minNotZero = value.min; + if (value !== 0 && (me.minNotZero === null || value < me.minNotZero)) { + me.minNotZero = value; } }); } @@ -247,7 +242,7 @@ module.exports = Scale.extend({ // Get the correct tooltip label getLabelForIndex: function(index, datasetIndex) { - return this.getScaleLabel(this.chart.data.datasets[datasetIndex].data[index]); + return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]); }, getPixelForTick: function(index) { From dba5bdbf187ac58b58f3613840235cff00b8110f Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Fri, 8 Feb 2019 01:54:43 +0200 Subject: [PATCH 71/76] border skipped added --- src/controllers/controller.bar.js | 5 +++++ src/elements/element.rectangle.js | 11 +++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index aef53b68afe..306118766c3 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -149,6 +149,11 @@ module.exports = DatasetController.extend({ var dataset = me.getDataset(); var options = me._resolveElementOptions(rectangle, index); + // float-bar support, if y arguments are array lets override rectangles styles, assigning no skippingBorder + if (helpers.isArray(dataset.data[index])) { + options.borderSkipped = null; + } + rectangle._xScale = me.getScaleForId(meta.xAxisID); rectangle._yScale = me.getScaleForId(meta.yAxisID); rectangle._datasetIndex = me.index; diff --git a/src/elements/element.rectangle.js b/src/elements/element.rectangle.js index fe3702cda4e..c406a62b70e 100644 --- a/src/elements/element.rectangle.js +++ b/src/elements/element.rectangle.js @@ -123,8 +123,13 @@ module.exports = Element.extend({ // Find first (starting) corner with fallback to 'bottom' var borders = ['bottom', 'left', 'top', 'right']; var startCorner = borders.indexOf(borderSkipped, 0); - if (startCorner === -1) { + if (borderSkipped === null) { startCorner = 0; + } else { + startCorner = borders.indexOf(borderSkipped, 0); + if (startCorner === -1) { + startCorner = 0; + } } function cornerAt(index) { @@ -135,7 +140,9 @@ module.exports = Element.extend({ var corner = cornerAt(0); ctx.moveTo(corner[0], corner[1]); - for (var i = 1; i < 4; i++) { + var cornersCount = borderSkipped === null ? 4 : 3; + + for (var i = 1; i <= cornersCount; i++) { corner = cornerAt(i); ctx.lineTo(corner[0], corner[1]); } From 0e5896796b7d7c5fc9c8ae6316bb5f328590c3a4 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Fri, 8 Feb 2019 02:29:26 +0200 Subject: [PATCH 72/76] _parseValue added. Scales updated --- src/core/core.scale.js | 38 +++++++++++++++++++++++++++++++ src/scales/scale.linear.js | 40 +++++++++++++++++++++------------ src/scales/scale.logarithmic.js | 33 +++++++++++++++------------ 3 files changed, 83 insertions(+), 28 deletions(-) diff --git a/src/core/core.scale.js b/src/core/core.scale.js index ff73d98115f..3f74f0f4c8b 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -522,6 +522,12 @@ module.exports = Element.extend({ if ((typeof rawValue === 'number' || rawValue instanceof Number) && !isFinite(rawValue)) { return NaN; } + + // Float-bar support. Handling arrays + if (helpers.isArray(rawValue)) { + return [this.getRightValue(rawValue[0]), this.getRightValue(rawValue[1])]; + } + // If it is in fact an object, dive in one more level if (rawValue) { if (this.isHorizontal()) { @@ -537,6 +543,38 @@ module.exports = Element.extend({ return rawValue; }, + _parseValue: function(raw) { + var value = this.getRightValue(raw); + var start, end, isarr; + + if (helpers.isArray(value)) { + start = value[0]; + end = value[1]; + isarr = true; + } else { + start = 0; + end = value; + isarr = false; + } + + return { + min: Math.min(start, end), + max: Math.max(start, end), + start: start, + end: end, + isarr: isarr + }; + }, + + getScaleLabel: function(rawValue) { + var v = this._parseValue(rawValue); + if (v.issar === true) { + return v.min === v.max ? v.min : v.min + ' ; ' + v.max; + } + + return +this.getRightValue(rawValue); + }, + /** * Used to get the value to display in the tooltip for the data at the given index * @param index diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index 41a4e4168a3..df7b828e471 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -70,20 +70,25 @@ module.exports = LinearScaleBase.extend({ 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 && !opts.ticks.beginAtZero) { + value.min = value.max; + } + if (opts.relativePoints) { positiveValues[index] = 100; - } else if (value < 0) { - negativeValues[index] += value; + } else if (value.min < 0 || value.max < 0) { + negativeValues[index] += value.min; } else { - positiveValues[index] += value; + positiveValues[index] += value.max; } }); } @@ -102,21 +107,28 @@ module.exports = LinearScaleBase.extend({ 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.isarr === false) { + value.min = value.end; + value.max = value.end; + } + + 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; } }); } @@ -151,7 +163,7 @@ module.exports = LinearScaleBase.extend({ }, getLabelForIndex: function(index, datasetIndex) { - return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]); + return this.getScaleLabel(this.chart.data.datasets[datasetIndex].data[index]); }, // Utils diff --git a/src/scales/scale.logarithmic.js b/src/scales/scale.logarithmic.js index 91f90845da3..fbe42612be4 100644 --- a/src/scales/scale.logarithmic.js +++ b/src/scales/scale.logarithmic.js @@ -113,13 +113,13 @@ module.exports = Scale.extend({ 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.min) || isNaN(value.max) || meta.data[index].hidden || value.max < 0 || value.max < 0) { return; } values[index] = values[index] || 0; - values[index] += value; + values[index] += value.max; }); } }); @@ -138,26 +138,31 @@ module.exports = Scale.extend({ 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.isarr === false) { + value.min = value.end; + value.max = value.end; + } + 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; } - 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; } }); } @@ -242,7 +247,7 @@ module.exports = Scale.extend({ // Get the correct tooltip label getLabelForIndex: function(index, datasetIndex) { - return +this.getRightValue(this.chart.data.datasets[datasetIndex].data[index]); + return this.getScaleLabel(this.chart.data.datasets[datasetIndex].data[index]); }, getPixelForTick: function(index) { From 124688c2582aa5f18e17ae878062e60897421ee8 Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Fri, 8 Feb 2019 02:37:13 +0200 Subject: [PATCH 73/76] format --- src/core/core.scale.js | 2 +- src/scales/scale.logarithmic.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/core.scale.js b/src/core/core.scale.js index 3f74f0f4c8b..0ff2b41b737 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -564,7 +564,7 @@ module.exports = Element.extend({ end: end, isarr: isarr }; - }, + }, getScaleLabel: function(rawValue) { var v = this._parseValue(rawValue); diff --git a/src/scales/scale.logarithmic.js b/src/scales/scale.logarithmic.js index fbe42612be4..7e5b1cbe750 100644 --- a/src/scales/scale.logarithmic.js +++ b/src/scales/scale.logarithmic.js @@ -152,7 +152,7 @@ module.exports = Scale.extend({ if (me.min === null) { me.min = value.min; } else if (value.min < me.min) { - me.min = value.min; + me.min = value.min; } if (me.max === null) { From 84dae3d8d33ac08b8f31475a49e7622943129edf Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Fri, 8 Feb 2019 02:53:51 +0200 Subject: [PATCH 74/76] + --- src/core/core.scale.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/core.scale.js b/src/core/core.scale.js index 0ff2b41b737..861f91c1a79 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -544,7 +544,7 @@ module.exports = Element.extend({ }, _parseValue: function(raw) { - var value = this.getRightValue(raw); + var value = +this.getRightValue(raw); var start, end, isarr; if (helpers.isArray(value)) { From 19a400cc1eb6efae2f4c53fb70469d22e066c74b Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Fri, 8 Feb 2019 03:20:22 +0200 Subject: [PATCH 75/76] controller bar update --- src/controllers/controller.bar.js | 49 +++++++++++++++++-------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 306118766c3..ffc5fc80a23 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -290,32 +290,35 @@ module.exports = DatasetController.extend({ var scale = me._getValueScale(); var isHorizontal = scale.isHorizontal(); var datasets = chart.data.datasets; - var value = +scale.getRightValue(datasets[datasetIndex].data[index]); + var value = scale._parseValue(datasets[datasetIndex].data[index]); var minBarLength = scale.options.minBarLength; var stacked = scale.options.stacked; var stack = meta.stack; - var start = 0; - var i, imeta, ivalue, base, head, size; + 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; + var i, imeta, ivalue, base, head, size, yStackValue; if (stacked || (stacked === undefined && stack !== undefined)) { - for (i = 0; i < datasetIndex; ++i) { - imeta = chart.getDatasetMeta(i); - - if (imeta.bar && - imeta.stack === stack && - imeta.controller._getValueScaleId() === scale.id && - chart.isDatasetVisible(i)) { - - ivalue = +scale.getRightValue(datasets[i].data[index]); - if ((value < 0 && ivalue < 0) || (value >= 0 && ivalue > 0)) { - start += ivalue; - } - } - } - } - - base = scale.getPixelForValue(start); - head = scale.getPixelForValue(start + value); + for (i = 0; i < datasetIndex; ++i) { + imeta = chart.getDatasetMeta(i); + + if (imeta.bar && + imeta.stack === stack && + imeta.controller._getValueScaleId() === scale.id && + chart.isDatasetVisible(i)) { + + yStackValue = scale._parseValue(datasets[i].data[index]); + ivalue = yStackValue.min >= 0 && yStackValue.max >= 0 ? yStackValue.max : yStackValue.min; + + if ((value.min < 0 && ivalue < 0) || (value.max >= 0 && ivalue >= 0)) { + start += ivalue; + } + } + } + } + + base = scale.getPixelForValue(start); + head = scale.getPixelForValue(start + yValue); size = head - base; if (minBarLength !== undefined && Math.abs(size) < minBarLength) { @@ -370,8 +373,10 @@ module.exports = DatasetController.extend({ 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(); } } From 87b0d91c60f9a294542f07560fba0d770cc97a4c Mon Sep 17 00:00:00 2001 From: gwyneblaidd Date: Fri, 8 Feb 2019 04:01:50 +0200 Subject: [PATCH 76/76] format --- src/controllers/controller.bar.js | 40 +++++++++++++++---------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index ffc5fc80a23..e96f6b92919 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -299,26 +299,26 @@ module.exports = DatasetController.extend({ var i, imeta, ivalue, base, head, size, yStackValue; if (stacked || (stacked === undefined && stack !== undefined)) { - for (i = 0; i < datasetIndex; ++i) { - imeta = chart.getDatasetMeta(i); - - if (imeta.bar && - imeta.stack === stack && - imeta.controller._getValueScaleId() === scale.id && - chart.isDatasetVisible(i)) { - - yStackValue = scale._parseValue(datasets[i].data[index]); - ivalue = yStackValue.min >= 0 && yStackValue.max >= 0 ? yStackValue.max : yStackValue.min; - - if ((value.min < 0 && ivalue < 0) || (value.max >= 0 && ivalue >= 0)) { - start += ivalue; - } - } - } - } - - base = scale.getPixelForValue(start); - head = scale.getPixelForValue(start + yValue); + for (i = 0; i < datasetIndex; ++i) { + imeta = chart.getDatasetMeta(i); + + if (imeta.bar && + imeta.stack === stack && + imeta.controller._getValueScaleId() === scale.id && + chart.isDatasetVisible(i)) { + + yStackValue = scale._parseValue(datasets[i].data[index]); + ivalue = yStackValue.min >= 0 && yStackValue.max >= 0 ? yStackValue.max : yStackValue.min; + + if ((value.min < 0 && ivalue < 0) || (value.max >= 0 && ivalue >= 0)) { + start += ivalue; + } + } + } + } + + base = scale.getPixelForValue(start); + head = scale.getPixelForValue(start + yValue); size = head - base; if (minBarLength !== undefined && Math.abs(size) < minBarLength) {