Quellcode durchsuchen

Expose widget-specific `chart` with a `chart()` method

master
Garrick Aden-Buie vor 6 Jahren
Ursprung
Commit
f0a3bf9fd5
2 geänderte Dateien mit 15 neuen und 1 gelöschten Zeilen
  1. +11
    -0
      dev/dev.Rmd
  2. +4
    -1
      inst/htmlwidgets/frappeChart.js

+ 11
- 0
dev/dev.Rmd Datei anzeigen

@@ -502,3 +502,14 @@ To make this work we will:

1. refactor the JS-side data processing code
1. make the created `chart` object available outside `renderValue()`
1. bind the factory function context to `el` as `widget`
1. Demo this by opening a rendered widget and showing `widget` as attached to the div
1. expose `chart` with a `chart()` method
1. Demo by finding widget div and running
```
let c = $0.widget.chart()
c.addDataPoint(2017, [2500, 1500])
```
1. Now, if nothing else, the `chart` object is accessible
so others can use or extend it.

+ 4
- 1
inst/htmlwidgets/frappeChart.js Datei anzeigen

@@ -32,6 +32,7 @@ HTMLWidgets.widget({
return {

renderValue: function(x) {
el.widget = this
x.data = prepareChartData(x.data)

chart = new frappe.Chart(el, x)
@@ -41,7 +42,9 @@ HTMLWidgets.widget({

// TODO: code to re-render the widget with a new size

}
},

chart: () => chart

};
}

Laden…
Abbrechen
Speichern