mirror of
https://gitlab.com/JKANetwork/CheckServer.git
synced 2026-03-07 19:12:01 +01:00
Start again
This commit is contained in:
241
vendors/echarts/test/ut/spec/component/visualMap/setOption.js
vendored
Normal file
241
vendors/echarts/test/ut/spec/component/visualMap/setOption.js
vendored
Normal file
@@ -0,0 +1,241 @@
|
||||
describe('vsiaulMap_setOption', function() {
|
||||
|
||||
var utHelper = window.utHelper;
|
||||
|
||||
var testCase = utHelper.prepare([
|
||||
'echarts/component/grid',
|
||||
'echarts/chart/scatter',
|
||||
'echarts/component/visualMap'
|
||||
]);
|
||||
|
||||
testCase.createChart()('defaultTargetController', function () {
|
||||
this.chart.setOption({
|
||||
xAxis: {},
|
||||
yAxis: {},
|
||||
series: [{type: 'scatter', data: [[12, 223]]}],
|
||||
visualMap: {
|
||||
inRange: {
|
||||
color: ['red', 'blue', 'yellow']
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var option = this.chart.getOption();
|
||||
|
||||
expect(option.visualMap.length).toEqual(1);
|
||||
expect(option.visualMap[0].inRange.color).toEqual(['red', 'blue', 'yellow']);
|
||||
expect(option.visualMap[0].target.inRange.color).toEqual(['red', 'blue', 'yellow']);
|
||||
expect(option.visualMap[0].controller.inRange.color).toEqual(['red', 'blue', 'yellow']);
|
||||
});
|
||||
|
||||
testCase.createChart()('ec2ColorCompatiable', function () {
|
||||
this.chart.setOption({
|
||||
xAxis: {},
|
||||
yAxis: {},
|
||||
series: [{type: 'scatter', data: [[12, 223]]}],
|
||||
visualMap: {
|
||||
color: ['yellow', 'blue', 'red']
|
||||
}
|
||||
});
|
||||
|
||||
var option = this.chart.getOption();
|
||||
|
||||
expect(option.visualMap.length).toEqual(1);
|
||||
expect(option.visualMap[0].color).toEqual(['yellow', 'blue', 'red']);
|
||||
expect(option.visualMap[0].target.inRange.color).toEqual(['red', 'blue', 'yellow']);
|
||||
expect(option.visualMap[0].controller.inRange.color).toEqual(['red', 'blue', 'yellow']);
|
||||
});
|
||||
|
||||
testCase.createChart()('remainVisualProp', function () {
|
||||
this.chart.setOption({
|
||||
xAxis: {},
|
||||
yAxis: {},
|
||||
series: [{type: 'scatter', data: [[12, 223]]}],
|
||||
visualMap: {
|
||||
inRange: {
|
||||
color: ['red', 'blue', 'yellow']
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.chart.setOption({
|
||||
visualMap: {}
|
||||
});
|
||||
|
||||
expectTheSame(this.chart.getOption());
|
||||
|
||||
this.chart.setOption({
|
||||
series: [{data: [[44, 55]]}] // visualMap depends series
|
||||
});
|
||||
|
||||
expectTheSame(this.chart.getOption());
|
||||
|
||||
function expectTheSame(option) {
|
||||
expect(option.visualMap.length).toEqual(1);
|
||||
expect(option.visualMap[0].inRange.color).toEqual(['red', 'blue', 'yellow']);
|
||||
expect(option.visualMap[0].target.inRange.color).toEqual(['red', 'blue', 'yellow']);
|
||||
expect(option.visualMap[0].controller.inRange.color).toEqual(['red', 'blue', 'yellow']);
|
||||
}
|
||||
});
|
||||
|
||||
testCase.createChart()('eraseAllVisualProps_notRelative', function () {
|
||||
this.chart.setOption({
|
||||
xAxis: {},
|
||||
yAxis: {},
|
||||
series: [{type: 'scatter', data: [[12, 223]]}],
|
||||
visualMap: {
|
||||
inRange: {
|
||||
color: ['red', 'blue', 'yellow'],
|
||||
symbolSize: [0.3, 0.5]
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var option = this.chart.getOption();
|
||||
|
||||
this.chart.setOption({
|
||||
visualMap: {
|
||||
inRange: {
|
||||
symbolSize: [0.4, 0.6]
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var option = this.chart.getOption();
|
||||
|
||||
expect(option.visualMap.length).toEqual(1);
|
||||
expect(option.visualMap[0].inRange.hasOwnProperty('color')).toEqual(false);
|
||||
expect(option.visualMap[0].target.inRange.hasOwnProperty('color')).toEqual(false);
|
||||
expect(option.visualMap[0].controller.inRange.hasOwnProperty('color')).toEqual(false);
|
||||
expect(option.visualMap[0].inRange.symbolSize).toEqual([0.4, 0.6]);
|
||||
expect(option.visualMap[0].target.inRange.symbolSize).toEqual([0.4, 0.6]);
|
||||
// Do not compare controller.inRange.symbolSize, which will be amplified to controller size.
|
||||
// expect(option.visualMap[0].controller.inRange.symbolSize).toEqual([?, ?]);
|
||||
});
|
||||
|
||||
testCase.createChart()('eraseAllVisualProps_reletive', function () {
|
||||
this.chart.setOption({
|
||||
xAxis: {},
|
||||
yAxis: {},
|
||||
series: [{type: 'scatter', data: [[12, 223]]}],
|
||||
visualMap: {
|
||||
inRange: {
|
||||
color: ['red', 'blue', 'yellow'],
|
||||
colorAlpha: [0.3, 0.5]
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.chart.setOption({
|
||||
visualMap: {
|
||||
inRange: {
|
||||
colorAlpha: [0.4, 0.6]
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var option = this.chart.getOption();
|
||||
|
||||
expect(option.visualMap.length).toEqual(1);
|
||||
expect(option.visualMap[0].inRange.hasOwnProperty('color')).toEqual(false);
|
||||
expect(option.visualMap[0].target.inRange.hasOwnProperty('color')).toEqual(false);
|
||||
expect(option.visualMap[0].controller.inRange.hasOwnProperty('color')).toEqual(false);
|
||||
expect(option.visualMap[0].inRange.colorAlpha).toEqual([0.4, 0.6]);
|
||||
expect(option.visualMap[0].target.inRange.colorAlpha).toEqual([0.4, 0.6]);
|
||||
expect(option.visualMap[0].controller.inRange.colorAlpha).toEqual([0.4, 0.6]);
|
||||
|
||||
this.chart.setOption({
|
||||
visualMap: {
|
||||
color: ['red', 'blue', 'green']
|
||||
}
|
||||
});
|
||||
|
||||
var option = this.chart.getOption();
|
||||
|
||||
expect(option.visualMap.length).toEqual(1);
|
||||
expect(option.visualMap[0].target.inRange.hasOwnProperty('colorAlpha')).toEqual(false);
|
||||
expect(option.visualMap[0].controller.inRange.hasOwnProperty('colorAlpha')).toEqual(false);
|
||||
expect(option.visualMap[0].target.inRange.color).toEqual(['green', 'blue', 'red']);
|
||||
expect(option.visualMap[0].controller.inRange.color).toEqual(['green', 'blue', 'red']);
|
||||
|
||||
this.chart.setOption({
|
||||
visualMap: {
|
||||
controller: {
|
||||
outOfRange: {
|
||||
symbol: ['diamond']
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var option = this.chart.getOption();
|
||||
|
||||
expect(option.visualMap.length).toEqual(1);
|
||||
expect(!option.visualMap[0].target.inRange).toEqual(true);
|
||||
expect(option.visualMap[0].controller.outOfRange.symbol).toEqual(['diamond']);
|
||||
});
|
||||
|
||||
testCase.createChart()('setOpacityWhenUseColor', function () {
|
||||
this.chart.setOption({
|
||||
xAxis: {},
|
||||
yAxis: {},
|
||||
series: [{type: 'scatter', data: [[12, 223]]}],
|
||||
visualMap: {
|
||||
inRange: {
|
||||
color: ['red', 'blue', 'yellow']
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var option = this.chart.getOption();
|
||||
|
||||
expect(!!option.visualMap[0].target.outOfRange.opacity).toEqual(true);
|
||||
});
|
||||
|
||||
testCase.createChart(2)('normalizeVisualRange', function () {
|
||||
this.charts[0].setOption({
|
||||
xAxis: {},
|
||||
yAxis: {},
|
||||
series: [{type: 'scatter', data: [[12, 223]]}],
|
||||
visualMap: [
|
||||
{type: 'continuous', inRange: {color: 'red'}},
|
||||
{type: 'continuous', inRange: {opacity: 0.4}},
|
||||
{type: 'piecewise', inRange: {color: 'red'}},
|
||||
{type: 'piecewise', inRange: {opacity: 0.4}},
|
||||
{type: 'piecewise', inRange: {symbol: 'diamond'}},
|
||||
{type: 'piecewise', inRange: {color: 'red'}, categories: ['a', 'b']},
|
||||
{type: 'piecewise', inRange: {color: {a: 'red'}}, categories: ['a', 'b']},
|
||||
{type: 'piecewise', inRange: {opacity: 0.4}, categories: ['a', 'b']}
|
||||
]
|
||||
});
|
||||
|
||||
var ecModel = this.charts[0].getModel();
|
||||
|
||||
function getVisual(idx, visualType) {
|
||||
return ecModel.getComponent('visualMap', idx)
|
||||
.targetVisuals.inRange[visualType].option.visual;
|
||||
}
|
||||
|
||||
function makeCategoryVisual(val) {
|
||||
var CATEGORY_DEFAULT_VISUAL_INDEX = -1;
|
||||
var arr = [];
|
||||
if (val != null) {
|
||||
arr[CATEGORY_DEFAULT_VISUAL_INDEX] = val;
|
||||
}
|
||||
for (var i = 1; i < arguments.length; i++) {
|
||||
arr.push(arguments[i]);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
expect(getVisual(0, 'color')).toEqual(['red']);
|
||||
expect(getVisual(1, 'opacity')).toEqual([0.4, 0.4]);
|
||||
expect(getVisual(2, 'color')).toEqual(['red']);
|
||||
expect(getVisual(3, 'opacity')).toEqual([0.4, 0.4]);
|
||||
expect(getVisual(4, 'symbol')).toEqual(['diamond']);
|
||||
expect(getVisual(5, 'color')).toEqual(makeCategoryVisual('red'));
|
||||
expect(getVisual(6, 'color')).toEqual(makeCategoryVisual(null, 'red'));
|
||||
expect(getVisual(7, 'opacity')).toEqual(makeCategoryVisual(0.4));
|
||||
});
|
||||
|
||||
});
|
||||
125
vendors/echarts/test/ut/spec/data/List.js
vendored
Normal file
125
vendors/echarts/test/ut/spec/data/List.js
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
describe('List', function () {
|
||||
|
||||
var utHelper = window.utHelper;
|
||||
|
||||
var testCase = utHelper.prepare(['echarts/data/List']);
|
||||
|
||||
describe('Data Manipulation', function () {
|
||||
|
||||
testCase('initData 1d', function (List) {
|
||||
var list = new List(['x', 'y']);
|
||||
list.initData([10, 20, 30]);
|
||||
expect(list.get('x', 0)).toEqual(10);
|
||||
expect(list.get('x', 1)).toEqual(20);
|
||||
expect(list.get('x', 2)).toEqual(30);
|
||||
expect(list.get('y', 1)).toEqual(20);
|
||||
});
|
||||
|
||||
testCase('initData 2d', function (List) {
|
||||
var list = new List(['x', 'y']);
|
||||
list.initData([[10, 15], [20, 25], [30, 35]]);
|
||||
expect(list.get('x', 1)).toEqual(20);
|
||||
expect(list.get('y', 1)).toEqual(25);
|
||||
});
|
||||
|
||||
testCase('initData 2d yx', function (List) {
|
||||
var list = new List(['y', 'x']);
|
||||
list.initData([[10, 15], [20, 25], [30, 35]]);
|
||||
expect(list.get('x', 1)).toEqual(25);
|
||||
expect(list.get('y', 1)).toEqual(20);
|
||||
});
|
||||
|
||||
testCase('Data with option 1d', function (List) {
|
||||
var list = new List(['x', 'y']);
|
||||
list.initData([1, {
|
||||
value: 2,
|
||||
somProp: 'foo'
|
||||
}]);
|
||||
expect(list.getItemModel(1).get('somProp')).toEqual('foo');
|
||||
expect(list.getItemModel(0).get('somProp')).toBeNull();
|
||||
});
|
||||
|
||||
testCase('Empty data', function (List) {
|
||||
var list = new List(['x', 'y']);
|
||||
list.initData([1, '-']);
|
||||
expect(list.get('y', 1)).toBeNaN();
|
||||
});
|
||||
|
||||
testCase('Stacked data', function (List) {
|
||||
var list1 = new List(['x', {
|
||||
name: 'y',
|
||||
stackable: true
|
||||
}]);
|
||||
var list2 = new List(['x', {
|
||||
name: 'y',
|
||||
stackable: true
|
||||
}]);
|
||||
list1.initData([1, '-', 2, -2]);
|
||||
list2.initData([1, 2, 3, 2]);
|
||||
|
||||
list2.stackedOn = list1;
|
||||
|
||||
expect(list2.get('y', 1, true)).toEqual(2);
|
||||
expect(list2.get('y', 2, true)).toEqual(5);
|
||||
expect(list2.get('y', 3, true)).toEqual(2);
|
||||
});
|
||||
|
||||
testCase('getRawValue', function (List) {
|
||||
var list = new List(['x', 'y']);
|
||||
|
||||
list.initData([1, 2, 3]);
|
||||
expect(list.getItemModel(1).option).toEqual(2);
|
||||
|
||||
list.initData([[10, 15], [20, 25], [30, 35]]);
|
||||
expect(list.getItemModel(1).option).toEqual([20, 25]);
|
||||
});
|
||||
|
||||
testCase('getDataExtent', function (List) {
|
||||
var list = new List(['x', 'y']);
|
||||
list.initData([1, 2, 3]);
|
||||
expect(list.getDataExtent('x')).toEqual([1, 3]);
|
||||
expect(list.getDataExtent('y')).toEqual([1, 3]);
|
||||
});
|
||||
|
||||
testCase('Data types', function (List) {
|
||||
var list = new List([{
|
||||
name: 'x',
|
||||
type: 'int'
|
||||
}, {
|
||||
name: 'y',
|
||||
type: 'float'
|
||||
}]);
|
||||
list.initData([[1.1, 1.1]]);
|
||||
expect(list.get('x', 0)).toEqual(1);
|
||||
expect(list.get('y', 0)).toBeCloseTo(1.1, 5);
|
||||
});
|
||||
|
||||
testCase('map', function (List) {
|
||||
var list = new List(['x', 'y']);
|
||||
list.initData([[10, 15], [20, 25], [30, 35]]);
|
||||
expect(list.map(['x', 'y'], function (x, y) {
|
||||
return [x + 2, y + 2];
|
||||
}).mapArray('x', function (x) {
|
||||
return x;
|
||||
})).toEqual([12, 22, 32]);
|
||||
});
|
||||
|
||||
testCase('mapArray', function (List) {
|
||||
var list = new List(['x', 'y']);
|
||||
list.initData([[10, 15], [20, 25], [30, 35]]);
|
||||
expect(list.mapArray(['x', 'y'], function (x, y) {
|
||||
return [x, y];
|
||||
})).toEqual([[10, 15], [20, 25], [30, 35]]);
|
||||
});
|
||||
|
||||
testCase('filterSelf', function (List) {
|
||||
var list = new List(['x', 'y']);
|
||||
list.initData([[10, 15], [20, 25], [30, 35]]);
|
||||
expect(list.filterSelf(['x', 'y'], function (x, y) {
|
||||
return x < 30 && x > 10;
|
||||
}).mapArray('x', function (x) {
|
||||
return x;
|
||||
})).toEqual([20]);
|
||||
});
|
||||
});
|
||||
});
|
||||
136
vendors/echarts/test/ut/spec/model/Component.js
vendored
Normal file
136
vendors/echarts/test/ut/spec/model/Component.js
vendored
Normal file
@@ -0,0 +1,136 @@
|
||||
describe('Component', function() {
|
||||
|
||||
var utHelper = window.utHelper;
|
||||
|
||||
var testCase = utHelper.prepare(['echarts/model/Component']);
|
||||
|
||||
describe('topologicalTravel', function () {
|
||||
|
||||
testCase('topologicalTravel_base', function (ComponentModel) {
|
||||
ComponentModel.extend({type: 'm1', dependencies: ['a1', 'a2']});
|
||||
ComponentModel.extend({type: 'a1'});
|
||||
ComponentModel.extend({type: 'a2'});
|
||||
var result = [];
|
||||
var allList = ComponentModel.getAllClassMainTypes();
|
||||
ComponentModel.topologicalTravel(['m1', 'a1', 'a2'], allList, function (componentType, dependencies) {
|
||||
result.push([componentType, dependencies]);
|
||||
});
|
||||
expect(result).toEqual([['a2', []], ['a1', []], ['m1', ['a1', 'a2']]]);
|
||||
});
|
||||
|
||||
testCase('topologicalTravel_a1IsAbsent', function (ComponentModel) {
|
||||
ComponentModel.extend({type: 'm1', dependencies: ['a1', 'a2']});
|
||||
ComponentModel.extend({type: 'a2'});
|
||||
var allList = ComponentModel.getAllClassMainTypes();
|
||||
var result = [];
|
||||
ComponentModel.topologicalTravel(['m1', 'a2'], allList, function (componentType, dependencies) {
|
||||
result.push([componentType, dependencies]);
|
||||
});
|
||||
expect(result).toEqual([['a2', []], ['m1', ['a1', 'a2']]]);
|
||||
});
|
||||
|
||||
testCase('topologicalTravel_empty', function (ComponentModel) {
|
||||
ComponentModel.extend({type: 'm1', dependencies: ['a1', 'a2']});
|
||||
ComponentModel.extend({type: 'a1'});
|
||||
ComponentModel.extend({type: 'a2'});
|
||||
var allList = ComponentModel.getAllClassMainTypes();
|
||||
var result = [];
|
||||
ComponentModel.topologicalTravel([], allList, function (componentType, dependencies) {
|
||||
result.push([componentType, dependencies]);
|
||||
});
|
||||
expect(result).toEqual([]);
|
||||
});
|
||||
|
||||
testCase('topologicalTravel_isolate', function (ComponentModel) {
|
||||
ComponentModel.extend({type: 'a2'});
|
||||
ComponentModel.extend({type: 'a1'});
|
||||
ComponentModel.extend({type: 'm1', dependencies: ['a2']});
|
||||
var allList = ComponentModel.getAllClassMainTypes();
|
||||
var result = [];
|
||||
ComponentModel.topologicalTravel(['a1', 'a2', 'm1'], allList, function (componentType, dependencies) {
|
||||
result.push([componentType, dependencies]);
|
||||
});
|
||||
expect(result).toEqual([['a1', []], ['a2', []], ['m1', ['a2']]]);
|
||||
});
|
||||
|
||||
testCase('topologicalTravel_diamond', function (ComponentModel) {
|
||||
ComponentModel.extend({type: 'a1', dependencies: []});
|
||||
ComponentModel.extend({type: 'a2', dependencies: ['a1']});
|
||||
ComponentModel.extend({type: 'a3', dependencies: ['a1']});
|
||||
ComponentModel.extend({type: 'm1', dependencies: ['a2', 'a3']});
|
||||
var allList = ComponentModel.getAllClassMainTypes();
|
||||
var result = [];
|
||||
ComponentModel.topologicalTravel(['m1', 'a1', 'a2', 'a3'], allList, function (componentType, dependencies) {
|
||||
result.push([componentType, dependencies]);
|
||||
});
|
||||
expect(result).toEqual([['a1', []], ['a3', ['a1']], ['a2', ['a1']], ['m1', ['a2', 'a3']]]);
|
||||
});
|
||||
|
||||
testCase('topologicalTravel_loop', function (ComponentModel) {
|
||||
ComponentModel.extend({type: 'm1', dependencies: ['a1', 'a2']});
|
||||
ComponentModel.extend({type: 'm2', dependencies: ['m1', 'a2']});
|
||||
ComponentModel.extend({type: 'a1', dependencies: ['m2', 'a2', 'a3']});
|
||||
ComponentModel.extend({type: 'a2'});
|
||||
ComponentModel.extend({type: 'a3'});
|
||||
var allList = ComponentModel.getAllClassMainTypes();
|
||||
expect(function () {
|
||||
ComponentModel.topologicalTravel(['m1', 'm2', 'a1'], allList);
|
||||
}).toThrowError(/Circl/);
|
||||
});
|
||||
|
||||
testCase('topologicalTravel_multipleEchartsInstance', function (ComponentModel) {
|
||||
ComponentModel.extend({type: 'm1', dependencies: ['a1', 'a2']});
|
||||
ComponentModel.extend({type: 'a1'});
|
||||
ComponentModel.extend({type: 'a2'});
|
||||
var allList = ComponentModel.getAllClassMainTypes();
|
||||
var result = [];
|
||||
ComponentModel.topologicalTravel(['m1', 'a1', 'a2'], allList, function (componentType, dependencies) {
|
||||
result.push([componentType, dependencies]);
|
||||
});
|
||||
expect(result).toEqual([['a2', []], ['a1', []], ['m1', ['a1', 'a2']]]);
|
||||
|
||||
result = [];
|
||||
ComponentModel.extend({type: 'm2', dependencies: ['a1', 'm1']});
|
||||
var allList = ComponentModel.getAllClassMainTypes();
|
||||
ComponentModel.topologicalTravel(['m2', 'm1', 'a1', 'a2'], allList, function (componentType, dependencies) {
|
||||
result.push([componentType, dependencies]);
|
||||
});
|
||||
expect(result).toEqual([['a2', []], ['a1', []], ['m1', ['a1', 'a2']], ['m2', ['a1', 'm1']]]);
|
||||
});
|
||||
|
||||
testCase('topologicalTravel_missingSomeNodeButHasDependencies', function (ComponentModel) {
|
||||
ComponentModel.extend({type: 'm1', dependencies: ['a1', 'a2']});
|
||||
ComponentModel.extend({type: 'a2', dependencies: ['a3']});
|
||||
ComponentModel.extend({type: 'a3'});
|
||||
ComponentModel.extend({type: 'a4'});
|
||||
var result = [];
|
||||
var allList = ComponentModel.getAllClassMainTypes();
|
||||
ComponentModel.topologicalTravel(['a3', 'm1'], allList, function (componentType, dependencies) {
|
||||
result.push([componentType, dependencies]);
|
||||
});
|
||||
expect(result).toEqual([['a3', []], ['a2', ['a3']], ['m1', ['a1', 'a2']]]);
|
||||
var result = [];
|
||||
var allList = ComponentModel.getAllClassMainTypes();
|
||||
ComponentModel.topologicalTravel(['m1', 'a3'], allList, function (componentType, dependencies) {
|
||||
result.push([componentType, dependencies]);
|
||||
});
|
||||
expect(result).toEqual([['a3', []], ['a2', ['a3']], ['m1', ['a1', 'a2']]]);
|
||||
});
|
||||
|
||||
testCase('topologicalTravel_subType', function (ComponentModel) {
|
||||
ComponentModel.extend({type: 'm1', dependencies: ['a1', 'a2']});
|
||||
ComponentModel.extend({type: 'a1.aaa', dependencies: ['a2']});
|
||||
ComponentModel.extend({type: 'a1.bbb', dependencies: ['a3', 'a4']});
|
||||
ComponentModel.extend({type: 'a2'});
|
||||
ComponentModel.extend({type: 'a3'});
|
||||
ComponentModel.extend({type: 'a4'});
|
||||
var result = [];
|
||||
var allList = ComponentModel.getAllClassMainTypes();
|
||||
ComponentModel.topologicalTravel(['m1', 'a1', 'a2', 'a4'], allList, function (componentType, dependencies) {
|
||||
result.push([componentType, dependencies]);
|
||||
});
|
||||
expect(result).toEqual([['a4', []], ['a2',[]], ['a1', ['a2','a3','a4']], ['m1', ['a1', 'a2']]]);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
808
vendors/echarts/test/ut/spec/model/Global.js
vendored
Normal file
808
vendors/echarts/test/ut/spec/model/Global.js
vendored
Normal file
@@ -0,0 +1,808 @@
|
||||
describe('modelAndOptionMapping', function() {
|
||||
|
||||
var utHelper = window.utHelper;
|
||||
|
||||
var testCase = utHelper.prepare([
|
||||
'echarts/component/grid',
|
||||
'echarts/chart/line',
|
||||
'echarts/chart/pie',
|
||||
'echarts/chart/bar',
|
||||
'echarts/component/toolbox',
|
||||
'echarts/component/dataZoom'
|
||||
]);
|
||||
|
||||
function getData0(chart, seriesIndex) {
|
||||
return getSeries(chart, seriesIndex).getData().get('y', 0);
|
||||
}
|
||||
|
||||
function getSeries(chart, seriesIndex) {
|
||||
return chart.getModel().getComponent('series', seriesIndex);
|
||||
}
|
||||
|
||||
function getModel(chart, type, index) {
|
||||
return chart.getModel().getComponent(type, index);
|
||||
}
|
||||
|
||||
function countSeries(chart) {
|
||||
return countModel(chart, 'series');
|
||||
}
|
||||
|
||||
function countModel(chart, type) {
|
||||
// FIXME
|
||||
// access private
|
||||
return chart.getModel()._componentsMap[type].length;
|
||||
}
|
||||
|
||||
function getChartView(chart, series) {
|
||||
return chart._chartsMap[series.__viewId];
|
||||
}
|
||||
|
||||
function countChartViews(chart) {
|
||||
return chart._chartsViews.length;
|
||||
}
|
||||
|
||||
function saveOrigins(chart) {
|
||||
var count = countSeries(chart);
|
||||
var origins = [];
|
||||
for (var i = 0; i < count; i++) {
|
||||
var series = getSeries(chart, i);
|
||||
origins.push({
|
||||
model: series,
|
||||
view: getChartView(chart, series)
|
||||
});
|
||||
}
|
||||
return origins;
|
||||
}
|
||||
|
||||
function modelEqualsToOrigin(chart, idxList, origins, boolResult) {
|
||||
for (var i = 0; i < idxList.length; i++) {
|
||||
var idx = idxList[i];
|
||||
expect(origins[idx].model === getSeries(chart, idx)).toEqual(boolResult);
|
||||
}
|
||||
}
|
||||
|
||||
function viewEqualsToOrigin(chart, idxList, origins, boolResult) {
|
||||
for (var i = 0; i < idxList.length; i++) {
|
||||
var idx = idxList[i];
|
||||
expect(
|
||||
origins[idx].view === getChartView(chart, getSeries(chart, idx))
|
||||
).toEqual(boolResult);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
describe('idNoNameNo', function () {
|
||||
|
||||
testCase.createChart()('sameTypeNotMerge', function () {
|
||||
var option = {
|
||||
xAxis: {data: ['a']},
|
||||
yAxis: {},
|
||||
series: [
|
||||
{type: 'line', data: [11]},
|
||||
{type: 'line', data: [22]},
|
||||
{type: 'line', data: [33]}
|
||||
]
|
||||
};
|
||||
var chart = this.chart;
|
||||
chart.setOption(option);
|
||||
|
||||
// Not merge
|
||||
var origins = saveOrigins(chart);
|
||||
chart.setOption(option, true);
|
||||
expect(countChartViews(chart)).toEqual(3);
|
||||
expect(countSeries(chart)).toEqual(3);
|
||||
modelEqualsToOrigin(chart, [0, 1, 2], origins, false);
|
||||
viewEqualsToOrigin(chart, [0, 1, 2], origins, true);
|
||||
});
|
||||
|
||||
testCase.createChart()('sameTypeMergeFull', function () {
|
||||
var option = {
|
||||
xAxis: {data: ['a']},
|
||||
yAxis: {},
|
||||
series: [
|
||||
{type: 'line', data: [11]},
|
||||
{type: 'line', data: [22]},
|
||||
{type: 'line', data: [33]}
|
||||
]
|
||||
};
|
||||
var chart = this.chart;
|
||||
chart.setOption(option);
|
||||
|
||||
// Merge
|
||||
var origins = saveOrigins(chart);
|
||||
chart.setOption({
|
||||
series: [
|
||||
{type: 'line', data: [111]},
|
||||
{type: 'line', data: [222]},
|
||||
{type: 'line', data: [333]}
|
||||
]
|
||||
});
|
||||
|
||||
expect(countSeries(chart)).toEqual(3);
|
||||
expect(countChartViews(chart)).toEqual(3);
|
||||
expect(getData0(chart, 0)).toEqual(111);
|
||||
expect(getData0(chart, 1)).toEqual(222);
|
||||
expect(getData0(chart, 2)).toEqual(333);
|
||||
viewEqualsToOrigin(chart, [0, 1, 2], origins, true);
|
||||
modelEqualsToOrigin(chart, [0, 1, 2], origins, true);
|
||||
});
|
||||
|
||||
testCase.createChart()('sameTypeMergePartial', function () {
|
||||
var option = {
|
||||
xAxis: {data: ['a']},
|
||||
yAxis: {},
|
||||
series: [
|
||||
{type: 'line', data: [11]},
|
||||
{type: 'line', data: [22]},
|
||||
{type: 'line', data: [33]}
|
||||
]
|
||||
};
|
||||
var chart = this.chart;
|
||||
chart.setOption(option);
|
||||
|
||||
// Merge
|
||||
var origins = saveOrigins(chart);
|
||||
chart.setOption({
|
||||
series: [
|
||||
{type: 'line', data: [22222]}
|
||||
]
|
||||
});
|
||||
|
||||
expect(countSeries(chart)).toEqual(3);
|
||||
expect(countChartViews(chart)).toEqual(3);
|
||||
expect(getData0(chart, 0)).toEqual(22222);
|
||||
expect(getData0(chart, 1)).toEqual(22);
|
||||
expect(getData0(chart, 2)).toEqual(33);
|
||||
viewEqualsToOrigin(chart, [0, 1, 2], origins, true);
|
||||
modelEqualsToOrigin(chart, [0, 1, 2], origins, true);
|
||||
});
|
||||
|
||||
testCase.createChart()('differentTypeMerge', function () {
|
||||
var option = {
|
||||
xAxis: {data: ['a']},
|
||||
yAxis: {},
|
||||
series: [
|
||||
{type: 'line', data: [11]},
|
||||
{type: 'line', data: [22]},
|
||||
{type: 'line', data: [33]}
|
||||
]
|
||||
};
|
||||
var chart = this.chart;
|
||||
chart.setOption(option);
|
||||
|
||||
// Merge
|
||||
var origins = saveOrigins(chart);
|
||||
chart.setOption({
|
||||
series: [
|
||||
{type: 'line', data: [111]},
|
||||
{type: 'bar', data: [222]},
|
||||
{type: 'line', data: [333]}
|
||||
]
|
||||
});
|
||||
|
||||
expect(countSeries(chart)).toEqual(3);
|
||||
expect(countChartViews(chart)).toEqual(3);
|
||||
expect(getData0(chart, 0)).toEqual(111);
|
||||
expect(getData0(chart, 1)).toEqual(222);
|
||||
expect(getData0(chart, 2)).toEqual(333);
|
||||
expect(getSeries(chart, 1).type === 'series.bar').toEqual(true);
|
||||
modelEqualsToOrigin(chart, [0, 2], origins, true);
|
||||
modelEqualsToOrigin(chart, [1], origins, false);
|
||||
viewEqualsToOrigin(chart, [0, 2], origins, true);
|
||||
viewEqualsToOrigin(chart, [1], origins, false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
describe('idSpecified', function () {
|
||||
|
||||
testCase.createChart()('sameTypeNotMerge', function () {
|
||||
var option = {
|
||||
xAxis: {data: ['a']},
|
||||
yAxis: {},
|
||||
series: [
|
||||
{type: 'line', data: [11]},
|
||||
{type: 'line', data: [22], id: 20},
|
||||
{type: 'line', data: [33], id: 30},
|
||||
{type: 'line', data: [44]},
|
||||
{type: 'line', data: [55]}
|
||||
]
|
||||
};
|
||||
var chart = this.chart;
|
||||
chart.setOption(option);
|
||||
|
||||
expect(countSeries(chart)).toEqual(5);
|
||||
expect(countChartViews(chart)).toEqual(5);
|
||||
expect(getData0(chart, 0)).toEqual(11);
|
||||
expect(getData0(chart, 1)).toEqual(22);
|
||||
expect(getData0(chart, 2)).toEqual(33);
|
||||
expect(getData0(chart, 3)).toEqual(44);
|
||||
expect(getData0(chart, 4)).toEqual(55);
|
||||
|
||||
var origins = saveOrigins(chart);
|
||||
chart.setOption(option, true);
|
||||
expect(countChartViews(chart)).toEqual(5);
|
||||
expect(countSeries(chart)).toEqual(5);
|
||||
|
||||
modelEqualsToOrigin(chart, [0, 1, 2, 3, 4], origins, false);
|
||||
viewEqualsToOrigin(chart, [0, 1, 2, 3, 4], origins, true);
|
||||
});
|
||||
|
||||
testCase.createChart()('sameTypeMerge', function () {
|
||||
var option = {
|
||||
xAxis: {data: ['a']},
|
||||
yAxis: {},
|
||||
series: [
|
||||
{type: 'line', data: [11]},
|
||||
{type: 'line', data: [22], id: 20},
|
||||
{type: 'line', data: [33], id: 30},
|
||||
{type: 'line', data: [44]},
|
||||
{type: 'line', data: [55]}
|
||||
]
|
||||
};
|
||||
var chart = this.chart;
|
||||
chart.setOption(option);
|
||||
|
||||
var origins = saveOrigins(chart);
|
||||
chart.setOption(option);
|
||||
expect(countChartViews(chart)).toEqual(5);
|
||||
expect(countSeries(chart)).toEqual(5);
|
||||
|
||||
modelEqualsToOrigin(chart, [0, 1, 2, 3, 4], origins, true);
|
||||
viewEqualsToOrigin(chart, [0, 1, 2, 3, 4], origins, true);
|
||||
});
|
||||
|
||||
testCase.createChart()('differentTypeNotMerge', function () {
|
||||
var option = {
|
||||
xAxis: {data: ['a']},
|
||||
yAxis: {},
|
||||
series: [
|
||||
{type: 'line', data: [11]},
|
||||
{type: 'line', data: [22], id: 20},
|
||||
{type: 'line', data: [33], id: 30},
|
||||
{type: 'line', data: [44]},
|
||||
{type: 'line', data: [55]}
|
||||
]
|
||||
};
|
||||
var chart = this.chart;
|
||||
chart.setOption(option);
|
||||
|
||||
var origins = saveOrigins(chart);
|
||||
var option2 = {
|
||||
xAxis: {data: ['a']},
|
||||
yAxis: {},
|
||||
series: [
|
||||
{type: 'line', data: [11]},
|
||||
{type: 'bar', data: [22], id: 20},
|
||||
{type: 'line', data: [33], id: 30},
|
||||
{type: 'bar', data: [44]},
|
||||
{type: 'line', data: [55]}
|
||||
]
|
||||
};
|
||||
chart.setOption(option2, true);
|
||||
expect(countChartViews(chart)).toEqual(5);
|
||||
expect(countSeries(chart)).toEqual(5);
|
||||
|
||||
modelEqualsToOrigin(chart, [0, 1, 2, 3, 4], origins, false);
|
||||
viewEqualsToOrigin(chart, [0, 2, 4], origins, true);
|
||||
viewEqualsToOrigin(chart, [1, 3], origins, false);
|
||||
});
|
||||
|
||||
testCase.createChart()('differentTypeMergeFull', function () {
|
||||
var option = {
|
||||
xAxis: {data: ['a']},
|
||||
yAxis: {},
|
||||
series: [
|
||||
{type: 'line', data: [11]},
|
||||
{type: 'line', data: [22], id: 20},
|
||||
{type: 'line', data: [33], id: 30, name: 'a'},
|
||||
{type: 'line', data: [44]},
|
||||
{type: 'line', data: [55]}
|
||||
]
|
||||
};
|
||||
var chart = this.chart;
|
||||
chart.setOption(option);
|
||||
|
||||
var origins = saveOrigins(chart);
|
||||
var option2 = {
|
||||
series: [
|
||||
{type: 'line', data: [11]},
|
||||
{type: 'bar', data: [22], id: 20, name: 'a'},
|
||||
{type: 'line', data: [33], id: 30},
|
||||
{type: 'bar', data: [44]},
|
||||
{type: 'line', data: [55]}
|
||||
]
|
||||
};
|
||||
chart.setOption(option2);
|
||||
expect(countChartViews(chart)).toEqual(5);
|
||||
expect(countSeries(chart)).toEqual(5);
|
||||
|
||||
modelEqualsToOrigin(chart, [0, 2, 4], origins, true);
|
||||
modelEqualsToOrigin(chart, [1, 3], origins, false);
|
||||
viewEqualsToOrigin(chart, [0, 2, 4], origins, true);
|
||||
viewEqualsToOrigin(chart, [1, 3], origins, false);
|
||||
});
|
||||
|
||||
testCase.createChart()('differentTypeMergePartial1', function () {
|
||||
var option = {
|
||||
xAxis: {data: ['a']},
|
||||
yAxis: {},
|
||||
series: [
|
||||
{type: 'line', data: [11]},
|
||||
{type: 'line', data: [22], id: 20},
|
||||
{type: 'line', data: [33]},
|
||||
{type: 'line', data: [44], id: 40},
|
||||
{type: 'line', data: [55]}
|
||||
]
|
||||
};
|
||||
var chart = this.chart;
|
||||
chart.setOption(option);
|
||||
|
||||
var origins = saveOrigins(chart);
|
||||
var option2 = {
|
||||
series: [
|
||||
{type: 'bar', data: [444], id: 40},
|
||||
{type: 'line', data: [333]},
|
||||
{type: 'line', data: [222], id: 20}
|
||||
]
|
||||
};
|
||||
chart.setOption(option2);
|
||||
expect(countChartViews(chart)).toEqual(5);
|
||||
expect(countSeries(chart)).toEqual(5);
|
||||
|
||||
expect(getData0(chart, 0)).toEqual(333);
|
||||
expect(getData0(chart, 1)).toEqual(222);
|
||||
expect(getData0(chart, 2)).toEqual(33);
|
||||
expect(getData0(chart, 3)).toEqual(444);
|
||||
expect(getData0(chart, 4)).toEqual(55);
|
||||
modelEqualsToOrigin(chart, [0, 1, 2, 4], origins, true);
|
||||
modelEqualsToOrigin(chart, [3], origins, false);
|
||||
viewEqualsToOrigin(chart, [0, 1, 2, 4], origins, true);
|
||||
viewEqualsToOrigin(chart, [3], origins, false);
|
||||
});
|
||||
|
||||
testCase.createChart()('differentTypeMergePartial2', function () {
|
||||
var option = {
|
||||
xAxis: {data: ['a']},
|
||||
yAxis: {},
|
||||
series: [
|
||||
{type: 'line', data: [11]},
|
||||
{type: 'line', data: [22], id: 20}
|
||||
]
|
||||
};
|
||||
var chart = this.chart;
|
||||
chart.setOption(option);
|
||||
|
||||
var option2 = {
|
||||
series: [
|
||||
{type: 'bar', data: [444], id: 40},
|
||||
{type: 'line', data: [333]},
|
||||
{type: 'line', data: [222], id: 20},
|
||||
{type: 'line', data: [111]}
|
||||
]
|
||||
};
|
||||
chart.setOption(option2);
|
||||
expect(countChartViews(chart)).toEqual(4);
|
||||
expect(countSeries(chart)).toEqual(4);
|
||||
|
||||
expect(getData0(chart, 0)).toEqual(333);
|
||||
expect(getData0(chart, 1)).toEqual(222);
|
||||
expect(getData0(chart, 2)).toEqual(444);
|
||||
expect(getData0(chart, 3)).toEqual(111);
|
||||
});
|
||||
|
||||
|
||||
testCase.createChart()('mergePartialDoNotMapToOtherId', function () {
|
||||
var option = {
|
||||
xAxis: {data: ['a']},
|
||||
yAxis: {},
|
||||
series: [
|
||||
{type: 'line', data: [11], id: 10},
|
||||
{type: 'line', data: [22], id: 20}
|
||||
]
|
||||
};
|
||||
var chart = this.chart;
|
||||
chart.setOption(option);
|
||||
|
||||
var option2 = {
|
||||
series: [
|
||||
{type: 'bar', data: [444], id: 40}
|
||||
]
|
||||
};
|
||||
chart.setOption(option2);
|
||||
expect(countChartViews(chart)).toEqual(3);
|
||||
expect(countSeries(chart)).toEqual(3);
|
||||
|
||||
expect(getData0(chart, 0)).toEqual(11);
|
||||
expect(getData0(chart, 1)).toEqual(22);
|
||||
expect(getData0(chart, 2)).toEqual(444);
|
||||
});
|
||||
|
||||
|
||||
testCase.createChart()('idDuplicate', function () {
|
||||
var option = {
|
||||
xAxis: {data: ['a']},
|
||||
yAxis: {},
|
||||
series: [
|
||||
{type: 'line', data: [11], id: 10},
|
||||
{type: 'line', data: [22], id: 10}
|
||||
]
|
||||
};
|
||||
|
||||
var chart = this.chart;
|
||||
|
||||
expect(function () {
|
||||
chart.setOption(option);
|
||||
}).toThrowError(/duplicate/);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
describe('noIdButNameExists', function () {
|
||||
|
||||
testCase.createChart()('sameTypeNotMerge', function () {
|
||||
var option = {
|
||||
xAxis: {data: ['a']},
|
||||
yAxis: {},
|
||||
series: [
|
||||
{type: 'line', data: [11]},
|
||||
{type: 'line', data: [22], name: 'a'},
|
||||
{type: 'line', data: [33], name: 'b'},
|
||||
{type: 'line', data: [44]},
|
||||
{type: 'line', data: [55], name: 'a'}
|
||||
]
|
||||
};
|
||||
var chart = this.chart;
|
||||
chart.setOption(option);
|
||||
|
||||
expect(getSeries(chart, 1)).not.toEqual(getSeries(chart, 4));
|
||||
|
||||
|
||||
expect(countSeries(chart)).toEqual(5);
|
||||
expect(countChartViews(chart)).toEqual(5);
|
||||
expect(getData0(chart, 0)).toEqual(11);
|
||||
expect(getData0(chart, 1)).toEqual(22);
|
||||
expect(getData0(chart, 2)).toEqual(33);
|
||||
expect(getData0(chart, 3)).toEqual(44);
|
||||
expect(getData0(chart, 4)).toEqual(55);
|
||||
|
||||
var origins = saveOrigins(chart);
|
||||
chart.setOption(option, true);
|
||||
expect(countChartViews(chart)).toEqual(5);
|
||||
expect(countSeries(chart)).toEqual(5);
|
||||
|
||||
modelEqualsToOrigin(chart, [0, 1, 2, 3, 4], origins, false);
|
||||
viewEqualsToOrigin(chart, [0, 1, 2, 3, 4], origins, true);
|
||||
});
|
||||
|
||||
testCase.createChart()('sameTypeMerge', function () {
|
||||
var option = {
|
||||
xAxis: {data: ['a']},
|
||||
yAxis: {},
|
||||
series: [
|
||||
{type: 'line', data: [11]},
|
||||
{type: 'line', data: [22], name: 'a'},
|
||||
{type: 'line', data: [33], name: 'b'},
|
||||
{type: 'line', data: [44]},
|
||||
{type: 'line', data: [55], name: 'a'}
|
||||
]
|
||||
};
|
||||
var chart = this.chart;
|
||||
chart.setOption(option);
|
||||
|
||||
var origins = saveOrigins(chart);
|
||||
chart.setOption(option);
|
||||
expect(countChartViews(chart)).toEqual(5);
|
||||
expect(countSeries(chart)).toEqual(5);
|
||||
|
||||
modelEqualsToOrigin(chart, [0, 1, 2, 3, 4], origins, true);
|
||||
viewEqualsToOrigin(chart, [0, 1, 2, 3, 4], origins, true);
|
||||
});
|
||||
|
||||
testCase.createChart()('differentTypeNotMerge', function () {
|
||||
var option = {
|
||||
xAxis: {data: ['a']},
|
||||
yAxis: {},
|
||||
series: [
|
||||
{type: 'line', data: [11]},
|
||||
{type: 'line', data: [22], name: 'a'},
|
||||
{type: 'line', data: [33], name: 'b'},
|
||||
{type: 'line', data: [44]},
|
||||
{type: 'line', data: [55], name: 'a'}
|
||||
]
|
||||
};
|
||||
var chart = this.chart;
|
||||
chart.setOption(option);
|
||||
|
||||
var origins = saveOrigins(chart);
|
||||
var option2 = {
|
||||
xAxis: {data: ['a']},
|
||||
yAxis: {},
|
||||
series: [
|
||||
{type: 'line', data: [11]},
|
||||
{type: 'bar', data: [22], name: 'a'},
|
||||
{type: 'line', data: [33], name: 'b'},
|
||||
{type: 'bar', data: [44]},
|
||||
{type: 'line', data: [55], name: 'a'}
|
||||
]
|
||||
};
|
||||
chart.setOption(option2, true);
|
||||
expect(countChartViews(chart)).toEqual(5);
|
||||
expect(countSeries(chart)).toEqual(5);
|
||||
|
||||
modelEqualsToOrigin(chart, [0, 1, 2, 3, 4], origins, false);
|
||||
viewEqualsToOrigin(chart, [0, 2, 4], origins, true);
|
||||
viewEqualsToOrigin(chart, [1, 3], origins, false);
|
||||
});
|
||||
|
||||
testCase.createChart()('differentTypeMergePartialOneMapTwo', function () {
|
||||
var option = {
|
||||
xAxis: {data: ['a']},
|
||||
yAxis: {},
|
||||
series: [
|
||||
{type: 'line', data: [11]},
|
||||
{type: 'line', data: [22], name: 'a'},
|
||||
{type: 'line', data: [33]},
|
||||
{type: 'line', data: [44], name: 'b'},
|
||||
{type: 'line', data: [55], name: 'a'}
|
||||
]
|
||||
};
|
||||
var chart = this.chart;
|
||||
chart.setOption(option);
|
||||
|
||||
var origins = saveOrigins(chart);
|
||||
var option2 = {
|
||||
series: [
|
||||
{type: 'bar', data: [444], id: 40},
|
||||
{type: 'line', data: [333]},
|
||||
{type: 'bar', data: [222], name: 'a'}
|
||||
]
|
||||
};
|
||||
chart.setOption(option2);
|
||||
expect(countChartViews(chart)).toEqual(6);
|
||||
expect(countSeries(chart)).toEqual(6);
|
||||
|
||||
expect(getData0(chart, 0)).toEqual(333);
|
||||
expect(getData0(chart, 1)).toEqual(222);
|
||||
expect(getData0(chart, 2)).toEqual(33);
|
||||
expect(getData0(chart, 3)).toEqual(44);
|
||||
expect(getData0(chart, 4)).toEqual(55);
|
||||
expect(getData0(chart, 5)).toEqual(444);
|
||||
modelEqualsToOrigin(chart, [0, 2, 3, 4], origins, true);
|
||||
modelEqualsToOrigin(chart, [1], origins, false);
|
||||
viewEqualsToOrigin(chart, [0, 2, 3, 4], origins, true);
|
||||
viewEqualsToOrigin(chart, [1], origins, false);
|
||||
});
|
||||
|
||||
testCase.createChart()('differentTypeMergePartialTwoMapOne', function () {
|
||||
var option = {
|
||||
xAxis: {data: ['a']},
|
||||
yAxis: {},
|
||||
series: [
|
||||
{type: 'line', data: [11]},
|
||||
{type: 'line', data: [22], name: 'a'}
|
||||
]
|
||||
};
|
||||
var chart = this.chart;
|
||||
chart.setOption(option);
|
||||
|
||||
var option2 = {
|
||||
series: [
|
||||
{type: 'bar', data: [444], name: 'a'},
|
||||
{type: 'line', data: [333]},
|
||||
{type: 'line', data: [222], name: 'a'},
|
||||
{type: 'line', data: [111]}
|
||||
]
|
||||
};
|
||||
chart.setOption(option2);
|
||||
expect(countChartViews(chart)).toEqual(4);
|
||||
expect(countSeries(chart)).toEqual(4);
|
||||
|
||||
expect(getData0(chart, 0)).toEqual(333);
|
||||
expect(getData0(chart, 1)).toEqual(444);
|
||||
expect(getData0(chart, 2)).toEqual(222);
|
||||
expect(getData0(chart, 3)).toEqual(111);
|
||||
});
|
||||
|
||||
testCase.createChart()('mergePartialCanMapToOtherName', function () {
|
||||
// Consider case: axis.name = 'some label', which can be overwritten.
|
||||
var option = {
|
||||
xAxis: {data: ['a']},
|
||||
yAxis: {},
|
||||
series: [
|
||||
{type: 'line', data: [11], name: 10},
|
||||
{type: 'line', data: [22], name: 20}
|
||||
]
|
||||
};
|
||||
var chart = this.chart;
|
||||
chart.setOption(option);
|
||||
|
||||
var option2 = {
|
||||
series: [
|
||||
{type: 'bar', data: [444], name: 40},
|
||||
{type: 'bar', data: [999], name: 40},
|
||||
{type: 'bar', data: [777], id: 70}
|
||||
]
|
||||
};
|
||||
chart.setOption(option2);
|
||||
expect(countChartViews(chart)).toEqual(3);
|
||||
expect(countSeries(chart)).toEqual(3);
|
||||
|
||||
expect(getData0(chart, 0)).toEqual(444);
|
||||
expect(getData0(chart, 1)).toEqual(999);
|
||||
expect(getData0(chart, 2)).toEqual(777);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
describe('ohters', function () {
|
||||
|
||||
testCase.createChart()('aBugCase', function () {
|
||||
var option = {
|
||||
series: [
|
||||
{
|
||||
type:'pie',
|
||||
radius: ['20%', '25%'],
|
||||
center:['20%', '20%'],
|
||||
avoidLabelOverlap: true,
|
||||
hoverAnimation :false,
|
||||
label: {
|
||||
normal: {
|
||||
show: true,
|
||||
position: 'center',
|
||||
textStyle: {
|
||||
fontSize: '30',
|
||||
fontWeight: 'bold'
|
||||
}
|
||||
},
|
||||
emphasis: {
|
||||
show: true
|
||||
}
|
||||
},
|
||||
data:[
|
||||
{value:135, name:'视频广告'},
|
||||
{value:1548}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
var chart = this.chart;
|
||||
chart.setOption(option);
|
||||
|
||||
chart.setOption({
|
||||
series: [
|
||||
{
|
||||
type:'pie',
|
||||
radius: ['20%', '25%'],
|
||||
center: ['20%', '20%'],
|
||||
avoidLabelOverlap: true,
|
||||
hoverAnimation: false,
|
||||
label: {
|
||||
normal: {
|
||||
show: true,
|
||||
position: 'center',
|
||||
textStyle: {
|
||||
fontSize: '30',
|
||||
fontWeight: 'bold'
|
||||
}
|
||||
}
|
||||
},
|
||||
data: [
|
||||
{value:135, name:'视频广告'},
|
||||
{value:1548}
|
||||
]
|
||||
},
|
||||
{
|
||||
type:'pie',
|
||||
radius: ['20%', '25%'],
|
||||
center: ['60%', '20%'],
|
||||
avoidLabelOverlap: true,
|
||||
hoverAnimation: false,
|
||||
label: {
|
||||
normal: {
|
||||
show: true,
|
||||
position: 'center',
|
||||
textStyle: {
|
||||
fontSize: '30',
|
||||
fontWeight: 'bold'
|
||||
}
|
||||
}
|
||||
},
|
||||
data: [
|
||||
{value:135, name:'视频广告'},
|
||||
{value:1548}
|
||||
]
|
||||
}
|
||||
]
|
||||
}, true);
|
||||
|
||||
expect(countChartViews(chart)).toEqual(2);
|
||||
expect(countSeries(chart)).toEqual(2);
|
||||
});
|
||||
|
||||
testCase.createChart()('color', function () {
|
||||
var option = {
|
||||
backgroundColor: 'rgba(1,1,1,1)',
|
||||
xAxis: {data: ['a']},
|
||||
yAxis: {},
|
||||
series: [
|
||||
{type: 'line', data: [11]},
|
||||
{type: 'line', data: [22]},
|
||||
{type: 'line', data: [33]}
|
||||
]
|
||||
};
|
||||
var chart = this.chart;
|
||||
chart.setOption(option);
|
||||
expect(chart._model.option.backgroundColor).toEqual('rgba(1,1,1,1)');
|
||||
|
||||
// Not merge
|
||||
chart.setOption({
|
||||
backgroundColor: '#fff'
|
||||
}, true);
|
||||
|
||||
expect(chart._model.option.backgroundColor).toEqual('#fff');
|
||||
});
|
||||
|
||||
testCase.createChart()('innerId', function () {
|
||||
var option = {
|
||||
xAxis: {data: ['a']},
|
||||
yAxis: {},
|
||||
toolbox: {
|
||||
feature: {
|
||||
dataZoom: {}
|
||||
}
|
||||
},
|
||||
dataZoom: [
|
||||
{type: 'inside', id: 'a'},
|
||||
{type: 'slider', id: 'b'}
|
||||
],
|
||||
series: [
|
||||
{type: 'line', data: [11]},
|
||||
{type: 'line', data: [22]}
|
||||
]
|
||||
};
|
||||
var chart = this.chart;
|
||||
chart.setOption(option);
|
||||
|
||||
expect(countModel(chart, 'dataZoom')).toEqual(4);
|
||||
expect(getModel(chart, 'dataZoom', 0).id).toEqual('a');
|
||||
expect(getModel(chart, 'dataZoom', 1).id).toEqual('b');
|
||||
|
||||
// Merge
|
||||
chart.setOption({
|
||||
dataZoom: [
|
||||
{type: 'slider', id: 'c'},
|
||||
{type: 'slider', name: 'x'}
|
||||
]
|
||||
});
|
||||
|
||||
expect(countModel(chart, 'dataZoom')).toEqual(5);
|
||||
expect(getModel(chart, 'dataZoom', 0).id).toEqual('a');
|
||||
expect(getModel(chart, 'dataZoom', 1).id).toEqual('b');
|
||||
expect(getModel(chart, 'dataZoom', 4).id).toEqual('c');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
161
vendors/echarts/test/ut/spec/model/timelineOptions.js
vendored
Normal file
161
vendors/echarts/test/ut/spec/model/timelineOptions.js
vendored
Normal file
@@ -0,0 +1,161 @@
|
||||
describe('timelineOptions', function() {
|
||||
|
||||
var utHelper = window.utHelper;
|
||||
|
||||
var testCase = utHelper.prepare([
|
||||
'echarts/component/grid',
|
||||
'echarts/chart/line',
|
||||
'echarts/chart/pie',
|
||||
'echarts/chart/bar',
|
||||
'echarts/component/timeline'
|
||||
]);
|
||||
|
||||
function getData0(chart, seriesIndex) {
|
||||
return getSeries(chart, seriesIndex).getData().get('y', 0);
|
||||
}
|
||||
|
||||
function getSeries(chart, seriesIndex) {
|
||||
return chart.getModel().getComponent('series', seriesIndex);
|
||||
}
|
||||
|
||||
testCase.createChart()('timeline_setOptionOnceMore_baseOption', function () {
|
||||
var option = {
|
||||
baseOption: {
|
||||
timeline: {
|
||||
axisType: 'category',
|
||||
autoPlay: false,
|
||||
playInterval: 1000
|
||||
},
|
||||
xAxis: {data: ['a']},
|
||||
yAxis: {}
|
||||
},
|
||||
options: [
|
||||
{
|
||||
series: [
|
||||
{type: 'line', data: [11]},
|
||||
{type: 'line', data: [22]}
|
||||
]
|
||||
},
|
||||
{
|
||||
series: [
|
||||
{type: 'line', data: [111]},
|
||||
{type: 'line', data: [222]}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
var chart = this.chart;
|
||||
chart.setOption(option);
|
||||
|
||||
expect(getData0(chart, 0)).toEqual(11);
|
||||
expect(getData0(chart, 1)).toEqual(22);
|
||||
|
||||
chart.setOption({
|
||||
xAxis: {data: ['b']}
|
||||
});
|
||||
|
||||
expect(getData0(chart, 0)).toEqual(11);
|
||||
expect(getData0(chart, 1)).toEqual(22);
|
||||
|
||||
chart.setOption({
|
||||
xAxis: {data: ['c']},
|
||||
timeline: {
|
||||
currentIndex: 1
|
||||
}
|
||||
});
|
||||
|
||||
expect(getData0(chart, 0)).toEqual(111);
|
||||
expect(getData0(chart, 1)).toEqual(222);
|
||||
});
|
||||
|
||||
|
||||
|
||||
testCase.createChart()('timeline_setOptionOnceMore_substitudeTimelineOptions', function () {
|
||||
var option = {
|
||||
baseOption: {
|
||||
timeline: {
|
||||
axisType: 'category',
|
||||
autoPlay: false,
|
||||
playInterval: 1000,
|
||||
currentIndex: 2
|
||||
},
|
||||
xAxis: {data: ['a']},
|
||||
yAxis: {}
|
||||
},
|
||||
options: [
|
||||
{
|
||||
series: [
|
||||
{type: 'line', data: [11]},
|
||||
{type: 'line', data: [22]}
|
||||
]
|
||||
},
|
||||
{
|
||||
series: [
|
||||
{type: 'line', data: [111]},
|
||||
{type: 'line', data: [222]}
|
||||
]
|
||||
},
|
||||
{
|
||||
series: [
|
||||
{type: 'line', data: [1111]},
|
||||
{type: 'line', data: [2222]}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
var chart = this.chart;
|
||||
chart.setOption(option);
|
||||
|
||||
var ecModel = chart.getModel();
|
||||
expect(getData0(chart, 0)).toEqual(1111);
|
||||
expect(getData0(chart, 1)).toEqual(2222);
|
||||
|
||||
chart.setOption({
|
||||
baseOption: {
|
||||
backgroundColor: '#987654',
|
||||
xAxis: {data: ['b']}
|
||||
},
|
||||
options: [
|
||||
{
|
||||
series: [
|
||||
{type: 'line', data: [55]},
|
||||
{type: 'line', data: [66]}
|
||||
]
|
||||
},
|
||||
{
|
||||
series: [
|
||||
{type: 'line', data: [555]},
|
||||
{type: 'line', data: [666]}
|
||||
]
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
var ecModel = chart.getModel();
|
||||
var option = ecModel.getOption();
|
||||
expect(option.backgroundColor).toEqual('#987654');
|
||||
expect(getData0(chart, 0)).toEqual(1111);
|
||||
expect(getData0(chart, 1)).toEqual(2222);
|
||||
|
||||
chart.setOption({
|
||||
timeline: {
|
||||
currentIndex: 0
|
||||
}
|
||||
});
|
||||
|
||||
expect(getData0(chart, 0)).toEqual(55);
|
||||
expect(getData0(chart, 1)).toEqual(66);
|
||||
|
||||
chart.setOption({
|
||||
timeline: {
|
||||
currentIndex: 2
|
||||
}
|
||||
});
|
||||
|
||||
// no 1111 2222 any more, replaced totally by new timeline.
|
||||
expect(getData0(chart, 0)).toEqual(55);
|
||||
expect(getData0(chart, 1)).toEqual(66);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
6
vendors/echarts/test/ut/spec/ui/config.js
vendored
Normal file
6
vendors/echarts/test/ut/spec/ui/config.js
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
require.config({
|
||||
paths: {
|
||||
'oldEcharts': 'tmp/oldEcharts',
|
||||
'newEcharts': 'tmp/newEcharts'
|
||||
}
|
||||
});
|
||||
586
vendors/echarts/test/ut/spec/ui/legend.js
vendored
Normal file
586
vendors/echarts/test/ut/spec/ui/legend.js
vendored
Normal file
@@ -0,0 +1,586 @@
|
||||
describe('legend', function() {
|
||||
|
||||
var uiHelper = window.uiHelper;
|
||||
|
||||
var suites = [{
|
||||
name: 'show',
|
||||
cases: [{
|
||||
name: 'should display legend as default',
|
||||
option: {
|
||||
series: [{
|
||||
name: 'a',
|
||||
type: 'line',
|
||||
data: [1, 2, 4]
|
||||
}],
|
||||
xAxis : [{
|
||||
type : 'category',
|
||||
data : ['x','y','z']
|
||||
}],
|
||||
yAxis : [{
|
||||
type : 'value'
|
||||
}],
|
||||
legend: {
|
||||
data: ['a']
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should hide legend when show set to be false',
|
||||
option: {
|
||||
series: [{
|
||||
name: 'a',
|
||||
type: 'line',
|
||||
data: [1, 2, 4]
|
||||
}],
|
||||
xAxis : [{
|
||||
type : 'category',
|
||||
data : ['x','y','z']
|
||||
}],
|
||||
yAxis : [{
|
||||
type : 'value'
|
||||
}],
|
||||
legend: {
|
||||
data: ['a'],
|
||||
show: false
|
||||
}
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
name: 'left',
|
||||
cases: [{
|
||||
name: 'should display left position',
|
||||
option: {
|
||||
series: [{
|
||||
name: 'a',
|
||||
type: 'line',
|
||||
data: [1, 2, 4]
|
||||
}],
|
||||
xAxis : [{
|
||||
type : 'category',
|
||||
data : ['x','y','z']
|
||||
}],
|
||||
yAxis : [{
|
||||
type : 'value'
|
||||
}],
|
||||
legend: {
|
||||
data: ['a'],
|
||||
left: 'left'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display at 20%',
|
||||
option: {
|
||||
series: [{
|
||||
name: 'a',
|
||||
type: 'line',
|
||||
data: [1, 2, 4]
|
||||
}],
|
||||
xAxis : [{
|
||||
type : 'category',
|
||||
data : ['x','y','z']
|
||||
}],
|
||||
yAxis : [{
|
||||
type : 'value'
|
||||
}],
|
||||
legend: {
|
||||
data: ['a'],
|
||||
left: '20%'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display at center',
|
||||
option: {
|
||||
series: [{
|
||||
name: 'a',
|
||||
type: 'line',
|
||||
data: [1, 2, 4]
|
||||
}],
|
||||
xAxis : [{
|
||||
type : 'category',
|
||||
data : ['x','y','z']
|
||||
}],
|
||||
yAxis : [{
|
||||
type : 'value'
|
||||
}],
|
||||
legend: {
|
||||
data: ['a'],
|
||||
left: 'center'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display at right',
|
||||
option: {
|
||||
series: [{
|
||||
name: 'a',
|
||||
type: 'line',
|
||||
data: [1, 2, 4]
|
||||
}],
|
||||
xAxis : [{
|
||||
type : 'category',
|
||||
data : ['x','y','z']
|
||||
}],
|
||||
yAxis : [{
|
||||
type : 'value'
|
||||
}],
|
||||
legend: {
|
||||
data: ['a'],
|
||||
left: 'right'
|
||||
}
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
name: 'top',
|
||||
cases: [{
|
||||
name: 'should display top position',
|
||||
option: {
|
||||
series: [{
|
||||
name: 'a',
|
||||
type: 'line',
|
||||
data: [1, 2, 4]
|
||||
}],
|
||||
xAxis : [{
|
||||
type : 'category',
|
||||
data : ['x','y','z']
|
||||
}],
|
||||
yAxis : [{
|
||||
type : 'value'
|
||||
}],
|
||||
legend: {
|
||||
data: ['a'],
|
||||
top: 50
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display at 20%',
|
||||
option: {
|
||||
series: [{
|
||||
name: 'a',
|
||||
type: 'line',
|
||||
data: [1, 2, 4]
|
||||
}],
|
||||
xAxis : [{
|
||||
type : 'category',
|
||||
data : ['x','y','z']
|
||||
}],
|
||||
yAxis : [{
|
||||
type : 'value'
|
||||
}],
|
||||
legend: {
|
||||
data: ['a'],
|
||||
top: '20%'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display at middle',
|
||||
option: {
|
||||
series: [{
|
||||
name: 'a',
|
||||
type: 'line',
|
||||
data: [1, 2, 4]
|
||||
}],
|
||||
xAxis : [{
|
||||
type : 'category',
|
||||
data : ['x','y','z']
|
||||
}],
|
||||
yAxis : [{
|
||||
type : 'value'
|
||||
}],
|
||||
legend: {
|
||||
data: ['a'],
|
||||
top: 'middle'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display at bottom',
|
||||
option: {
|
||||
series: [{
|
||||
name: 'a',
|
||||
type: 'line',
|
||||
data: [1, 2, 4]
|
||||
}],
|
||||
xAxis : [{
|
||||
type : 'category',
|
||||
data : ['x','y','z']
|
||||
}],
|
||||
yAxis : [{
|
||||
type : 'value'
|
||||
}],
|
||||
legend: {
|
||||
data: ['a'],
|
||||
top: 'bottom'
|
||||
}
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
name: 'right',
|
||||
cases: [{
|
||||
name: 'should display right position',
|
||||
option: {
|
||||
series: [{
|
||||
name: 'a',
|
||||
type: 'line',
|
||||
data: [1, 2, 4]
|
||||
}],
|
||||
xAxis : [{
|
||||
type : 'category',
|
||||
data : ['x','y','z']
|
||||
}],
|
||||
yAxis : [{
|
||||
type : 'value'
|
||||
}],
|
||||
legend: {
|
||||
data: ['a'],
|
||||
right: 50
|
||||
}
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
name: 'bottom',
|
||||
cases: [{
|
||||
name: 'should display bottom position',
|
||||
option: {
|
||||
series: [{
|
||||
name: 'a',
|
||||
type: 'line',
|
||||
data: [1, 2, 4]
|
||||
}],
|
||||
xAxis : [{
|
||||
type : 'category',
|
||||
data : ['x','y','z']
|
||||
}],
|
||||
yAxis : [{
|
||||
type : 'value'
|
||||
}],
|
||||
legend: {
|
||||
data: ['a'],
|
||||
bottom: 50
|
||||
}
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
name: 'left and right',
|
||||
cases: [{
|
||||
name: 'are both set',
|
||||
test: 'equalOption',
|
||||
option1: {
|
||||
series: [{
|
||||
name: 'a',
|
||||
type: 'line',
|
||||
data: [1, 2, 4]
|
||||
}],
|
||||
xAxis : [{
|
||||
type : 'category',
|
||||
data : ['x','y','z']
|
||||
}],
|
||||
yAxis : [{
|
||||
type : 'value'
|
||||
}],
|
||||
legend: {
|
||||
data: ['a'],
|
||||
left: 50,
|
||||
right: 50
|
||||
}
|
||||
},
|
||||
option2: {
|
||||
series: [{
|
||||
name: 'a',
|
||||
type: 'line',
|
||||
data: [1, 2, 4]
|
||||
}],
|
||||
xAxis : [{
|
||||
type : 'category',
|
||||
data : ['x','y','z']
|
||||
}],
|
||||
yAxis : [{
|
||||
type : 'value'
|
||||
}],
|
||||
legend: {
|
||||
data: ['a'],
|
||||
left: 50
|
||||
}
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
name: 'top and bottom',
|
||||
cases: [{
|
||||
name: 'are both set',
|
||||
test: 'equalOption',
|
||||
option1: {
|
||||
series: [{
|
||||
name: 'a',
|
||||
type: 'line',
|
||||
data: [1, 2, 4]
|
||||
}],
|
||||
xAxis : [{
|
||||
type : 'category',
|
||||
data : ['x','y','z']
|
||||
}],
|
||||
yAxis : [{
|
||||
type : 'value'
|
||||
}],
|
||||
legend: {
|
||||
data: ['a'],
|
||||
top: 50,
|
||||
bottom: 50
|
||||
}
|
||||
},
|
||||
option2: {
|
||||
series: [{
|
||||
name: 'a',
|
||||
type: 'line',
|
||||
data: [1, 2, 4]
|
||||
}],
|
||||
xAxis : [{
|
||||
type : 'category',
|
||||
data : ['x','y','z']
|
||||
}],
|
||||
yAxis : [{
|
||||
type : 'value'
|
||||
}],
|
||||
legend: {
|
||||
data: ['a'],
|
||||
top: 50
|
||||
}
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
name: 'width',
|
||||
cases: [{
|
||||
name: 'should display in seperate lines',
|
||||
test: 'notEqualOption',
|
||||
option1: {
|
||||
series: [{
|
||||
name: 'this is a',
|
||||
type: 'line',
|
||||
data: []
|
||||
}, {
|
||||
name: 'this is b',
|
||||
type: 'line',
|
||||
data: []
|
||||
}, {
|
||||
name: 'this is c',
|
||||
type: 'line',
|
||||
data: []
|
||||
}],
|
||||
xAxis : [{
|
||||
type : 'category',
|
||||
data : ['x','y','z']
|
||||
}],
|
||||
yAxis : [{
|
||||
type : 'value'
|
||||
}],
|
||||
legend: {
|
||||
data: ['this is a', 'this is b',
|
||||
'this is c'],
|
||||
width: 200
|
||||
}
|
||||
},
|
||||
option2: {
|
||||
series: [{
|
||||
name: 'this is a',
|
||||
type: 'line',
|
||||
data: []
|
||||
}, {
|
||||
name: 'this is b',
|
||||
type: 'line',
|
||||
data: []
|
||||
}, {
|
||||
name: 'this is c',
|
||||
type: 'line',
|
||||
data: []
|
||||
}],
|
||||
xAxis : [{
|
||||
type : 'category',
|
||||
data : ['x','y','z']
|
||||
}],
|
||||
yAxis : [{
|
||||
type : 'value'
|
||||
}],
|
||||
legend: {
|
||||
data: ['this is a', 'this is b',
|
||||
'this is c']
|
||||
}
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
name: 'hight',
|
||||
cases: [{
|
||||
name: 'should display in seperate lines',
|
||||
test: 'notEqualOption',
|
||||
option1: {
|
||||
series: [{
|
||||
name: 'this is a',
|
||||
type: 'line',
|
||||
data: []
|
||||
}, {
|
||||
name: 'this is b',
|
||||
type: 'line',
|
||||
data: []
|
||||
}, {
|
||||
name: 'this is c',
|
||||
type: 'line',
|
||||
data: []
|
||||
}],
|
||||
xAxis : [{
|
||||
type : 'category',
|
||||
data : ['x','y','z']
|
||||
}],
|
||||
yAxis : [{
|
||||
type : 'value'
|
||||
}],
|
||||
legend: {
|
||||
data: ['this is a', 'this is b',
|
||||
'this is c'],
|
||||
height: 50,
|
||||
orient: 'vertical'
|
||||
}
|
||||
},
|
||||
option2: {
|
||||
series: [{
|
||||
name: 'this is a',
|
||||
type: 'line',
|
||||
data: []
|
||||
}, {
|
||||
name: 'this is b',
|
||||
type: 'line',
|
||||
data: []
|
||||
}, {
|
||||
name: 'this is c',
|
||||
type: 'line',
|
||||
data: []
|
||||
}],
|
||||
xAxis : [{
|
||||
type : 'category',
|
||||
data : ['x','y','z']
|
||||
}],
|
||||
yAxis : [{
|
||||
type : 'value'
|
||||
}],
|
||||
legend: {
|
||||
data: ['this is a', 'this is b',
|
||||
'this is c'],
|
||||
orient: 'vertical'
|
||||
}
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
name: 'orient',
|
||||
cases: [{
|
||||
name: 'should display horizontally',
|
||||
option: {
|
||||
series: [{
|
||||
name: 'this is a',
|
||||
type: 'line',
|
||||
data: []
|
||||
}, {
|
||||
name: 'this is b',
|
||||
type: 'line',
|
||||
data: []
|
||||
}, {
|
||||
name: 'this is c',
|
||||
type: 'line',
|
||||
data: []
|
||||
}],
|
||||
xAxis : [{
|
||||
type : 'category',
|
||||
data : ['x','y','z']
|
||||
}],
|
||||
yAxis : [{
|
||||
type : 'value'
|
||||
}],
|
||||
legend: {
|
||||
data: ['this is a', 'this is b',
|
||||
'this is c'],
|
||||
orient: 'horizontal'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display vertically',
|
||||
option: {
|
||||
series: [{
|
||||
name: 'this is a',
|
||||
type: 'line',
|
||||
data: []
|
||||
}, {
|
||||
name: 'this is b',
|
||||
type: 'line',
|
||||
data: []
|
||||
}, {
|
||||
name: 'this is c',
|
||||
type: 'line',
|
||||
data: []
|
||||
}],
|
||||
xAxis : [{
|
||||
type : 'category',
|
||||
data : ['x','y','z']
|
||||
}],
|
||||
yAxis : [{
|
||||
type : 'value'
|
||||
}],
|
||||
legend: {
|
||||
data: ['this is a', 'this is b',
|
||||
'this is c'],
|
||||
orient: 'vertical'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display different with horizontal and vertical',
|
||||
test: 'notEqualOption',
|
||||
option1: {
|
||||
series: [{
|
||||
name: 'this is a',
|
||||
type: 'line',
|
||||
data: []
|
||||
}, {
|
||||
name: 'this is b',
|
||||
type: 'line',
|
||||
data: []
|
||||
}, {
|
||||
name: 'this is c',
|
||||
type: 'line',
|
||||
data: []
|
||||
}],
|
||||
xAxis : [{
|
||||
type : 'category',
|
||||
data : ['x','y','z']
|
||||
}],
|
||||
yAxis : [{
|
||||
type : 'value'
|
||||
}],
|
||||
legend: {
|
||||
data: ['this is a', 'this is b',
|
||||
'this is c'],
|
||||
orient: 'vertical'
|
||||
}
|
||||
},
|
||||
option2: {
|
||||
series: [{
|
||||
name: 'this is a',
|
||||
type: 'line',
|
||||
data: []
|
||||
}, {
|
||||
name: 'this is b',
|
||||
type: 'line',
|
||||
data: []
|
||||
}, {
|
||||
name: 'this is c',
|
||||
type: 'line',
|
||||
data: []
|
||||
}],
|
||||
xAxis : [{
|
||||
type : 'category',
|
||||
data : ['x','y','z']
|
||||
}],
|
||||
yAxis : [{
|
||||
type : 'value'
|
||||
}],
|
||||
legend: {
|
||||
data: ['this is a', 'this is b',
|
||||
'this is c']
|
||||
}
|
||||
}
|
||||
}]
|
||||
}];
|
||||
|
||||
uiHelper.testOptionSpec('legend', suites);
|
||||
|
||||
});
|
||||
434
vendors/echarts/test/ut/spec/ui/title.js
vendored
Normal file
434
vendors/echarts/test/ut/spec/ui/title.js
vendored
Normal file
@@ -0,0 +1,434 @@
|
||||
describe('title', function() {
|
||||
|
||||
var uiHelper = window.uiHelper;
|
||||
|
||||
var suites = [{
|
||||
name: 'show',
|
||||
cases: [{
|
||||
name: 'should display given title by default',
|
||||
option: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'test title'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should hide title when show is false',
|
||||
option: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'hidden title',
|
||||
display: false
|
||||
}
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
name: 'text',
|
||||
cases: [{
|
||||
name: 'should display title',
|
||||
option: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'here is a title'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display long title in a line',
|
||||
option: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'here is a very long long long long long long long '
|
||||
+ 'long long long long long long long long long long '
|
||||
+ 'long long long long long long long long long title'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should run into a new line with \\n',
|
||||
option: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'first line\nsecond line'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display no title by default',
|
||||
option: {
|
||||
series: []
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
name: 'subtext',
|
||||
cases: [{
|
||||
name: 'should display subtext without text',
|
||||
option: {
|
||||
series: [],
|
||||
title: {
|
||||
subtext: 'subtext without text'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display subtext with text',
|
||||
option: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'this is text',
|
||||
subtext: 'subtext without text'
|
||||
}
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
name: 'padding',
|
||||
cases: [{
|
||||
name: 'should display padding 5px as default',
|
||||
test: 'equalOption',
|
||||
option1: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'this is title with 5px padding'
|
||||
}
|
||||
},
|
||||
option2: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'this is title with 5px padding',
|
||||
padding: 5
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display one-value padding',
|
||||
test: 'notEqualOption',
|
||||
option1: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'should display one-value padding'
|
||||
}
|
||||
},
|
||||
option2: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'should display one-value padding',
|
||||
padding: 50
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display two-value padding',
|
||||
test: 'notEqualOption',
|
||||
option1: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'display two-value padding'
|
||||
}
|
||||
},
|
||||
option2: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'display two-value padding',
|
||||
padding: [20, 50]
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display four-value padding',
|
||||
test: 'notEqualOption',
|
||||
option1: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'compare padding with 10, 30, 50, 70'
|
||||
}
|
||||
},
|
||||
option2: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'compare padding with 10, 30, 50, 70',
|
||||
padding: [10, 30, 50, 70]
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display four-value and two-value padding accordingly',
|
||||
test: 'equalOption',
|
||||
option1: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'compare padding with 20, 50 and 20, 50, 20, 50',
|
||||
padding: [20, 50]
|
||||
}
|
||||
},
|
||||
option2: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'compare padding with 20, 50 and 20, 50, 20, 50',
|
||||
padding: [20, 50, 20, 50]
|
||||
}
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
name: 'itemGap',
|
||||
cases: [{
|
||||
name: 'should have default itemGap as 5px',
|
||||
test: 'equalOption',
|
||||
option1: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'title',
|
||||
subtext: 'subtext'
|
||||
}
|
||||
},
|
||||
option2: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'title',
|
||||
subtext: 'subtext',
|
||||
itemGap: 5
|
||||
}
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
name: 'left',
|
||||
cases: [{
|
||||
name: 'should display left position',
|
||||
option: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'this is title',
|
||||
left: 50
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display at 20%',
|
||||
option: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'this is title',
|
||||
left: '20%'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display at center',
|
||||
option: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'this is title',
|
||||
left: 'center'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display at right',
|
||||
option: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'this is title',
|
||||
left: 'right'
|
||||
}
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
name: 'top',
|
||||
cases: [{
|
||||
name: 'should display top position',
|
||||
option: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'this is title',
|
||||
top: 50
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display at 20%',
|
||||
option: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'this is title',
|
||||
top: '20%'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display at middle',
|
||||
option: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'this is title',
|
||||
top: 'middle'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display at bottom',
|
||||
option: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'this is title',
|
||||
top: 'bottom'
|
||||
}
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
name: 'right',
|
||||
cases: [{
|
||||
name: 'should display right position',
|
||||
option: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'this is title',
|
||||
right: 50
|
||||
}
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
name: 'bottom',
|
||||
cases: [{
|
||||
name: 'should display bottom position',
|
||||
option: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'this is title',
|
||||
bottom: 50
|
||||
}
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
name: 'left and right',
|
||||
cases: [{
|
||||
name: 'are both set',
|
||||
test: 'equalOption',
|
||||
option1: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'this is title',
|
||||
left: 50,
|
||||
right: 50
|
||||
}
|
||||
},
|
||||
option2: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'this is title',
|
||||
left: 50
|
||||
}
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
name: 'top and bottom',
|
||||
cases: [{
|
||||
name: 'are both set',
|
||||
test: 'equalOption',
|
||||
option1: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'this is title',
|
||||
top: 50,
|
||||
bottom: 50
|
||||
}
|
||||
},
|
||||
option2: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'this is title',
|
||||
top: 50
|
||||
}
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
name: 'backgroundColor',
|
||||
cases: [{
|
||||
name: 'should show specific background color',
|
||||
option: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'this is title',
|
||||
backgroundColor: 'rgba(255, 100, 0, 0.2)'
|
||||
}
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
name: 'borderColor',
|
||||
cases: [{
|
||||
name: 'should show specific border color at default border width',
|
||||
test: 'equalOption',
|
||||
option1: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'this is title',
|
||||
borderColor: '#f00'
|
||||
}
|
||||
},
|
||||
option2: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'this is title',
|
||||
borderColor: '#f00',
|
||||
borderWidth: 1
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display larger border width',
|
||||
option: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'this is title',
|
||||
borderWidth: 15
|
||||
}
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
name: 'shadowBlur and shadowColor',
|
||||
cases: [{
|
||||
name: 'should display shadow blur',
|
||||
option: {
|
||||
series: [],
|
||||
title: {
|
||||
backgroundColor: 'green',
|
||||
text: 'this is title',
|
||||
shadowColor: 'red',
|
||||
shadowBlur: 5
|
||||
}
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
name: 'shadowOffsetX',
|
||||
cases: [{
|
||||
name: 'should display shadow blur',
|
||||
option: {
|
||||
series: [],
|
||||
title: {
|
||||
backgroundColor: 'green',
|
||||
text: 'this is title',
|
||||
shadowColor: 'red',
|
||||
shadowBlur: 5,
|
||||
shadowOffsetX: 10
|
||||
}
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
name: 'shadowOffsetY',
|
||||
cases: [{
|
||||
name: 'should display shadow blur',
|
||||
option: {
|
||||
series: [],
|
||||
title: {
|
||||
backgroundColor: 'green',
|
||||
text: 'this is title',
|
||||
shadowColor: 'red',
|
||||
shadowBlur: 5,
|
||||
shadowOffsetY: 10
|
||||
}
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
name: 'shadowOffsetX and shadowOffsetY',
|
||||
cases: [{
|
||||
name: 'should display shadow blur',
|
||||
option: {
|
||||
series: [],
|
||||
title: {
|
||||
backgroundColor: 'green',
|
||||
text: 'this is title',
|
||||
shadowColor: 'red',
|
||||
shadowBlur: 5,
|
||||
shadowOffsetX: 10,
|
||||
shadowOffsetY: 10
|
||||
}
|
||||
}
|
||||
}]
|
||||
}];
|
||||
|
||||
uiHelper.testOptionSpec('title', suites);
|
||||
|
||||
});
|
||||
353
vendors/echarts/test/ut/spec/ui/title.subtextStyle.js
vendored
Normal file
353
vendors/echarts/test/ut/spec/ui/title.subtextStyle.js
vendored
Normal file
@@ -0,0 +1,353 @@
|
||||
describe('title.subtextStyle', function() {
|
||||
|
||||
var uiHelper = window.uiHelper;
|
||||
|
||||
var suites = [{
|
||||
name: 'subtextStyle.color',
|
||||
cases: [{
|
||||
name: 'should display expected color name',
|
||||
option: {
|
||||
series: [],
|
||||
title: {
|
||||
subtext: 'a red subtitle',
|
||||
subtextStyle: {
|
||||
color: 'red'
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display expected color 6-digit hex',
|
||||
option: {
|
||||
series: [],
|
||||
title: {
|
||||
subtext: 'an orange subtitle',
|
||||
subtextStyle: {
|
||||
color: '#ff6600'
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display expected color 3-digit hex',
|
||||
option: {
|
||||
series: [],
|
||||
title: {
|
||||
subtext: 'an orange subtitle',
|
||||
subtextStyle: {
|
||||
color: '#f60'
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display expected color rgb',
|
||||
option: {
|
||||
series: [],
|
||||
title: {
|
||||
subtext: 'an orange subtitle',
|
||||
subtextStyle: {
|
||||
color: 'rgb(255, 127, 0)'
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display expected color rgba',
|
||||
option: {
|
||||
series: [],
|
||||
title: {
|
||||
subtext: 'an orange subtitle with alpha',
|
||||
subtextStyle: {
|
||||
color: 'rgba(255, 127, 0, 0.5)'
|
||||
}
|
||||
}
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
name: 'subtextStyle.fontStyle',
|
||||
cases: [{
|
||||
name: 'should display normal font style',
|
||||
option: {
|
||||
series: [],
|
||||
title: {
|
||||
subtext: 'normal font',
|
||||
subtextStyle: {
|
||||
fontStyle: 'normal'
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display italic font style',
|
||||
option: {
|
||||
series: [],
|
||||
title: {
|
||||
subtext: 'italic font',
|
||||
subtextStyle: {
|
||||
fontStyle: 'italic'
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display oblique font style',
|
||||
option: {
|
||||
series: [],
|
||||
title: {
|
||||
subtext: 'oblique font',
|
||||
subtextStyle: {
|
||||
fontStyle: 'oblique'
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display italic not as normal',
|
||||
test: 'notEqualOption',
|
||||
option1: {
|
||||
series: [],
|
||||
title: {
|
||||
subtext: 'italic vs. normal',
|
||||
subtextStyle: {
|
||||
fontStyle: 'italic'
|
||||
}
|
||||
}
|
||||
},
|
||||
option2: {
|
||||
series: [],
|
||||
title: {
|
||||
subtext: 'italic vs. normal',
|
||||
subtextStyle: {
|
||||
fontStyle: 'normal'
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display oblique not as normal',
|
||||
test: 'notEqualOption',
|
||||
option1: {
|
||||
series: [],
|
||||
title: {
|
||||
subtext: 'oblique vs. normal',
|
||||
subtextStyle: {
|
||||
fontStyle: 'oblique'
|
||||
}
|
||||
}
|
||||
},
|
||||
option2: {
|
||||
series: [],
|
||||
title: {
|
||||
subtext: 'oblique vs. normal',
|
||||
subtextStyle: {
|
||||
fontStyle: 'normal'
|
||||
}
|
||||
}
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
name: 'subtextStyle.fontWeight',
|
||||
cases: [{
|
||||
name: 'should display default normal font weight',
|
||||
test: 'equalOption',
|
||||
option1: {
|
||||
series: [],
|
||||
title: {
|
||||
subtext: 'normal font'
|
||||
}
|
||||
},
|
||||
option2: {
|
||||
series: [],
|
||||
title: {
|
||||
subtext: 'normal font',
|
||||
subtextStyle: {
|
||||
fontWeight: 'normal'
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display bold font weight',
|
||||
test: 'notEqualOption',
|
||||
option1: {
|
||||
series: [],
|
||||
title: {
|
||||
subtext: 'bold font vs. normal font',
|
||||
subtextStyle: {
|
||||
fontStyle: 'bold'
|
||||
}
|
||||
}
|
||||
},
|
||||
option2: {
|
||||
series: [],
|
||||
title: {
|
||||
subtext: 'bold font vs. normal font',
|
||||
subtextStyle: {
|
||||
fontStyle: 'normal'
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display bolder font weight',
|
||||
test: 'notEqualOption',
|
||||
option1: {
|
||||
series: [],
|
||||
title: {
|
||||
subtext: 'bolder font vs. normal font',
|
||||
subtextStyle: {
|
||||
fontStyle: 'bolder'
|
||||
}
|
||||
}
|
||||
},
|
||||
option2: {
|
||||
series: [],
|
||||
title: {
|
||||
subtext: 'bolder font vs. normal font',
|
||||
subtextStyle: {
|
||||
fontStyle: 'normal'
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display light font weight',
|
||||
test: 'notEqualOption',
|
||||
option1: {
|
||||
series: [],
|
||||
title: {
|
||||
subtext: 'light font vs. normal font',
|
||||
subtextStyle: {
|
||||
fontStyle: 'light'
|
||||
}
|
||||
}
|
||||
},
|
||||
option2: {
|
||||
series: [],
|
||||
title: {
|
||||
subtext: 'light font vs. normal font',
|
||||
subtextStyle: {
|
||||
fontStyle: 'normal'
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display numbering font weight',
|
||||
test: 'notEqualOption',
|
||||
option1: {
|
||||
series: [],
|
||||
title: {
|
||||
subtext: '100 font vs. normal font',
|
||||
subtextStyle: {
|
||||
fontStyle: '100'
|
||||
}
|
||||
}
|
||||
},
|
||||
option2: {
|
||||
series: [],
|
||||
title: {
|
||||
subtext: '100 font vs. normal font',
|
||||
subtextStyle: {
|
||||
fontStyle: 'normal'
|
||||
}
|
||||
}
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
name: 'subtextStyle.fontFamily',
|
||||
cases: [{
|
||||
name: 'should display default fontFamily as sans-serif',
|
||||
test: 'equalOption',
|
||||
option1: {
|
||||
series: [],
|
||||
title: {
|
||||
subtext: 'sans-serif'
|
||||
}
|
||||
},
|
||||
option2: {
|
||||
series: [],
|
||||
title: {
|
||||
subtext: 'sans-serif',
|
||||
fontFamily: 'sans-serif'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display default fontFamily as Arial',
|
||||
test: 'notEqualOption',
|
||||
option1: {
|
||||
series: [],
|
||||
title: {
|
||||
subtext: 'Arial vs. sans-serif',
|
||||
subtextStyle: {
|
||||
fontFamily: 'Arial'
|
||||
}
|
||||
}
|
||||
},
|
||||
option2: {
|
||||
series: [],
|
||||
title: {
|
||||
subtext: 'Arial vs. sans-serif',
|
||||
subtextStyle: {
|
||||
fontFamily: 'sans-serif'
|
||||
}
|
||||
}
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
name: 'textStyle.fontSize',
|
||||
cases: [{
|
||||
name: 'should display default fontSize at 18',
|
||||
test: 'equalOption',
|
||||
option1: {
|
||||
series: [],
|
||||
title: {
|
||||
subtext: 'default font size, should be 18'
|
||||
}
|
||||
},
|
||||
option2: {
|
||||
series: [],
|
||||
title: {
|
||||
subtext: 'default font size, should be 18',
|
||||
subtextStyle: {
|
||||
fontSize: 18
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display larger fontSize',
|
||||
test: 'notEqualOption',
|
||||
option1: {
|
||||
series: [],
|
||||
title: {
|
||||
subtext: 'larger font size, 30',
|
||||
subtextStyle: {
|
||||
fontSize: 30
|
||||
}
|
||||
}
|
||||
},
|
||||
option2: {
|
||||
series: [],
|
||||
title: {
|
||||
subtext: 'larger font size, 30',
|
||||
subtextStyle: {
|
||||
fontSize: 18
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display smaller fontSize',
|
||||
test: 'notEqualOption',
|
||||
option1: {
|
||||
series: [],
|
||||
title: {
|
||||
subtext: 'smaller font size, 12',
|
||||
subtextStyle: {
|
||||
fontSize: 12
|
||||
}
|
||||
}
|
||||
},
|
||||
option2: {
|
||||
series: [],
|
||||
title: {
|
||||
subtext: 'smaller font size, 12',
|
||||
subtextStyle: {
|
||||
fontSize: 18
|
||||
}
|
||||
}
|
||||
}
|
||||
}]
|
||||
}];
|
||||
|
||||
uiHelper.testOptionSpec('title.subtextStyle', suites);
|
||||
|
||||
});
|
||||
351
vendors/echarts/test/ut/spec/ui/title.textStyle.js
vendored
Normal file
351
vendors/echarts/test/ut/spec/ui/title.textStyle.js
vendored
Normal file
@@ -0,0 +1,351 @@
|
||||
describe('title.textStyle', function() {
|
||||
|
||||
var uiHelper = window.uiHelper;
|
||||
|
||||
var suites = [{
|
||||
name: 'textStyle.color',
|
||||
cases: [{
|
||||
name: 'should display expected color name',
|
||||
option: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'a red title',
|
||||
textStyle: {
|
||||
color: 'red'
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display expected color 6-digit hex',
|
||||
option: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'an orange title',
|
||||
textStyle: {
|
||||
color: '#ff6600'
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display expected color 3-digit hex',
|
||||
option: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'an orange title',
|
||||
textStyle: {
|
||||
color: '#f60'
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display expected color rgb',
|
||||
option: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'an orange title',
|
||||
textStyle: {
|
||||
color: 'rgb(255, 127, 0)'
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display expected color rgba',
|
||||
option: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'an orange title with alpha',
|
||||
textStyle: {
|
||||
color: 'rgba(255, 127, 0, 0.5)'
|
||||
}
|
||||
}
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
name: 'textStyle.fontStyle',
|
||||
cases: [{
|
||||
name: 'should display normal font style',
|
||||
option: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'normal font',
|
||||
textStyle: {
|
||||
fontStyle: 'normal'
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display italic font style',
|
||||
option: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'italic font',
|
||||
textStyle: {
|
||||
fontStyle: 'italic'
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display oblique font style',
|
||||
option: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'oblique font',
|
||||
textStyle: {
|
||||
fontStyle: 'oblique'
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display italic not as normal',
|
||||
test: 'notEqualOption',
|
||||
option1: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'italic vs. normal',
|
||||
textStyle: {
|
||||
fontStyle: 'italic'
|
||||
}
|
||||
}
|
||||
},
|
||||
option2: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'italic vs. normal',
|
||||
textStyle: {
|
||||
fontStyle: 'normal'
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display oblique not as normal',
|
||||
test: 'notEqualOption',
|
||||
option1: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'oblique vs. normal',
|
||||
textStyle: {
|
||||
fontStyle: 'oblique'
|
||||
}
|
||||
}
|
||||
},
|
||||
option2: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'oblique vs. normal',
|
||||
textStyle: {
|
||||
fontStyle: 'normal'
|
||||
}
|
||||
}
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
name: 'textStyle.fontWeight',
|
||||
cases: [{
|
||||
name: 'should display default normal font weight',
|
||||
test: 'equalOption',
|
||||
option1: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'normal font'
|
||||
}
|
||||
},
|
||||
option2: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'normal font',
|
||||
textStyle: {
|
||||
fontWeight: 'normal'
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display bold font weight',
|
||||
test: 'notEqualOption',
|
||||
option1: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'bold font vs. normal font',
|
||||
textStyle: {
|
||||
fontStyle: 'bold'
|
||||
}
|
||||
}
|
||||
},
|
||||
option2: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'bold font vs. normal font',
|
||||
textStyle: {
|
||||
fontStyle: 'normal'
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display bolder font weight',
|
||||
test: 'notEqualOption',
|
||||
option1: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'bolder font vs. normal font',
|
||||
textStyle: {
|
||||
fontStyle: 'bolder'
|
||||
}
|
||||
}
|
||||
},
|
||||
option2: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'bolder font vs. normal font',
|
||||
textStyle: {
|
||||
fontStyle: 'normal'
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display light font weight',
|
||||
test: 'notEqualOption',
|
||||
option1: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'light font vs. normal font',
|
||||
textStyle: {
|
||||
fontStyle: 'light'
|
||||
}
|
||||
}
|
||||
},
|
||||
option2: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'light font vs. normal font',
|
||||
textStyle: {
|
||||
fontStyle: 'normal'
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display numbering font weight',
|
||||
test: 'notEqualOption',
|
||||
option1: {
|
||||
series: [],
|
||||
title: {
|
||||
text: '100 font vs. normal font',
|
||||
textStyle: {
|
||||
fontStyle: '100'
|
||||
}
|
||||
}
|
||||
},
|
||||
option2: {
|
||||
series: [],
|
||||
title: {
|
||||
text: '100 font vs. normal font',
|
||||
textStyle: {
|
||||
fontStyle: 'normal'
|
||||
}
|
||||
}
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
name: 'textStyle.fontFamily',
|
||||
cases: [{
|
||||
name: 'should display default fontFamily as sans-serif',
|
||||
test: 'equalOption',
|
||||
option1: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'sans-serif'
|
||||
}
|
||||
},
|
||||
option2: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'sans-serif',
|
||||
fontFamily: 'sans-serif'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display default fontFamily as Arial',
|
||||
test: 'notEqualOption',
|
||||
option1: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'Arial vs. sans-serif',
|
||||
textStyle: {
|
||||
fontFamily: 'Arial'
|
||||
}
|
||||
}
|
||||
},
|
||||
option2: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'Arial vs. sans-serif',
|
||||
fontFamily: 'sans-serif'
|
||||
}
|
||||
}
|
||||
}]
|
||||
}, {
|
||||
name: 'textStyle.fontSize',
|
||||
cases: [{
|
||||
name: 'should display default fontSize at 18',
|
||||
test: 'equalOption',
|
||||
option1: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'default font size, should be 18'
|
||||
}
|
||||
},
|
||||
option2: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'default font size, should be 18',
|
||||
textStyle: {
|
||||
fontSize: 18
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display larger fontSize',
|
||||
test: 'notEqualOption',
|
||||
option1: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'larger font size, 30',
|
||||
textStyle: {
|
||||
fontSize: 30
|
||||
}
|
||||
}
|
||||
},
|
||||
option2: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'larger font size, 30',
|
||||
textStyle: {
|
||||
fontSize: 18
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
name: 'should display smaller fontSize',
|
||||
test: 'notEqualOption',
|
||||
option1: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'smaller font size, 12',
|
||||
textStyle: {
|
||||
fontSize: 12
|
||||
}
|
||||
}
|
||||
},
|
||||
option2: {
|
||||
series: [],
|
||||
title: {
|
||||
text: 'smaller font size, 12',
|
||||
textStyle: {
|
||||
fontSize: 18
|
||||
}
|
||||
}
|
||||
}
|
||||
}]
|
||||
}];
|
||||
|
||||
uiHelper.testOptionSpec('title.textStyle', suites);
|
||||
|
||||
});
|
||||
76
vendors/echarts/test/ut/spec/util/graphic.js
vendored
Normal file
76
vendors/echarts/test/ut/spec/util/graphic.js
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
describe('util/graphic', function() {
|
||||
|
||||
var utHelper = window.utHelper;
|
||||
var graphic;
|
||||
|
||||
beforeAll(function (done) { // jshint ignore:line
|
||||
utHelper.resetPackageLoader(function () {
|
||||
window.require(['echarts/util/graphic'], function (g) {
|
||||
graphic = g;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('subPixelOptimize', function () {
|
||||
|
||||
it('subPixelOptimize_base', function (done) {
|
||||
expect(graphic.subPixelOptimize(5, 1)).toEqual(4.5);
|
||||
expect(graphic.subPixelOptimize(5, 2)).toEqual(5);
|
||||
expect(graphic.subPixelOptimize(5, 43)).toEqual(4.5);
|
||||
expect(graphic.subPixelOptimize(7.5, 1)).toEqual(7.5);
|
||||
expect(graphic.subPixelOptimize(7.5, 2)).toEqual(7);
|
||||
expect(graphic.subPixelOptimize(14, 1, true)).toEqual(14.5);
|
||||
expect(graphic.subPixelOptimize(14, 2, true)).toEqual(14);
|
||||
expect(graphic.subPixelOptimize(-11, 1)).toEqual(-11.5);
|
||||
expect(graphic.subPixelOptimize(-11, 2)).toEqual(-11);
|
||||
expect(graphic.subPixelOptimize(0, 2)).toEqual(0);
|
||||
expect(graphic.subPixelOptimize(0, 1)).toEqual(-0.5);
|
||||
expect(graphic.subPixelOptimize(5, 0)).toEqual(5);
|
||||
done();
|
||||
});
|
||||
|
||||
it('subPixelOptimize_line', function (done) {
|
||||
function doSubPixelOptimizeLine(x, y, width, height, lineWidth) {
|
||||
return graphic.subPixelOptimizeLine(makeParam(x, y, width, height, lineWidth));
|
||||
}
|
||||
function makeParam(x1, y1, x2, y2, lineWidth) {
|
||||
return {
|
||||
shape: {x1: x1, y1: y1, x2: x2, y2: y2},
|
||||
style: {lineWidth: lineWidth}
|
||||
};
|
||||
}
|
||||
expect(doSubPixelOptimizeLine(5, 11, 3, 7, 1)).toEqual(makeParam(5, 11, 3, 7, 1));
|
||||
expect(doSubPixelOptimizeLine(5, 11, 5, 7, 1)).toEqual(makeParam(5.5, 11, 5.5, 7, 1));
|
||||
expect(doSubPixelOptimizeLine(5, 11, 5, 7, 2)).toEqual(makeParam(5, 11, 5, 7, 2));
|
||||
expect(doSubPixelOptimizeLine(5, 11, 15, 11, 1)).toEqual(makeParam(5, 11.5, 15, 11.5, 1));
|
||||
expect(doSubPixelOptimizeLine(5, 11, 15, 11, 2)).toEqual(makeParam(5, 11, 15, 11, 2));
|
||||
expect(doSubPixelOptimizeLine(5, 11, 15, 11, 3)).toEqual(makeParam(5, 11.5, 15, 11.5, 3));
|
||||
expect(doSubPixelOptimizeLine(5, 11, 15, 11.5, 3)).toEqual(makeParam(5, 11, 15, 11.5, 3));
|
||||
expect(doSubPixelOptimizeLine(5, 11.5, 15, 11.5, 3)).toEqual(makeParam(5, 11.5, 15, 11.5, 3));
|
||||
expect(doSubPixelOptimizeLine(5, 11.5, 15, 11.5, 4)).toEqual(makeParam(5, 12, 15, 12, 4));
|
||||
done();
|
||||
});
|
||||
|
||||
it('subPixelOptimize_rect', function (done) {
|
||||
function doSubPixelOptimizeRect(x, y, width, height, lineWidth) {
|
||||
return graphic.subPixelOptimizeRect(makeParam(x, y, width, height, lineWidth));
|
||||
}
|
||||
function makeParam(x, y, width, height, lineWidth) {
|
||||
return {
|
||||
shape: {x: x, y: y, width: width, height: height},
|
||||
style: {lineWidth: lineWidth}
|
||||
};
|
||||
}
|
||||
expect(doSubPixelOptimizeRect(5, 11, 3, 7, 1)).toEqual(makeParam(5.5, 11.5, 2, 6, 1));
|
||||
expect(doSubPixelOptimizeRect(5, 11, 3, 7, 2)).toEqual(makeParam(5, 11, 3, 7, 2));
|
||||
expect(doSubPixelOptimizeRect(5, 11, 3, 7, 3)).toEqual(makeParam(5.5, 11.5, 2, 6, 3));
|
||||
// Boundary value tests
|
||||
expect(doSubPixelOptimizeRect(5, 11, 1, 7, 1)).toEqual(makeParam(5.5, 11.5, 1, 6, 1));
|
||||
expect(doSubPixelOptimizeRect(5, 11, 1, 0, 1)).toEqual(makeParam(5.5, 11.5, 1, 0, 1));
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
100
vendors/echarts/test/ut/spec/util/model.js
vendored
Normal file
100
vendors/echarts/test/ut/spec/util/model.js
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
describe('util/model', function() {
|
||||
|
||||
var utHelper = window.utHelper;
|
||||
var modelUtil;
|
||||
|
||||
beforeAll(function (done) { // jshint ignore:line
|
||||
utHelper.resetPackageLoader(function () {
|
||||
window.require(['echarts/util/model'], function (h) {
|
||||
modelUtil = h;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function makeRecords(result) {
|
||||
var o = {};
|
||||
modelUtil.eachAxisDim(function (dimNames) {
|
||||
o[dimNames.name] = {};
|
||||
var r = result[dimNames.name] || [];
|
||||
for (var i = 0; i < r.length; i++) {
|
||||
o[dimNames.name][r[i]] = true;
|
||||
}
|
||||
});
|
||||
return o;
|
||||
}
|
||||
|
||||
describe('findLinkedNodes', function () {
|
||||
|
||||
function forEachModel(models, callback) {
|
||||
for (var i = 0; i < models.length; i++) {
|
||||
callback(models[i]);
|
||||
}
|
||||
}
|
||||
|
||||
function axisIndicesGetter(model, dimNames) {
|
||||
return model[dimNames.axisIndex];
|
||||
}
|
||||
|
||||
it('findLinkedNodes_base', function (done) {
|
||||
var models = [
|
||||
{xAxisIndex: [1, 2], yAxisIndex: [0]},
|
||||
{xAxisIndex: [3], yAxisIndex: [1]},
|
||||
{xAxisIndex: [5], yAxisIndex: []},
|
||||
{xAxisIndex: [2, 5], yAxisIndex: []}
|
||||
];
|
||||
var result = modelUtil.createLinkedNodesFinder(
|
||||
utHelper.curry(forEachModel, models),
|
||||
modelUtil.eachAxisDim,
|
||||
axisIndicesGetter
|
||||
)(models[0]);
|
||||
expect(result).toEqual({
|
||||
nodes: [models[0], models[3], models[2]],
|
||||
records: makeRecords({x: [1, 2, 5], y: [0]})
|
||||
});
|
||||
done();
|
||||
});
|
||||
|
||||
it('findLinkedNodes_crossXY', function (done) {
|
||||
var models = [
|
||||
{xAxisIndex: [1, 2], yAxisIndex: [0]},
|
||||
{xAxisIndex: [3], yAxisIndex: [3, 0]},
|
||||
{xAxisIndex: [6, 3], yAxisIndex: [9]},
|
||||
{xAxisIndex: [5, 3], yAxisIndex: []},
|
||||
{xAxisIndex: [8], yAxisIndex: [4]}
|
||||
];
|
||||
var result = modelUtil.createLinkedNodesFinder(
|
||||
utHelper.curry(forEachModel, models),
|
||||
modelUtil.eachAxisDim,
|
||||
axisIndicesGetter
|
||||
)(models[0]);
|
||||
expect(result).toEqual({
|
||||
nodes: [models[0], models[1], models[2], models[3]],
|
||||
records: makeRecords({x: [1, 2, 3, 5, 6], y: [0, 3, 9]})
|
||||
});
|
||||
done();
|
||||
});
|
||||
|
||||
it('findLinkedNodes_emptySourceModel', function (done) {
|
||||
var models = [
|
||||
{xAxisIndex: [1, 2], yAxisIndex: [0]},
|
||||
{xAxisIndex: [3], yAxisIndex: [3, 0]},
|
||||
{xAxisIndex: [6, 3], yAxisIndex: [9]},
|
||||
{xAxisIndex: [5, 3], yAxisIndex: []},
|
||||
{xAxisIndex: [8], yAxisIndex: [4]}
|
||||
];
|
||||
var result = modelUtil.createLinkedNodesFinder(
|
||||
utHelper.curry(forEachModel, models),
|
||||
modelUtil.eachAxisDim,
|
||||
axisIndicesGetter
|
||||
)();
|
||||
expect(result).toEqual({
|
||||
nodes: [],
|
||||
records: makeRecords({x: [], y: []})
|
||||
});
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
200
vendors/echarts/test/ut/spec/util/number.js
vendored
Normal file
200
vendors/echarts/test/ut/spec/util/number.js
vendored
Normal file
@@ -0,0 +1,200 @@
|
||||
describe('util/number', function () {
|
||||
|
||||
var utHelper = window.utHelper;
|
||||
|
||||
var testCase = utHelper.prepare(['echarts/util/number']);
|
||||
|
||||
describe('linearMap', function () {
|
||||
|
||||
testCase('accuracyError', function (numberUtil) {
|
||||
var range = [-15918.3, 17724.9];
|
||||
var result = numberUtil.linearMap(100, [0, 100], range, true);
|
||||
// Should not be 17724.899999999998.
|
||||
expect(result).toEqual(range[1]);
|
||||
|
||||
var range = [-62.83, 83.56];
|
||||
var result = numberUtil.linearMap(100, [0, 100], range, true);
|
||||
// Should not be 83.55999999999999.
|
||||
expect(result).toEqual(range[1]);
|
||||
});
|
||||
|
||||
testCase('clamp', function (numberUtil) {
|
||||
// (1) normal order.
|
||||
var range = [-15918.3, 17724.9];
|
||||
// bigger than max
|
||||
var result = numberUtil.linearMap(100.1, [0, 100], range, true);
|
||||
expect(result).toEqual(range[1]);
|
||||
// smaller than min
|
||||
var result = numberUtil.linearMap(-2, [0, 100], range, true);
|
||||
expect(result).toEqual(range[0]);
|
||||
// equals to max
|
||||
var result = numberUtil.linearMap(100, [0, 100], range, true);
|
||||
expect(result).toEqual(range[1]);
|
||||
// equals to min
|
||||
var result = numberUtil.linearMap(0, [0, 100], range, true);
|
||||
expect(result).toEqual(range[0]);
|
||||
|
||||
// (2) inverse range
|
||||
var range = [17724.9, -15918.3];
|
||||
// bigger than max
|
||||
var result = numberUtil.linearMap(102, [0, 100], range, true);
|
||||
expect(result).toEqual(range[1]);
|
||||
// smaller than min
|
||||
var result = numberUtil.linearMap(-0.001, [0, 100], range, true);
|
||||
expect(result).toEqual(range[0]);
|
||||
// equals to max
|
||||
var result = numberUtil.linearMap(100, [0, 100], range, true);
|
||||
expect(result).toEqual(range[1]);
|
||||
// equals to min
|
||||
var result = numberUtil.linearMap(0, [0, 100], range, true);
|
||||
expect(result).toEqual(range[0]);
|
||||
|
||||
// (2) inverse domain
|
||||
// bigger than max, inverse domain
|
||||
var range = [-15918.3, 17724.9];
|
||||
// bigger than max
|
||||
var result = numberUtil.linearMap(102, [100, 0], range, true);
|
||||
expect(result).toEqual(range[0]);
|
||||
// smaller than min
|
||||
var result = numberUtil.linearMap(-0.001, [100, 0], range, true);
|
||||
expect(result).toEqual(range[1]);
|
||||
// equals to max
|
||||
var result = numberUtil.linearMap(100, [100, 0], range, true);
|
||||
expect(result).toEqual(range[0]);
|
||||
// equals to min
|
||||
var result = numberUtil.linearMap(0, [100, 0], range, true);
|
||||
expect(result).toEqual(range[1]);
|
||||
|
||||
// (3) inverse domain, inverse range
|
||||
var range = [17724.9, -15918.3];
|
||||
// bigger than max
|
||||
var result = numberUtil.linearMap(100.1, [100, 0], range, true);
|
||||
expect(result).toEqual(range[0]);
|
||||
// smaller than min
|
||||
var result = numberUtil.linearMap(-2, [100, 0], range, true);
|
||||
expect(result).toEqual(range[1]);
|
||||
// equals to max
|
||||
var result = numberUtil.linearMap(100, [100, 0], range, true);
|
||||
expect(result).toEqual(range[0]);
|
||||
// equals to min
|
||||
var result = numberUtil.linearMap(0, [100, 0], range, true);
|
||||
expect(result).toEqual(range[1]);
|
||||
});
|
||||
|
||||
testCase('noClamp', function (numberUtil) {
|
||||
// (1) normal order.
|
||||
var range = [-15918.3, 17724.9];
|
||||
// bigger than max
|
||||
var result = numberUtil.linearMap(100.1, [0, 100], range, false);
|
||||
expect(result).toEqual(17758.543199999996);
|
||||
// smaller than min
|
||||
var result = numberUtil.linearMap(-2, [0, 100], range, false);
|
||||
expect(result).toEqual(-16591.164);
|
||||
// equals to max
|
||||
var result = numberUtil.linearMap(100, [0, 100], range, false);
|
||||
expect(result).toEqual(17724.9);
|
||||
// equals to min
|
||||
var result = numberUtil.linearMap(0, [0, 100], range, false);
|
||||
expect(result).toEqual(-15918.3);
|
||||
|
||||
// (2) inverse range
|
||||
var range = [17724.9, -15918.3];
|
||||
// bigger than max
|
||||
var result = numberUtil.linearMap(102, [0, 100], range, false);
|
||||
expect(result).toEqual(-16591.163999999997);
|
||||
// smaller than min
|
||||
var result = numberUtil.linearMap(-0.001, [0, 100], range, false);
|
||||
expect(result).toEqual(17725.236432);
|
||||
// equals to max
|
||||
var result = numberUtil.linearMap(100, [0, 100], range, false);
|
||||
expect(result).toEqual(-15918.3);
|
||||
// equals to min
|
||||
var result = numberUtil.linearMap(0, [0, 100], range, false);
|
||||
expect(result).toEqual(17724.9);
|
||||
|
||||
// (2) inverse domain
|
||||
// bigger than max, inverse domain
|
||||
var range = [-15918.3, 17724.9];
|
||||
// bigger than max
|
||||
var result = numberUtil.linearMap(102, [100, 0], range, false);
|
||||
expect(result).toEqual(-16591.164);
|
||||
// smaller than min
|
||||
var result = numberUtil.linearMap(-0.001, [100, 0], range, false);
|
||||
expect(result).toEqual(17725.236432);
|
||||
// equals to max
|
||||
var result = numberUtil.linearMap(100, [100, 0], range, false);
|
||||
expect(result).toEqual(-15918.3);
|
||||
// equals to min
|
||||
var result = numberUtil.linearMap(0, [100, 0], range, false);
|
||||
expect(result).toEqual(17724.9);
|
||||
|
||||
// (3) inverse domain, inverse range
|
||||
var range = [17724.9, -15918.3];
|
||||
// bigger than max
|
||||
var result = numberUtil.linearMap(100.1, [100, 0], range, false);
|
||||
expect(result).toEqual(17758.5432);
|
||||
// smaller than min
|
||||
var result = numberUtil.linearMap(-2, [100, 0], range, false);
|
||||
expect(result).toEqual(-16591.163999999997);
|
||||
// equals to max
|
||||
var result = numberUtil.linearMap(100, [100, 0], range, false);
|
||||
expect(result).toEqual(17724.9);
|
||||
// equals to min
|
||||
var result = numberUtil.linearMap(0, [100, 0], range, false);
|
||||
expect(result).toEqual(-15918.3);
|
||||
});
|
||||
|
||||
testCase('normal', function (numberUtil) {
|
||||
|
||||
doTest(true);
|
||||
doTest(false);
|
||||
|
||||
function doTest(clamp) {
|
||||
// normal
|
||||
var range = [444, 555];
|
||||
var result = numberUtil.linearMap(40, [0, 100], range, clamp);
|
||||
expect(result).toEqual(488.4);
|
||||
|
||||
// inverse range
|
||||
var range = [555, 444];
|
||||
var result = numberUtil.linearMap(40, [0, 100], range, clamp);
|
||||
expect(result).toEqual(510.6);
|
||||
|
||||
// inverse domain and range
|
||||
var range = [555, 444];
|
||||
var result = numberUtil.linearMap(40, [100, 0], range, clamp);
|
||||
expect(result).toEqual(488.4);
|
||||
|
||||
// inverse domain
|
||||
var range = [444, 555];
|
||||
var result = numberUtil.linearMap(40, [100, 0], range, clamp);
|
||||
expect(result).toEqual(510.6);
|
||||
}
|
||||
});
|
||||
|
||||
testCase('zeroInterval', function (numberUtil) {
|
||||
|
||||
doTest(true);
|
||||
doTest(false);
|
||||
|
||||
function doTest(clamp) {
|
||||
// zero domain interval
|
||||
var range = [444, 555];
|
||||
var result = numberUtil.linearMap(40, [1212222223.2323232, 1212222223.2323232], range, clamp);
|
||||
expect(result).toEqual(499.5); // half of range.
|
||||
|
||||
// zero range interval
|
||||
var range = [1221212.1221372238, 1221212.1221372238];
|
||||
var result = numberUtil.linearMap(40, [0, 100], range, clamp);
|
||||
expect(result).toEqual(1221212.1221372238);
|
||||
|
||||
// zero domain interval and range interval
|
||||
var range = [1221212.1221372238, 1221212.1221372238];
|
||||
var result = numberUtil.linearMap(40, [43.55454545, 43.55454545], range, clamp);
|
||||
expect(result).toEqual(1221212.1221372238);
|
||||
}
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user