Sha256: 2edf849716f53ffe431399271c36407528f7b7c348e2dfe40e622320e267ba94

Contents?: true

Size: 1.84 KB

Versions: 15

Compression:

Stored size: 1.84 KB

Contents

import Highcharts from 'highcharts'

import { highchartsTheme } from '../pb_dashboard/pbChartsLightTheme.js'

class pbChart {
  defaults = {
    callbackInitializeBefore: () => {},
    callbackInitializeAfter: () => {},
    callbackRefreshBefore: () => {},
    callbackRefreshAfter: () => {},
    callbackDestroyBefore: () => {},
    callbackDestroyAfter: () => {},
    property: 'Value'
  }

  extendDefaults(defaults, options) {
    for (let property in options) {
      if (options.hasOwnProperty(property)) {
        defaults[property] = options[property]
      }
    }
    return defaults
  }

  constructor(element, options) {
    this.element = element
    this.options = options
    this.settings = this.extendDefaults(this.defaults, options)
    this.setupChart()
  }

  setupChart() {
    Highcharts.setOptions(highchartsTheme)

    Highcharts.chart(this.defaults.id, {
      title: {
        text: this.defaults.title
      },
      chart: {
        type: this.defaults.type
      },
      subtitle: {
        text: this.defaults.subtitle
      },
      yAxis: {
        title: {
          text: this.defaults.axisTitle
        }
      },
      plotOptions: {
        series: {
          pointStart: this.defaults.pointStart
        }
      },
      series: this.defaults.chartData,
      credits: false,
    })
  }

  refresh(silent = false) {
    if (!silent) {
      this.settings.callbackRefreshBefore.call()
    }

    this.this.destroy(silent)
    this.this.initialize(silent)
    if (!silent) {
      this.settings.callbackRefreshAfter.call()
    }
  }

  destroy(silent = false) {
    if (!silent) {
      this.settings.callbackDestroyBefore.call()
    }
    if (!silent) {
      this.settings.callbackDestroyAfter.call()
    }
  }

  refreshSilently() {
    this.this.refresh(true)
  }

  destroySilently() {
    this.this.destroy(true)
  }
}

export default pbChart

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
playbook_ui-3.0.1 app/pb_kits/playbook/plugins/pb_chart_plugin.js
playbook_ui-3.0.0 app/pb_kits/playbook/plugins/pb_chart_plugin.js
playbook_ui-2.9.9 app/pb_kits/playbook/plugins/pb_chart_plugin.js
playbook_ui-2.9.8 app/pb_kits/playbook/plugins/pb_chart_plugin.js
playbook_ui-2.9.7 app/pb_kits/playbook/plugins/pb_chart_plugin.js
playbook_ui-2.9.6 app/pb_kits/playbook/plugins/pb_chart_plugin.js
playbook_ui-2.9.5 app/pb_kits/playbook/plugins/pb_chart_plugin.js
playbook_ui-2.9.4 app/pb_kits/playbook/plugins/pb_chart_plugin.js
playbook_ui-2.9.3 app/pb_kits/playbook/plugins/pb_chart_plugin.js
playbook_ui-2.9.2 app/pb_kits/playbook/plugins/pb_chart_plugin.js
playbook_ui-2.9.1 app/pb_kits/playbook/plugins/pb_chart_plugin.js
playbook_ui-2.9.0 app/pb_kits/playbook/plugins/pb_chart_plugin.js
playbook_ui-2.8.9 app/pb_kits/playbook/plugins/pb_chart_plugin.js
playbook_ui-2.8.8 app/pb_kits/playbook/plugins/pb_chart_plugin.js
playbook_ui-2.8.7 app/pb_kits/playbook/plugins/pb_chart_plugin.js