Sha256: f44c6e7127ce053072b9b33ca402b3c337a360a5510abf1f0438b760a612a24d

Contents?: true

Size: 1.14 KB

Versions: 21

Compression:

Stored size: 1.14 KB

Contents

// NB Chartkick and Highcharts are defined as global in rollup
const Chartkick = window.Chartkick

import { Controller } from "stimulus"

export default class extends Controller {
  static targets = [ "chart" ]

  // Called on ajax:success
  redisplay(event) {
    // let [json, status, xhr] = event.detail
    let json = event.detail[0]
    if (this.chartCreated()) {
      this.chartTarget.getChartObject().updateData(json)
    } else {
      new Chartkick.LineChart("chart1", json, this.chartOptions)
    }
  }

  // Returns true if the chart target has already been initialised
  chartCreated() {
    return Object.prototype.hasOwnProperty.call(this.chartTarget, "getChartObject")
  }

  get chartOptions() {
    return {
      curve: false,
      library: {
        chart: {
          zoomType: "x"
        },
        plotOptions: {
          series: {
            animation: {
              duration: 400
            }
          }
        },
        colors: [
          "#005eb8",
          "#009639",
          "#434348",
          "#90ed7d",
          "#f7a35c",
          "#8085e9",
          "#f15c80",
          "#e4d354"
        ]
      }
    }
  }
}

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
renalware-core-2.1.1 app/javascript/renalware/controllers/charts_controller.js
renalware-core-2.1.0 app/javascript/renalware/controllers/charts_controller.js
renalware-core-2.0.167 app/javascript/renalware/controllers/charts_controller.js
renalware-core-2.0.166 app/javascript/renalware/controllers/charts_controller.js
renalware-core-2.0.165 app/javascript/renalware/controllers/charts_controller.js
renalware-core-2.0.164 app/javascript/renalware/controllers/charts_controller.js
renalware-core-2.0.163 app/javascript/renalware/controllers/charts_controller.js
renalware-core-2.0.162 app/javascript/renalware/controllers/charts_controller.js
renalware-core-2.0.161 app/javascript/renalware/controllers/charts_controller.js
renalware-core-2.0.160 app/javascript/renalware/controllers/charts_controller.js
renalware-core-2.0.159 app/javascript/renalware/controllers/charts_controller.js
renalware-core-2.0.158 app/javascript/renalware/controllers/charts_controller.js
renalware-core-2.0.157 app/javascript/renalware/controllers/charts_controller.js
renalware-core-2.0.156 app/javascript/renalware/controllers/charts_controller.js
renalware-core-2.0.155 app/javascript/renalware/controllers/charts_controller.js
renalware-core-2.0.153 app/javascript/renalware/controllers/charts_controller.js
renalware-core-2.0.152 app/javascript/renalware/controllers/charts_controller.js
renalware-core-2.0.151 app/javascript/renalware/controllers/charts_controller.js
renalware-core-2.0.149 app/javascript/renalware/controllers/charts_controller.js
renalware-core-2.0.148 app/javascript/renalware/controllers/charts_controller.js