Skip to content

Chart Names for Client Side Rendering #33

Open

Description

@drcrook1

Hey,

So all charts get generated with the "drawChart()" function, which I bind the initial chart to the dom and render a new one. Any time a new chart gets rendered, all charts are redrawn. Also, if I need to update a chart, all charts are redrawn.

Any chance we can get an option to name the drawChart function for each chart? Defaulting to drawChart() is great, but an option would be nice.

Activity

  1. kmd1970 commented on Dec 23, 2016

    @kmd1970

    @drcrook1 This can be added easily, see below.

    Main.fs (line 162) replace:

    let jsTemplate =
            """google.setOnLoadCallback(drawChart);
                function drawChart() {   

    with

    let jsTemplate =
            """google.setOnLoadCallback({CALLBACK});
                function {CALLBACK}() {
                    var data = new google.visualization.DataTable({DATA});

    Main.fs (near line 296) replace:

        member __.GetInlineJS() =
            let dataJson = __.dataTable.ToGoogleDataTable().GetJson()         
            let optionsJson = JsonConvert.SerializeObject(__.options)
            Html.jsTemplate.Replace("{DATA}", dataJson)
                .Replace("{OPTIONS}", optionsJson)
                .Replace("{TYPE}", __.``type``.ToString())
                .Replace("{GUID}", __.Id)

    with

        member __.GetInlineJS() =
            let dataJson = __.dataTable.ToGoogleDataTable().GetJson()         
            let optionsJson = JsonConvert.SerializeObject(__.options)
            Html.jsTemplate.Replace("{DATA}", dataJson)
                .Replace("{CALLBACK}",__.CallBack)
                .Replace("{OPTIONS}", optionsJson)
                .Replace("{TYPE}", __.``type``.ToString())
                .Replace("{GUID}", __.Id)

    Main.fs (near line 306) add:

    member val CallBack = "drawChart" with get, set

    Main.fs (near line 329) add:

    member __.WithCallBack newCallBack = __.CallBack <- newCallBack

    Main.fs (near line 404) add:

    static member WithCallBack callback (chart:GoogleChart) =
            chart.WithCallBack callback
            chart

    You can now use the syntax:

     chart.CallBack <- "drawPieChart" 
     chart.Id <- "myPieChart"
     chart.GetInlineHtml()

    which creates

    google.setOnLoadCallback(drawPieChart);
    function drawPieChart() {
              var data = new google.visualization.DataTable( ...
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions