blob: 4dd5ab3892c88fdb4c8b363c73108105cafe7d3f [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
Akron88d237e2020-10-21 08:05:18 +02009"use strict";
10
hebasta0f29e292018-07-24 11:42:25 +020011define([ 'util' ], function() {
hebasta10e0c212018-06-19 17:09:08 +020012
hebasta0f29e292018-07-24 11:42:25 +020013 return {
14
15 /**
16 * Create new statistic object
17 */
Akron88d237e2020-10-21 08:05:18 +020018 create : function (statistic) {
hebasta0f29e292018-07-24 11:42:25 +020019 return Object.create(this)._init(statistic);
20 },
21
Akron88d237e2020-10-21 08:05:18 +020022
hebasta0f29e292018-07-24 11:42:25 +020023 /**
24 * Initialize statistic object
25 */
Akron88d237e2020-10-21 08:05:18 +020026 _init : function (statistic) {
hebasta0f29e292018-07-24 11:42:25 +020027 if (statistic === undefined) {
28 throw new Error("Missing parameter");
29 } else {
30 this._statistic = statistic;
31 return this;
32 }
33 },
34
Akron88d237e2020-10-21 08:05:18 +020035
hebasta0f29e292018-07-24 11:42:25 +020036 /**
37 * Display statistic object as HTML Description List Element
38 */
Akron88d237e2020-10-21 08:05:18 +020039 element : function () {
hebasta0f29e292018-07-24 11:42:25 +020040
41 // if this._element already exists return without doing something
42 if (this._element !== undefined) {
43 return this._element;
44 }
hebasta0f29e292018-07-24 11:42:25 +020045
46 // create HTML Description List Element
Akron88d237e2020-10-21 08:05:18 +020047 const statDL = document.createElement('dl');
Akron2f979122018-07-25 17:00:23 +020048 statDL.classList.add("flex");
hebastacf5f9b62018-06-29 14:27:50 +020049
Akron88d237e2020-10-21 08:05:18 +020050 const statistic = this._statistic;
51 let statSp, statDT, statDD;
52
53 Object.keys(statistic).forEach(function (k) {
hebasta0f29e292018-07-24 11:42:25 +020054 statSp = statDL.addE('div')
55 statDT = statSp.addE('dt');
hebasta0f29e292018-07-24 11:42:25 +020056 statDT.addT(k);
57 statDT.setAttribute('title', k);
58 statDD = statSp.addE('dd');
Akron751e9e42019-03-13 09:54:55 +010059 statDD.addT(new Number(statistic[k]).toLocaleString());
Akronb50964a2020-10-12 11:44:37 +020060 });
hebasta0f29e292018-07-24 11:42:25 +020061
62 this._element = statDL;
63 return this._element;
Akron88d237e2020-10-21 08:05:18 +020064 }
hebasta0f29e292018-07-24 11:42:25 +020065 }
66
hebasta10e0c212018-06-19 17:09:08 +020067});