blob: 0c3c6caa481851ca5c5089ba37894b4bc1eb3010 [file] [log] [blame]
hebasta10e0c212018-06-19 17:09:08 +02001/**
2 *
3 * Creates and displays corpus statistic
4 *
5 * @author Helge Stallkamp
6 *
7 */
hebasta10e0c212018-06-19 17:09:08 +02008
hebasta0f29e292018-07-24 11:42:25 +02009define([ 'util' ], function() {
hebasta10e0c212018-06-19 17:09:08 +020010
hebasta0f29e292018-07-24 11:42:25 +020011 return {
12
13 /**
14 * Create new statistic object
15 */
16 create : function(statistic) {
17 return Object.create(this)._init(statistic);
18 },
19
20 /**
21 * Initialize statistic object
22 */
23 _init : function(statistic) {
24 if (statistic === undefined) {
25 throw new Error("Missing parameter");
26 } else {
27 this._statistic = statistic;
28 return this;
29 }
30 },
31
32 /**
33 * Display statistic object as HTML Description List Element
34 */
35 element : function() {
36
37 // if this._element already exists return without doing something
38 if (this._element !== undefined) {
39 return this._element;
40 }
hebasta0f29e292018-07-24 11:42:25 +020041
42 // create HTML Description List Element
hebasta4c92eec2018-06-29 10:11:15 +020043 var statDL = document.createElement('dl');
Akron2f979122018-07-25 17:00:23 +020044 statDL.classList.add("flex");
hebasta0f29e292018-07-24 11:42:25 +020045 var statistic = this._statistic;
hebastacf5f9b62018-06-29 14:27:50 +020046
Akronb50964a2020-10-12 11:44:37 +020047 Object.keys(statistic).forEach(function(k) {
hebasta0f29e292018-07-24 11:42:25 +020048 statSp = statDL.addE('div')
49 statDT = statSp.addE('dt');
hebasta0f29e292018-07-24 11:42:25 +020050 statDT.addT(k);
51 statDT.setAttribute('title', k);
52 statDD = statSp.addE('dd');
Akron751e9e42019-03-13 09:54:55 +010053 statDD.addT(new Number(statistic[k]).toLocaleString());
Akronb50964a2020-10-12 11:44:37 +020054 });
hebasta0f29e292018-07-24 11:42:25 +020055
56 this._element = statDL;
57 return this._element;
58 },
59
60 }
61
hebasta10e0c212018-06-19 17:09:08 +020062});