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 | |
hebasta | 0f29e29 | 2018-07-24 11:42:25 +0200 | [diff] [blame] | 9 | define([ 'util' ], function() { |
hebasta | 10e0c21 | 2018-06-19 17:09:08 +0200 | [diff] [blame] | 10 | |
hebasta | 0f29e29 | 2018-07-24 11:42:25 +0200 | [diff] [blame] | 11 | 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 | } |
hebasta | 0f29e29 | 2018-07-24 11:42:25 +0200 | [diff] [blame] | 41 | |
| 42 | // create HTML Description List Element |
hebasta | 4c92eec | 2018-06-29 10:11:15 +0200 | [diff] [blame] | 43 | var statDL = document.createElement('dl'); |
Akron | 2f97912 | 2018-07-25 17:00:23 +0200 | [diff] [blame] | 44 | statDL.classList.add("flex"); |
hebasta | 0f29e29 | 2018-07-24 11:42:25 +0200 | [diff] [blame] | 45 | var statistic = this._statistic; |
hebasta | cf5f9b6 | 2018-06-29 14:27:50 +0200 | [diff] [blame] | 46 | |
hebasta | 0f29e29 | 2018-07-24 11:42:25 +0200 | [diff] [blame] | 47 | var keys = Object.keys(statistic); |
| 48 | for (i = 0; i < keys.length; i++) { |
| 49 | statSp = statDL.addE('div') |
| 50 | statDT = statSp.addE('dt'); |
| 51 | var k = keys[i]; |
| 52 | statDT.addT(k); |
| 53 | statDT.setAttribute('title', k); |
| 54 | statDD = statSp.addE('dd'); |
Akron | 2f97912 | 2018-07-25 17:00:23 +0200 | [diff] [blame] | 55 | statDD.addT(statistic[k].toLocaleString()); |
hebasta | 0f29e29 | 2018-07-24 11:42:25 +0200 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | this._element = statDL; |
| 59 | return this._element; |
| 60 | }, |
| 61 | |
| 62 | } |
| 63 | |
hebasta | 10e0c21 | 2018-06-19 17:09:08 +0200 | [diff] [blame] | 64 | }); |