Facebook
From Beige Bat, 10 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 629
  1. <?xml version="1.0"?>
  2. <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
  3. <div id="lineChart"></div>
  4.  
  5. <script type="text/javascript">
  6. Object.prototype.extend = function () {
  7.    for (i in arguments) {
  8.     tempObj = new arguments[i];
  9.     for (property in tempObj) {
  10.         this[property] = tempObj[property];
  11.     }
  12.    }
  13.   };
  14.  
  15. var ChartAbstract = function() {
  16.     /**
  17.      * Szerokość wykresu
  18.      * @type number
  19.      */
  20.     this.width = null;
  21.            
  22.     /**
  23.      * Wysokośc wykresu
  24.      * @type number        
  25.      **/
  26.     this.width = null;
  27.            
  28.     /**
  29.      * Uchwyt kontenera
  30.      * @type Object
  31.      */
  32.     this.svgContainer = null;
  33.    
  34.     /**
  35.      * Dane wykresu
  36.      * @type Array
  37.      */
  38.     this.data = null;
  39.    
  40.     /**
  41.      * Dane wykresu
  42.      * @type Array
  43.      */
  44.     this.config = null;
  45.    
  46.     /**
  47.      * Stałe opisujące typy danych
  48.      */
  49.     this.NUMBER      = 'number';
  50.     this.BOOLEAN     = 'boolean';
  51.     this.OBJECT      = 'object';
  52.     this.STRING      = 'string';
  53.     this.UNDEFINED   = 'undefined';
  54.    
  55.    
  56.     /**
  57.      * Domyslna konfiguracja
  58.      * @type Object
  59.      */
  60.     this.defaultConfig = {
  61.         showLines: 1, //Czy pokazywać linie
  62.         animate: 0 //Czy animować
  63.     }    
  64.        
  65.     /**
  66.      * Zwraca wartośc konfiguracji generatora(piewsze sprawdza przesłaną przez użytkownika a później domyślną)
  67.      *
  68.      * @param string key Klucz konfiguracji z tablicy
  69.      * @param string type Opcjonalnie: Typ zmiennej, jeśli będzie się różnił rzuci wyjątek
  70.      * @returns mixed
  71.      */
  72.     function get(key, type) {
  73.         var returnValue = null;
  74.        
  75.         if (typeof(this.config[key]) != 'undefined')
  76.             returnValue = this.config[key];
  77.         else if (typeof(this.defaultConfig[key]) != 'undefined')
  78.             returnValue = this.defaultConfig[key];
  79.         else
  80.             throw 'Undefined property '+key+' in object';
  81.        
  82.         if (typeof(type) == 'string' && typeof(returnValue) != type) {
  83.             throw 'Invalid type of return value';
  84.         }
  85.             return returnValue;
  86.     }
  87.    
  88.     /**
  89.      * Funkcja pełni rolę konstruktora
  90.      *
  91.      * @param number chartWidth Szerokość wykresu w pixelach
  92.      * @param number chartHeight Wysokość wykresu w pixelach
  93.      * @param object chartData Obiekt z danymi którymi chcemy reprezentować na wykresie
  94.      * @param object chartConfig Obiekt z konfiguracją dla wykresu
  95.      * @param object containerObj Kontener w którym ma zostać osadzony element z wykresem
  96.      */
  97.     function init(chartWidth, chartHeight, chartData, chartConfig, containerObj) {
  98.         this.width = (typeof(chartWidth) == 'undefined') ? 700 : chartWidth;
  99.         this.width = (typeof(chartHeight) == 'undefined') ? 300 : chartHeight;
  100.        
  101.         if (typeof(idContainer) != 'string')
  102.             idContainer = 'svgContainer';
  103.         this.svgContainer = document.getElementById(idContainer);
  104.        
  105.         this.data = (typeof(chartData) == 'undefined') ? [] : chartData;
  106.         this.config = (typeof(chartConfig) == 'undefined') ? [] : chartConfig;
  107.        
  108.         if (data.length < 1)
  109.             throw 'Nie przesłano danych do wygenerowania wykresu';
  110.        
  111.         return null;
  112.     }
  113. };
  114.  
  115. var LineChart = function () {
  116.     var html = '';
  117.     this.extend(ChartAbstract);
  118. }
  119.  
  120. var chart = new LineChart;
  121. console.log(chart);
  122.  
  123. </script>