8e65ba11a0c4b32ad50fc581de3c06fec294b48e.svn-base 3.9 KB

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