idea ide updates
[scannr.git] / js / flotr2 / spec / Graph.js
blob:a/js/flotr2/spec/Graph.js -> blob:b/js/flotr2/spec/Graph.js
describe('Graph', function () { describe('Graph', function () {
   
describe('Options', function () { describe('Options', function () {
var var
nodeA, nodeB, nodeA, nodeB,
a, b, x, i, a, b, x, i,
d1 = [], d1 = [],
options = {}; options = {};
   
for (i = 0; i < 100; i++) { for (i = 0; i < 100; i++) {
x = (i*1000*3600*24*36.5); x = (i * 1000 * 3600 * 24 * 36.5);
d1.push([x, i+Math.random()*30+Math.sin(i/20+Math.random()*2)*20+Math.sin(i/10+Math.random())*10]); d1.push([x, i + Math.random() * 30 + Math.sin(i / 20 + Math.random() * 2) * 20 + Math.sin(i / 10 + Math.random()) * 10]);
} }
   
options = { options = {
xaxis : { xaxis: {
mode : 'time', mode: 'time',
labelsAngle : 45 labelsAngle: 45
}, },
selection : { selection: {
mode : 'x' mode: 'x'
}, },
HtmlText : false, HtmlText: false,
}; };
   
beforeEach(function () { beforeEach(function () {
nodeA = buildNode(); nodeA = buildNode();
Flotr = TestFlotr; Flotr = TestFlotr;
  });
   
  afterEach(function () {
  destroyNode(nodeA);
  a = b = null;
  Flotr = null;
  });
   
  it('should override nested default options with user options', function () {
  a = new TestFlotr.Graph(nodeA, d1, options);
  expect(a.options.xaxis.mode).toEqual(options.xaxis.mode);
  });
   
  it('should retain default options if user option\'s nested object does not define property', function () {
  a = new TestFlotr.Graph(nodeA, d1, options);
  expect(a.options.xaxis.tickFormatter).toBeTruthy();
  });
   
  it('should not affect default options when modifying graph options (objects)', function () {
  a = new TestFlotr.Graph(nodeA, d1, options);
  a.options.x2axis = {
  titleAlign: 'left'
  };
  a.options.xaxis.scaling = 'logarithmic';
  expect(TestFlotr.defaultOptions.xaxis.scaling).toEqual('linear');
  expect(TestFlotr.defaultOptions.x2axis.titleAlign).toBeFalsy();
  });
   
  /*
  it('should not affect default options when modifying graph options (arrays)', function() {
  a = new TestFlotr.Graph(nodeA, d1, options);
  a.options.colors[1] = '#bada55';
  expect(TestFlotr.defaultOptions.colors[1]).toNotBe('#bada55');
  });
  */
   
}); });
   
afterEach(function () { function buildNode() {
destroyNode(nodeA); var node = document.createElement('div');
a = b = null; document.body.appendChild(node);
Flotr = null; node.style.width = '320px';
}); node.style.height = '240px';
  return node;
  }
   
it('should override nested default options with user options', function() { function destroyNode(node) {
a = new TestFlotr.Graph(nodeA, d1, options); document.body.removeChild(node);
expect(a.options.xaxis.mode).toEqual(options.xaxis.mode); }
});  
   
it('should retain default options if user option\'s nested object does not define property', function() {  
a = new TestFlotr.Graph(nodeA, d1, options);  
expect(a.options.xaxis.tickFormatter).toBeTruthy();  
});  
   
it('should not affect default options when modifying graph options (objects)', function() {  
a = new TestFlotr.Graph(nodeA, d1, options);  
a.options.x2axis = {  
titleAlign : 'left'  
};  
a.options.xaxis.scaling = 'logarithmic';  
expect(TestFlotr.defaultOptions.xaxis.scaling).toEqual('linear');  
expect(TestFlotr.defaultOptions.x2axis.titleAlign).toBeFalsy();  
});  
   
/*  
it('should not affect default options when modifying graph options (arrays)', function() {  
a = new TestFlotr.Graph(nodeA, d1, options);  
a.options.colors[1] = '#bada55';  
expect(TestFlotr.defaultOptions.colors[1]).toNotBe('#bada55');  
});  
*/  
   
});  
   
function buildNode () {  
var node = document.createElement('div');  
document.body.appendChild(node);  
node.style.width = '320px';  
node.style.height = '240px';  
return node;  
}  
   
function destroyNode (node) {  
document.body.removeChild(node);  
}  
   
}); });