0f43dda960a87ee1dd20ce811ffd73400f74f1d2.svn-base 3.7 KB

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