@iamproperty/components 2.7.6 → 2.7.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/css/core.min.css +1 -1
- package/assets/css/core.min.css.map +1 -1
- package/assets/css/style.min.css +1 -1
- package/assets/css/style.min.css.map +1 -1
- package/assets/js/modules/chart.js +217 -0
- package/assets/js/modules/helpers.js +18 -14
- package/assets/js/modules/table.js +89 -89
- package/assets/js/scripts.bundle.js +49 -55
- package/assets/js/scripts.bundle.js.map +1 -1
- package/assets/js/scripts.bundle.min.js +2 -2
- package/assets/js/scripts.bundle.min.js.map +1 -1
- package/assets/sass/foundations/icons.scss +3 -2
- package/assets/svg/icons.svg +483 -0
- package/dist/components.common.js +57 -56
- package/dist/components.common.js.map +1 -1
- package/dist/components.umd.js +57 -56
- package/dist/components.umd.js.map +1 -1
- package/dist/components.umd.min.js +1 -1
- package/dist/components.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Chart/Chart.vue +8 -165
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="container" ref="wrapper">
|
|
3
3
|
<slot></slot>
|
|
4
|
-
<figure class="chart__wrapper">
|
|
4
|
+
<figure class="chart__wrapper" ref="chartWrapper">
|
|
5
5
|
<figcaption v-html="caption"></figcaption>
|
|
6
6
|
<div :class="`chart__key chart__key--${type} h5`" role="presentation">
|
|
7
7
|
<div :key="index" v-for="(item,index) in fields" class="key">{{item.key}}</div>
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
<div :key="index" v-for="(point,index) in yaxis" :data-value="point.value" :style="`--percent:${((point.value-min)/(max-min))*100}%;`" class="guideline">
|
|
21
21
|
</div>
|
|
22
22
|
</div>
|
|
23
|
-
<span
|
|
23
|
+
<span class="lines" v-if="type == 'line'"></span>
|
|
24
24
|
</Table>
|
|
25
|
-
<div
|
|
25
|
+
<div class="pies" v-if="type == 'pie'"></div>
|
|
26
26
|
</div>
|
|
27
27
|
</figure>
|
|
28
28
|
</div>
|
|
@@ -35,9 +35,10 @@
|
|
|
35
35
|
<script>
|
|
36
36
|
import { ucfirst, unsnake } from '../../helpers/strings'
|
|
37
37
|
import Table from '@/elements/Table/Table.vue'
|
|
38
|
+
import chartModule from '../../../assets/js/modules/chart.js'
|
|
38
39
|
|
|
39
40
|
export default {
|
|
40
|
-
name: '
|
|
41
|
+
name: 'Chart',
|
|
41
42
|
components: {
|
|
42
43
|
Table
|
|
43
44
|
},
|
|
@@ -73,172 +74,14 @@ export default {
|
|
|
73
74
|
required: true
|
|
74
75
|
}
|
|
75
76
|
},
|
|
76
|
-
computed: {
|
|
77
|
-
drawLines (){
|
|
78
|
-
return () => {
|
|
79
|
-
|
|
80
|
-
let lines = Array();
|
|
81
|
-
let spacer = 200/(Object.keys(this.items).length - 1);
|
|
82
|
-
const max = this.max - this.min;
|
|
83
|
-
|
|
84
|
-
// Creates the lines array from the fields array
|
|
85
|
-
this.fields.forEach((field, index) => {
|
|
86
|
-
|
|
87
|
-
if(index != 0){
|
|
88
|
-
|
|
89
|
-
lines[index-1] = '';
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
// populate the lines array from the items array
|
|
94
|
-
this.items.forEach((item, index) => {
|
|
95
|
-
|
|
96
|
-
Object.keys(item).forEach((key, subindex) => {
|
|
97
|
-
|
|
98
|
-
if(subindex != 0){
|
|
99
|
-
|
|
100
|
-
let value = item[key]
|
|
101
|
-
|
|
102
|
-
value = value.replace('£','');
|
|
103
|
-
value = value.replace('%','');
|
|
104
|
-
value = Number.parseFloat(value) - this.min;
|
|
105
|
-
|
|
106
|
-
const percent = (value/max) * 100;
|
|
107
|
-
let command = index == 0 ? 'M' : 'L';
|
|
108
|
-
|
|
109
|
-
lines[subindex-1] += `${command} ${spacer * index} ${100-percent} `;
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
// Create the line strings
|
|
115
|
-
let returnString = '';
|
|
116
|
-
|
|
117
|
-
lines.forEach((line, index) => {
|
|
118
|
-
|
|
119
|
-
returnString += `
|
|
120
|
-
<svg viewBox="0 0 200 100" class="line" preserveAspectRatio="none">
|
|
121
|
-
<path fill="none" d="${line}"></path>
|
|
122
|
-
</svg>`
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
return returnString;
|
|
126
|
-
}
|
|
127
|
-
},
|
|
128
|
-
drawPie (){
|
|
129
|
-
return () => {
|
|
130
|
-
|
|
131
|
-
let returnString = '';
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
this.items.forEach((item, index) => {
|
|
135
|
-
|
|
136
|
-
let paths = '';
|
|
137
|
-
let tooltips = '';
|
|
138
|
-
|
|
139
|
-
let cumulativePercent = 0;
|
|
140
|
-
|
|
141
|
-
function getCoordinatesForPercent(percent) {
|
|
142
|
-
const x = Math.cos(2 * Math.PI * percent);
|
|
143
|
-
const y = Math.sin(2 * Math.PI * percent);
|
|
144
|
-
return [x*100, y*100];
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
let total = 0;
|
|
148
|
-
|
|
149
|
-
let titleKey = Object.keys(item)[0]
|
|
150
|
-
let title = item[titleKey]
|
|
151
|
-
|
|
152
|
-
Object.keys(item).forEach((key, subindex) => {
|
|
153
|
-
|
|
154
|
-
if(subindex != 0){
|
|
155
|
-
let value = item[key]
|
|
156
|
-
|
|
157
|
-
value = value.replace('£','');
|
|
158
|
-
value = value.replace('%','');
|
|
159
|
-
value = Number.parseInt(value);
|
|
160
|
-
|
|
161
|
-
total += value;
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
Object.keys(item).forEach((key, subindex) => {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
if(subindex != 0){
|
|
169
|
-
|
|
170
|
-
let value = item[key]
|
|
171
|
-
|
|
172
|
-
value = value.replace('£','');
|
|
173
|
-
value = value.replace('%','');
|
|
174
|
-
value = Number.parseInt(value);
|
|
175
|
-
|
|
176
|
-
let percent = value/total;
|
|
177
|
-
|
|
178
|
-
//lines[subindex-1] += `${command} ${spacer * index} ${100-percent} `;
|
|
179
|
-
const [startX, startY] = getCoordinatesForPercent(cumulativePercent);
|
|
180
|
-
|
|
181
|
-
// each slice starts where the last slice ended, so keep a cumulative percent
|
|
182
|
-
cumulativePercent += percent;
|
|
183
|
-
|
|
184
|
-
const [endX, endY] = getCoordinatesForPercent(cumulativePercent);
|
|
185
|
-
|
|
186
|
-
// if the slice is more than 50%, take the large arc (the long way around)
|
|
187
|
-
const largeArcFlag = percent > .5 ? 1 : 0;
|
|
188
|
-
|
|
189
|
-
// create an array and join it just for code readability
|
|
190
|
-
const pathData = [
|
|
191
|
-
`M ${startX} ${startY}`, // Move
|
|
192
|
-
`A 100 100 0 ${largeArcFlag} 1 ${endX} ${endY}`, // Arc
|
|
193
|
-
`L 0 0`, // Line
|
|
194
|
-
].join(' ');
|
|
195
|
-
|
|
196
|
-
paths += `<path d="${pathData}"></path>`;
|
|
197
|
-
tooltips += `<foreignObject x="-70" y="-70" width="140" height="140" style="transform: rotate(90deg)"><div><span class="h5 mb-0">${ucfirst(unsnake(title))}<br/> ${ucfirst(unsnake(key))}<br/> ${item[key]}</span></div></foreignObject>`;
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
returnString += `<div class="pie"><svg viewBox="-105 -105 210 210" style="transform: rotate(-90deg)" preserveAspectRatio="none">${paths}<foreignObject x="-70" y="-70" width="140" height="140" style="transform: rotate(90deg)"><div><span class="h5 mb-0">${title}</span></div></foreignObject>${tooltips}</svg></div>`
|
|
202
|
-
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
return returnString;
|
|
207
|
-
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
},
|
|
211
77
|
mounted(){
|
|
212
78
|
this.$nextTick(function () {
|
|
213
79
|
|
|
214
80
|
// If the data gets updated we may need to recreate the tbody as it get detached when sorted in the table.js
|
|
215
|
-
|
|
216
|
-
const max = this.max -
|
|
217
|
-
|
|
218
|
-
Array.from(chart.querySelectorAll('tbody tr')).forEach((tr, index) => {
|
|
219
|
-
|
|
220
|
-
let group = tr.querySelector('td:first-child').innerHTML;
|
|
221
|
-
|
|
222
|
-
Array.from(tr.querySelectorAll('td[data-numeric]:not([data-numeric="0"]):not(:first-child)')).forEach((td, index) => {
|
|
223
|
-
|
|
224
|
-
const value = Number.parseFloat(td.getAttribute('data-numeric'));
|
|
225
|
-
let percent = ((value - this.min)/(max)) * 100;
|
|
226
|
-
const content = td.innerHTML;
|
|
227
|
-
const label = td.getAttribute('data-label');
|
|
228
|
-
let bottom = 0;
|
|
229
|
-
|
|
230
|
-
// If the value is negative the position below the 0 line
|
|
231
|
-
if(this.min < 0){
|
|
232
|
-
bottom = Math.abs((this.min)/(max)*100);
|
|
233
|
-
if(value < 0){
|
|
234
|
-
bottom = bottom - percent;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
td.setAttribute("style",`--bottom:${bottom}%;--percent:${percent}%;`);
|
|
81
|
+
const min = this.min;
|
|
82
|
+
const max = this.max - min;
|
|
238
83
|
|
|
239
|
-
|
|
240
|
-
});
|
|
241
|
-
});
|
|
84
|
+
chartModule(this.$refs.chartWrapper, min, max, this.type);
|
|
242
85
|
})
|
|
243
86
|
}
|
|
244
87
|
}
|