Allow "spriting" text in fixtures (#7073)

Allow "blit" text drawing in fixtures
This commit is contained in:
Jukka Kurkela 2020-02-14 19:33:08 +02:00 committed by GitHub
parent 1b1c7fc302
commit f0fd28af66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 143 additions and 29 deletions

View File

@ -0,0 +1,30 @@
module.exports = {
threshold: 0.01,
config: {
type: 'horizontalBar',
data: {
datasets: [{
data: [10, 5, 0, 25, 78]
}],
labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5']
},
options: {
legend: false,
title: false,
elements: {
rectangle: {
backgroundColor: '#AAAAAA80',
borderColor: '#80808080',
borderWidth: {bottom: 6, left: 15, top: 6, right: 15}
}
},
scales: {
x: {display: false},
y: {display: true}
}
}
},
options: {
spriteText: true
}
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -9,6 +9,8 @@ function getValues(scale) {
}
describe('Category scale tests', function() {
describe('auto', jasmine.fixture.specs('scale.category'));
it('Should register the constructor with the scale service', function() {
var Constructor = Chart.scaleService.getScaleConstructor('category');
expect(Constructor).not.toBe(undefined);
@ -57,33 +59,6 @@ describe('Category scale tests', function() {
expect(defaultConfig.ticks.callback).toEqual(jasmine.any(Function));
});
it('Should generate ticks from the data labels', function() {
var scaleID = 'myScale';
var mockData = {
datasets: [{
yAxisID: scaleID,
data: [10, 5, 0, 25, 78]
}],
labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5']
};
var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('category'));
config.position = 'bottom';
var Constructor = Chart.scaleService.getScaleConstructor('category');
var scale = new Constructor({
ctx: {},
options: config,
chart: {
data: mockData
},
id: scaleID
});
scale.determineDataLimits();
scale.ticks = scale.buildTicks();
expect(getValues(scale)).toEqual(mockData.labels);
});
it('Should generate ticks from the data xLabels', function() {
var scaleID = 'myScale';

102
test/spriting.js Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,3 +1,5 @@
import {spritingOn, spritingOff} from './spriting';
function createCanvas(w, h) {
var canvas = document.createElement('canvas');
canvas.width = w;
@ -62,7 +64,11 @@ function acquireChart(config, options) {
window.document.body.appendChild(wrapper);
try {
chart = new Chart(canvas.getContext('2d'), config);
var ctx = canvas.getContext('2d');
if (options.spriteText) {
spritingOn(ctx);
}
chart = new Chart(ctx, config);
} catch (e) {
window.document.body.removeChild(wrapper);
throw e;
@ -77,6 +83,7 @@ function acquireChart(config, options) {
}
function releaseChart(chart) {
spritingOff(chart.ctx);
chart.destroy();
var wrapper = (chart.$test || {}).wrapper;
@ -146,7 +153,7 @@ function triggerMouseEvent(chart, type, el) {
node.dispatchEvent(event);
}
module.exports = {
export default {
injectCSS: injectCSS,
createCanvas: createCanvas,
acquireChart: acquireChart,