scatterplot-datalet.html 3.55 KB

<link rel="import" href="../base-ajax-json-alasql-datalet/base-ajax-json-alasql-datalet.html">


<dom-module id="scatterplot-datalet">
    <template>
        <link rel="stylesheet" href="../../bower_components/d3-scatterplot/dist/d3-scatterplot.min.css">
        <style is="custom-style">
            :host ::content #scatterplot-placeholder {
                width: 100%;
                height: 70%;
                background: #ffffff;
                position: relative;
            }
        </style>
        <div id="scatterplot-placeholder"></div>
        <base-ajax-json-alasql-datalet data-url="{{dataUrl}}" fields="{{fields}}" data="{{data}}" title="{{title}}" description="{{description}}" export_menu="{{export_menu}}"></base-ajax-json-alasql-datalet>
    </template>
    <script src="../shared_js/d3.js"></script>
    <script type="text/javascript" src="../../bower_components/d3-scatterplot/dist/d3-scatterplot.js"></script>
    <script>

        var ScatterplotBehavior = {
            presentData: function () {

                var self =this;
                var scatterSeries = [];
                var series = [];
                var point = [];

                for (var j = 0; j < this.data[0]["data"].length; j++) {
                    point = [this.data[0].data[j], this.data[1].data[j]];
                    series.push(point);
                }

                scatterSeries.push({data: series});

                this.properties.series = scatterSeries;
                this._component.legend = false;

                var conf = {
//                    width: 500,
//                    height: 500,
                    x:{
                        label: self._component.yAxisLabel
                    },
                    y:{
                        label: self._component.yAxisLabel
                    },
                    dot: {
                        // color: 'red'
                    }
                };

                var plot = new D3ScatterPlot("#scatterplot-placeholder", this.properties.series[0].data, conf);
                plot.init();
            }
        };

        ScatterplotDatalet = Polymer({
            is: 'scatterplot-datalet',
            properties: {
                xAxisLabel: {
                    type: String,
                    value: ""
                },
                yAxisLabel: {
                    type: String,
                    value: ""
                },
                behavior : {
                    type : Object,
                    value : {}
                },
                /**
                 * Control the export menu
                 * xxxx BITMASK. FROM RIGHT : HTML, PNG, RTF, MY SPACE (eg. 1111 show all, 0000 hide all)
                 *
                 * @attribute export_menu
                 * @type Number
                 * @default 15
                 */
                export_menu : {
                    type  : Number,
                    value : 15 // xxxx BITMASK. FROM RIGHT : HTML, PNG, RTF, MY SPACE (eg. 1111 show all, 0000 hide all)
                }
            },

            /**
             * 'ready' callback extend the scatterchartComponentBehavior with HighchartsComponentBehavior and scatterchartBehavior
             * and run the Datalet workcycle.
             *
             * @method ready
             */
            ready: function(){
                this.behavior = $.extend(true, {}, BaseDataletBehavior, WorkcycleBehavior, AjaxJsonAlasqlBehavior, ScatterplotBehavior);
                this.async(function(){this.behavior.init(this)},0);
            }
        });
    </script>
</dom-module>