How to modify highcharter htmlwidget code

可紊 提交于 2019-12-13 01:22:51

问题


I want to change the core code of the highcharter in R (the requirement comes from this post). I want to change core code of the highcharts in R as I know how to modify it in javascript:

(function(H) {
  (...)

  H.seriesTypes.column.prototype.translate3dShapes = function() {
      (...)    

        point.shapeType = 'cuboid';
        shapeArgs.z = z;
        shapeArgs.depth = point.options.depth; // changed from: shapeArgs.depth = depth;
        shapeArgs.insidePlotArea = true;

      (...) 
  };

})(Highcharts);

Calling this code using js_typeof or such as these solutions can't be helpful anymore.

The question is *how to change the core code of the highcharter in R


回答1:


You can create your custom highchart widget using the following:

  • First you can have a minimal widget with highcharter::highchartzero(). This custom widget only load highcharts.js.
  • Then add the highcharts3d using highcharter::hc_add_dependency("highcharts-3d.js")
  • Finally you can add the js as a dependency to the widget using htmltools::htmlDependency function (internally hc_add_dependency uses this function)

The code will be something like (not tested) this:

hc <- highcharter::highchartzero() %>% 
  highcharter::hc_add_dependency("highcharts-3d.js")

hc # see the source code and see only highcharts and highcharts-3d is loaded.

# adding depedency
dep <- htmlDependency(
    name = "change-depth",
    version = "1.0.0",
    src = "the/folder/", # absolute path I think!
    script = "your_js_script.js"
  )

hc$dependencies <- c(hc$dependencies, list(dep))

hc # see the source again

hc %>% hc_add_series(...) # add the data


来源:https://stackoverflow.com/questions/47998499/how-to-modify-highcharter-htmlwidget-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!