mirror of
https://github.com/chartjs/Chart.js.git
synced 2024-10-06 12:19:08 +02:00
Allow "spriting" text in fixtures (#7073)
Allow "blit" text drawing in fixtures
This commit is contained in:
parent
1b1c7fc302
commit
f0fd28af66
30
test/fixtures/scale.category/ticks-from-data.js
vendored
Normal file
30
test/fixtures/scale.category/ticks-from-data.js
vendored
Normal 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
|
||||||
|
}
|
||||||
|
};
|
BIN
test/fixtures/scale.category/ticks-from-data.png
vendored
Normal file
BIN
test/fixtures/scale.category/ticks-from-data.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
@ -9,6 +9,8 @@ function getValues(scale) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
describe('Category scale tests', function() {
|
describe('Category scale tests', function() {
|
||||||
|
describe('auto', jasmine.fixture.specs('scale.category'));
|
||||||
|
|
||||||
it('Should register the constructor with the scale service', function() {
|
it('Should register the constructor with the scale service', function() {
|
||||||
var Constructor = Chart.scaleService.getScaleConstructor('category');
|
var Constructor = Chart.scaleService.getScaleConstructor('category');
|
||||||
expect(Constructor).not.toBe(undefined);
|
expect(Constructor).not.toBe(undefined);
|
||||||
@ -57,33 +59,6 @@ describe('Category scale tests', function() {
|
|||||||
expect(defaultConfig.ticks.callback).toEqual(jasmine.any(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() {
|
it('Should generate ticks from the data xLabels', function() {
|
||||||
var scaleID = 'myScale';
|
var scaleID = 'myScale';
|
||||||
|
102
test/spriting.js
Normal file
102
test/spriting.js
Normal file
File diff suppressed because one or more lines are too long
@ -1,3 +1,5 @@
|
|||||||
|
import {spritingOn, spritingOff} from './spriting';
|
||||||
|
|
||||||
function createCanvas(w, h) {
|
function createCanvas(w, h) {
|
||||||
var canvas = document.createElement('canvas');
|
var canvas = document.createElement('canvas');
|
||||||
canvas.width = w;
|
canvas.width = w;
|
||||||
@ -62,7 +64,11 @@ function acquireChart(config, options) {
|
|||||||
window.document.body.appendChild(wrapper);
|
window.document.body.appendChild(wrapper);
|
||||||
|
|
||||||
try {
|
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) {
|
} catch (e) {
|
||||||
window.document.body.removeChild(wrapper);
|
window.document.body.removeChild(wrapper);
|
||||||
throw e;
|
throw e;
|
||||||
@ -77,6 +83,7 @@ function acquireChart(config, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function releaseChart(chart) {
|
function releaseChart(chart) {
|
||||||
|
spritingOff(chart.ctx);
|
||||||
chart.destroy();
|
chart.destroy();
|
||||||
|
|
||||||
var wrapper = (chart.$test || {}).wrapper;
|
var wrapper = (chart.$test || {}).wrapper;
|
||||||
@ -146,7 +153,7 @@ function triggerMouseEvent(chart, type, el) {
|
|||||||
node.dispatchEvent(event);
|
node.dispatchEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
injectCSS: injectCSS,
|
injectCSS: injectCSS,
|
||||||
createCanvas: createCanvas,
|
createCanvas: createCanvas,
|
||||||
acquireChart: acquireChart,
|
acquireChart: acquireChart,
|
||||||
|
Loading…
Reference in New Issue
Block a user