api.chart.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { Chart } from './core'
  2. Chart.prototype.resize = function(size) {
  3. var $$ = this.internal,
  4. config = $$.config
  5. config.size_width = size ? size.width : null
  6. config.size_height = size ? size.height : null
  7. this.flush()
  8. }
  9. Chart.prototype.flush = function() {
  10. var $$ = this.internal
  11. $$.updateAndRedraw({
  12. withLegend: true,
  13. withTransition: false,
  14. withTransitionForTransform: false
  15. })
  16. }
  17. Chart.prototype.destroy = function() {
  18. var $$ = this.internal
  19. window.clearInterval($$.intervalForObserveInserted)
  20. if ($$.resizeTimeout !== undefined) {
  21. window.clearTimeout($$.resizeTimeout)
  22. }
  23. window.removeEventListener('resize', $$.resizeIfElementDisplayed)
  24. // Removes the inner resize functions
  25. $$.resizeFunction.remove()
  26. // Unbinds from the window focus event
  27. $$.unbindWindowFocus()
  28. $$.selectChart.classed('c3', false).html('')
  29. // MEMO: this is needed because the reference of some elements will not be released, then memory leak will happen.
  30. Object.keys($$).forEach(function(key) {
  31. $$[key] = null
  32. })
  33. return null
  34. }