Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.00 KB | None | 0 0
  1. <template>
  2. <div class="results__card"
  3. :class="{'results__card--unavailable': disabled}"
  4. >
  5. <div class="results__button-container">
  6. <button
  7. class="results__button results__button--green"
  8. :class="{'results__button--green--active': currentQL === qLevels.strongly }"
  9. @click="currentQL = qLevels.strongly"
  10. >Strongly Qualified</button>
  11. <button
  12. class="results__button results__button--yellow"
  13. :class="{'results__button--yellow--active': currentQL === qLevels.somewhat }"
  14. @click="currentQL = qLevels.somewhat"
  15. >Somewhat Qualified</button>
  16. <button
  17. class="results__button results__button--red"
  18. :class="{'results__button--red--active': currentQL === qLevels.not }"
  19. @click="currentQL = qLevels.not"
  20. >Not Qualified</button>
  21. </div>
  22. <div class="results__body">
  23. <div class="results__chart">
  24. <bar
  25. :width="400"
  26. :height="400"
  27. :chart-data="chartData"
  28. :chart-options="chartOptions"
  29. >
  30. </bar>
  31. <p class="results__yaxe-desc">Average Score</p>
  32. </div>
  33. </div>
  34. </div>
  35. </template>
  36.  
  37. <script>
  38. import Bar from './Bar'
  39.  
  40. import { CHART_COLORS_BY_USER_ROLE as URColor } from '../colors'
  41.  
  42. const QUALIFICATION_LEVELS = {
  43. strongly: 'STRONGLY_QUALIFIED',
  44. somewhat: 'SOMEWHAT_QUALIFIED',
  45. not: 'NOT_QUALIFIED',
  46. }
  47. const STACK_NAMES_LIST = [
  48. 'Ceo',
  49. 'Board',
  50. 'Staff',
  51. 'Hq',
  52. 'Country',
  53. ]
  54.  
  55. function getStacked (stack) {
  56. return {
  57. label: '',
  58. backgroundColor: URColor.stacked,
  59. hoverBackgroundColor: URColor.stacked,
  60. data: [10],
  61. stack,
  62. }
  63. }
  64.  
  65. function getStacks () {
  66. return STACK_NAMES_LIST.map(getStacked)
  67. }
  68.  
  69. export default ({
  70. name: 'Results',
  71. components: {
  72. Bar,
  73. },
  74. data () {
  75. return {
  76. currentQL: this.$props.qualificationLevel,
  77. qLevels: QUALIFICATION_LEVELS,
  78. }
  79. },
  80. props: {
  81. qualificationLevel: {
  82. type: String,
  83. default: QUALIFICATION_LEVELS.strongly,
  84. },
  85. results: {
  86. type: Object,
  87. default: null,
  88. },
  89. disabled: {
  90. type: Boolean,
  91. required: true,
  92. }
  93. },
  94. computed: {
  95. qualificationKey () {
  96. switch (this.currentQL) {
  97. case QUALIFICATION_LEVELS.strongly: return 'strongly'
  98. case QUALIFICATION_LEVELS.somewhat: return 'somewhat'
  99. case QUALIFICATION_LEVELS.not: return 'not'
  100. }
  101. },
  102. ceo () {
  103. if (!this.results) return 0
  104. return this.results[this.qualificationKey].ceo.averageScore
  105. },
  106. board () {
  107. if (!this.results) return 0
  108. return this.results[this.qualificationKey].board.averageScore
  109. },
  110. staff () {
  111. if (!this.results) return 0
  112. return this.results[this.qualificationKey].staff.averageScore
  113. },
  114. hq () {
  115. if (!this.results) return 0
  116. return this.results[this.qualificationKey].hq.averageScore
  117. },
  118. country () {
  119. if (!this.results) return 0
  120. return this.results[this.qualificationKey].country.averageScore
  121. },
  122. chartData () {
  123. return {
  124. datasets: [
  125. {
  126. label: 'CEO (Self Assessment)',
  127. backgroundColor: [URColor.ceo, '#fff'],
  128. hoverBackgroundColor: [URColor.ceo, '#fff'],
  129. data: [this.ceo],
  130. stack: STACK_NAMES_LIST[0],
  131. },
  132. {
  133. label: 'Board',
  134. backgroundColor: URColor.board,
  135. hoverBackgroundColor: URColor.board,
  136. data: [this.board],
  137. stack: STACK_NAMES_LIST[1],
  138. },
  139. {
  140. label: 'Staff',
  141. backgroundColor: URColor.staff,
  142. hoverBackgroundColor: URColor.staff,
  143. data: [this.staff],
  144. stack: STACK_NAMES_LIST[2],
  145. },
  146. {
  147. label: 'HQ',
  148. backgroundColor: URColor.hq,
  149. hoverBackgroundColor: URColor.hq,
  150. data: [this.hq],
  151. stack: STACK_NAMES_LIST[3],
  152. },
  153. {
  154. label: 'Country',
  155. backgroundColor: URColor.country,
  156. hoverBackgroundColor: URColor.country,
  157. data: [this.country],
  158. stack: STACK_NAMES_LIST[4],
  159. },
  160. ...getStacks(),
  161. ]
  162. }
  163. },
  164. chartOptions () {
  165. return {
  166. tooltips: {
  167. enabled: true,
  168. },
  169. legend: false,
  170. title: {
  171. display: false,
  172. },
  173. maintainAspectRatio: false,
  174. scales: {
  175. xAxes: [{
  176. stacked: true,
  177. categoryPercentage: 1.0,
  178. barPercentage: 0.6,
  179. scaleLabel: {
  180. beginAtZero: true,
  181. },
  182. }],
  183. yAxes: [{
  184. stacked: true,
  185. display: true,
  186. gridLines: {
  187. display: false,
  188. },
  189. ticks: {
  190. display: true,
  191. beginAtZero: true,
  192. callback: function (value) {
  193. if (value === 1 || value === 5) return value
  194. },
  195. fontColor: URColor.stacked,
  196. fontSize: 20,
  197. min: 0,
  198. max: 5,
  199. }
  200. }],
  201. }
  202. }
  203. }
  204. },
  205. })
  206. </script>
  207.  
  208. <style lang="scss" scoped>
  209. @import "../../../styles/variables";
  210.  
  211. .results {
  212. &__yaxe-desc {
  213. position: absolute;
  214. left: 0;
  215. top: 0;
  216. bottom: 0;
  217. right: 0;
  218. color: $grey;
  219. font-size: 1.4rem;
  220. transform: rotate(-90deg);
  221. margin: 0;
  222. padding: 0;
  223. text-align: center;
  224. pointer-events: none;
  225. }
  226.  
  227. &__button {
  228. &-container {
  229. display: inline-flex;
  230. }
  231.  
  232. display: flex;
  233. flex: 1;
  234. margin: 1rem 0.2rem;
  235. padding: 0;
  236. color: $white;
  237. border: 2px solid black;
  238. min-width: 8rem;
  239. min-height: 2rem;
  240. align-items: center;
  241. justify-content: center;
  242. border-radius: 5px;
  243.  
  244. &--green {
  245. color: $green;
  246. border-color: $green;
  247. background-color: white;
  248.  
  249. &--active {
  250. color: $white;
  251. background-color: $green;
  252. }
  253. }
  254.  
  255. &--red {
  256. color: $red;
  257. border-color: $red;
  258. background-color: white;
  259.  
  260. &--active {
  261. color: $white;
  262. background-color: $red;
  263. }
  264. }
  265.  
  266. &--yellow {
  267. color: $orange;
  268. border-color: $orange;
  269. background-color: white;
  270.  
  271. &--active {
  272. color: $white;
  273. background-color: $orange;
  274. }
  275. }
  276. }
  277.  
  278. &__card {
  279. display: flex;
  280. align-items: center;
  281. justify-content: space-between;
  282. flex-direction: column;
  283. width: 27rem;
  284. height: 32rem;
  285. margin: 0.5rem;
  286. user-select: none;
  287. &--unavailable {
  288. filter: grayscale(100%);
  289. }
  290. }
  291. &__body {
  292. display: flex;
  293. flex: 1;
  294. align-items: center;
  295. justify-content: center;
  296. }
  297. &__title {
  298. font-size: 1.4rem;
  299. font-weight: bold;
  300. }
  301. &__chart {
  302. display: flex;
  303. flex: 1;
  304. position: relative;
  305. margin: 0;
  306. padding: 0;
  307. }
  308. }
  309. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement