0988351ccbf8544bcb74bcd2453ea4e0d72c22f9.svn-base 3.7 KB

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