Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chart Names for Client Side Rendering #33

Open
drcrook1 opened this issue Apr 19, 2016 · 1 comment
Open

Chart Names for Client Side Rendering #33

drcrook1 opened this issue Apr 19, 2016 · 1 comment

Comments

@drcrook1
Copy link

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.

@kmd1970
Copy link

kmd1970 commented Dec 23, 2016

@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
Projects
None yet
Development

No branches or pull requests

3 participants