<!--
    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="../ti-widget-common-behaviors/ti-widget-common-behaviors.html">
<link rel="import" href="../paper-icon-button/paper-icon-button.html">
<link rel="import" href="../iron-icons/device-icons.html">
<link rel="import" href="../ti-widget-graphs/ti-widget-temperaturegraph.html">
<link rel="import" href="ti-tile-properties.html">
<link rel="import" href="ti-tile-base.html">
<link rel="import" href="ti-tile-styles.html">
<link rel="import" href="../iron-flex-layout/iron-flex-layout.html">
<!--
`ti-tile-temperaturegraph` is an empty container widget to host child widgets.

Example:

    <ti-tile-temperaturegraph></ti-tile-temperaturegraph>

See demo for a full working example of how to use this component.

@group Instrument Tiles
@element ti-tile-temperaturegraph
@demo demo.html
@extends ti-tile-base
@homepage ../../../ti-guicomposer-helpindex/demo.html
-->
<dom-module id='ti-tile-temperaturegraph'  >

    <template>
        <style  is="custom-style" include="ti-tile-styles">
            :host {
                width: 470px;
                min-width: 250px;
                min-height:150px;
            }
            #instrument_div {
                width: 100%;
                top: 0;
                bottom: 0;
            }
            #instrument {
                top: 0px;
                bottom: 5px;
                right: 5px;
                left: 5px;
                position: absolute;
                display:block;

            }
        </style>
        <div id="containerDiv" layout vertical style$="background-color:{{backgroundColor}};padding:{{containerPadding}};">
	        <div id="shadow-bottom" fit class$="paper-material-bottom-z-[[elevation]]"></div>
	        <div id="shadow-top" fit class$="paper-material-top-z-[[elevation]]"></div>
            <div id="tileTitle" style$="display:flex;align-items:center;justify-content:left;top:0;left:0;width:calc(100%+26px);margin:-13px;[[titleStyle]];">
                <span style="vertical-align:middle;margin:13px;text-align:left;">[[titleText]]: {{value}} &deg;{{temperatureScale}}</span>
            </div>
            <div id="instrument_div" flex>
                <ti-widget-temperaturegraph id="instrument" temperature="{{value}}" fixed-scale min-temp-k="{{minValue}}" max-temp-k="{{maxValue}}" min-temp-c="{{minValue}}" max-temp-c="{{maxValue}}" min-temp-f="{{minValue}}" max-temp-f="{{maxValue}}" temperature-scale="{{temperatureScale}}" target-temperature-scale="{{targetTemperatureScale}}" seconds-between-ticks="{{secondsBetweenTicks}}" num-values-to-plot="{{numValuesToPlot}}"></ti-widget-temperaturegraph>
            </div>
            <template is="dom-if" restamp="true" if="{{_isInDesigner}}">
                <paper-icon-button id="editIcon"  class="pointer" icon="create" on-tap="editProperties" title="edit tile properties" style$="[[_getIconStyle(_iconColor)]]" ></paper-icon-button>
                <paper-icon-button id="moveLeftIcon" class="pointer" icon="arrow-back" on-tap="moveLeft" title="move tile left" style$="[[_getArrowStyle(_arrowStyle,_iconColor)]]"></paper-icon-button>
                <paper-icon-button id="moveRightIcon" class="pointer" icon="arrow-forward" on-tap="moveRight" title="move tile right" style$="[[_getArrowStyle(_arrowStyle,_iconColor)]]"></paper-icon-button>
                <paper-icon-button id="resizeIcon" class="resize" icon="device:signal-cellular-0-bar"  title="resize tile"  style$="[[_getIconStyle(_resizeCornerColor)]]"></paper-icon-button>
                <paper-icon-button id="pinIcon" class="pointer" icon="{{_pinIcon}}" on-tap="togglePin" style$="[[_getIconStyle(_iconColor)]]"></paper-icon-button>
            </template>

        </div>
        <content></content>
    </template>
    <script>
        Polymer ({
            is: 'ti-tile-temperaturegraph',


            hostAttributes: {
            },
            behaviors: [TiTileBase],
            properties: {
                /**
                 * The title to display at the top of the tile
                 *
                 * @attribute titleText
                 * @type string
                 * @default ''
                 */
                titleText: {
                    notify: true,
                    type: String,
                    value: "Temperature"
                },
                /**
                 * The temperature value to display in the graph
                 *
                 * @attribute value
                 * @type Number
                 * @default 0
                 */
                value: {
                    notify: true,
                    type: Number,
                    value: 0
                },
				/**
                 * The minimum value to display in the graph
                 *
                 * @attribute minValue
                 * @type Number
                 * @default 0
                 */
                minValue: {
                    notify: true,
                    type: Number,
                    value: 0
                },
				/**
                 * The maximum value to display in the graph
                 *
                 * @attribute maxValue
                 * @type Number
                 * @default 100
                 */				
                maxValue: {
                    notify: true,
                    type: Number,
                    value: 100
                },
				/**
                 * The temperature scale that the values are to be displayed in:
				 * - use C for Celsius
				 * - use F for Farenheit
				 * - use K for Kelvin
                 *
                 * @attribute temperatureScale
                 * @type string
                 * @default "F"
                 */	
                temperatureScale: {
                    notify: true,
                    type: String,
                    value: "F"
                },
				/**
                 * The temperature scale that the values sent from the target are in:
				 * - use C for Celsius
				 * - use F for Farenheit
				 * - use K for Kelvin
                 *
                 * @attribute targetTemperatureScale
                 * @type string
                 * @default "F"
                 */	
                targetTemperatureScale: {
                    notify: true,
                    type: String,
                    value: "F"
                },
				/**
                 * The number of seconds that are to elapse before adding another time scale value
                 *
                 * @attribute secondsBetweenTicks
                 * @type Number
                 * @default 15
                 */	
                secondsBetweenTicks: {
                    notify: true,
                    type: Number,
                    value: 15
                },
				/**
                 * The max. number of values to display at one time in the graph
                 *
                 * @attribute numValuesToPlot
                 * @type Number
                 * @default 75
                 */					
                numValuesToPlot: {
                    notify: true,
                    type: Number,
                    value: 75
                }
            },

            getCategory: function() {
                return 'Graph';
            },
            getComponentName: function() {
                return 'Sliding Temperature Graph';
            },
            ready: function() {
                this.async(function() {
                    this.onResizedByDesigner();
                }.bind(this),0);
            },
            onResizedByDesigner: function(){
				if (this.$ && this.$.instrument.onResize) {
					this.$.instrument.onResize();
				}
            }

        });
    </script>
</dom-module>
