2018-07-30 22:54:39 +02:00
|
|
|
HTMLWidgets.widget({
|
|
|
|
|
|
|
|
name: 'apexcharter',
|
|
|
|
|
|
|
|
type: 'output',
|
|
|
|
|
|
|
|
factory: function(el, width, height) {
|
|
|
|
|
|
|
|
var ax_opts, chart;
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
renderValue: function(x) {
|
|
|
|
|
|
|
|
|
|
|
|
// Global options
|
|
|
|
ax_opts = x.ax_opts;
|
|
|
|
|
|
|
|
// Sizing
|
2018-08-01 23:02:29 +02:00
|
|
|
if (typeof ax_opts.chart === 'undefined') {
|
|
|
|
ax_opts.chart = {};
|
|
|
|
}
|
2018-07-30 22:54:39 +02:00
|
|
|
ax_opts.chart.width = width;
|
|
|
|
ax_opts.chart.height = height;
|
|
|
|
|
|
|
|
// Generate chart
|
|
|
|
chart = new ApexCharts(document.querySelector("#" + el.id), ax_opts);
|
|
|
|
chart.render();
|
|
|
|
|
|
|
|
},
|
2018-09-07 18:06:41 +02:00
|
|
|
|
|
|
|
getChart: function(){
|
|
|
|
return chart;
|
|
|
|
},
|
2018-07-30 22:54:39 +02:00
|
|
|
|
|
|
|
resize: function(width, height) {
|
|
|
|
chart.updateOptions({
|
|
|
|
chart: {
|
|
|
|
width: width,
|
|
|
|
height: height
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|
2018-09-07 18:06:41 +02:00
|
|
|
|
|
|
|
// From Friss tuto (https://github.com/FrissAnalytics/shinyJsTutorials/blob/master/tutorials/tutorial_03.Rmd)
|
|
|
|
function get_widget(id){
|
|
|
|
|
|
|
|
// Get the HTMLWidgets object
|
|
|
|
var htmlWidgetsObj = HTMLWidgets.find("#" + id);
|
|
|
|
|
|
|
|
// Use the getChart method we created to get the underlying billboard chart
|
|
|
|
var widgetObj ;
|
|
|
|
|
|
|
|
if (typeof htmlWidgetsObj != 'undefined') {
|
|
|
|
widgetObj = htmlWidgetsObj.getChart();
|
|
|
|
}
|
|
|
|
|
|
|
|
return(widgetObj);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (HTMLWidgets.shinyMode) {
|
|
|
|
// data = load
|
2018-09-09 22:09:05 +02:00
|
|
|
Shiny.addCustomMessageHandler('update-apexchart-series',
|
2018-09-07 18:06:41 +02:00
|
|
|
function(obj) {
|
2018-09-09 22:09:05 +02:00
|
|
|
var chart = get_widget(obj.id);
|
2018-09-07 18:06:41 +02:00
|
|
|
if (typeof chart != 'undefined') {
|
2018-09-09 22:09:05 +02:00
|
|
|
chart.updateSeries(obj.data.newSeries, obj.data.animate);
|
2018-09-07 18:06:41 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|