hebasta | 10e0c21 | 2018-06-19 17:09:08 +0200 | [diff] [blame] | 1 | /** |
| 2 | * |
| 3 | * Creates and displays corpus statistic |
| 4 | * |
| 5 | * @author Helge Stallkamp |
| 6 | * |
| 7 | */ |
hebasta | 10e0c21 | 2018-06-19 17:09:08 +0200 | [diff] [blame] | 8 | |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 9 | "use strict"; |
| 10 | |
hebasta | 0f29e29 | 2018-07-24 11:42:25 +0200 | [diff] [blame] | 11 | define([ 'util' ], function() { |
hebasta | 10e0c21 | 2018-06-19 17:09:08 +0200 | [diff] [blame] | 12 | |
hebasta | 0f29e29 | 2018-07-24 11:42:25 +0200 | [diff] [blame] | 13 | return { |
| 14 | |
| 15 | /** |
| 16 | * Create new statistic object |
| 17 | */ |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 18 | create : function (statistic) { |
hebasta | 0f29e29 | 2018-07-24 11:42:25 +0200 | [diff] [blame] | 19 | return Object.create(this)._init(statistic); |
| 20 | }, |
| 21 | |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 22 | |
hebasta | 0f29e29 | 2018-07-24 11:42:25 +0200 | [diff] [blame] | 23 | /** |
| 24 | * Initialize statistic object |
| 25 | */ |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 26 | _init : function (statistic) { |
hebasta | 0f29e29 | 2018-07-24 11:42:25 +0200 | [diff] [blame] | 27 | if (statistic === undefined) { |
| 28 | throw new Error("Missing parameter"); |
| 29 | } else { |
| 30 | this._statistic = statistic; |
| 31 | return this; |
| 32 | } |
| 33 | }, |
| 34 | |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 35 | |
hebasta | 0f29e29 | 2018-07-24 11:42:25 +0200 | [diff] [blame] | 36 | /** |
| 37 | * Display statistic object as HTML Description List Element |
| 38 | */ |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 39 | element : function () { |
hebasta | 0f29e29 | 2018-07-24 11:42:25 +0200 | [diff] [blame] | 40 | |
Akron | 24aa005 | 2020-11-10 11:00:34 +0100 | [diff] [blame] | 41 | // if this._el already exists return without doing something |
| 42 | if (this._el !== undefined) { |
| 43 | return this._el; |
hebasta | 0f29e29 | 2018-07-24 11:42:25 +0200 | [diff] [blame] | 44 | } |
hebasta | 0f29e29 | 2018-07-24 11:42:25 +0200 | [diff] [blame] | 45 | |
| 46 | // create HTML Description List Element |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 47 | const statDL = document.createElement('dl'); |
Akron | 2f97912 | 2018-07-25 17:00:23 +0200 | [diff] [blame] | 48 | statDL.classList.add("flex"); |
hebasta | cf5f9b6 | 2018-06-29 14:27:50 +0200 | [diff] [blame] | 49 | |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 50 | const statistic = this._statistic; |
| 51 | let statSp, statDT, statDD; |
| 52 | |
| 53 | Object.keys(statistic).forEach(function (k) { |
hebasta | 0f29e29 | 2018-07-24 11:42:25 +0200 | [diff] [blame] | 54 | statSp = statDL.addE('div') |
| 55 | statDT = statSp.addE('dt'); |
hebasta | 0f29e29 | 2018-07-24 11:42:25 +0200 | [diff] [blame] | 56 | statDT.addT(k); |
| 57 | statDT.setAttribute('title', k); |
| 58 | statDD = statSp.addE('dd'); |
Akron | 751e9e4 | 2019-03-13 09:54:55 +0100 | [diff] [blame] | 59 | statDD.addT(new Number(statistic[k]).toLocaleString()); |
Akron | b50964a | 2020-10-12 11:44:37 +0200 | [diff] [blame] | 60 | }); |
hebasta | 0f29e29 | 2018-07-24 11:42:25 +0200 | [diff] [blame] | 61 | |
Akron | 24aa005 | 2020-11-10 11:00:34 +0100 | [diff] [blame] | 62 | this._el = statDL; |
| 63 | return this._el; |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 64 | } |
hebasta | 0f29e29 | 2018-07-24 11:42:25 +0200 | [diff] [blame] | 65 | } |
| 66 | |
hebasta | 10e0c21 | 2018-06-19 17:09:08 +0200 | [diff] [blame] | 67 | }); |