{"remainingRequest":"D:\\jenkins\\workspace\\xq-web-fvue\\node_modules\\vue-loader\\lib\\index.js??vue-loader-options!D:\\jenkins\\workspace\\xq-web-fvue\\node_modules\\@jiaminghi\\data-view\\lib\\components\\scrollRankingBoard\\src\\main.vue?vue&type=script&lang=js&","dependencies":[{"path":"D:\\jenkins\\workspace\\xq-web-fvue\\node_modules\\@jiaminghi\\data-view\\lib\\components\\scrollRankingBoard\\src\\main.vue","mtime":499162500000},{"path":"D:\\jenkins\\workspace\\xq-web-fvue\\node_modules\\babel-loader\\lib\\index.js","mtime":315532800000},{"path":"D:\\jenkins\\workspace\\xq-web-fvue\\node_modules\\cache-loader\\dist\\cjs.js","mtime":499162500000},{"path":"D:\\jenkins\\workspace\\xq-web-fvue\\node_modules\\vue-loader\\lib\\index.js","mtime":499162500000}],"contextDependencies":[],"result":["//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n//\n\nimport autoResize from '../../../mixin/autoResize'\n\nimport { deepMerge } from '@jiaminghi/charts/lib/util/index'\n\nimport { deepClone } from '@jiaminghi/c-render/lib/plugin/util'\n\nexport default {\n  name: 'DvScrollRankingBoard',\n  mixins: [autoResize],\n  props: {\n    config: {\n      type: Object,\n      default: () => ({})\n    }\n  },\n  data () {\n    return {\n      ref: 'scroll-ranking-board',\n\n      defaultConfig: {\n        /**\n         * @description Board data\n         * @type {Array<Object>}\n         * @default data = []\n         */\n        data: [],\n        /**\n         * @description Row num\n         * @type {Number}\n         * @default rowNum = 5\n         */\n        rowNum: 5,\n        /**\n         * @description Scroll wait time\n         * @type {Number}\n         * @default waitTime = 2000\n         */\n        waitTime: 2000,\n        /**\n         * @description Carousel type\n         * @type {String}\n         * @default carousel = 'single'\n         * @example carousel = 'single' | 'page'\n         */\n        carousel: 'single',\n        /**\n         * @description Value unit\n         * @type {String}\n         * @default unit = ''\n         * @example unit = 'ton'\n         */\n        unit: '',\n        /**\n         * @description Auto sort by value\n         * @type {Boolean}\n         * @default sort = true\n         */\n        sort: true,\n        /**\n         * @description Value formatter\n         * @type {Function}\n         * @default valueFormatter = null\n         */\n        valueFormatter: null\n      },\n\n      mergedConfig: null,\n\n      rowsData: [],\n\n      rows: [],\n\n      heights: [],\n\n      animationIndex: 0,\n\n      animationHandler: '',\n\n      updater: 0\n    }\n  },\n  watch: {\n    config () {\n      const { stopAnimation, calcData } = this\n\n      stopAnimation()\n\n      calcData()\n    }\n  },\n  methods: {\n    afterAutoResizeMixinInit () {\n      const { calcData } = this\n\n      calcData()\n    },\n    onResize () {\n      const { mergedConfig, calcHeights } = this\n\n      if (!mergedConfig) return\n\n      calcHeights(true)\n    },\n    calcData () {\n      const { mergeConfig, calcRowsData } = this\n\n      mergeConfig()\n\n      calcRowsData()\n\n      const { calcHeights } = this\n\n      calcHeights()\n\n      const { animation } = this\n\n      animation(true)\n    },\n    mergeConfig () {\n      let { config, defaultConfig } = this\n\n      this.mergedConfig = deepMerge(deepClone(defaultConfig, true), config || {})\n    },\n    calcRowsData () {\n      let { data, rowNum, sort } = this.mergedConfig\n\n      sort && data.sort(({ value: a }, { value: b }) => {\n        if (a > b) return -1\n        if (a < b) return 1\n        if (a === b) return 0\n      })\n\n      const value = data.map(({ value }) => value)\n      \n      const min = Math.min(...value) || 0\n\n      // abs of min\n      const minAbs = Math.abs(min)\n\n      const max = Math.max(...value) || 0\n\n      // abs of max\n      const maxAbs = Math.abs(max)\n\n      const total = max + minAbs\n\n      data = data.map((row, i) => ({ ...row, ranking: i + 1, percent: (row.value + minAbs) / total * 100 }))\n\n      const rowLength = data.length\n\n      if (rowLength > rowNum && rowLength < 2 * rowNum) {\n        data = [...data, ...data]\n      }\n\n      data = data.map((d, i) => ({ ...d, scroll: i }))\n\n      this.rowsData = data\n      this.rows = data\n    },\n    calcHeights (onresize = false) {\n      const { height, mergedConfig } = this\n\n      const { rowNum, data } = mergedConfig\n\n      const avgHeight = height / rowNum\n\n      this.avgHeight = avgHeight\n\n      if (!onresize) this.heights = new Array(data.length).fill(avgHeight)\n    },\n    async animation (start = false) {\n      let { avgHeight, animationIndex, mergedConfig, rowsData, animation, updater } = this\n\n      const { waitTime, carousel, rowNum } = mergedConfig\n\n      const rowLength = rowsData.length\n\n      if (rowNum >= rowLength) return\n\n      if (start) {\n        await new Promise(resolve => setTimeout(resolve, waitTime))\n        if (updater !== this.updater) return\n      }\n\n      const animationNum = carousel === 'single' ? 1 : rowNum\n\n      let rows = rowsData.slice(animationIndex)\n      rows.push(...rowsData.slice(0, animationIndex))\n\n      this.rows = rows.slice(0, rowNum + 1)\n      this.heights = new Array(rowLength).fill(avgHeight)\n\n      await new Promise(resolve => setTimeout(resolve, 300))\n      if (updater !== this.updater) return\n\n      this.heights.splice(0, animationNum, ...new Array(animationNum).fill(0))\n\n      animationIndex += animationNum\n\n      const back = animationIndex - rowLength\n      if (back >= 0) animationIndex = back\n\n      this.animationIndex = animationIndex\n      this.animationHandler = setTimeout(animation, waitTime - 300)\n    },\n    stopAnimation () {\n      const { animationHandler, updater } = this\n\n      this.updater = (updater + 1) % 999999\n\n      if (!animationHandler) return\n\n      clearTimeout(animationHandler)\n    },\n  },\n  destroyed () {\n    const { stopAnimation } = this\n\n    stopAnimation()\n  }\n}\n",null]}