Przeglądaj źródła

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

master
Garrick Aden-Buie 6 lat temu
rodzic
commit
f0a3bf9fd5
2 zmienionych plików z 15 dodań i 1 usunięć
  1. +11
    -0
      dev/dev.Rmd
  2. +4
    -1
      inst/htmlwidgets/frappeChart.js

+ 11
- 0
dev/dev.Rmd Wyświetl plik



1. refactor the JS-side data processing code 1. refactor the JS-side data processing code
1. make the created `chart` object available outside `renderValue()` 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 Wyświetl plik

return { return {


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


chart = new frappe.Chart(el, x) chart = new frappe.Chart(el, x)


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


}
},

chart: () => chart


}; };
} }

Ładowanie…
Anuluj
Zapisz