/// <reference path="~/GeneratedArtifacts/viewModel.js" />
/// <reference path="../Scripts/wijmo.cba.js" />

myapp.ChartHitTest.FlexChart_render = function (element, contentItem) {
    var chart = new c1.cba.FlexChart($(element), contentItem);
    var collectionView = new c1.cba.LightSwitchCollectionView(contentItem);
    chart.wjControl.itemsSource = collectionView;
    myapp.chart = chart.wjControl;
};

myapp.ChartHitTest.Info_render = function (element, contentItem) {
    var chart = myapp.chart,
        formatHitInfo = function (hitInfo, pt) {
            var s = '<div>Chart element: ' + wijmo.chart.ChartElement[hitInfo.chartElement] + '</div>';
            if (hitInfo.series) {
                s += '<div>Series name: ' + hitInfo.series.name;
                if (hitInfo.pointIndex !== null) {
                    s += '<div>Point index: ' + hitInfo.pointIndex + '</div>';
                    s += '<div>Distance: ' + hitInfo.distance.toFixed(0) + '</div>';

                    if (hitInfo.chartElement == wijmo.chart.ChartElement.PlotArea) {
                        s += '<div>x: ' + pt.x.toFixed(2) + '</div>';
                        s += '<div>y: ' + pt.y.toFixed(2) + '</div>';
                    }
                }
            }
            return s;
        }, info = $("<div id=\"info\"></div>").appendTo($(element));

    chart.hostElement.onmousemove = function (e) {
        var hit = chart.hitTest(e);
        var info = document.getElementById("info");
        info.innerHTML = formatHitInfo(hit, chart.pointToData(e));
    };
};