@politicalwatch/tipi-uikit 1.3.0
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/.browserslistrc +2 -0
- package/.editorconfig +7 -0
- package/.eslintrc.js +11 -0
- package/.postcssrc.json +5 -0
- package/.prettierrc.js +7 -0
- package/.stylelintrc +24 -0
- package/README.md +21 -0
- package/package.json +45 -0
- package/src/assets/.gitkeep +0 -0
- package/src/assets/birthday_bg.png +0 -0
- package/src/assets/party_logos/bildu.png +0 -0
- package/src/assets/party_logos/bng.png +0 -0
- package/src/assets/party_logos/ca.jpeg +0 -0
- package/src/assets/party_logos/ciudadanos.png +0 -0
- package/src/assets/party_logos/compromis.jpg +0 -0
- package/src/assets/party_logos/cup.png +0 -0
- package/src/assets/party_logos/eajpnv.png +0 -0
- package/src/assets/party_logos/encomupodem.jpg +0 -0
- package/src/assets/party_logos/erc.png +0 -0
- package/src/assets/party_logos/fac.png +0 -0
- package/src/assets/party_logos/icon/bng.svg +4 -0
- package/src/assets/party_logos/icon/coalicioncanaria.svg +7 -0
- package/src/assets/party_logos/icon/compromis.svg +3 -0
- package/src/assets/party_logos/icon/cs.svg +3 -0
- package/src/assets/party_logos/icon/cup.svg +4 -0
- package/src/assets/party_logos/icon/ehbildu.svg +4 -0
- package/src/assets/party_logos/icon/encomu.svg +3 -0
- package/src/assets/party_logos/icon/erc.svg +5 -0
- package/src/assets/party_logos/icon/foroasturias.svg +4 -0
- package/src/assets/party_logos/icon/iu.svg +3 -0
- package/src/assets/party_logos/icon/jxcat.svg +3 -0
- package/src/assets/party_logos/icon/maspais.svg +3 -0
- package/src/assets/party_logos/icon/nuevacanaria.svg +3 -0
- package/src/assets/party_logos/icon/pdecat.svg +3 -0
- package/src/assets/party_logos/icon/pnv.svg +4 -0
- package/src/assets/party_logos/icon/podemos.svg +3 -0
- package/src/assets/party_logos/icon/pp.svg +4 -0
- package/src/assets/party_logos/icon/prc.svg +5 -0
- package/src/assets/party_logos/icon/psoe.svg +3 -0
- package/src/assets/party_logos/icon/sumar.svg +73 -0
- package/src/assets/party_logos/icon/teruelexiste.svg +3 -0
- package/src/assets/party_logos/icon/unidaspodemos.svg +27 -0
- package/src/assets/party_logos/icon/upn.svg +5 -0
- package/src/assets/party_logos/icon/vox.svg +4 -0
- package/src/assets/party_logos/iu.png +0 -0
- package/src/assets/party_logos/jxcat.png +0 -0
- package/src/assets/party_logos/mas-pais.jpg +0 -0
- package/src/assets/party_logos/nueva_canarias.png +0 -0
- package/src/assets/party_logos/pdecat.png +0 -0
- package/src/assets/party_logos/podemos.jpg +0 -0
- package/src/assets/party_logos/pp.png +0 -0
- package/src/assets/party_logos/prc.png +0 -0
- package/src/assets/party_logos/psc.png +0 -0
- package/src/assets/party_logos/pse-ee.png +0 -0
- package/src/assets/party_logos/psoe.png +0 -0
- package/src/assets/party_logos/teruelexiste.svg +4 -0
- package/src/assets/party_logos/unidaspodemos.png +0 -0
- package/src/assets/party_logos/upn.jpg +0 -0
- package/src/assets/party_logos/vox.png +0 -0
- package/src/assets/svg/icon-advanced.svg +3 -0
- package/src/assets/svg/icon-bell.svg +3 -0
- package/src/assets/svg/icon-birthday.svg +18 -0
- package/src/assets/svg/icon-building.svg +3 -0
- package/src/assets/svg/icon-calendar.svg +4 -0
- package/src/assets/svg/icon-chevron-down.svg +3 -0
- package/src/assets/svg/icon-chevron-left.svg +3 -0
- package/src/assets/svg/icon-chevron-right.svg +3 -0
- package/src/assets/svg/icon-chevron-up.svg +3 -0
- package/src/assets/svg/icon-clock.svg +4 -0
- package/src/assets/svg/icon-close-menu.svg +3 -0
- package/src/assets/svg/icon-close.svg +3 -0
- package/src/assets/svg/icon-conversation.svg +3 -0
- package/src/assets/svg/icon-denied.svg +3 -0
- package/src/assets/svg/icon-document.svg +4 -0
- package/src/assets/svg/icon-download.svg +3 -0
- package/src/assets/svg/icon-error.svg +3 -0
- package/src/assets/svg/icon-github.svg +9 -0
- package/src/assets/svg/icon-hamburger.svg +1 -0
- package/src/assets/svg/icon-info.svg +3 -0
- package/src/assets/svg/icon-less.svg +3 -0
- package/src/assets/svg/icon-location.svg +3 -0
- package/src/assets/svg/icon-mail.svg +4 -0
- package/src/assets/svg/icon-more.svg +5 -0
- package/src/assets/svg/icon-open-blank.svg +3 -0
- package/src/assets/svg/icon-plus.svg +3 -0
- package/src/assets/svg/icon-search.svg +4 -0
- package/src/assets/svg/icon-success.svg +3 -0
- package/src/assets/svg/icon-twitter.svg +3 -0
- package/src/assets/svg/icon-upload.svg +3 -0
- package/src/components/CSVDownload/CSVDownload.vue +77 -0
- package/src/components/Charts/Barchart/d3.barchart.js +488 -0
- package/src/components/Charts/Barchart/d3.barchart.vue +16 -0
- package/src/components/Charts/Sliceschart/d3.sliceschart.js +272 -0
- package/src/components/Charts/Sliceschart/d3.sliceschart.vue +20 -0
- package/src/components/Charts/Sunburst/d3.sunburst.js +416 -0
- package/src/components/Charts/Sunburst/d3.sunburst.vue +23 -0
- package/src/components/Charts/WordsCloud/d3.wordscloud.js +336 -0
- package/src/components/Charts/WordsCloud/d3.wordscloud.vue +16 -0
- package/src/components/Charts/d3.chart.js +242 -0
- package/src/components/Charts/d3.chart.vue +80 -0
- package/src/components/Charts/styles.scss +92 -0
- package/src/components/CongressLink/CongressLink.vue +17 -0
- package/src/components/Deputy/Deputy.vue +119 -0
- package/src/components/Header/Header.vue +15 -0
- package/src/components/Icon/Icon.vue +33 -0
- package/src/components/InitiativeCard/InitiativeCard.vue +98 -0
- package/src/components/InitiativeMeta/InitiativeMeta.vue +85 -0
- package/src/components/Loader/Loader.vue +27 -0
- package/src/components/Message/Message.vue +29 -0
- package/src/components/Navbar/Navbar.vue +96 -0
- package/src/components/Neuron/Neuron.vue +209 -0
- package/src/components/PartyLogo/PartyLogo.vue +59 -0
- package/src/components/PartyLogo/PartyLogoIcon.vue +229 -0
- package/src/components/Results/Results.vue +109 -0
- package/src/components/Splash/Splash.vue +42 -0
- package/src/components/Text/Text.vue +59 -0
- package/src/components/TipiCharts/TipiBarchart.vue +204 -0
- package/src/components/TopicCard/TopicCard.vue +40 -0
- package/src/components/TopicLink/TopicLink.vue +33 -0
- package/src/components/TopicPill/TopicPill.vue +69 -0
- package/src/components/Topics/Topics.vue +84 -0
- package/src/components/TwoCircles/TwoCircles.vue +138 -0
- package/src/components/index.js +53 -0
- package/src/main.js +11 -0
- package/src/styles/01_settings/_settings__breakpoints.scss +28 -0
- package/src/styles/01_settings/_settings__colors.scss +30 -0
- package/src/styles/01_settings/_settings__fonts.scss +3 -0
- package/src/styles/01_settings/_settings__icons.scss +0 -0
- package/src/styles/01_settings/_settings__variables.scss +45 -0
- package/src/styles/02_tools/_tools__functions.scss +19 -0
- package/src/styles/02_tools/_tools__mixins.scss +321 -0
- package/src/styles/03_generic/_generic__box-sizing.scss +12 -0
- package/src/styles/03_generic/_generic__global.scss +20 -0
- package/src/styles/03_generic/_generic__normalize.scss +371 -0
- package/src/styles/04_base/_base__anchors.scss +8 -0
- package/src/styles/04_base/_base__blockquotes.scss +8 -0
- package/src/styles/04_base/_base__forms.scss +32 -0
- package/src/styles/04_base/_base__headings.scss +23 -0
- package/src/styles/04_base/_base__images.scss +4 -0
- package/src/styles/04_base/_base__lists.scss +66 -0
- package/src/styles/04_base/_base__paragraphs.scss +11 -0
- package/src/styles/04_base/_base__tables.scss +95 -0
- package/src/styles/05_objects/_objects__columns.scss +29 -0
- package/src/styles/05_objects/_objects__container.scss +19 -0
- package/src/styles/05_objects/_objects__grid.scss +57 -0
- package/src/styles/05_objects/_objects__masonry.scss +11 -0
- package/src/styles/05_objects/_objects__media.scss +24 -0
- package/src/styles/05_objects/_objects__section.scss +21 -0
- package/src/styles/06_components/_components__button.scss +178 -0
- package/src/styles/06_components/_components__congress-link.scss +12 -0
- package/src/styles/06_components/_components__decorator.scss +10 -0
- package/src/styles/06_components/_components__deputy.scss +167 -0
- package/src/styles/06_components/_components__disclaimer.scss +24 -0
- package/src/styles/06_components/_components__forms.scss +454 -0
- package/src/styles/06_components/_components__header.scss +36 -0
- package/src/styles/06_components/_components__icon.scss +17 -0
- package/src/styles/06_components/_components__initiative-card.scss +49 -0
- package/src/styles/06_components/_components__initiative-meta.scss +91 -0
- package/src/styles/06_components/_components__loader.scss +125 -0
- package/src/styles/06_components/_components__menu.scss +104 -0
- package/src/styles/06_components/_components__message.scss +66 -0
- package/src/styles/06_components/_components__navbar.scss +114 -0
- package/src/styles/06_components/_components__party-logo.scss +21 -0
- package/src/styles/06_components/_components__splash.scss +29 -0
- package/src/styles/06_components/_components__text.scss +69 -0
- package/src/styles/06_components/_components__topic-card.scss +36 -0
- package/src/styles/06_components/_components__topic-link.scss +37 -0
- package/src/styles/06_components/_components__topics.scss +107 -0
- package/src/styles/07_trumps/_trumps__borders.scss +1 -0
- package/src/styles/07_trumps/_trumps__colors.scss +3 -0
- package/src/styles/07_trumps/_trumps__grid.scss +1 -0
- package/src/styles/07_trumps/_trumps__helpers.scss +17 -0
- package/src/styles/07_trumps/_trumps__texts.scss +39 -0
- package/src/styles/07_trumps/_trumps__visibility.scss +56 -0
- package/src/styles/main.scss +54 -0
- package/src/utils/index.js +26 -0
- package/svgo.config.js +16 -0
- package/vite.config.js +57 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<span v-show="initiatives.length">
|
|
3
|
+
<a
|
|
4
|
+
v-if="!csvItems.length"
|
|
5
|
+
:class="{ disabled: !canDownloadCSV }"
|
|
6
|
+
:title="!canDownloadCSV ? 'Demasiados resultados para poder descargar. Afina la búsqueda' : 'Descarga CSV con todos los resultados'"
|
|
7
|
+
@click.prevent="loadCSVItems"
|
|
8
|
+
class="c-button c-button--compact c-button--secondary c-button--icon-right" href="#">
|
|
9
|
+
{{ label }}
|
|
10
|
+
<span class="c-icon c-icon--type-download">
|
|
11
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="12" height="16" fill="none" viewBox="0 0 12 16">
|
|
12
|
+
<path fill="#2D4252" d="M12 5.647H8.571V0H3.43v5.647H0l6 6.588 6-6.588zm-12 8.47V16h12v-1.882H0z"></path>
|
|
13
|
+
</svg>
|
|
14
|
+
</span>
|
|
15
|
+
</a>
|
|
16
|
+
<vue-csv-downloader
|
|
17
|
+
v-else
|
|
18
|
+
:data="csvItems"
|
|
19
|
+
:fields="csvFields"
|
|
20
|
+
:downloadName="getNameFromCSV()"
|
|
21
|
+
id="downloadCSV"
|
|
22
|
+
class="c-button c-button--icon-right" :class="buttonClass">
|
|
23
|
+
{{ label }}
|
|
24
|
+
<span class="c-icon c-icon--type-download">
|
|
25
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="12" height="16" fill="none" viewBox="0 0 12 16">
|
|
26
|
+
<path fill="#2D4252" d="M12 5.647H8.571V0H3.43v5.647H0l6 6.588 6-6.588zm-12 8.47V16h12v-1.882H0z"></path>
|
|
27
|
+
</svg>
|
|
28
|
+
</span>
|
|
29
|
+
</vue-csv-downloader>
|
|
30
|
+
</span>
|
|
31
|
+
</template>
|
|
32
|
+
|
|
33
|
+
<script>
|
|
34
|
+
import VueCsvDownloader from 'vue-csv-downloader';
|
|
35
|
+
|
|
36
|
+
export default {
|
|
37
|
+
name: 'TipiCsvDownload',
|
|
38
|
+
components: {
|
|
39
|
+
VueCsvDownloader,
|
|
40
|
+
},
|
|
41
|
+
props: {
|
|
42
|
+
initiatives: {
|
|
43
|
+
type: Array,
|
|
44
|
+
default: function() { return []; },
|
|
45
|
+
},
|
|
46
|
+
csvItems: Array,
|
|
47
|
+
canDownloadCSV: Boolean,
|
|
48
|
+
csvFields: {
|
|
49
|
+
type: Array,
|
|
50
|
+
default: function() { return ['title', 'reference', 'initiative_type_alt', 'authors', 'deputies', 'tagged.0.topics', 'tagged.0.tags', 'place', 'status', 'created','updated', 'url']; },
|
|
51
|
+
},
|
|
52
|
+
label: {
|
|
53
|
+
type: String,
|
|
54
|
+
default: 'Descarga los datos',
|
|
55
|
+
},
|
|
56
|
+
buttonClass: {
|
|
57
|
+
type: String,
|
|
58
|
+
default: 'c-button--compact',
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
methods: {
|
|
62
|
+
loadCSVItems: function(event) {
|
|
63
|
+
this.$emit('loadCSVItems', event);
|
|
64
|
+
},
|
|
65
|
+
getNameFromCSV: function() {
|
|
66
|
+
let d = new Date();
|
|
67
|
+
return "export-" + d.toISOString() + ".csv";
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
</script>
|
|
72
|
+
|
|
73
|
+
<style scoped lang="scss">
|
|
74
|
+
.c-button--secondary {
|
|
75
|
+
margin-right: 16px;
|
|
76
|
+
}
|
|
77
|
+
</style>
|
|
@@ -0,0 +1,488 @@
|
|
|
1
|
+
import d3chart from "../d3.chart";
|
|
2
|
+
import { select, selectAll } from "d3-selection";
|
|
3
|
+
import { scaleBand, scaleLinear, scaleOrdinal } from "d3-scale";
|
|
4
|
+
import { max } from "d3-array";
|
|
5
|
+
import { transition } from "d3-transition";
|
|
6
|
+
import { axisBottom, axisLeft } from "d3-axis";
|
|
7
|
+
import {
|
|
8
|
+
easeLinear,
|
|
9
|
+
easePolyIn,
|
|
10
|
+
easePolyOut,
|
|
11
|
+
easePoly,
|
|
12
|
+
easePolyInOut,
|
|
13
|
+
easeQuadIn,
|
|
14
|
+
easeQuadOut,
|
|
15
|
+
easeQuad,
|
|
16
|
+
easeQuadInOut,
|
|
17
|
+
easeCubicIn,
|
|
18
|
+
easeCubicOut,
|
|
19
|
+
easeCubic,
|
|
20
|
+
easeCubicInOut,
|
|
21
|
+
easeSinIn,
|
|
22
|
+
easeSinOut,
|
|
23
|
+
easeSin,
|
|
24
|
+
easeSinInOut,
|
|
25
|
+
easeExpIn,
|
|
26
|
+
easeExpOut,
|
|
27
|
+
easeExp,
|
|
28
|
+
easeExpInOut,
|
|
29
|
+
easeCircleIn,
|
|
30
|
+
easeCircleOut,
|
|
31
|
+
easeCircle,
|
|
32
|
+
easeCircleInOut,
|
|
33
|
+
easeElasticIn,
|
|
34
|
+
easeElastic,
|
|
35
|
+
easeElasticOut,
|
|
36
|
+
easeElasticInOut,
|
|
37
|
+
easeBackIn,
|
|
38
|
+
easeBackOut,
|
|
39
|
+
easeBack,
|
|
40
|
+
easeBackInOut,
|
|
41
|
+
easeBounceIn,
|
|
42
|
+
easeBounce,
|
|
43
|
+
easeBounceOut,
|
|
44
|
+
easeBounceInOut
|
|
45
|
+
} from "d3-ease";
|
|
46
|
+
import {
|
|
47
|
+
schemeCategory10,
|
|
48
|
+
schemeAccent,
|
|
49
|
+
schemeDark2,
|
|
50
|
+
schemePaired,
|
|
51
|
+
schemePastel1,
|
|
52
|
+
schemePastel2,
|
|
53
|
+
schemeSet1,
|
|
54
|
+
schemeSet2,
|
|
55
|
+
schemeSet3,
|
|
56
|
+
schemeTableau10
|
|
57
|
+
} from "d3-scale-chromatic";
|
|
58
|
+
|
|
59
|
+
const d3 = {
|
|
60
|
+
select,
|
|
61
|
+
selectAll,
|
|
62
|
+
scaleBand,
|
|
63
|
+
scaleLinear,
|
|
64
|
+
scaleOrdinal,
|
|
65
|
+
max,
|
|
66
|
+
transition,
|
|
67
|
+
axisBottom,
|
|
68
|
+
axisLeft,
|
|
69
|
+
easeLinear,
|
|
70
|
+
easePolyIn,
|
|
71
|
+
easePolyOut,
|
|
72
|
+
easePoly,
|
|
73
|
+
easePolyInOut,
|
|
74
|
+
easeQuadIn,
|
|
75
|
+
easeQuadOut,
|
|
76
|
+
easeQuad,
|
|
77
|
+
easeQuadInOut,
|
|
78
|
+
easeCubicIn,
|
|
79
|
+
easeCubicOut,
|
|
80
|
+
easeCubic,
|
|
81
|
+
easeCubicInOut,
|
|
82
|
+
easeSinIn,
|
|
83
|
+
easeSinOut,
|
|
84
|
+
easeSin,
|
|
85
|
+
easeSinInOut,
|
|
86
|
+
easeExpIn,
|
|
87
|
+
easeExpOut,
|
|
88
|
+
easeExp,
|
|
89
|
+
easeExpInOut,
|
|
90
|
+
easeCircleIn,
|
|
91
|
+
easeCircleOut,
|
|
92
|
+
easeCircle,
|
|
93
|
+
easeCircleInOut,
|
|
94
|
+
easeElasticIn,
|
|
95
|
+
easeElastic,
|
|
96
|
+
easeElasticOut,
|
|
97
|
+
easeElasticInOut,
|
|
98
|
+
easeBackIn,
|
|
99
|
+
easeBackOut,
|
|
100
|
+
easeBack,
|
|
101
|
+
easeBackInOut,
|
|
102
|
+
easeBounceIn,
|
|
103
|
+
easeBounce,
|
|
104
|
+
easeBounceOut,
|
|
105
|
+
easeBounceInOut,
|
|
106
|
+
schemeCategory10,
|
|
107
|
+
schemeAccent,
|
|
108
|
+
schemeDark2,
|
|
109
|
+
schemePaired,
|
|
110
|
+
schemePastel1,
|
|
111
|
+
schemePastel2,
|
|
112
|
+
schemeSet1,
|
|
113
|
+
schemeSet2,
|
|
114
|
+
schemeSet3,
|
|
115
|
+
schemeTableau10
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
import pluralize from "pluralize";
|
|
119
|
+
|
|
120
|
+
const REFERENCE = "Texto de referencia";
|
|
121
|
+
const SCANNED = "Texto escaneado";
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* D3 Bar Chart
|
|
125
|
+
*/
|
|
126
|
+
class d3barchart extends d3chart {
|
|
127
|
+
constructor(selection, data, config) {
|
|
128
|
+
super(selection, data, config, {
|
|
129
|
+
margin: { top: 10, right: 30, bottom: 20, left: 40 },
|
|
130
|
+
key: "key",
|
|
131
|
+
currentKey: false,
|
|
132
|
+
values: [],
|
|
133
|
+
orientation: "vertical",
|
|
134
|
+
labelRotation: 0,
|
|
135
|
+
color: {
|
|
136
|
+
key: false,
|
|
137
|
+
keys: false,
|
|
138
|
+
scheme: false,
|
|
139
|
+
current: "#1f77b4",
|
|
140
|
+
default: "#AAA",
|
|
141
|
+
axis: "#000"
|
|
142
|
+
},
|
|
143
|
+
axis: {
|
|
144
|
+
yTitle: false,
|
|
145
|
+
xTitle: false,
|
|
146
|
+
yFormat: ".0f",
|
|
147
|
+
xFormat: ".0f",
|
|
148
|
+
yTicks: 10,
|
|
149
|
+
xTicks: 10
|
|
150
|
+
},
|
|
151
|
+
tooltip: { label: false, suffix: false, suffixPlural: false },
|
|
152
|
+
keys: { [SCANNED]: SCANNED, [REFERENCE]: REFERENCE },
|
|
153
|
+
transition: { duration: 350, ease: "easeLinear" }
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Init chart
|
|
159
|
+
*/
|
|
160
|
+
initChart() {
|
|
161
|
+
// Set up dimensions
|
|
162
|
+
this.getDimensions();
|
|
163
|
+
this.initChartFrame("barchart");
|
|
164
|
+
|
|
165
|
+
if (this.cfg.tooltip.suffix && this.cfg.tooltip.suffixPlural) {
|
|
166
|
+
pluralize.addIrregularRule(this.cfg.tooltip.suffix, this.cfg.tooltip.suffixPlural);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Set up scales
|
|
170
|
+
this.xScale = d3.scaleBand();
|
|
171
|
+
this.xScaleInn = d3.scaleBand();
|
|
172
|
+
this.yScale = d3.scaleLinear();
|
|
173
|
+
|
|
174
|
+
// Axis group
|
|
175
|
+
this.axisg = this.g.append("g").attr("class", "chart__axis chart__axis--barchart");
|
|
176
|
+
|
|
177
|
+
// Horizontal grid
|
|
178
|
+
this.yGrid = this.axisg
|
|
179
|
+
.append("g")
|
|
180
|
+
.attr("class", "chart__grid chart__grid--y chart__grid--barchart");
|
|
181
|
+
|
|
182
|
+
// Bottom axis
|
|
183
|
+
this.xAxis = this.axisg.append("g").attr("class", "chart__axis-x chart__axis-x--barchart");
|
|
184
|
+
|
|
185
|
+
// Vertical axis title
|
|
186
|
+
if (this.cfg.axis.yTitle)
|
|
187
|
+
this.yAxisTitle = this.axisg
|
|
188
|
+
.append("text")
|
|
189
|
+
.attr("class", "chart__axis-title chart__axis-title--barchart")
|
|
190
|
+
.attr("transform", "rotate(-90)")
|
|
191
|
+
.style("text-anchor", "middle");
|
|
192
|
+
|
|
193
|
+
this.setChartDimension();
|
|
194
|
+
this.updateChart();
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Resize chart pipe
|
|
199
|
+
*/
|
|
200
|
+
setScales() {
|
|
201
|
+
this.xScale
|
|
202
|
+
.rangeRound(
|
|
203
|
+
this.cfg.orientation !== "horizontal" ? [0, this.cfg.width] : [0, this.cfg.height]
|
|
204
|
+
)
|
|
205
|
+
.paddingInner(0.1)
|
|
206
|
+
.domain(this.data.map(d => d[this.cfg.key]));
|
|
207
|
+
|
|
208
|
+
this.xScaleInn
|
|
209
|
+
.domain(this.cfg.values)
|
|
210
|
+
.rangeRound([0, this.xScale.bandwidth()])
|
|
211
|
+
.paddingInner(0.05);
|
|
212
|
+
|
|
213
|
+
const yMax = this.calculateBiggestNumber();
|
|
214
|
+
this.yScale
|
|
215
|
+
.rangeRound(
|
|
216
|
+
this.cfg.orientation !== "horizontal" ? [0, this.cfg.height] : [this.cfg.width, 0]
|
|
217
|
+
)
|
|
218
|
+
.domain([yMax, 0]);
|
|
219
|
+
|
|
220
|
+
if (this.cfg.color.scheme instanceof Array === true) {
|
|
221
|
+
this.colorScale = d3.scaleOrdinal().range(this.cfg.color.scheme);
|
|
222
|
+
} else if (typeof this.cfg.color.scheme === "string") {
|
|
223
|
+
this.colorScale = d3.scaleOrdinal(d3[this.cfg.color.scheme]);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const yGridFunction =
|
|
227
|
+
this.cfg.orientation !== "horizontal"
|
|
228
|
+
? d3
|
|
229
|
+
.axisLeft(this.yScale)
|
|
230
|
+
.tickSize(-this.cfg.width)
|
|
231
|
+
.ticks(this.cfg.axis.yTicks, this.cfg.axis.yFormat)
|
|
232
|
+
: d3
|
|
233
|
+
.axisBottom(this.yScale)
|
|
234
|
+
.tickSize(-this.cfg.height)
|
|
235
|
+
.ticks(this.cfg.axis.yTicks, this.cfg.axis.yFormat);
|
|
236
|
+
|
|
237
|
+
const xAxisFunction =
|
|
238
|
+
this.cfg.orientation !== "horizontal" ? d3.axisBottom(this.xScale) : d3.axisLeft(this.xScale);
|
|
239
|
+
|
|
240
|
+
// Horizontal grid
|
|
241
|
+
this.yGrid
|
|
242
|
+
.attr(
|
|
243
|
+
"transform",
|
|
244
|
+
this.cfg.orientation !== "horizontal" ? "translate(0,0)" : `translate(0,${this.cfg.height})`
|
|
245
|
+
)
|
|
246
|
+
.transition(this.transition)
|
|
247
|
+
.call(yGridFunction);
|
|
248
|
+
|
|
249
|
+
// Bottom axis
|
|
250
|
+
this.xAxis
|
|
251
|
+
.attr(
|
|
252
|
+
"transform",
|
|
253
|
+
this.cfg.orientation !== "horizontal" ? `translate(0,${this.cfg.height})` : "translate(0,0)"
|
|
254
|
+
)
|
|
255
|
+
.call(xAxisFunction);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Set chart dimensional sizes
|
|
260
|
+
*/
|
|
261
|
+
setChartDimension() {
|
|
262
|
+
// SVG element
|
|
263
|
+
this.svg
|
|
264
|
+
.attr(
|
|
265
|
+
"viewBox",
|
|
266
|
+
`0 0 ${this.cfg.width + this.cfg.margin.left + this.cfg.margin.right} ${this.cfg.height +
|
|
267
|
+
this.cfg.margin.top +
|
|
268
|
+
this.cfg.margin.bottom}`
|
|
269
|
+
)
|
|
270
|
+
.attr("width", this.cfg.width + this.cfg.margin.left + this.cfg.margin.right)
|
|
271
|
+
.attr("height", this.cfg.height + this.cfg.margin.top + this.cfg.margin.bottom);
|
|
272
|
+
|
|
273
|
+
// Vertical axis title
|
|
274
|
+
if (this.cfg.axis.yTitle)
|
|
275
|
+
this.yAxisTitle
|
|
276
|
+
.attr("y", -this.cfg.margin.left + 10)
|
|
277
|
+
.attr("x", -this.cfg.height / 2)
|
|
278
|
+
.text(this.cfg.axis.yTitle);
|
|
279
|
+
|
|
280
|
+
// Bottom axis label rotation
|
|
281
|
+
if (this.cfg.labelRotation !== 0)
|
|
282
|
+
this.xAxis
|
|
283
|
+
.selectAll("text")
|
|
284
|
+
.attr("y", Math.cos((this.cfg.labelRotation * Math.PI) / 180) * 9)
|
|
285
|
+
.attr("x", Math.sin((this.cfg.labelRotation * Math.PI) / 180) * 9)
|
|
286
|
+
.attr("dy", ".35em")
|
|
287
|
+
.attr("transform", `rotate(${this.cfg.labelRotation})`)
|
|
288
|
+
.style("text-anchor", "start");
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Bind data to main elements groups
|
|
293
|
+
*/
|
|
294
|
+
bindData() {
|
|
295
|
+
// Set transition
|
|
296
|
+
this.transition = d3
|
|
297
|
+
.transition("t")
|
|
298
|
+
.duration(this.cfg.transition.duration)
|
|
299
|
+
.ease(d3[this.cfg.transition.ease]);
|
|
300
|
+
|
|
301
|
+
// Bars groups
|
|
302
|
+
this.g.selectAll(".chart__bar-group").remove();
|
|
303
|
+
this.itemg = this.g.selectAll(".chart__bar-group").data(this.data, d => d[this.cfg.key]);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
hasComparissionData() {
|
|
307
|
+
return this.data.some(item => item[REFERENCE] > 0);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
calculateTotals() {
|
|
311
|
+
const totalCompared = this.data.reduce((total, item) => {
|
|
312
|
+
return total + item[REFERENCE];
|
|
313
|
+
}, 0);
|
|
314
|
+
const totalOriginal = this.data.reduce((total, item) => {
|
|
315
|
+
return total + item[SCANNED];
|
|
316
|
+
}, 0);
|
|
317
|
+
return { [REFERENCE]: totalCompared, [SCANNED]: totalOriginal };
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
calculateMaximums() {
|
|
321
|
+
const maxCompared = this.data.reduce(
|
|
322
|
+
(max, item) => this.getBiggerNumber(max, item[REFERENCE]),
|
|
323
|
+
0
|
|
324
|
+
);
|
|
325
|
+
const maxOriginal = this.data.reduce(
|
|
326
|
+
(max, item) => this.getBiggerNumber(max, item[SCANNED]),
|
|
327
|
+
0
|
|
328
|
+
);
|
|
329
|
+
return { [REFERENCE]: maxCompared, [SCANNED]: maxOriginal };
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
getBiggerNumber(a, b) {
|
|
333
|
+
if (a > b) {
|
|
334
|
+
return a;
|
|
335
|
+
}
|
|
336
|
+
return b;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
calculateBiggestNumber() {
|
|
340
|
+
const totals = this.calculateTotals();
|
|
341
|
+
const maximums = this.calculateMaximums();
|
|
342
|
+
|
|
343
|
+
const referenceMax = maximums[REFERENCE];
|
|
344
|
+
const referenceTotal = totals[REFERENCE];
|
|
345
|
+
|
|
346
|
+
const scannedMax = maximums[SCANNED];
|
|
347
|
+
const scannedTotal = totals[SCANNED];
|
|
348
|
+
|
|
349
|
+
const referencePercentage = this.calculatePercentage(referenceMax, referenceTotal);
|
|
350
|
+
const scannedPercentage = this.calculatePercentage(scannedMax, scannedTotal);
|
|
351
|
+
|
|
352
|
+
const biggest = this.getBiggerNumber(referencePercentage, scannedPercentage);
|
|
353
|
+
return this.roundToNextStep(biggest);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
roundToNextStep(x) {
|
|
357
|
+
return Math.ceil(x / 10) * 10;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
calculatePercentage(value, total) {
|
|
361
|
+
return (value * 100) / total;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Add new chart's elements
|
|
366
|
+
*/
|
|
367
|
+
enterElements() {
|
|
368
|
+
const totals = this.calculateTotals();
|
|
369
|
+
|
|
370
|
+
const newbars = this.itemg
|
|
371
|
+
.enter()
|
|
372
|
+
.append("g")
|
|
373
|
+
.attr("class", "chart__bar-group chart__bar-group--barchart")
|
|
374
|
+
.attr("transform", d => {
|
|
375
|
+
if (this.cfg.orientation !== "horizontal") {
|
|
376
|
+
return `translate(${this.xScale(d[this.cfg.key])},0)`;
|
|
377
|
+
}
|
|
378
|
+
return `translate(0,${this.xScale(d[this.cfg.key])})`;
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
const rects = newbars
|
|
382
|
+
.selectAll(".chart__bar")
|
|
383
|
+
.data(d =>
|
|
384
|
+
this.cfg.values.map(v => {
|
|
385
|
+
const dat = { ...d };
|
|
386
|
+
dat[this.cfg.key] = d[this.cfg.key];
|
|
387
|
+
return dat;
|
|
388
|
+
})
|
|
389
|
+
)
|
|
390
|
+
.enter()
|
|
391
|
+
.append("rect")
|
|
392
|
+
.attr("class", "chart__bar chart__bar--barchart")
|
|
393
|
+
.classed("chart__bar--current", d => {
|
|
394
|
+
return this.cfg.currentKey && d[this.cfg.key] === this.cfg.currentKey;
|
|
395
|
+
})
|
|
396
|
+
.attr("x", (d, i) => {
|
|
397
|
+
return this.cfg.orientation !== "horizontal"
|
|
398
|
+
? this.xScaleInn(this.cfg.values[i % this.cfg.values.length])
|
|
399
|
+
: 0;
|
|
400
|
+
})
|
|
401
|
+
.attr("y", (d, i) => {
|
|
402
|
+
return this.cfg.orientation !== "horizontal"
|
|
403
|
+
? this.cfg.height
|
|
404
|
+
: this.xScaleInn(this.cfg.values[i % this.cfg.values.length]);
|
|
405
|
+
})
|
|
406
|
+
.attr("height", 0)
|
|
407
|
+
.attr("width", 0)
|
|
408
|
+
.on("mouseover", (d, i) => {
|
|
409
|
+
const key = this.cfg.values[i % this.cfg.values.length];
|
|
410
|
+
const label = this.cfg.tooltip.suffixPlural
|
|
411
|
+
? pluralize(this.cfg.tooltip.suffix, d[key])
|
|
412
|
+
: this.cfg.tooltip.suffix;
|
|
413
|
+
|
|
414
|
+
const labelKey = this.cfg.keys[key];
|
|
415
|
+
|
|
416
|
+
const percentage = this.calculatePercentage(d[key], totals[key]).toFixed(2);
|
|
417
|
+
|
|
418
|
+
const text = this.cfg.tooltip.suffix
|
|
419
|
+
? `<div>${labelKey}: ${percentage}% ${label}</div>`
|
|
420
|
+
: `<div>${labelKey}: ${percentage}%</div>`;
|
|
421
|
+
this.tooltip.html(text).classed("active", true);
|
|
422
|
+
})
|
|
423
|
+
.on("mouseout", () => {
|
|
424
|
+
this.tooltip.classed("active", false);
|
|
425
|
+
})
|
|
426
|
+
.on("mousemove", () => {
|
|
427
|
+
this.tooltip
|
|
428
|
+
.style("left", window.event["pageX"] - 28 + "px")
|
|
429
|
+
.style("top", window.event["pageY"] - 40 + "px");
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Update chart's elements based on data change
|
|
435
|
+
*/
|
|
436
|
+
updateElements() {
|
|
437
|
+
const totals = this.calculateTotals();
|
|
438
|
+
|
|
439
|
+
// Bars groups
|
|
440
|
+
this.itemg.transition(this.transition).attr("transform", d => {
|
|
441
|
+
return this.cfg.orientation !== "horizontal"
|
|
442
|
+
? `translate(${this.xScale(d[this.cfg.key])},0)`
|
|
443
|
+
: `translate(0,${this.xScale(d[this.cfg.key])})`;
|
|
444
|
+
});
|
|
445
|
+
// Bars
|
|
446
|
+
this.g
|
|
447
|
+
.selectAll(".chart__bar")
|
|
448
|
+
.transition(this.transition)
|
|
449
|
+
.attr("fill", (d, i) => this.colorElement(d, this.cfg.values[i % this.cfg.values.length]))
|
|
450
|
+
.attr("opacity", (d, i) => (i % 2 == 1 && this.hasComparissionData() ? 0.6 : 1))
|
|
451
|
+
.attr("x", (d, i) => {
|
|
452
|
+
return this.cfg.orientation !== "horizontal"
|
|
453
|
+
? this.xScaleInn(this.cfg.values[i % this.cfg.values.length])
|
|
454
|
+
: 0;
|
|
455
|
+
})
|
|
456
|
+
.attr("y", (d, i) => {
|
|
457
|
+
return this.cfg.orientation !== "horizontal"
|
|
458
|
+
? this.yScale(+d[this.cfg.values[i % this.cfg.values.length]])
|
|
459
|
+
: this.xScaleInn(this.cfg.values[i % this.cfg.values.length]);
|
|
460
|
+
})
|
|
461
|
+
.attr("width", (d, i) => {
|
|
462
|
+
const key = this.cfg.values[i % this.cfg.values.length];
|
|
463
|
+
const percentage = this.calculatePercentage(d[key], totals[key]);
|
|
464
|
+
|
|
465
|
+
return this.cfg.orientation !== "horizontal"
|
|
466
|
+
? this.xScaleInn.bandwidth()
|
|
467
|
+
: this.yScale(percentage);
|
|
468
|
+
})
|
|
469
|
+
.attr("height", (d, i) => {
|
|
470
|
+
return this.cfg.orientation !== "horizontal"
|
|
471
|
+
? this.cfg.height - this.yScale(+d[this.cfg.values[i % this.cfg.values.length]])
|
|
472
|
+
: this.xScaleInn.bandwidth();
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* Remove chart's elements without data
|
|
478
|
+
*/
|
|
479
|
+
exitElements() {
|
|
480
|
+
this.itemg
|
|
481
|
+
.exit()
|
|
482
|
+
.transition(this.transition)
|
|
483
|
+
.style("opacity", 0)
|
|
484
|
+
.remove();
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
export default d3barchart;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import D3Chart from '../d3.chart.vue';
|
|
3
|
+
import d3barchart from './d3.barchart';
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
name: 'D3BarChart',
|
|
7
|
+
extends: D3Chart,
|
|
8
|
+
mounted() {
|
|
9
|
+
this.chart = new d3barchart(
|
|
10
|
+
this.$refs.chart,
|
|
11
|
+
JSON.parse(JSON.stringify(this.datum)),
|
|
12
|
+
this.config,
|
|
13
|
+
);
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
</script>
|