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AAL,IAAmB,CAD9B;AAEL,2BAAO,MAFF;AAGL,4BAAQ,KAHH;AAIL,sCAAgB,KAAK,KAArB,SAA8B,KAAK;AAJ9B;AADuD,aAA9B,CAA3B,EAOH,CACF,KAAK,WAAL,EADE,EAEF,KAAK,SAAL,EAFE,EAGF,KAAK,OAAL,EAHE,CAPG,CAAP;AAYD;AA1LM,KA/KF;AA4WP,UA5WO,kBA4WC,CA5WD,EA4WE;AACP,YAAI,KAAK,SAAL,GAAiB,CAArB,EAAwB,OAAO,SAAP;AAExB,eAAO,KAAK,IAAL,KAAc,OAAd,GACH,KAAK,QAAL,EADG,GAEH,KAAK,MAAL,EAFJ;AAGD;AAlXM,CARM,CAAf","sourcesContent":["// Mixins\nimport Colorable from '../../mixins/colorable'\n\n// Utilities\nimport mixins, { ExtractVue } from '../../util/mixins'\nimport { genPoints } from './helpers/core'\nimport { genPath } from './helpers/path'\n\n// Types\nimport Vue, { VNode } from 'vue'\nimport { Prop, PropValidator } from 'vue/types/options'\n\nexport type SparklineItem = number | { value: number }\n\nexport type SparklineText = {\n x: number\n value: string\n}\n\nexport interface Boundary {\n minX: number\n minY: number\n maxX: number\n maxY: number\n}\n\nexport interface Point {\n x: number\n y: number\n value: number\n}\n\nexport interface BarText {\n points: Point[]\n boundary: Boundary\n offsetX: number\n}\n\ninterface options extends Vue {\n $refs: {\n path: SVGPathElement\n }\n}\n\nexport default mixins<options &\n/* eslint-disable indent */\n ExtractVue<[\n typeof Colorable\n ]>\n/* eslint-enable indent */\n>(\n Colorable\n).extend({\n name: 'VSparkline',\n\n props: {\n autoDraw: Boolean,\n autoDrawDuration: {\n type: Number,\n default: 2000\n },\n autoDrawEasing: {\n type: String,\n default: 'ease'\n },\n autoLineWidth: {\n type: Boolean,\n default: false\n },\n color: {\n type: String,\n default: 'primary'\n },\n fill: {\n type: Boolean,\n default: false\n },\n gradient: {\n type: Array as Prop<string[]>,\n default: () => ([])\n },\n gradientDirection: {\n type: String as Prop<'top' | 'bottom' | 'left' | 'right'>,\n validator: (val: string) => ['top', 'bottom', 'left', 'right'].includes(val),\n default: 'top'\n },\n height: {\n type: [String, Number],\n default: 75\n },\n labels: {\n type: Array as Prop<SparklineItem[]>,\n default: () => ([])\n },\n lineWidth: {\n type: [String, Number],\n default: 4\n },\n padding: {\n type: [String, Number],\n default: 8\n },\n smooth: {\n type: [Boolean, Number, String],\n default: false\n },\n showLabels: Boolean,\n type: {\n type: String,\n default: 'trend',\n validator: (val: string) => ['trend', 'bar'].includes(val)\n } as PropValidator<'trend' | 'bar'>,\n value: {\n type: Array as Prop<SparklineItem[]>,\n default: () => ([])\n },\n width: {\n type: [Number, String],\n default: 300\n },\n labelSize: {\n type: [Number, String],\n default: 7\n }\n },\n\n data: () => ({\n lastLength: 0\n }),\n\n computed: {\n parsedPadding (): number {\n return Number(this.padding)\n },\n parsedWidth (): number {\n return Number(this.width)\n },\n totalBars (): number {\n return this.value.length\n },\n _lineWidth (): number {\n if (this.autoLineWidth && this.type !== 'trend') {\n const totalPadding = this.parsedPadding * (this.totalBars + 1)\n return (this.parsedWidth - totalPadding) / this.totalBars\n } else {\n return Number(this.lineWidth) || 4\n }\n },\n boundary (): Boundary {\n const height = Number(this.height)\n\n return {\n minX: this.parsedPadding,\n minY: this.parsedPadding,\n maxX: this.parsedWidth - this.parsedPadding,\n maxY: height - this.parsedPadding\n }\n },\n hasLabels (): boolean {\n return Boolean(\n this.showLabels ||\n this.labels.length > 0 ||\n this.$scopedSlots.label\n )\n },\n parsedLabels (): SparklineText[] {\n const labels = []\n const points = this.points\n const len = points.length\n\n for (let i = 0; labels.length < len; i++) {\n const item = points[i]\n let value = this.labels[i]\n\n if (!value) {\n value = item === Object(item)\n ? item.value\n : item\n }\n\n labels.push({\n ...item,\n value: String(value)\n })\n }\n\n return labels\n },\n points (): Point[] {\n return genPoints(this.value.slice(), this.boundary, this.type)\n },\n textY (): number {\n return this.boundary.maxY + 6\n }\n },\n\n watch: {\n value: {\n immediate: true,\n handler () {\n this.$nextTick(() => {\n if (!this.autoDraw || this.type === 'bar') return\n\n const path = this.$refs.path\n const length = path.getTotalLength()\n\n if (!this.fill) {\n path.style.transition = 'none'\n path.style.strokeDasharray = length + ' ' + length\n path.style.strokeDashoffset = Math.abs(length - (this.lastLength || 0)).toString()\n path.getBoundingClientRect()\n path.style.transition = `stroke-dashoffset ${this.autoDrawDuration}ms ${this.autoDrawEasing}`\n path.style.strokeDashoffset = '0'\n } else {\n path.style.transformOrigin = 'bottom center'\n path.style.transition = 'none'\n path.style.transform = `scaleY(0)`\n path.getBoundingClientRect()\n path.style.transition = `transform ${this.autoDrawDuration}ms ${this.autoDrawEasing}`\n path.style.transform = `scaleY(1)`\n }\n this.lastLength = length\n })\n }\n }\n },\n\n methods: {\n genGradient () {\n const gradientDirection = this.gradientDirection\n const gradient = this.gradient.slice()\n\n // Pushes empty string to force\n // a fallback to currentColor\n if (!gradient.length) gradient.push('')\n\n const len = Math.max(gradient.length - 1, 1)\n const stops = gradient.reverse().map((color, index) =>\n this.$createElement('stop', {\n attrs: {\n offset: index / len,\n 'stop-color': color || this.color || 'currentColor'\n }\n })\n )\n\n return this.$createElement('defs', [\n this.$createElement('linearGradient', {\n attrs: {\n id: this._uid,\n x1: +(gradientDirection === 'left'),\n y1: +(gradientDirection === 'top'),\n x2: +(gradientDirection === 'right'),\n y2: +(gradientDirection === 'bottom')\n }\n }, stops)\n ])\n },\n genG (children: VNode[]) {\n return this.$createElement('g', {\n style: {\n fontSize: '8',\n textAnchor: 'middle',\n dominantBaseline: 'mathematical',\n fill: this.color || 'currentColor'\n }\n }, children)\n },\n genLabels () {\n if (!this.hasLabels) return undefined\n\n return this.genG(this.parsedLabels.map(this.genText))\n },\n genPath () {\n const radius = this.smooth === true ? 8 : Number(this.smooth)\n\n return this.$createElement('path', {\n attrs: {\n id: this._uid,\n d: genPath(this.points.slice(), radius, this.fill, Number(this.height)),\n fill: this.fill ? `url(#${this._uid})` : 'none',\n stroke: this.fill ? 'none' : `url(#${this._uid})`\n },\n ref: 'path'\n })\n },\n genText (item: SparklineText, index: number) {\n const children = this.$scopedSlots.label\n ? this.$scopedSlots.label({ index, value: item.value })\n : item.value\n\n return this.$createElement('text', {\n attrs: {\n x: item.x,\n y: this.textY\n }\n }, [children])\n },\n genBar () {\n if (!this.value || this.totalBars < 2) return undefined as never\n const { width, height, parsedPadding, _lineWidth } = this\n const viewWidth = width || this.totalBars * parsedPadding * 2\n const viewHeight = height || 75\n const boundary: Boundary = {\n minX: parsedPadding,\n minY: parsedPadding,\n maxX: Number(viewWidth) - parsedPadding,\n maxY: Number(viewHeight) - parsedPadding\n }\n const props = {\n ...this.$props\n }\n\n props.points = genPoints(this.value, boundary, this.type)\n\n const totalWidth = boundary.maxX / (props.points.length - 1)\n\n props.boundary = boundary\n props.lineWidth = _lineWidth || (totalWidth - Number(parsedPadding || 5))\n props.offsetX = 0\n if (!this.autoLineWidth) {\n props.offsetX = ((boundary.maxX / this.totalBars) / 2) - boundary.minX\n }\n\n return this.$createElement('svg', {\n attrs: {\n width: '100%',\n height: '25%',\n viewBox: `0 0 ${viewWidth} ${viewHeight}`\n }\n }, [\n this.genGradient(),\n this.genClipPath(props.offsetX, props.lineWidth, 'sparkline-bar-' + this._uid),\n this.hasLabels ? this.genBarLabels(props as BarText) : undefined as never,\n this.$createElement('g', {\n attrs: {\n transform: `scale(1,-1) translate(0,-${boundary.maxY})`,\n 'clip-path': `url(#sparkline-bar-${this._uid}-clip)`,\n fill: `url(#${this._uid})`\n }\n }, [\n this.$createElement('rect', {\n attrs: {\n x: 0,\n y: 0,\n width: viewWidth,\n height: viewHeight\n }\n })\n ])\n ])\n },\n genClipPath (offsetX: number, lineWidth: number, id: string) {\n const { maxY } = this.boundary\n const rounding = typeof this.smooth === 'number'\n ? this.smooth\n : this.smooth ? 2 : 0\n\n return this.$createElement('clipPath', {\n attrs: {\n id: `${id}-clip`\n }\n }, this.points.map(item => {\n return this.$createElement('rect', {\n attrs: {\n x: item.x + offsetX,\n y: 0,\n width: lineWidth,\n height: Math.max(maxY - item.y, 0),\n rx: rounding,\n ry: rounding\n }\n }, [\n this.autoDraw ? this.$createElement('animate', {\n attrs: {\n attributeName: 'height',\n from: 0,\n to: maxY - item.y,\n dur: `${this.autoDrawDuration}ms`,\n fill: 'freeze'\n }\n }) : undefined as never\n ])\n }))\n },\n genBarLabels (props: BarText): VNode {\n const offsetX = props.offsetX || 0\n\n const children = props.points.map(item => (\n this.$createElement('text', {\n attrs: {\n x: item.x + offsetX + this._lineWidth / 2,\n y: props.boundary.maxY + (Number(this.labelSize) || 7),\n 'font-size': Number(this.labelSize) || 7\n }\n }, item.value.toString())\n ))\n\n return this.genG(children)\n },\n genTrend () {\n return this.$createElement('svg', this.setTextColor(this.color, {\n attrs: {\n 'stroke-width': this._lineWidth || 1,\n width: '100%',\n height: '25%',\n viewBox: `0 0 ${this.width} ${this.height}`\n }\n }), [\n this.genGradient(),\n this.genLabels(),\n this.genPath()\n ])\n }\n },\n\n render (h): VNode {\n if (this.totalBars < 2) return undefined as never\n\n return this.type === 'trend'\n ? this.genTrend()\n : this.genBar()\n }\n})\n"],"sourceRoot":""}
|