GraFiddle / angular-chart

AngularJS directive for adjustable dynamically updating c3 charts
http://grafiddle.github.io/angular-chart/
MIT License
127 stars 40 forks source link

Exposed the "resize()" function of c3 to outside. #34

Closed ulilicht closed 9 years ago

ulilicht commented 9 years ago

Hi Max,

I'd like to expose the resize() function from c3; I need to call it when resizing the div which contains the chart but not resizing the window itself.

Unfortunately, I could not figure out how to test this functionality. I don't know how to get the "chart" property of the directive in the test. If I could, I would maybe test it like this:

describe('. resize', function () { it('- Resize on chart should be callable from outside.', function () {

  directiveScope.chart = {resize: angular.noop};
  spyOn(directiveScope.chart, 'resize');
  elementScope.options.resize();

  expect(directiveScope.chart.resize()).toHaveBeenCalled();

});

}); Where directiveScope is the scope of the directive and elementScope is the scope of outside.

Something else: Unfortunately, it seems that indentation of my changes are not correct. Can you tell me, how to use your project style in Webstorm/PHPStorm?

coveralls commented 9 years ago

Coverage Status

Coverage decreased (-0.35%) when pulling c0b9da1188d2cc82c931979b8f1eaeeebbc24aa9 on ulilicht:develop into ee42934036f574cb3fc917ead8fd0258f7efc4fd on maxklenk:develop.

maxklenk commented 9 years ago

Thank you for pointing out this function. I added this feature and the corresponding size options to ensure that the current state of the chart is always represented in the options.

The Idea of your test was totally right, just replace directiveScope with elementScope and use $scope for the outer elementScope:

it('- Chart should be resized when called.', function () {
  // setup spys
  spyOn(elementScope.chart, 'resize');

  // set option
  var size = {
    width: 300,
    heigth: 100
  };
  $scope.options.resize(size);

  // check configuration change
  expect(elementScope.configuration.size).toBe(size);
  expect(elementScope.chart.resize).toHaveBeenCalled();
});

I will add a .editorconfig file later, which will define the indentation and provides plugins for all major editor: http://editorconfig.org/