<#@ template language="C#" HostSpecific="True" #>
<#@ output extension=".cshtml" #>
<#@ include file="..\..\ViewHead.cshtml.include.t4" #>
<#@ parameter name="DbContextTypeName" type="System.String" #>
@using C1.Web.Mvc.Chart
@using System.Drawing
@addTagHelper *, C1.AspNetCore.Mvc
<#@ include file="..\..\FunctionTemplate.include.t4"#>
<#@ include file="..\..\ClientFunctions.include.t4" #>
<#@ include file="..\..\ClientEvent.include.t4" #>
<#@ include file="BaseChart.Core.include.t4" #>

<#
    if(!Options["UseRemoteBind"] && !string.IsNullOrEmpty(Options["EntitySetName"]))
    {
#>
@model IEnumerable<<#= ViewDataTypeName #>>

<#
    }

    bool isFlexChart = Options["ControlType"] == "FlexChart";
    string controlType = isFlexChart? "chart": "radar";
    List<FunctionTemplate> functions = new List<FunctionTemplate>();
    int index = 1;
    foreach (var series in Options["SeriesList"])
    {
        if(series["SeriesType"] == "YFunctionSeries")
        {
            series["Func"] = "yFunctionSeries_Fun" + index;

            var func = new FunctionTemplate();
            func.Name = series["Func"];
            func.Parameters = new List<string> { "value" };
            functions.Add(func);
        }
        else if (series["SeriesType"] == "ParametricFunctionSeries")
        {
            series["XFunc"] = "parametricFunctionSeries_XFun" + index;
            series["YFunc"] = "parametricFunctionSeries_YFun" + index;

            var xFunc = new FunctionTemplate();
            xFunc.Name = series["XFunc"];
            xFunc.Parameters = new List<string> { "value" };
            functions.Add(xFunc);
            var yFunc = new FunctionTemplate();
            yFunc.Name = series["YFunc"];
            yFunc.Parameters = new List<string> { "value" };
            functions.Add(yFunc);
        }
        index++;
    }
    if(isFlexChart && Options["LineMarker"]["IsDirty"] && Options["LineMarker"]["ShowContent"])
    {
        var marker = new FunctionTemplate();
        marker.Name = "lineMarkerContent";
        marker.Body = "return '<div>x:' + pt.x + ', y:' + pt.y + '</div>';";
        marker.Parameters = new List<string> { "hitInfo", "pt" };
        functions.Add(marker);
    }
    GenerateFunctions(functions);
    GenerateSVG();
#>

<c1-flex-<#= controlType #><#
    PushIndentAndCount("c1-flex-" + controlType); // indent for attributes of c1-flex-chart tag
    ResetLineLength();

    GenerateLegend(false);
    GenerateBindingAttributes(false);
    GenerateSelection(false);
    GenerateHeaderFooter();
    GenerateAppearance(false);
    GenerateClientEvents();

    PopIndentAndCount();//remove indent for attributes of c1-flex-chart tag

#>><#

    GenerateHeaderFooterStyle();
    GenerateDataLabel(false);
    GenerateAnimation();
    GenerateDataBind();
    GenerateTooltip();

    //SeriesList
    if(Options["SeriesList"].Length > 0)
    {
        // SerieList
        foreach (var series in Options["SeriesList"])
        {
            string seriesType = series["SeriesType"];
            WriteLine("");
            switch(seriesType)
            {
                case "Normal" :
                Write("    <c1-flex-chart-series");
                GenerateSeries(series);
                Write("    </c1-flex-chart-series>");
                break;

                case "RadarSeries" :
                Write("    <c1-flex-radar-series");
                GenerateSeries(series);
                Write("    </c1-flex-radar-series>");
                break;

                case "TrendLine" :
                Write("    <c1-flex-chart-trendline");
                GenerateTrendLineSeries(series);
                Write("    </c1-flex-chart-trendline>");
                break;

                case "MovingAverage" :
                Write("    <c1-flex-chart-movingaverage");
                GenerateMovingAverageSeries(series);
                Write("    </c1-flex-chart-movingaverage>");
                break;

                case "YFunctionSeries" :
                Write("    <c1-flex-chart-yfunction");
                GenerateYFunctionSeries(series);
                Write("    </c1-flex-chart-yfunction>");
                break;

                case "ParametricFunctionSeries" :
                Write("    <c1-flex-chart-parameterfunction");
                GenerateParametricFunctionSeries(series);
                Write("    </c1-flex-chart-parameterfunction>");
                break;

                case "WaterfallSeries" :
                Write("    <c1-flex-chart-waterfall");
                GenerateWaterfall(series);
                Write("    </c1-flex-chart-waterfall>");
                break;

                case "BoxWhiskerSeries" :
                Write("    <c1-flex-chart-boxwhisker");
                GenerateBoxWhisker(series);
                Write("    </c1-flex-chart-boxwhisker>");
                break;

                case "ErrorBarSeries" :
                Write("    <c1-flex-chart-error-bar");
                GenerateErrorBar(series);
                Write("    </c1-flex-chart-error-bar>");
                break;
            }
        }
    }
    else
    {
        if(!string.IsNullOrEmpty(Options["EntitySetName"]))
        {
            WriteLine("");
            Write("    <c1-flex-" + controlType + "-series />");
        }
    }


    //Axes
    if(Options["AxisX"]["IsDirty"])
    {
        GenerateAxis(Options["AxisX"], "AxisX", "    ");
    }

    if(Options["AxisY"]["IsDirty"])
    {
        GenerateAxis(Options["AxisY"], "AxisY", "    ");
    }

    //Annotations
    if(isFlexChart && Options["Annotations"].Length > 0)
    {
#>

    <c1-annotation-layer><#
        foreach (var annotation in Options["Annotations"])
        {
            WriteLine("");
            string type = annotation["Type"];
            if(!annotation["IsDirty"])
            {#>
        <c1-annotation-<#= type.ToLower() #> /><#
            }
            else 
            {
                switch(type)
                {
                    case "Circle" : #>
        <c1-annotation-circle<#
                    GenerateCircle(annotation);#>>
        </c1-annotation-circle><#
                    break;

                    case "Ellipse" : #>
        <c1-annotation-ellipse<#
                    GenerateEllipse(annotation);#>>
        </c1-annotation-ellipse><#
                    break;

                    case "Image" : #>
        <c1-annotation-image<#
                    GenerateImage(annotation);#>>
        </c1-annotation-image><#
                    break;

                    case "Line" : #>
        <c1-annotation-line<#
                    GenerateLine(annotation);#>>
        </c1-annotation-line><#
                    break;

                    case "Rectangle" : #>
        <c1-annotation-rectangle<#
                    GenerateRectangle(annotation);#>>
        </c1-annotation-rectangle><#
                    break;

                    case "Square" : #>
        <c1-annotation-square<#
                    GenerateSquare(annotation);#>>
        </c1-annotation-square><#
                    break;

                    case "Text" : #>
        <c1-annotation-text<#
                    GenerateShape(annotation);#>>
        </c1-annotation-text><#
                    break;

                    case "Polygon" : #>
        <c1-annotation-polygon<#
                    GenerateShape(annotation);#>><#
                    GeneratePolygon(annotation);#>

        </c1-annotation-polygon><#
                    break;
            }
        }
    }
#>

    </c1-annotation-layer><#
    }

    if(isFlexChart && Options["RangeSelector"]["UseRangeSelector"])
    {
        WriteLine("");
        Write("    <c1-range-selector");
        if(Options["RangeSelector"]["IsDirty"])
        {
            var range = Options["RangeSelector"];
            if(!range["IsVisible"])
            {
                WriteAttribute("is-visible", "false");
            }
            if(range["Max"] != null)
            {
                WriteAttribute("max", range["Max"] + "f");
            }
            if(range["Min"] != null)
            {
                WriteAttribute("min", range["Min"] + "f");
            }
            if(range["Orientation"] != "X")
            {
                WriteAttribute("orientation", range["Orientation"]);
            }
            if(range["Seamless"])
            {
                WriteAttribute("seamless", "true");
            }
        }
        Write(" />");
    }

    if(isFlexChart && Options["LineMarker"]["UseLineMarker"])
    {
        var marker = Options["LineMarker"];
        WriteLine("");
        Write("    <c1-line-marker");
        if(Options["LineMarker"]["IsDirty"])
        {
            if(!marker["IsVisible"])
            {
                WriteAttribute("is-visible", "false");
            }
            if(marker["Alignment"] != "Auto")
            {
                WriteAttribute("alignment", marker["Alignment"]);
            }
            if(marker["ShowContent"])
            {
                WriteAttribute("content", "lineMarkerContent");
            }
            if(marker["Interaction"] == "Drag")
            {
                if(marker["DragContent"])
                {
                    WriteAttribute("drag-content", "true");
                }
                if(marker["DragLines"])
                {
                    WriteAttribute("drag-lines", "true");
                }
                if(marker["DragThreshold"] != 0)
                {
                    WriteAttribute("drag-threshold", marker["DragThreshold"]);
                }
            }
            if(marker["Interaction"] != "None")
            {
                if(marker["HorizontalPosition"] != null)
                {
                    WriteAttribute("horizontal-position", marker["HorizontalPosition"] + "f");
                }
                if(marker["SeriesIndex"] != null)
                {
                    WriteAttribute("series-index", marker["SeriesIndex"]);
                }
                if(marker["VerticalPosition"] != null)
                {
                    WriteAttribute("vertical-position", marker["VerticalPosition"] + "f");
                }
                WriteAttribute("interaction", marker["Interaction"]);
            }
            if(marker["Lines"] != "None")
            {
                WriteAttribute("lines", marker["Lines"]);
            }
        }
        Write(" />");
    }
    if(isFlexChart)
    {
        GeneratePlotAreas();
    }
    if(isFlexChart && Options["Options"]["Funnel"]["IsDirty"])
    {
        var funnel = Options["Options"]["Funnel"];
        WriteLine("");
        Write("    <c1-chart-options>");
        WriteLine("");
        Write("        <c1-funnel-options");
        if(funnel["NeckWidth"] != 0.2f)
        {
            WriteAttribute("neck-width", funnel["NeckWidth"] + "F");
        }
        if(funnel["NeckHeight"] != 0f)
        {
            WriteAttribute("neck-height", funnel["NeckHeight"] + "F");
        }
        if(funnel["Type"] != "Default")
        {
            WriteAttribute("type", "Rectangle");
        }

        WriteLine(" />");
        Write("    </c1-chart-options>");
    }
#>

</c1-flex-<#= controlType #>>


