
<!--
    Copyright (c) 2015, Texas Instruments Incorporated
    All rights reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions
    are met:

    *   Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.
    *   Neither the name of Texas Instruments Incorporated nor the names of
    its contributors may be used to endorse or promote products derived
    from this software without specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
    THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
    OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
    WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
    OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
    EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->

<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../iron-resizable-behavior/iron-resizable-behavior.html">
<link rel="import" href="../ti-widget-graphs/ti-widget-base-graph.html">
<link rel="import" href="../ti-widget-common/ti-widget-label.html">
<link rel="import" href="../iron-flex-layout/iron-flex-layout.html">
<!--
'ti-widget-linegraph' plots arrays of data as lines on a graph.  It wraps the jQuery flot library.

-   up to 4 lines can be displayed at the same time, each with its own y-axis and with all values plotted against a common x-axis.
    -   Be sure to set the numChannels property to the number of data series you wish to have displayed
-   each data series is defined as a string with comma separated values
    - the index of each array element is used to determine its position along the x-axis.
    - array elements should represent sampled data, with a common sampling rate for each array and with the data for all arrays being phase aligned.
-   properties for each data series include
    -   color
    -   min, max
    -   units (y-axis)
    -   label (for legend)
    -   xAxisLabel (to label the x-axis)

Please click on TiWidgetBaseGraph (below or in the drop-list at the top) to view documentation for the properties of this component.

@group Ti Elements
@element ti-widget-linegraph
@demo demo.html
@homepage ../ti-guicomposer-helpindex/demo.html
-->
<dom-module id='ti-widget-linegraph'  >
    <template>
        <style is="custom-style">
            /* TODO(polyup): For speed, consider reworking these styles with .classes
                     and #ids rather than [attributes].
    */
            [layout] {
            @apply(--layout);
            }
            [layout][vertical] {
            @apply(--layout-vertical);
            }
            [layout][justified] {
            @apply(--layout-justified);
            }
            [flex] {
            @apply(--layout-flex);
            }
            :host {
                transition:width 0.01s, height 0.01s;
            }
            #title {
                color: #555;
                font-size: large;
                white-space: normal;
                text-align: center;
                padding-bottom: 1em;
            }
            #chart {
                width:100%;
            }
            #xAxisLabel {
                width:100%;
                text-align:center;
                font-size:x-small;
                bottom: 0.25em;
                padding-bottom: 3px;
            }
        </style>

        <div style="height:100%; width:100%;" layout vertical justified>
            <label id="title">{{titleLabel}}</label>
            <div id="chart" flex onresize="onResize" style$="{{_getStyleTag('background-color',backgroundColor)}}" strCursorX="[[strCursorX]]"></div>
            <div id="xAxisLabel" style$="{{_isHidden(hideXAxis)}}">{{xAxisLabel}} ({{strCursorX}})</div>
            <content></content>
        </div>
    </template>

    <script>
        // global variable here, common to all instances
        var _debug = false;


        Polymer ({
            is: 'ti-widget-linegraph',
            behaviors: [
                TiWidgetBaseGraph,
                Polymer.IronResizableBehavior
            ],
            /**
             * fired when it is safe to access the graph's properties.
             *  - To receive the event notification, in javascript, use
             *  templateObj.$.<componentId>.addEventListener("graphReady",function(event){...});
             *
             * @event graphReady
             */
            properties: {
                
            },
            attached: function(){
                // notify listeners chart is ready so properties can be set
                this.async(function(){
                    this.fire("graphReady");
                }.bind(this),1)
            }
        });
    </script>

</dom-module>
