/*global jQuery, google */

(function ($, g) {
    'use strict';

    g.load('visualization', '1', {
        packages: ['corechart'],
        callback: function () {
            var options = {
                    backgroundColor: '#eee',
                    hAxis: {title: 'Risk %'},
                    legend: 'none',
                    title: 'Graph based on the latest 100 portfolios',
                    vAxis: {title: 'Return %'}
                },
                chart = new g.visualization.ScatterChart(
                    $('#efficient-frontier').get()[0]);

            chart.setAction({
                id: "portfolioDetails",
                text: "",
                action: function () {
                    console.log(chart.getSelection());
                }
            });

            function percentageFormatter(number) {
                return (number * 100).toFixed(2) * 1;
            }

            function handleRender(e, data) {
                var dataArray = [
                    ['Risk', 'Return']
                ];

                data.rows.forEach(function (ptf) {
                    dataArray.push([
                        percentageFormatter(parseFloat(ptf.value.risk)),
                        percentageFormatter(parseFloat(ptf.value.ret))
                    ]);
                });

                chart.draw(g.visualization.arrayToDataTable(dataArray),
                    options);
            }

            $.subscribe('render.latestptfschart.conpa', handleRender);

        }
    });

}(jQuery, google));

/*global jQuery, google */

(function ($, g) {
    'use strict';

    g.load('visualization', '1', {
        packages: ['corechart'],
        callback: function () {
            function percentageFormatter(number) {
                return (number * 100).toFixed(2) * 1;
            }

            function handleRender(e, data) {
                var options = {
                        backgroundColor: '#eee',
                        title: 'Graph based on the latest 100 portfolios',
                        hAxis: {title: 'Risk %'},
                        vAxis: {title: 'Return %'},
                        legend: 'none'
                    },
                    dataArray = [],
                    dataTable = new google.visualization.DataTable(),
                    chart = new g.visualization.ScatterChart(
                        $('#efficient-frontier').get()[0]);

                dataTable.addColumn('number', 'Risk');
                dataTable.addColumn('number', 'Return');
                dataTable.addColumn({type: 'string', role: 'tooltip'});

                data.rows.forEach(function (ptf) {
                    var risk = percentageFormatter(parseFloat(ptf.value.risk)),
                        ret = percentageFormatter(parseFloat(ptf.value.ret)),
                        perf = percentageFormatter(parseFloat(ptf.value.perf));

                    dataArray.push([risk, ret,
                        "Risk: " + risk + "%\n" +
                        "Return: " + ret + "%\n" +
                        "Performance: " + perf + "%"
                    ]);
                });
                dataTable.addRows(dataArray);

                chart.draw(dataTable, options);
            }

            $.subscribe('render.latestptfschart.conpa', handleRender);
        }
    });

}(jQuery, google));

Add tooltip to the latest ptf chart.
Add tooltip to the latest ptf chart.
