-
Notifications
You must be signed in to change notification settings - Fork 0
/
sgvizler.js
4850 lines (4428 loc) · 177 KB
/
sgvizler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Sgvizler - https://dev.data2000.no/sgvizler/
// (c) 2011--2013 - Martin G. Skjæveland - MIT license
(function (window, undefined) { // trick: safekeep 'undefined', and minify.
"use strict";
/*global window, jQuery */
/*jslint todo: true */
var document = window.document, // trick: minify.
S = {}, // local scope sgvizler variable.
// Used in end. (Odd names such that these variables are not
// accidentally accessed by child modules.)
globalGetSet,
globalDefaultsQuery,
globalDefaultsChart;
//// OTHER SOURCE FILES ARE CONCATENATED IN BELOW
//// ENDING WITH end.js.part
/**
* Holds central constants.
*
* @class sgvizler.core
*/
S.core = (function () {
// global public constants
var
/**
* The version number of this sgvizler.
* @property {string} VERSION
* @final
* @public
* @for sgvizler
* @since 0.6.0
**/
VERSION = "0.6.0",
/**
* sgvizler's homepage.
* @property {string} HOMEPAGE
* @final
* @public
* @for sgvizler
* @since 0.6.0
**/
HOMEPAGE = "http://mgskjaeveland.github.io/sgvizler/",
// global private constants
LOGOIMAGE = "http://beta.data2000.no/sgvizler/misc/image/mr.sgvizler.png",
CHARTSCSS = "http://mgskjaeveland.github.io/sgvizler/v/0.6/sgvizler.charts.css";
return {
VERSION: VERSION,
HOMEPAGE: HOMEPAGE,
LOGOIMAGE: LOGOIMAGE,
CHARTSCSS: CHARTSCSS
};
}());
/**
* A helpful set of static utility functions: type checking
* variables, generic get-setter, get-setting values in
* hierarchial objects, array functions, DOM manipulation, and
* inheritance.
*
* Dependencies:
*
* - jQuery
*
* @class sgvizler.util
* @static
*/
S.util = (function () {
/*global $ */
var
/**
* Checks if `input` is a string.
* @method isString
* @protected
* @param input
* @return {boolean} True iff `input` is a string.
* @since 0.6.0
**/
isString = function (input) {
return typeof input === 'string';
},
/**
* Checks if `input` is a number.
* @method isNumber
* @protected
* @param input
* @return {boolean} True iff `input` is a number.
* @since 0.6.0
**/
isNumber = function (input) {
return typeof input === 'number';
},
/**
* Checks if `input` is a boolean.
* @method isBoolean
* @protected
* @param input
* @return {boolean} True iff `input` is a boolean.
* @since 0.6.0
**/
isBoolean = function (input) {
return typeof input === 'boolean';
},
/**
* Checks if `input` is a primitive, i.e., either a string,
* a number or a boolean.
* @method isPrimitive
* @protected
* @param input
* @return {boolean} True iff `input` is a string, a number or a boolean.
* @since 0.6.0
**/
isPrimitive = function (input) {
return isString(input) || isNumber(input) || isBoolean(input);
},
/**
* Checks if `input` is a function.
* @method isFunction
* @protected
* @param input
* @requires jQuery
* @return {boolean} True iff `input` is a function.
* @since 0.6.0
**/
isFunction = $.isFunction,
/**
* Checks if `input` is an array.
* @method isArray
* @protected
* @param input
* @requires jQuery
* @return {boolean} True iff `input` is an array.
* @since 0.6.0
**/
isArray = $.isArray,
/**
* Checks if `input` is a URL.
* @method isURL
* @protected
* @param input
* @return {boolean} True iff `input` is a URL.
* @since 0.6.0
**/
URLpattern = new RegExp(
'^(https?:\\/\\/)?' // protocol
+ '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' // domain name
+ '((\\d{1,3}\\.){3}\\d{1,3}))' // OR ip (v4) address
+ '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' // port and path
+ '(\\?[;&a-z\\d%_.~+=-]*)?' // query string
+ '(\\#[-a-z\\d_]*)?$', // fragment locator
'i'
),
isURL = function (input) {
return URLpattern.test(input);
},
/**
* Establish "classical inheritance" from Parent to
* Child. Child is linked to the Parent's prototype
* through a new proxy object. This means the Child has a
* prototype object of its own, and access to the Parent's
* prototype.
*
* Taken from book "JavaScript Patterns".
* @method inherit
* @protected
* @param {Object} Child
* @param {Object} Parent
* @since 0.6.0
**/
inherit = (function () {
var Proxy = function () {};
return function (Child, Parent) {
Proxy.prototype = Parent.prototype;
Child.prototype = new Proxy();
//Child.superobject = Parent.prototype;
Child.prototype.constructor = Child;
};
}()),
/**
* Generic set/get method. If `value` is defined, then the
* attribute/property `attr` of `setObject` is set to
* `value` and `returnObject` is returned. Otherwise, the
* (value of) `attr` attribute/property is
* returned. Useful for a casading pattern.
* @method getset
* @protected
* @param {string} attr The name of the property to get/set.
* @param {Object} [value] The value to set.
* @param {Object} setObject The object for which the property shall be set/get.
* @param {Object} returnObject The object to return if value is undefined.
* @return {any} Either `returnObject` or `setObject[attr]`
* @example
* getset('age', 55, person.myArray, person)
* sets `person.myArray.age = 55` and returns `person`.
*
* getset('age', undefined, person.myArray, person)
* returns `person.myArray.age`.
* @since 0.6.0
**/
getset = function (attr, value, setObject, returnObject) {
if (value !== undefined) {
setObject[attr] = value;
}
return (value !== undefined) ? returnObject : setObject[attr];
},
/**
* Checks if a string starts with (is the prefix of) an other string.
* @method startsWith
* @protected
* @param {string} string
* @param {string} prefix
* @return {boolean} True iff `prefix` is the prefix of `string`.
* @example
* startsWith("Hal", "Hallo!"); // returns true
* startsWith("hal", "Hallo!"); // returns false
* @since 0.6.0
**/
startsWith = function (string, prefix) {
return string.lastIndexOf(prefix, 0) === 0;
},
/**
* Gets the object located at `path` from `object`. `path`
* is given in dot notation.
*
* @method getObjectByPath
* @protected
* @param {string} path
* @param {Object} [object=window]
* @param {boolean} [create=false]
* @return {Object} Returns the object/value located at
* the `path` of `object`; otherwise, if `create` is true,
* it is created.
* @example
* getObjectByPath('sgvizler.visualization.Table', registry, true)
* returns the object located at
* `registry['sgvizler']['visualization']['Table']` if it
* exists; otherwise, since `'create' === true`, the path
* and (empty) object is created and returned.
* @since 0.6.0
**/
getObjectByPath = function (path, object, create) {
var i, len,
segments = path.split('.'),
cursor = object || window; // window is the global scope.
for (i = 0, len = segments.length; i < len; i += 1) {
if (cursor !== undefined && // cursor must be defined
cursor[segments[i]] === undefined &&
create) { // create new child element.
cursor[segments[i]] = {};
}
cursor = cursor && cursor[segments[i]]; // if cursor is undefined, it remains undefined.
}
return cursor;
},
/**
* Checks if a an array contains a given element.
* @method isInArray
* @protected
* @param {any} item
* @param {Array} array
* @return {boolean} True iff `array` contains an element `item`.
* @since 0.6.0
**/
isInArray = function (item, array) {
return ($.inArray(item, array) !== -1);
},
/**
* Removes duplicates from an array.
* @method removeDuplicates
* @protected
* @param {Array} array
* @return {Array} The input array with duplicates removed.
* @example
* removeDuplicates([1, 1, 1, 2, 4, 3, 2]); // returns [1, 2, 4, 3]
* @since 0.6.0
**/
removeDuplicates = function (array) {
var i, len,
unique = [];
for (i = 0, len = array.length; i < len; i += 1) {
if (!isInArray(array[i], unique)) {
unique.push(array[i]);
}
}
return unique;
},
/**
* Converts `input` to an array. If `input` is undefined,
* then an empty array is returned. If `input` is
* primitive, then it is put in an (empty) array. If `input`
* /is/ an array, then the `input` is simply returned.
*
* Useful for converting input to other methods to arrays.
* @method toArray
* @protected
* @param {undefined|primitive|Array} input
* @return {Array} An array representation of `input`.
* @example
* toArray(undefined); // returns []
* toArray('myString'); // returns ['myString']
* toArray([1, 2, 3]); // returns [1, 2, 3]
* toArray(function () {}); // throws TypeError
* @since 0.6.0
**/
toArray = function (input) {
var output;
if (input === undefined) {
output = [];
} else if (isPrimitive(input)) {
output = [input];
} else if (isArray(input)) {
output = input;
} else {
throw new TypeError();
}
return output;
},
/**
* Creates an HTML element according to a custom made
* "array syntax". Used to make HTML DOM manipulation more
* code compact.
* @method createHTMLElement
* @protected
* @param {string} elementType The type of element to
* create, e.g., "div" or "h1".
* @param {Object} [attributes] Object of
* attribute--value's to be added to the element.
* @param {Array|primitive} [children] An array of
* children to be added to the element; each element in
* the `children` array is an array of three elements, one
* for each parameter of this method. If this argument is
* a primitive, then it is inserted as a text node.
* @return {Object} Element (ready for insertion into DOM.)
* @example
* createHTMLElement('ul', { 'class': "myClass", 'id': "myID" }, [ ['li', null, "One" ],
* ['li', { 'id': "ABC" } , 2 ],
* ['li', null, true] ] );
*
* will create the HTML element:
*
* <ul id="myID" class="myClass">
* <li>One</li>
* <li id="ABC">2</li>
* <li>true</li>
* </ul>
* @since 0.6.0
**/
createHTMLElement = function createHTMLElement(elementType, attributes, children) {
var i, len,
element = $(document.createElement(elementType)),
attr,
childs = toArray(children), // [sic]
child;
// Add attributes to element.
for (attr in attributes) {
if (attributes.hasOwnProperty(attr)) {
element.attr(attr, attributes[attr]);
}
}
// Add children to element. String are "simply" added, else it
// should be an array of arguments to (recursive) create() call.
for (i = 0, len = childs.length; i < len; i += 1) {
child = childs[i];
if (isPrimitive(child)) {
element.append(child);
} else if (isArray(child)) {
element.append(createHTMLElement.apply(undefined, child));
} else {
throw new TypeError();
}
}
return element;
};
return {
isString: isString,
isNumber: isNumber,
isBoolean: isBoolean,
isPrimitive: isPrimitive,
isFunction: isFunction,
isArray: isArray,
isURL: isURL,
startsWith: startsWith,
isInArray: isInArray,
toArray: toArray,
removeDuplicates: removeDuplicates,
getObjectByPath: getObjectByPath,
getset: getset,
inherit: inherit,
createHTMLElement: createHTMLElement
};
}());
/**
* Static class for handling prefixes and namespaces. Use for
* storing prefixes used in SPARQL queries and for formatting
* result sets, i.e., replacing namespaces with prefixes, which
* many chart functions automatically do.
*
* Already defined prefixes are `rdf`, `rdfs`, `owl` and `xsd`.
*
* Dependencies:
*
* - sgvizler.util
*
* @class sgvizler.namespace
* @static
*/
S.namespace = (function () {
// Module dependencies:
var startsWith = S.util.startsWith,
isString = S.util.isString,
/**
* Stores prefix--namespace pairs.
* @property nss
* @type Object
* @private
* @since 0.1
**/
nss = {
'rdf' : "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
'rdfs': "http://www.w3.org/2000/01/rdf-schema#",
'owl' : "http://www.w3.org/2002/07/owl#",
'xsd' : "http://www.w3.org/2001/XMLSchema#"
},
/**
* @property baseURL
* @type String
* @private
* @since 0.6.0
**/
baseURL = null;
/////////////////////////////////////////////////////////
// PUBLICs
return {
/**
* Get a namespace.
*
* See also set.
*
* @method get
* @protected
* @param {string} prefix The prefix to get the namespace for.
* @return {string} The namespace set for 'prefix';
* undefined if 'prefix' does not exist.
* @example
* get('xsd'); // returns "http://www.w3.org/2001/XMLSchema#"
* @since 0.6.0
**/
get: function (prefix) {
return nss[prefix];
},
/**
* Set a namespace.
*
* See also get.
*
* @method set
* @protected
* @param {string} prefix The prefix to set.
* @param {string} namespace The namespace to set.
* @example
* set('foaf', "http://xmlns.com/foaf/0.1/");
* sets `'foaf'` as prefix for the FOAF namespace.
* @since 0.6.0
**/
set: function (prefix, namespace) {
nss[prefix] = namespace;
},
/**
* Get Base URL value.
*
* See also setBaseURL.
*
* @method getBaseURL
* @return {string} The base URL.
* @protected
* @since 0.6.0
**/
getBaseURL: function () {
return baseURL;
},
/**
* Set Base URL value.
*
* See also setBaseURL.
*
* @method getBaseURL
* @param {string} url The base URL.
* @protected
* @since 0.6.0
**/
setBaseURL: function (url) {
baseURL = url;
},
/**
* Get all prefixes in SPARQL format.
* @method prefixesSPARQL
* @protected
* @return {string} An SPARQL formatted prefix declaration
* text block containing all set prefixes.
* @since 0.1
**/
prefixesSPARQL: function () {
var prefix,
prefixes = "";
for (prefix in nss) {
if (nss.hasOwnProperty(prefix)) {
prefixes += "PREFIX " + prefix + ": <" + nss[prefix] + ">\n";
}
}
return prefixes;
},
/**
* Replace a namespace with its prefix, for string which
* starts with a namespace. Typically used for URLs of
* resources.
*
* Leaves other strings untouched.
*
* See also unprefixify.
*
* @method prefixify
* @protected
* @param {string} url
* @return {string}
* @example
* prefixify("http://www.w3.org/2002/07/owl#Class"); // returns "owl:Class"
* prefixify("Hello World!"); // returns "Hello World!"
* @since 0.3.3
**/
prefixify: function (url) {
var prefix;
if (isString(url)) {
for (prefix in nss) {
if (nss.hasOwnProperty(prefix) &&
startsWith(url, nss[prefix])) {
return url.replace(nss[prefix], prefix + ":");
}
}
}
return url;
},
/**
* Replace a prefix with its namespace, for string which
* starts with a prefix: Typically used for prefixed URLs
* (QNames) of resources.
*
* Leaves other strings untouched.
*
* See also prefixify.
*
* @method unprefixify
* @protected
* @param {string} qname
* @return {string}
* @example
* unprefixify("owl:Class"); // returns "http://www.w3.org/2002/07/owl#Class"
* unprefixify("Hello World!"); // returns "Hello World!"
* @since 0.3.3
**/
unprefixify: function (qname) {
var prefix;
if (isString(qname)) {
for (prefix in nss) {
if (nss.hasOwnProperty(prefix) &&
startsWith(qname, prefix + ":")) {
return qname.replace(prefix + ":", nss[prefix]);
}
}
}
return qname;
}
};
}());
//TODO publish libs at libFolder
/**
* Static class for handling functions used for drawing charts,
* mainpulating datacharts, and what their dependencies are.
*
* Dependencies:
*
* - sgvizler.util
*
* See also:
*
* - sgvizler.charts, sgvizler.datatables (classes for creating new such functions)
* - sgvizler.loader (class for loading dependencies)
*
* @class sgvizler.registry
* @static
*/
S.registry = (function () {
// Module dependencies:
var util = S.util,
/**
* The Google Visualization package name.
* @property GVIZ
* @type String
* @private
* @final
* @since 0.6.0
**/
GVIZ = 'google.visualization',
/**
* The Google Visualization DataTable class name.
* @property DATATABLE
* @type String
* @private
* @final
* @since 0.6.0
**/
DATATABLE = GVIZ + '.DataTable',
/**
* The Google Maps package name.
* @property GVIZ
* @type String
* @private
* @final
* @since 0.6.0
**/
GMAP = 'google.maps',
/**
* Stores the modules of the registered functions
* according to the type of function, i.e., `chart` or
* `datatable`.
* @property modules
* @type Object
* @private
* @since 0.6.0
**/
modules = {
chart: [GVIZ],//, GMAP],
datatable: []
},
/**
* Stores registered function names and their
* dependencies, e.g., specifies which google
* visualization packages to load for the different
* charts.
*
* Property legend:
*
* - `t`: type. Values: `core`, `datatable`, `chart` (default)
* - `d`: dependences. Object containing functions--gviz package/js file
* - `i`: the function itself, as in I.
*
* @property registry
* @type Object
* @private
* @since 0.6.0
**/
registry = {
google: {
//////////////////////////////////////////////////////
// google.visualization
visualization: {
DataTable: {
t: 'core',
d: { i: GVIZ }
},
LineChart: {
d: { i: 'corechart' }
},
AreaChart: {
d: { i: 'corechart' }
},
SteppedAreaChart: {
d: { i: 'corechart' }
},
PieChart: {
d: { i: 'corechart' }
},
BubbleChart: {
d: { i: 'corechart' }
},
ColumnChart: {
d: { i: 'corechart' }
},
BarChart: {
d: { i: 'corechart' }
},
ImageSparkLine: {
d: { i: 'imagesparkline' }
},
ScatterChart: {
d: { i: 'corechart' }
},
CandlestickChart: {
d: { i: 'corechart' }
},
Gauge: {
d: { i: 'gauge' }
},
OrgChart: {
d: { i: 'orgchart' }
},
TreeMap: {
d: { i: 'treemap' }
},
AnnotatedTimeLine: {
d: { i: 'annotatedtimeline' }
},
MotionChart: {
d: { i: 'motionchart' }
},
GeoChart: {
d: { i: 'geochart' }
},
GeoMap: {
d: { i: 'geomap' }
},
Map: {
d: { i: 'map' }
},
Table: {
d: { i: 'table' }
}
},
//////////////////////////////////////////////////////
// google.maps
maps: {
Map: {
d: { i: 'map' }
}
}
}
};
////////////////////////////////////////////
// PUBLICs
return {
// Constants
GVIZ: GVIZ,
GMAP: GMAP,
DATATABLE: DATATABLE,
/**
* Get list of registered chart module (names), i.e., modules for
* which there are registered functions for drawing
* charts.
* @method chartModules
* @protected
* @return {Array} (an array of strings)
* @since 0.6.0
**/
chartModules: function () {
return modules.chart;
},
/**
* Get list of registered chart functions names (not the
* functions themselves).
* @method chartsFunctions
* @protected
* @return {Array} (an array of strings)
* @since 0.6.0
**/
chartFunctions: function () {
var i, len,
libs = modules.chart,//TODO: should be chartModules() but gives "is not defined"-error.
lib,
func,
charts = [];
for (i = 0, len = libs.length; i < len; i += 1) {
lib = util.getObjectByPath(libs[i], registry);
for (func in lib) {
if (lib.hasOwnProperty(func) &&
(lib[func].t === undefined ||
lib[func].t === 'chart')) {
charts.push(libs[i] + "." + func);
}
}
}
return charts;
},
/**
* Get list of dependencies, either google visualization
* packages or javascripts (URLs), for given function
* name.
* @method getDependencies
* @protected
* @param {String} functionName
* @return {Array} (an array of strings)
* @since 0.6.0
**/
getDependencies: function (functionName) {
var regFunc = util.getObjectByPath(functionName, registry),
deps = (regFunc && regFunc.d) || {};
// rename i to functionName:
if (deps.i) {
deps[functionName] = deps.i;
delete deps.i;
}
return deps;
},
/**
* Add function to registry.
* @method addFunction
* @protected
* @param {String} module name of module to which function belongs.
* @param {String} name name of function.
* @param {String} type of function, usually either `'chart'`, `'datatable'`.
* @param {Object} dependencies list of function
* name--dependency pairs. Example: `{ 'XYZ':
* 'http://example.org/XYZ.js' }` if the function requires
* the XYX function to draw and this function is located
* at `http://example.org/XYZ.js`.
* @since 0.6.0
**/
addFunction: function (module, name, type, dependencies) {
var regFunc; // The function's place in registry.
// Add module if it is new.
if (!util.isInArray(module, modules[type])) {
modules[type].push(module);
}
// Add function to registry.
regFunc = util.getObjectByPath(module + "." + name, registry, true);
if (type) {
regFunc.t = type;
}
if (dependencies) {
regFunc.d = dependencies;
}
}
};
}());
/**
* Handles all logging, either to console or designated HTML
* container.
*
* Needs more work.
*
* @class sgvizler.logger
* @static
*/
S.logger = (function () {
/*global $, console*/
// Module dependencies:
//var util = S.util,
var
/**
* The timestamp for the load start of the current running
* version of sgvizler. Used to calculate time elapse of
* future events.
* @property start
* @type number
* @private
* @since 0.6.0
**/
startTime = Date.now(),
/**
* @method timeElapsed
* @private
* @return {number} The number of seconds elapsed since
* this sgvizler got loaded.
* @since 0.6.0
**/
elapsedTime = function () {
return (Date.now() - startTime) / 1000;
},
/**
* @property waitingCharts
* @type number
* @private
* @beta
**/
waitingCharts = 0;
return {
/**
* Logs a message.
* @method log
* @protected
* @param {string} message The message to log.
* @beta
*/
log: function (message) {
console.log(elapsedTime() + "s: " + message);
},
// TODO
loadingChart: function () {
waitingCharts += 1;
if (!$('body,html').css('cursor', 'progress')) {
$('body,html').css('cursor', 'progress');
}
},
doneLoadingChart: function () {
waitingCharts -= 1;
if (waitingCharts === 0 && $('body,html').css('cursor', 'progress')) {
$('body,html').css('cursor', 'default');
}
}
// TODO
// displayFeedback: function (query, messageName) {
// var message,
// container = query.logContainer();
// if (query.loglevel() === 0) {
// message = "";
// } else if (query.loglevel() === 1) {
// if (messageName === "LOADING") {
// message = "Loading...";
// } else if (messageName === "ERROR_ENDPOINT" || messageName === "ERROR_UNKNOWN") {
// message = "Error.";
// }
// } else {
// if (messageName === "LOADING") {
// message = "Sending query ...";
// } else if (messageName === "ERROR_ENDPOINT") {
// message = "Error querying endpoint. Possible errors:" +
// util.html.ul(
// util.html.a(query.endpoint(), "SPARQL endpoint") + " down? " +
// util.html.a(query.endpoint() + query.endpointQueryURL + query.encodedQuery(),
// "Check if query runs at the endpoint") + ".",
// "Malformed SPARQL query? " +
// util.html.a(query.validatorQueryURL() + query.encodedQuery(), "Check if it validates") + ".",
// "CORS supported and enabled? Read more about " +
// util.html.a(S.homepage + "/wiki/Compatibility", "CORS and compatibility") + ".",
// "Is your " + util.html.a(S.homepage + "/wiki/Compatibility", "browser support") + "ed?",
// "Hmm.. it might be a bug! Please file a report to " +
// util.html.a(S.homepage + "/issues/", "the issues") + "."
// );
// } else if (messageName === "ERROR_UNKNOWN") {
// message = "Unknown error.";