03d80cc89a73edabcfea30dabbb16f6f06aac635.svn-base 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <div class="pane-container">
  3. <component :is="currentType.componentName" :data="chartData" :schema="schema" :chart-style="chartStyle" class="visualize-window" />
  4. <div v-if="isEditMode" class="chart-style-panel">
  5. <el-form label-position="top" size="mini">
  6. <el-form-item :label="$t('chart.chartType')+':'">
  7. <div class="chart-type-list">
  8. <span v-for="item in chartTypeList" :key="item.type" :class="{activedIcon :item.type===chartType, disabledIcon: !isUsable(item)}" @click="switchChartType(item)">
  9. <el-tooltip :content="item.name +': '+item.matchRule.desc" placement="top">
  10. <svg-icon class="icon" :icon-class="isUsable(item)? item.icon : (item.icon + '_disabled')" />
  11. </el-tooltip>
  12. </span>
  13. </div>
  14. </el-form-item>
  15. </el-form>
  16. </div>
  17. </div>
  18. </template>
  19. <script>
  20. import lineChart from '@/widgets/lineChart'
  21. import DataTable from '@/widgets/DataTable'
  22. import BarChart from '@/widgets/BarChart'
  23. import StackBarChart from '@/widgets/StackBarChart'
  24. import HorizontalBar from '@/widgets/horizontalBar'
  25. import PieChart from '@/widgets/PieChart'
  26. import chartTypeList from '@/utils/chartTypeList'
  27. import store from '../store'
  28. export default {
  29. components: { lineChart, DataTable, BarChart, StackBarChart, PieChart, HorizontalBar },
  30. props: {
  31. data: {
  32. type: Array,
  33. required: true
  34. },
  35. schema: {
  36. type: Array,
  37. required: true
  38. },
  39. chartStyle: {
  40. require: false,
  41. type: Object
  42. },
  43. chartType: {
  44. type: String,
  45. default: 'table'
  46. },
  47. isEditMode: {
  48. type: Boolean,
  49. default: true
  50. }
  51. },
  52. data() {
  53. return {
  54. chartTypeList
  55. }
  56. },
  57. computed: {
  58. allSelected() {
  59. return store.state.caculCols.concat(store.state.dimensions)
  60. },
  61. chartData() {
  62. return this.currentType.dataTransfer ? this.currentType.dataTransfer(this.data, this.schema) : this.data
  63. },
  64. currentType() {
  65. return chartTypeList.find(item => item.type === this.chartType)
  66. }
  67. },
  68. watch: {
  69. allSelected: {
  70. deep: true,
  71. handler() {
  72. if (!this.currentType.matchRule.isUsable(store.state.dimensions, store.state.caculCols)) {
  73. this.$emit('update:chartType', 'table')
  74. }
  75. }
  76. }
  77. },
  78. methods: {
  79. isUsable(chart) {
  80. return chart.matchRule.isUsable(store.state.dimensions, store.state.caculCols)
  81. },
  82. switchChartType(chart) {
  83. if (!chart.matchRule.isUsable(store.state.dimensions, store.state.caculCols)) {
  84. return
  85. }
  86. this.$emit('update:chartType', chart.type)
  87. }
  88. }
  89. }
  90. </script>
  91. <style lang="scss" scoped>
  92. .pane-container {
  93. display: flex;
  94. height: 100%;
  95. .visualize-window {
  96. width: 100%;
  97. }
  98. .chart-style-panel {
  99. width: 200px;
  100. flex-shrink: 0;
  101. padding: 10px;
  102. .chart-type-list {
  103. width: 100%;
  104. display: grid;
  105. justify-items: center;
  106. grid-template-columns: repeat(5, 1fr);
  107. grid-auto-rows: 1fr;
  108. grid-gap: 10px;
  109. span {
  110. line-height: initial;
  111. height: 100%;
  112. font-size: 22px;
  113. cursor: pointer;
  114. text-align: center;
  115. width: 100%;
  116. position: relative;
  117. .icon {
  118. position: absolute;
  119. top: 0;
  120. left: 0;
  121. right: 0;
  122. bottom:0;
  123. margin: auto;
  124. }
  125. }
  126. span::before {
  127. content: '';
  128. width: 100%;
  129. padding-bottom: 100%;
  130. display: block;
  131. }
  132. .disabledIcon {
  133. cursor: not-allowed;
  134. }
  135. .activedIcon {
  136. background: #c9c9c9;
  137. }
  138. }
  139. }
  140. }
  141. </style>