- <?xml version="1.0"?>
- <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
- <div id="lineChart"></div>
- <script type="text/javascript">
- Object.prototype.extend = function () {
- for (i in arguments) {
- tempObj = new arguments[i];
- for (property in tempObj) {
- this[property] = tempObj[property];
- }
- }
- };
- var ChartAbstract = function() {
- /**
- * Szerokość wykresu
- * @type number
- */
- this.width = null;
- /**
- * Wysokośc wykresu
- * @type number
- **/
- this.width = null;
- /**
- * Uchwyt kontenera
- * @type Object
- */
- this.svgContainer = null;
- /**
- * Dane wykresu
- * @type Array
- */
- this.data = null;
- /**
- * Dane wykresu
- * @type Array
- */
- this.config = null;
- /**
- * Stałe opisujące typy danych
- */
- this.NUMBER = 'number';
- this.BOOLEAN = 'boolean';
- this.OBJECT = 'object';
- this.STRING = 'string';
- this.UNDEFINED = 'undefined';
- /**
- * Domyslna konfiguracja
- * @type Object
- */
- this.defaultConfig = {
- showLines: 1, //Czy pokazywać linie
- animate: 0 //Czy animować
- }
- /**
- * Zwraca wartośc konfiguracji generatora(piewsze sprawdza przesłaną przez użytkownika a później domyślną)
- *
- * @param string key Klucz konfiguracji z tablicy
- * @param string type Opcjonalnie: Typ zmiennej, jeśli będzie się różnił rzuci wyjątek
- * @returns mixed
- */
- function get(key, type) {
- var returnValue = null;
- if (typeof(this.config[key]) != 'undefined')
- returnValue = this.config[key];
- else if (typeof(this.defaultConfig[key]) != 'undefined')
- returnValue = this.defaultConfig[key];
- else
- throw 'Undefined property '+key+' in object';
- if (typeof(type) == 'string' && typeof(returnValue) != type) {
- throw 'Invalid type of return value';
- }
- return returnValue;
- }
- /**
- * Funkcja pełni rolę konstruktora
- *
- * @param number chartWidth Szerokość wykresu w pixelach
- * @param number chartHeight Wysokość wykresu w pixelach
- * @param object chartData Obiekt z danymi którymi chcemy reprezentować na wykresie
- * @param object chartConfig Obiekt z konfiguracją dla wykresu
- * @param object containerObj Kontener w którym ma zostać osadzony element z wykresem
- */
- function init(chartWidth, chartHeight, chartData, chartConfig, containerObj) {
- this.width = (typeof(chartWidth) == 'undefined') ? 700 : chartWidth;
- this.width = (typeof(chartHeight) == 'undefined') ? 300 : chartHeight;
- if (typeof(idContainer) != 'string')
- idContainer = 'svgContainer';
- this.svgContainer = document.getElementById(idContainer);
- this.data = (typeof(chartData) == 'undefined') ? [] : chartData;
- this.config = (typeof(chartConfig) == 'undefined') ? [] : chartConfig;
- if (data.length < 1)
- throw 'Nie przesłano danych do wygenerowania wykresu';
- return null;
- }
- };
- var LineChart = function () {
- var html = '';
- this.extend(ChartAbstract);
- }
- var chart = new LineChart;
- console.log(chart);
- </script>