|
23 | 23 | * recommended used framework version
|
24 | 24 | * @type {string}
|
25 | 25 | */
|
26 |
| - ccm: 'https://akless.github.io/ccm/version/ccm-11.5.0.min.js', |
27 |
| - // ccm: '//akless.github.io/ccm/ccm.js', |
| 26 | + ccm: 'https://ccmjs.github.io/ccm/ccm.js', |
| 27 | + // ccm: 'https://ccmjs.github.io/ccm/versions/ccm-18.0.4.min.js', |
28 | 28 |
|
29 | 29 | /**
|
30 | 30 | * default instance configuration
|
31 | 31 | * @type {object}
|
32 | 32 | */
|
33 | 33 | config: {
|
34 |
| - boxes: { |
| 34 | + data: { |
35 | 35 | "EU": 30,
|
36 | 36 | "US": 70,
|
37 | 37 | "CHN": 50
|
|
46 | 46 | }
|
47 | 47 | },
|
48 | 48 | styles: {
|
49 |
| - "EU": { |
50 |
| - fill: "orange", |
51 |
| - stroke: "red", |
52 |
| - "stroke-width": 3, |
53 |
| - "fill-opacity": 0.5 |
54 |
| - }, |
55 |
| - "US": { |
56 |
| - fill: "lime", |
57 |
| - stroke: "purple", |
58 |
| - "stroke-width": 3, |
59 |
| - "fill-opacity": 0.5 |
60 |
| - }, |
61 |
| - "CHN": { |
62 |
| - fill: "yellow", |
63 |
| - stroke: "orange", |
64 |
| - "stroke-width": 3, |
65 |
| - "fill-opacity": 0.5 |
66 |
| - }, |
| 49 | + "fill": "coral", |
67 | 50 | "text": {
|
68 |
| - "font-family": "Verdana", |
69 | 51 | "font-size": 8
|
70 | 52 | }
|
71 |
| - }, |
72 |
| - |
73 |
| - // css: [ 'ccm.load', '//kaul.inf.h-brs.de/data/ccm/histogram/resources/default.css' ], |
| 53 | + } |
74 | 54 |
|
75 |
| - // css: [ 'ccm.load', 'https://mkaul.github.io/ccm-components/histogram/resources/default.css' ], |
76 |
| - // user: [ 'ccm.instance', 'https://akless.github.io/ccm-components/user/versions/ccm.user-2.0.0.min.js' ], |
77 |
| - // logger: [ 'ccm.instance', 'https://akless.github.io/ccm-components/log/versions/ccm.log-1.0.0.min.js', [ 'ccm.get', 'https://akless.github.io/ccm-components/log/resources/log_configs.min.js', 'greedy' ] ], |
78 |
| - // onfinish: function( instance, results ){ console.log( results ); } |
| 55 | + // css: [ 'ccm.load', 'https://ccmjs.github.io/mkaul-components/histogram/resources/default.css' ] |
79 | 56 | },
|
80 | 57 |
|
81 | 58 | /**
|
82 | 59 | * for creating instances of this component
|
83 | 60 | * @constructor
|
84 | 61 | */
|
85 | 62 | Instance: function () {
|
86 |
| - |
| 63 | + |
| 64 | + "use strict"; |
| 65 | + |
87 | 66 | /**
|
88 | 67 | * own reference for inner functions
|
89 | 68 | * @type {Instance}
|
90 | 69 | */
|
91 | 70 | const self = this;
|
92 |
| - |
| 71 | + |
93 | 72 | /**
|
94 | 73 | * shortcut to help functions
|
95 |
| - * @type {Object} |
| 74 | + * @type {Object.<string,function>} |
96 | 75 | */
|
97 | 76 | let $;
|
98 |
| - |
| 77 | + |
99 | 78 | /**
|
100 | 79 | * init is called once after all dependencies are solved and is then deleted
|
101 |
| - * @param {function} callback - called after all synchronous and asynchronous operations are complete |
102 | 80 | */
|
103 |
| - this.init = callback => { |
104 |
| - |
105 |
| - // Is content given via LightDOM (inner HTML of Custom Element)? |
| 81 | + this.init = async () => { |
| 82 | + |
| 83 | + // Is config given via LightDOM (inner HTML of Custom Element)? |
106 | 84 | // Then use it with higher priority
|
107 |
| - if ( self.inner && self.inner.innerHTML.trim() ) self.text = self.inner.innerHTML; |
108 |
| - |
109 |
| - // ToDo interprete LightDOM |
| 85 | + if ( self.inner && self.inner.innerHTML.trim() ){ |
| 86 | + |
| 87 | + // interprete LightDOM |
| 88 | + self.lightDOM = JSON.parse( self.inner.innerHTML ); |
| 89 | + |
| 90 | + // merge into config |
| 91 | + Object.assign( self, self.lightDOM ); |
| 92 | + |
| 93 | + } |
110 | 94 |
|
111 |
| - callback(); |
112 | 95 | };
|
113 |
| - |
| 96 | + |
114 | 97 | /**
|
115 | 98 | * is called once after the initialization and is then deleted
|
116 |
| - * @param {function} callback - called after all synchronous and asynchronous operations are complete |
117 | 99 | */
|
118 |
| - this.ready = callback => { |
| 100 | + this.ready = async () => { |
119 | 101 |
|
120 | 102 | // set shortcut to help functions
|
121 | 103 | $ = self.ccm.helper;
|
122 |
| - |
123 |
| - callback(); |
124 |
| - }; |
125 |
| - |
| 104 | + |
| 105 | + }; |
| 106 | + |
126 | 107 | /**
|
127 | 108 | * starts the instance
|
128 |
| - * @param {function} [callback] - called after all synchronous and asynchronous operations are complete |
129 | 109 | */
|
130 |
| - this.start = callback => { |
| 110 | + this.start = async () => { |
131 | 111 |
|
132 | 112 | // has logger instance? => log 'start' event
|
133 |
| - if ( self.logger ) self.logger.log( 'start' ); |
| 113 | + self.logger && self.logger.log( 'start' ); |
134 | 114 |
|
135 |
| - const dimensions = Object.keys( self.boxes ); |
| 115 | + const dimensions = Object.keys( self.data ); |
136 | 116 | const dim_count = dimensions.length;
|
137 | 117 | let list = self.html.main.inner;
|
138 | 118 |
|
139 | 119 | dimensions.map( (dim, index) => {
|
140 | 120 | const width = parseFloat( self.html.main.width ) / dim_count;
|
141 | 121 | const height = parseFloat( self.html.main.height );
|
142 | 122 |
|
| 123 | + const stroke_width = self.styles[ dim ] && self.styles[ dim ]["stroke-width"] || 1; |
| 124 | + |
143 | 125 | const rect = { tag: 'rect',
|
144 | 126 | x: index * width,
|
145 |
| - y: height - self.boxes[ dim ] - self.styles[ dim ]["stroke-width"] || 1, |
146 |
| - width: width - self.styles[ dim ]["stroke-width"] || 1, |
147 |
| - height: self.boxes[ dim ], |
148 |
| - inner: { tag: 'title', inner: dim + ': ' + self.boxes[ dim ] } |
| 127 | + y: height - self.data[ dim ] - stroke_width, |
| 128 | + width: width - stroke_width, |
| 129 | + height: self.data[ dim ], |
| 130 | + inner: { tag: 'title', inner: dim + ': ' + self.data[ dim ] } |
149 | 131 | };
|
150 |
| - list.push( $.integrate(rect, self.styles[ dim ]) ); |
| 132 | + list.push( $.integrate(rect, $.integrate( self.styles, self.styles[ dim ])) ); |
151 | 133 | list.push( $.clone( $.integrate( { tag:'text',
|
152 | 134 | x: index * width + 0.5 * width,
|
153 | 135 | y: height - 10,
|
154 | 136 | "text-anchor": "middle",
|
155 | 137 | inner: [
|
156 | 138 | dim,
|
157 |
| - { tag: 'title', inner: dim + ': ' + self.boxes[ dim ] } |
| 139 | + { tag: 'title', inner: dim + ': ' + self.data[ dim ] } |
158 | 140 | ]
|
159 | 141 | }, self.styles.text ) ) );
|
160 | 142 | });
|
|
165 | 147 | // set content of own website area
|
166 | 148 | $.setContent( self.element, main_elem );
|
167 | 149 |
|
168 |
| - // Hack in order to get SVG rendered inside the shadow root |
| 150 | + // Hack in order to get SVG rendered inside the shadow DOM |
169 | 151 | self.element.innerHTML += '';
|
170 | 152 |
|
171 |
| - if ( callback ) callback(); |
172 | 153 | };
|
173 | 154 |
|
174 | 155 | }
|
|
0 commit comments