| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056 |
- /* global Ext, expect */
- topSuite("Ext.chart.legend.SpriteLegend", ['Ext.chart.*', 'Ext.data.ArrayStore'], function() {
- function generateStoreData(pointCount) {
- var data = [
- { month: 'Jan' },
- { month: 'Feb' },
- { month: 'Mar' },
- { month: 'Apr' },
- { month: 'May' },
- { month: 'Jun' },
- { month: 'Jul' },
- { month: 'Aug' },
- { month: 'Sep' },
- { month: 'Oct' },
- { month: 'Nov' },
- { month: 'Dec' }
- ],
- i = 0,
- j = 0,
- ln = data.length,
- entry;
- for (; i < ln; i++) {
- entry = data[i];
- for (j = 0; j < pointCount; j++) {
- entry['data' + (j + 1).toString()] = Math.random() * 10;
- }
- }
- return data;
- }
-
- beforeEach(function() {
- // Silence Sencha download server warnings
- spyOn(Ext.log, 'warn');
- });
- describe('markers', function () {
- var chart;
- afterEach(function () {
- Ext.destroy(chart);
- });
- it('should be visible even if the series markers are hidden', function () {
- var layoutDone;
- runs(function () {
- chart = new Ext.chart.CartesianChart({
- renderTo: Ext.getBody(),
- width: 300,
- height: 300,
- store: {
- data: [
- { x: 1, y: 1 },
- { x: 2, y: 3 },
- { x: 3, y: 1 }
- ]
- },
- axes: [
- {
- type: 'numeric',
- position: 'left'
- },
- {
- type: 'numeric',
- position: 'bottom'
- }
- ],
- series: [{
- showMarkers: false,
- marker: {
- type: 'square'
- },
- type: 'line',
- xField: 'x',
- yField: 'y'
- }],
- legend: true,
- listeners: {
- layout: function () {
- layoutDone = true;
- }
- }
- });
- });
- waitsFor(function () {
- return layoutDone;
- });
- runs(function () {
- var sprite = chart.getLegend().getSprites()[0];
- expect(sprite.getMarker().attr.hidden).toBe(false);
- });
- });
- });
- describe('docked', function () {
- var chart;
- afterEach(function () {
- Ext.destroy(chart);
- });
- it('should position the sprite legend properly', function () {
- var side = 400,
- layoutDone,
- legendSpriteCount,
- legendSpriteIds;
- chart = new Ext.chart.CartesianChart({
- renderTo: Ext.getBody(),
- width: side,
- height: side,
- store: {
- data: [
- { x: 1, y: 1 },
- { x: 2, y: 3 },
- { x: 3, y: 1 }
- ]
- },
- axes: [
- {
- type: 'numeric',
- position: 'left'
- },
- {
- type: 'category',
- position: 'bottom'
- }
- ],
- series: {
- type: 'bar',
- xField: 'x',
- yField: 'y'
- },
- listeners: {
- layout: function () {
- layoutDone = true;
- }
- }
- });
- waitsFor(function () {
- return layoutDone;
- });
- runs(function () {
- chart.setLegend({
- type: 'sprite',
- docked: 'top'
- });
- layoutDone = false;
- });
- waitsFor(function () {
- return layoutDone;
- });
- runs(function () {
- // docked: 'top'
- var chartRect = chart.getChartRect(),
- legend = chart.getLegend(),
- legendSize = legend.getSize(),
- legendSurface = legend.getSurface(),
- legendSprites = legendSurface.getItems(),
- legendRect = legendSurface.getRect();
- expect(chartRect[0]).toBe(0);
- expect(chartRect[1]).toBe(legendSize.height);
- expect(chartRect[2]).toBe(side);
- expect(chartRect[3]).toBe(side - legendSize.height);
- expect(legendRect[0]).toBe(0);
- expect(legendRect[1]).toBe(0);
- expect(legendRect[2]).toBe(side);
- expect(legendRect[3]).toBe(legendSize.height);
- legendSpriteCount = legendSprites.length;
- // Don't want to be too specific here, as the number of sprites may change
- // in the future, but there must be something there.
- expect(legendSpriteCount).toBeGreaterThan(0);
- legendSpriteIds = {};
- for (var i = 0; i < legendSpriteCount; i++) {
- legendSpriteIds[legendSprites[i].getId()] = true;
- }
- chart.setLegend({
- type: 'sprite',
- docked: 'top' // that's not a mistake, setting again to 'top'
- });
- layoutDone = false;
- });
- waitsFor(function () {
- return layoutDone;
- });
- runs(function () {
- // docked: 'top'
- var chartRect = chart.getChartRect(),
- legend = chart.getLegend(),
- legendSize = legend.getSize(),
- legendSurface = legend.getSurface(),
- legendSprites = legendSurface.getItems(),
- legendRect = legendSurface.getRect();
- // Sprites from the previous legend should not remain in the chart's
- // 'legend' surface. We should get the same number of sprites, not double
- // the sprites ...
- expect(legendSprites.length).toBe(legendSpriteCount);
- // ... and those sprites should be all different.
- for (var i = 0; i < legendSpriteCount; i++) {
- expect(legendSprites[i].getId() in legendSpriteIds).toBe(false);
- }
- expect(chartRect[0]).toBe(0);
- expect(chartRect[1]).toBe(legendSize.height);
- expect(chartRect[2]).toBe(side);
- expect(chartRect[3]).toBe(side - legendSize.height);
- expect(legendRect[0]).toBe(0);
- expect(legendRect[1]).toBe(0);
- expect(legendRect[2]).toBe(side);
- expect(legendRect[3]).toBe(legendSize.height);
- chart.setLegend({
- type: 'sprite',
- docked: 'right'
- });
- layoutDone = false;
- });
- waitsFor(function () {
- return layoutDone;
- });
- runs(function () {
- // docked: 'right'
- var chartRect = chart.getChartRect(),
- legend = chart.getLegend(),
- legendSize = legend.getSize(),
- legendRect = legend.getSurface().getRect();
- expect(chartRect[0]).toBe(0);
- expect(chartRect[1]).toBe(0);
- expect(chartRect[2]).toBe(side - legendSize.width);
- expect(chartRect[3]).toBe(side);
- expect(legendRect[0]).toBe(side - legendSize.width);
- expect(legendRect[1]).toBe(0);
- expect(legendRect[2]).toBe(legendSize.width);
- expect(legendRect[3]).toBe(side);
- chart.setLegend({
- type: 'sprite',
- docked: 'bottom'
- });
- layoutDone = false;
- });
- waitsFor(function () {
- return layoutDone;
- });
- runs(function () {
- // docked: 'bottom'
- var chartRect = chart.getChartRect(),
- legend = chart.getLegend(),
- legendSize = legend.getSize(),
- legendRect = legend.getSurface().getRect();
- expect(chartRect[0]).toBe(0);
- expect(chartRect[1]).toBe(0);
- expect(chartRect[2]).toBe(side);
- expect(chartRect[3]).toBe(side - legendSize.height);
- expect(legendRect[0]).toBe(0);
- expect(legendRect[1]).toBe(side - legendSize.height);
- expect(legendRect[2]).toBe(side);
- expect(legendRect[3]).toBe(legendSize.height);
- chart.setLegend({
- type: 'sprite',
- docked: 'left'
- });
- layoutDone = false;
- });
- waitsFor(function () {
- return layoutDone;
- });
- runs(function () {
- // docked: 'left'
- var chartRect = chart.getChartRect(),
- legend = chart.getLegend(),
- legendSize = legend.getSize(),
- legendRect = legend.getSurface().getRect();
- expect(chartRect[0]).toBe(legendSize.width);
- expect(chartRect[1]).toBe(0);
- expect(chartRect[2]).toBe(side - legendSize.width);
- expect(chartRect[3]).toBe(side);
- expect(legendRect[0]).toBe(0);
- expect(legendRect[1]).toBe(0);
- expect(legendRect[2]).toBe(legendSize.width);
- expect(legendRect[3]).toBe(side);
- chart.setLegend(null);
- layoutDone = false;
- });
- waitsFor(function () {
- return layoutDone;
- });
- runs(function () {
- // legend: null
- var chartRect = chart.getChartRect();
- expect(chartRect[0]).toBe(0);
- expect(chartRect[1]).toBe(0);
- expect(chartRect[2]).toBe(side);
- expect(chartRect[3]).toBe(side);
- chart.setLegend({
- type: 'sprite',
- docked: 'right' // creating ...
- });
- layoutDone = false;
- });
- waitsFor(function () {
- return layoutDone;
- });
- runs(function () {
- var legend = chart.getLegend(),
- legendSurface = legend.getSurface();
- expect(legendSurface.getHidden()).toBe(false);
- chart.getLegend().setHidden(true); // ... and hiding
- layoutDone = false;
- });
- waitsFor(function () {
- return layoutDone;
- });
- runs(function () {
- // docked: 'right',
- // hidden: true
- var chartRect = chart.getChartRect(),
- legend = chart.getLegend(),
- legendSurface = legend.getSurface();
- expect(chartRect[0]).toBe(0);
- expect(chartRect[1]).toBe(0);
- expect(chartRect[2]).toBe(side);
- expect(chartRect[3]).toBe(side);
- expect(legendSurface.getHidden()).toBe(true);
- chart.getLegend().setHidden(false);
- layoutDone = false;
- });
- waitsFor(function () {
- return layoutDone;
- });
- runs(function () {
- // docked: 'right',
- // hidden: false
- var chartRect = chart.getChartRect(),
- legend = chart.getLegend(),
- legendSize = legend.getSize(),
- legendSurface = legend.getSurface();
- expect(chartRect[0]).toBe(0);
- expect(chartRect[1]).toBe(0);
- expect(chartRect[2]).toBe(side - legendSize.width);
- expect(chartRect[3]).toBe(side);
- expect(legendSurface.getHidden()).toBe(false);
- chart.setLegend({
- type: 'sprite',
- docked: 'right',
- hidden: true // creating already hidden
- });
- layoutDone = false;
- });
- waitsFor(function () {
- return layoutDone;
- });
- runs(function () {
- // docked: 'right',
- // hidden: true
- var chartRect = chart.getChartRect(),
- legend = chart.getLegend(),
- legendSurface = legend.getSurface();
- expect(chartRect[0]).toBe(0);
- expect(chartRect[1]).toBe(0);
- expect(chartRect[2]).toBe(side);
- expect(chartRect[3]).toBe(side);
- expect(legendSurface.getHidden()).toBe(true);
- });
- });
- });
- describe("updateTheme", function () {
- var storeData = generateStoreData(2);
- var chartConfig = {
- animation: false,
- width: 400,
- height: 300,
- renderTo: document.body,
- axes: [{
- type: 'numeric',
- position: 'left',
- adjustByMajorUnit: true,
- grid: true,
- fields: ['data1'],
- minimum: 0
- }, {
- type: 'category',
- position: 'bottom',
- grid: true,
- fields: ['month'],
- label: {
- rotate: {
- degrees: -45
- }
- }
- }],
- series: [{
- type: 'bar',
- title: [ 'IE', 'Firefox' ],
- xField: 'month',
- yField: [ 'data1', 'data2' ],
- stacked: true,
- style: {
- opacity: 0.80
- },
- highlight: {
- fillStyle: 'yellow'
- }
- }]
- };
- var store, chart;
- beforeEach(function () {
- store = new Ext.data.Store({
- fields: [ 'month', 'data1', 'data2' ],
- data: storeData
- });
- });
- afterEach(function () {
- Ext.destroy(chart, store);
- });
- it("should use the style from the theme, " +
- "if the user hasn't provided their own config", function () {
- var CustomTheme = Ext.define(null, {
- extend: 'Ext.chart.theme.Base',
- singleton: true,
- config: {
- legend: {
- label: {
- fontSize: 15,
- fontWeight: 'bold',
- fontFamily: 'Tahoma',
- fillStyle: '#ff0000'
- },
- border: {
- lineWidth: 2,
- radius: 5,
- fillStyle: '#ffff00',
- strokeStyle: '#ff0000'
- }
- }
- }
- });
- var config = Ext.merge({
- theme: new CustomTheme,
- store: store,
- legend: {
- type: 'sprite',
- docked: 'top'
- }
- }, chartConfig);
- chart = new Ext.chart.CartesianChart(config);
- var legend = chart.getLegend();
- var borderSprite = legend.getBorder();
- var itemSprites = legend.getSprites();
- expect(borderSprite.attr.lineWidth).toBe(2);
- expect(borderSprite.attr.radius).toBe(5);
- expect(borderSprite.attr.fillStyle).toBe('#ffff00');
- expect(borderSprite.attr.strokeStyle).toBe('#ff0000');
- for (var i = 0, ln = itemSprites.length; i < ln; i++) {
- var label = itemSprites[i].getLabel();
- expect(label.attr.fontSize).toBe('15px');
- expect(label.attr.fontWeight).toBe('bold');
- expect(label.attr.fontFamily).toBe('Tahoma');
- expect(label.attr.fillStyle).toBe('#ff0000');
- }
- });
- it("should should use the style from the user config, if it was provided", function () {
- var config = Ext.merge({
- store: store,
- legend: {
- type: 'sprite',
- docked: 'top',
- label: {
- fontSize: 15,
- fontWeight: 'bold',
- fontFamily: 'Tahoma',
- fillStyle: '#ff0000'
- },
- border: {
- lineWidth: 2,
- radius: 5,
- fillStyle: '#ffff00',
- strokeStyle: '#ff0000'
- }
- }
- }, chartConfig);
- chart = new Ext.chart.CartesianChart(config);
- var legend = chart.getLegend();
- var borderSprite = legend.getBorder();
- var itemSprites = legend.getSprites();
- expect(borderSprite.attr.lineWidth).toBe(2);
- expect(borderSprite.attr.radius).toBe(5);
- expect(borderSprite.attr.fillStyle).toBe('#ffff00');
- expect(borderSprite.attr.strokeStyle).toBe('#ff0000');
- for (var i = 0, ln = itemSprites.length; i < ln; i++) {
- var label = itemSprites[i].getLabel();
- expect(label.attr.fontSize).toBe('15px');
- expect(label.attr.fontWeight).toBe('bold');
- expect(label.attr.fontFamily).toBe('Tahoma');
- expect(label.attr.fillStyle).toBe('#ff0000');
- }
- });
- });
- // Safari 7 times out here in Modern for unknown reason in TeamCity only.
- // Works fine locally (tested in Safari 7.0 (9537.71).
- TODO(Ext.isSafari7).
- describe("store", function () {
- var storeData = generateStoreData(4),
- store, chart, legend;
- beforeEach(function () {
- var layoutEndSpy;
- store = new Ext.data.Store({
- fields: [ 'month', 'data1', 'data2', 'data3', 'data4' ],
- data: storeData
- });
- chart = new Ext.chart.CartesianChart({
- animation: false,
- width: 400,
- height: 300,
- renderTo: document.body,
- store: store,
- legend: {
- type: 'sprite',
- docked: 'top'
- },
- axes: [{
- type: 'numeric',
- position: 'left',
- adjustByMajorUnit: true,
- grid: true,
- fields: ['data1'],
- minimum: 0
- }, {
- type: 'category',
- position: 'bottom',
- grid: true,
- fields: ['month'],
- label: {
- rotate: {
- degrees: -45
- }
- }
- }],
- series: [{
- type: 'bar',
- title: [ 'IE', 'Firefox', 'Chrome', 'Safari' ],
- xField: 'month',
- yField: [ 'data1', 'data2', 'data3', 'data4' ],
- stacked: true,
- style: {
- opacity: 0.80
- },
- highlight: {
- fillStyle: 'yellow'
- }
- }]
- });
- legend = chart.getLegend();
- layoutEndSpy = spyOn(chart, 'onLayoutEnd').andCallThrough();
- waitsForSpy(layoutEndSpy, "chart layout to finish");
- });
- afterEach(function () {
- Ext.destroy(chart, store);
- });
- it("should trigger sprite/layout update on data update", function () {
- var series = chart.getSeries()[0],
- oldBorderWidth, newBorderWidth,
- oldSecondItem, oldSecondItemX, newSecondItem, newSecondItemX;
- runs(function () {
- oldBorderWidth = legend.borderSprite.getBBox().width;
- oldSecondItem = legend.getSprites()[1];
- oldSecondItemX = oldSecondItem.getBBox().x;
- expect(oldSecondItemX > 0).toBe(true);
- series.setTitle([ 'Edge', 'Firewall', 'Cross', 'Savanna' ]);
- });
- // Wait for the required test conditions to become true
- waitsFor(function () {
- newBorderWidth = legend.borderSprite.getBBox().width;
- newSecondItem = legend.getSprites()[1];
- newSecondItemX = newSecondItem.getBBox().x;
- return newBorderWidth > oldBorderWidth &&
- newSecondItem === oldSecondItem &&
- newSecondItem.getLabel().attr.text === 'Firewall' &&
- newSecondItemX > oldSecondItemX;
- });
- });
- it("should trigger sprite/layout update on data change", function () {
- var series = chart.getSeries()[0],
- oldBorderWidth, newBorderWidth,
- oldSecondItem, oldSecondItemX, newSecondItem, newSecondItemX;
- runs(function () {
- oldBorderWidth = legend.borderSprite.getBBox().width;
- oldSecondItem = legend.getSprites()[1];
- oldSecondItemX = oldSecondItem.getBBox().x;
- expect(oldSecondItemX > 0).toBe(true);
- series.setTitle([ 'IE', 'Chrome', 'Safari' ]);
- });
- // Wait for the required test conditions to become true
- waitsFor(function () {
- newBorderWidth = legend.borderSprite.getBBox().width;
- newSecondItem = legend.getSprites()[1];
- newSecondItemX = newSecondItem.getBBox().x;
- return newBorderWidth < oldBorderWidth &&
- // The sprite should be reused.
- newSecondItem === oldSecondItem &&
- newSecondItem.getLabel().attr.text === 'Chrome' &&
- legend.getSprites().length === 4 &&
- // The second sprite now displays the third title ('Chrome'),
- // but because the whole legend is centered, it should actually
- // move to the right, as there is now one less item.
- newSecondItemX > oldSecondItemX &&
- legend.getSprites()[3].getLabel().attr.text === 'data4';
- });
- });
- it("should trigger sprite/layout update on data sort", function () {
- var oldBorderWidth, newBorderWidth,
- performLayoutSpy = spyOn(legend, 'performLayout').andCallThrough(),
- sprites = legend.getSprites();
- function checkPositions(sprites) {
- expect(sprites[0].getBBox().x < sprites[1].getBBox().x).toBe(true);
- expect(sprites[1].getBBox().x < sprites[2].getBBox().x).toBe(true);
- expect(sprites[2].getBBox().x < sprites[3].getBBox().x).toBe(true);
- }
- runs(function () {
- // Initial positions:
- // IE - Firefox - Chrome - Safari
- checkPositions(sprites);
- oldBorderWidth = legend.borderSprite.getBBox().width;
- chart.legendStore.sort('name', 'DESC');
- performLayoutSpy.reset();
- });
- waitsForSpy(performLayoutSpy, "legend layout to finish after DESC sort");
- runs(function () {
- newBorderWidth = legend.borderSprite.getBBox().width;
- // Relative positions of the sprites should stay the same.
- checkPositions(sprites);
- // The sum of all sprite widths should stay the same,
- // and thus the legend border width too.
- // Safari - IE - Firefox - Chrome
- expect(sprites[0].getLabel().attr.text).toBe('Safari');
- expect(sprites[1].getLabel().attr.text).toBe('IE');
- expect(sprites[2].getLabel().attr.text).toBe('Firefox');
- expect(sprites[3].getLabel().attr.text).toBe('Chrome');
- chart.legendStore.sort('name', 'ASC');
- performLayoutSpy.reset();
- });
-
- waitsForSpy(performLayoutSpy, "legend layout to finish after ASC sort");
- runs(function() {
- // Relative positions of the sprites should stay the same.
- checkPositions(sprites);
- // Chrome - Firefox - IE - Safari
- expect(sprites[0].getLabel().attr.text).toBe('Chrome');
- expect(sprites[1].getLabel().attr.text).toBe('Firefox');
- expect(sprites[2].getLabel().attr.text).toBe('IE');
- expect(sprites[3].getLabel().attr.text).toBe('Safari');
- });
- });
- });
- describe('series colors', function () {
- var chart, layoutEnd;
- var colors1 = ['red', 'blue', 'green', 'orange', 'yellow'];
- var colors2 = ['gold', 'cyan', 'magenta', 'lime', 'navy'];
- var n = colors1.length;
- var data = (function () {
- var data = [];
- for (var i = 0; i < n; i++) {
- var point = {
- x: 'cat' + (i+1)
- };
- for (var j = 0; j < n; j++) {
- point['y' + (j+1)] = j+1;
- }
- data.push(point);
- }
- return data;
- })();
- afterEach(function () {
- chart = Ext.destroy(chart);
- layoutEnd = false;
- });
- it('should use theme colors in a cartesian (bar) chart', function () {
- runs(function () {
- chart = Ext.create({
- xtype: 'cartesian',
- animation: false,
- renderTo: document.body,
- width: 400,
- height: 400,
- store: {
- data: data.slice()
- },
- legend: {
- type: 'sprite',
- docked: 'right'
- },
- series: [{
- type: 'bar',
- xField: 'x',
- yField: ['y1', 'y2', 'y3', 'y4', 'y5']
- }],
- listeners: {
- layout: function () {
- layoutEnd = true;
- }
- }
- });
- });
- waitsFor(function () {
- return layoutEnd;
- });
- runs(function () {
- var series = chart.getSeries()[0],
- seriesSprites = series.getSprites(),
- legendSprites = chart.getLegend().getSprites(),
- themeColors = chart.getTheme().getColors();
- for (var i = 0; i < n; i++) {
- expect(seriesSprites[i].attr.fillStyle).toBe(themeColors[i]);
- expect(legendSprites[i].getMarker().attr.fillStyle).toBe(themeColors[i]);
- }
- });
- });
- it('should use theme colors in a polar (pie3d) chart', function () {
- runs(function () {
- chart = Ext.create({
- xtype: 'polar',
- animation: false,
- renderTo: document.body,
- width: 400,
- height: 400,
- store: {
- data: data.slice()
- },
- legend: {
- type: 'sprite',
- docked: 'right'
- },
- series: [{
- type: 'pie3d',
- angleField: 'y1',
- label: {
- field: 'x'
- }
- }],
- listeners: {
- layout: function () {
- layoutEnd = true;
- }
- }
- });
- });
- waitsFor(function () {
- return layoutEnd;
- });
- runs(function () {
- var series = chart.getSeries()[0],
- seriesSprites = series.getSprites(),
- legendSprites = chart.getLegend().getSprites(),
- themeColors = chart.getTheme().getColors();
- for (var i = 0; i < n; i++) {
- expect(seriesSprites[i * series.spritesPerSlice].attr.baseColor).toBe(themeColors[i]);
- expect(legendSprites[i].getMarker().attr.fillStyle).toBe(themeColors[i]);
- }
- });
- });
- it('should use colors from the series "colors" config (cartesian, bar)', function () {
- runs(function () {
- chart = Ext.create({
- xtype: 'cartesian',
- animation: false,
- renderTo: document.body,
- width: 400,
- height: 400,
- store: {
- data: data.slice()
- },
- legend: {
- type: 'sprite',
- docked: 'right'
- },
- series: [{
- type: 'bar',
- xField: 'x',
- yField: ['y1', 'y2', 'y3', 'y4', 'y5'],
- colors: colors1.slice()
- }],
- listeners: {
- layout: function () {
- layoutEnd = true;
- }
- }
- });
- });
- waitsFor(function () {
- return layoutEnd;
- });
- runs(function () {
- var series = chart.getSeries()[0],
- seriesSprites = series.getSprites(),
- legendSprites = chart.getLegend().getSprites();
- for (var i = 0; i < n; i++) {
- var hexColor = Ext.util.Color.fly(colors1[i]).toString();
- expect(seriesSprites[i].attr.fillStyle).toBe(hexColor);
- expect(legendSprites[i].getMarker().attr.fillStyle).toBe(hexColor);
- }
- });
- });
- it('should use colors from the series "colors" config (polar, pie3d)', function () {
- runs(function () {
- chart = Ext.create({
- xtype: 'polar',
- animation: false,
- renderTo: document.body,
- width: 400,
- height: 400,
- store: {
- data: data.slice()
- },
- legend: {
- type: 'sprite',
- docked: 'right'
- },
- series: [{
- type: 'pie3d',
- angleField: 'y1',
- label: {
- field: 'x'
- },
- colors: colors1.slice()
- }],
- listeners: {
- layout: function () {
- layoutEnd = true;
- }
- }
- });
- });
- waitsFor(function () {
- return layoutEnd;
- });
- runs(function () {
- var series = chart.getSeries()[0],
- seriesSprites = series.getSprites(),
- legendSprites = chart.getLegend().getSprites();
- for (var i = 0; i < n; i++) {
- var hexColor = Ext.util.Color.fly(colors1[i]).toString();
- expect(seriesSprites[i * series.spritesPerSlice].attr.baseColor).toBe(hexColor);
- expect(legendSprites[i].getMarker().attr.fillStyle).toBe(hexColor);
- }
- });
- });
- it('should reflect dynamic changes to the series "colors" config (cartesian, bar)', function () {
- runs(function () {
- chart = Ext.create({
- xtype: 'cartesian',
- animation: false,
- renderTo: document.body,
- width: 400,
- height: 400,
- store: {
- data: data.slice()
- },
- legend: {
- type: 'sprite',
- docked: 'right'
- },
- series: [{
- type: 'bar',
- xField: 'x',
- yField: ['y1', 'y2', 'y3', 'y4', 'y5'],
- colors: colors1.slice()
- }],
- listeners: {
- layout: function () {
- layoutEnd = true;
- }
- }
- });
- });
- waitsFor(function () {
- return layoutEnd;
- });
- runs(function () {
- layoutEnd = false;
- chart.getSeries()[0].setColors(colors2.slice());
- });
- waits(1);
- runs(function () {
- var series = chart.getSeries()[0],
- seriesSprites = series.getSprites(),
- legendSprites = chart.getLegend().getSprites();
- for (var i = 0; i < n; i++) {
- var hexColor = Ext.util.Color.fly(colors2[i]).toString();
- expect(seriesSprites[i].attr.fillStyle).toBe(hexColor);
- expect(legendSprites[i].getMarker().attr.fillStyle).toBe(hexColor);
- }
- });
- });
- it('should reflect dynamic changes to the series "colors" config (polar, pie3d)', function () {
- runs(function () {
- chart = Ext.create({
- xtype: 'polar',
- animation: false,
- renderTo: document.body,
- width: 400,
- height: 400,
- store: {
- data: data.slice()
- },
- legend: {
- type: 'sprite',
- docked: 'right'
- },
- series: [{
- type: 'pie3d',
- angleField: 'y1',
- label: {
- field: 'x'
- },
- colors: colors1.slice()
- }],
- listeners: {
- layout: function () {
- layoutEnd = true;
- }
- }
- });
- });
- waitsFor(function () {
- return layoutEnd;
- });
- runs(function () {
- layoutEnd = false;
- chart.getSeries()[0].setColors(colors2.slice());
- });
- waits(1);
- runs(function () {
- var series = chart.getSeries()[0],
- seriesSprites = series.getSprites(),
- legendSprites = chart.getLegend().getSprites();
- for (var i = 0; i < n; i++) {
- var hexColor = Ext.util.Color.fly(colors2[i]).toString();
- expect(seriesSprites[i * series.spritesPerSlice].attr.baseColor).toBe(hexColor);
- expect(legendSprites[i].getMarker().attr.fillStyle).toBe(hexColor);
- }
- });
- });
- });
- });
|