Sha256: d4ab7e9a859f7e5ea489de90bac5ab15e8f10f881580634c4480e73a7ac43e40

Contents?: true

Size: 979 Bytes

Versions: 1

Compression:

Stored size: 979 Bytes

Contents

import { Controller } from "@hotwired/stimulus"
import { Chart, registerables } from "https://cdn.jsdelivr.net/npm/chart.js@4.4.7/+esm"

Chart.register(...registerables)

Chart.defaults.backgroundColor = getCssVariableValue("--color-primary")
Chart.defaults.borderColor = getCssVariableValue("--color-border")
Chart.defaults.color = getCssVariableValue("--color-text")

Chart.defaults.font.family = getCssVariableValue("--font-system-ui")
Chart.defaults.font.size = 12

function getCssVariableValue(variableName) {
  return getComputedStyle(document.documentElement).getPropertyValue(variableName).trim()
}

export default class extends Controller {
  static values = { type: { type: String, default: "line" }, data: Object, options: Object }

  connect() {
    this.chart = new Chart(this.element, this.#settings)
  }

  disconnect() {
    this.chart.destroy()
  }

  get #settings() {
    return { type: this.typeValue, data: this.dataValue, options: this.optionsValue }
  }
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
css-zero-0.0.87 lib/generators/css_zero/add/templates/app/javascript/controllers/chart_controller.js