head = base + size;
}
+ const actualBase = baseValue || 0;
+ if (base === vScale.getPixelForValue(actualBase)) {
+ const halfGrid = vScale.getLineWidthForValue(actualBase) / 2;
+ if (size > 0) {
+ base += halfGrid;
+ size -= halfGrid;
+ } else if (size < 0) {
+ base -= halfGrid;
+ size += halfGrid;
+ }
+ }
+
return {
size,
base,
}
}
+ getLineWidthForValue(value) {
+ const me = this;
+ const grid = me.options.grid;
+ if (!me._isVisible() || !grid.display) {
+ return 0;
+ }
+ const ticks = me.ticks;
+ const index = ticks.findIndex(t => t.value === value);
+ if (index >= 0) {
+ const opts = grid.setContext(me.getContext(index));
+ return opts.lineWidth;
+ }
+ return 0;
+ }
+
/**
* @protected
*/
--- /dev/null
+module.exports = {
+ config: {
+ type: 'bar',
+ data: {
+ labels: ['a', 'b'],
+ datasets: [{
+ backgroundColor: '#AAFFCC',
+ borderColor: '#0000FF',
+ borderWidth: 1,
+ data: [1, 2]
+ }]
+ },
+ options: {
+ scales: {
+ x: {
+ display: false
+ },
+ y: {
+ ticks: {
+ display: false
+ },
+ grid: {
+ color: function(context) {
+ return context.tick.value === 0 ? 'red' : 'transparent';
+ },
+ lineWidth: 5,
+ tickLength: 0
+ },
+ }
+ },
+ maintainAspectRatio: false
+ }
+ },
+ options: {
+ canvas: {
+ width: 128,
+ height: 128
+ }
+ }
+};
--- /dev/null
+module.exports = {
+ config: {
+ type: 'bar',
+ data: {
+ labels: ['a', 'b'],
+ datasets: [{
+ backgroundColor: '#AAFFCC',
+ borderColor: '#0000FF',
+ borderWidth: 1,
+ data: [1, 2]
+ }]
+ },
+ options: {
+ indexAxis: 'y',
+ scales: {
+ y: {
+ display: false
+ },
+ x: {
+ ticks: {
+ display: false
+ },
+ grid: {
+ color: function(context) {
+ return context.tick.value === 0 ? 'red' : 'transparent';
+ },
+ lineWidth: 5,
+ tickLength: 0
+ },
+ }
+ },
+ maintainAspectRatio: false
+ }
+ },
+ options: {
+ canvas: {
+ width: 128,
+ height: 128
+ }
+ }
+};
--- /dev/null
+module.exports = {
+ config: {
+ type: 'bar',
+ data: {
+ labels: ['a', 'b'],
+ datasets: [{
+ backgroundColor: '#AAFFCC',
+ borderColor: '#0000FF',
+ borderWidth: 1,
+ data: [1, -1]
+ }]
+ },
+ options: {
+ indexAxis: 'y',
+ scales: {
+ y: {
+ display: false
+ },
+ x: {
+ ticks: {
+ display: false
+ },
+ grid: {
+ color: function(context) {
+ return context.tick.value === 0 ? 'red' : 'transparent';
+ },
+ lineWidth: 5,
+ tickLength: 0
+ },
+ }
+ },
+ maintainAspectRatio: false
+ }
+ },
+ options: {
+ canvas: {
+ width: 128,
+ height: 128
+ }
+ }
+};
--- /dev/null
+module.exports = {
+ config: {
+ type: 'bar',
+ data: {
+ labels: ['a', 'b'],
+ datasets: [{
+ backgroundColor: '#AAFFCC',
+ borderColor: '#0000FF',
+ borderWidth: 1,
+ data: [1, -1]
+ }]
+ },
+ options: {
+ scales: {
+ x: {
+ display: false
+ },
+ y: {
+ ticks: {
+ display: false
+ },
+ grid: {
+ color: function(context) {
+ return context.tick.value === 0 ? 'red' : 'transparent';
+ },
+ lineWidth: 5,
+ tickLength: 0
+ },
+ }
+ },
+ maintainAspectRatio: false
+ }
+ },
+ options: {
+ canvas: {
+ width: 128,
+ height: 128
+ }
+ }
+};
--- /dev/null
+module.exports = {
+ config: {
+ type: 'bar',
+ data: {
+ labels: ['a', 'b'],
+ datasets: [{
+ backgroundColor: '#AAFFCC',
+ borderColor: '#0000FF',
+ borderWidth: 1,
+ data: [-1, -2]
+ }]
+ },
+ options: {
+ indexAxis: 'y',
+ scales: {
+ y: {
+ display: false
+ },
+ x: {
+ ticks: {
+ display: false
+ },
+ grid: {
+ color: function(context) {
+ return context.tick.value === 0 ? 'red' : 'transparent';
+ },
+ lineWidth: 5,
+ tickLength: 0,
+ borderWidth: 0
+ },
+ }
+ },
+ maintainAspectRatio: false
+ }
+ },
+ options: {
+ canvas: {
+ width: 128,
+ height: 128
+ }
+ }
+};
--- /dev/null
+module.exports = {
+ config: {
+ type: 'bar',
+ data: {
+ labels: ['a', 'b'],
+ datasets: [{
+ backgroundColor: '#AAFFCC',
+ borderColor: '#0000FF',
+ borderWidth: 1,
+ data: [-1, -2]
+ }]
+ },
+ options: {
+ scales: {
+ x: {
+ display: false
+ },
+ y: {
+ ticks: {
+ display: false
+ },
+ grid: {
+ color: function(context) {
+ return context.tick.value === 0 ? 'red' : 'transparent';
+ },
+ borderWidth: 0,
+ lineWidth: 5,
+ tickLength: 0
+ },
+ }
+ },
+ maintainAspectRatio: false
+ }
+ },
+ options: {
+ canvas: {
+ width: 128,
+ height: 128
+ }
+ }
+};
--- /dev/null
+module.exports = {
+ config: {
+ type: 'bar',
+ data: {
+ labels: ['a', 'b'],
+ datasets: [{
+ backgroundColor: '#AAFFCC',
+ borderColor: '#0000FF',
+ borderWidth: 1,
+ data: [1, 3]
+ }]
+ },
+ options: {
+ base: 2,
+ indexAxis: 'y',
+ scales: {
+ y: {
+ display: false
+ },
+ x: {
+ ticks: {
+ display: false
+ },
+ grid: {
+ color: function(context) {
+ return context.tick.value === 2 ? 'red' : 'transparent';
+ },
+ lineWidth: 5,
+ tickLength: 0
+ },
+ }
+ },
+ maintainAspectRatio: false
+ }
+ },
+ options: {
+ canvas: {
+ width: 128,
+ height: 128
+ }
+ }
+};
--- /dev/null
+module.exports = {
+ config: {
+ type: 'bar',
+ data: {
+ labels: ['a', 'b'],
+ datasets: [{
+ backgroundColor: '#AAFFCC',
+ borderColor: '#0000FF',
+ borderWidth: 1,
+ data: [1, 3]
+ }]
+ },
+ options: {
+ base: 2,
+ scales: {
+ x: {
+ display: false
+ },
+ y: {
+ ticks: {
+ display: false
+ },
+ grid: {
+ color: function(context) {
+ return context.tick.value === 2 ? 'red' : 'transparent';
+ },
+ lineWidth: 5,
+ tickLength: 0
+ },
+ }
+ },
+ maintainAspectRatio: false
+ }
+ },
+ options: {
+ canvas: {
+ width: 128,
+ height: 128
+ }
+ }
+};
});
var data = chart.getDatasetMeta(0).data;
+ var halfBaseLine = chart.scales.y.getLineWidthForValue(0) / 2;
- expect(data[0].base - minBarLength).toEqual(data[0].y);
- expect(data[1].base + minBarLength).toEqual(data[1].y);
+ expect(data[0].base - minBarLength + halfBaseLine).toEqual(data[0].y);
+ expect(data[1].base + minBarLength - halfBaseLine).toEqual(data[1].y);
});
it('minBarLength settings should be used on X axis on horizontal bar chart', function() {
});
var data = chart.getDatasetMeta(0).data;
+ var halfBaseLine = chart.scales.x.getLineWidthForValue(0) / 2;
- expect(data[0].base + minBarLength).toEqual(data[0].x);
- expect(data[1].base - minBarLength).toEqual(data[1].x);
+ expect(data[0].base + minBarLength - halfBaseLine).toEqual(data[0].x);
+ expect(data[1].base - minBarLength + halfBaseLine).toEqual(data[1].x);
});
it('should respect the data visibility settings', function() {
* @return {string}
*/
getLabelForValue(value: number): string;
+
+ /**
+ * Returns the grid line width at given value
+ */
+ getLineWidthForValue(value: number): number;
+
/**
* Returns the location of the given data point. Value can either be an index or a numerical value
* The coordinate (0, 0) is at the upper-left corner of the canvas