UNPKG

zmp-vue

Version:

Build full featured iOS & Android apps using ZMP & Vue

160 lines (155 loc) 5.6 kB
"use strict"; exports.__esModule = true; exports.default = void 0; var _vue = require("vue"); var _hoisted_1 = { class: "gauge" }; function render(_ctx, _cache) { return (0, _vue.openBlock)(), (0, _vue.createBlock)("div", _hoisted_1, [((0, _vue.openBlock)(), (0, _vue.createBlock)("svg", { class: "gauge-svg", width: _ctx.size + "px", height: (_ctx.semiCircle ? _ctx.size / 2 : _ctx.size) + "px", viewBox: "0 0 " + _ctx.size + " " + (_ctx.semiCircle ? _ctx.size / 2 : _ctx.size) }, [_ctx.semiCircle ? ((0, _vue.openBlock)(), (0, _vue.createBlock)("path", { key: 0, class: "gauge-back-semi", d: "M" + (_ctx.size - _ctx.borderWidth / 2) + "," + _ctx.size / 2 + " a1,1 0 0,0 -" + (_ctx.size - _ctx.borderWidth) + ",0", stroke: _ctx.borderBgColor, "stroke-width": _ctx.borderWidth, fill: _ctx.bgColor || 'none' }, null, 8, ["d", "stroke", "stroke-width", "fill"])) : (0, _vue.createCommentVNode)("", true), _ctx.semiCircle ? ((0, _vue.openBlock)(), (0, _vue.createBlock)("path", { key: 1, class: "gauge-front-semi", d: "M" + (_ctx.size - _ctx.borderWidth / 2) + "," + _ctx.size / 2 + " a1,1 0 0,0 -" + (_ctx.size - _ctx.borderWidth) + ",0", stroke: _ctx.borderColor, "stroke-width": _ctx.borderWidth, "stroke-dasharray": _ctx.length / 2, "stroke-dashoffset": _ctx.length / 2 * (1 + _ctx.progress), fill: _ctx.borderBgColor ? 'none' : _ctx.bgColor || 'none' }, null, 8, ["d", "stroke", "stroke-width", "stroke-dasharray", "stroke-dashoffset", "fill"])) : (0, _vue.createCommentVNode)("", true), !_ctx.semiCircle && _ctx.borderBgColor ? ((0, _vue.openBlock)(), (0, _vue.createBlock)("circle", { key: 2, class: "gauge-back-circle", stroke: _ctx.borderBgColor, "stroke-width": _ctx.borderWidth, fill: _ctx.bgColor || 'none', cx: _ctx.size / 2, cy: _ctx.size / 2, r: _ctx.radius }, null, 8, ["stroke", "stroke-width", "fill", "cx", "cy", "r"])) : (0, _vue.createCommentVNode)("", true), !_ctx.semiCircle ? ((0, _vue.openBlock)(), (0, _vue.createBlock)("circle", { key: 3, class: "gauge-front-circle", transform: "rotate(-90 " + _ctx.size / 2 + " " + _ctx.size / 2 + ")", stroke: _ctx.borderColor, "stroke-width": _ctx.borderWidth, "stroke-dasharray": _ctx.length, "stroke-dashoffset": _ctx.length * (1 - _ctx.progress), fill: _ctx.borderBgColor ? 'none' : _ctx.bgColor || 'none', cx: _ctx.size / 2, cy: _ctx.size / 2, r: _ctx.radius }, null, 8, ["transform", "stroke", "stroke-width", "stroke-dasharray", "stroke-dashoffset", "fill", "cx", "cy", "r"])) : (0, _vue.createCommentVNode)("", true), _ctx.valueText ? ((0, _vue.openBlock)(), (0, _vue.createBlock)("text", { key: 4, class: "gauge-value-text", x: "50%", y: _ctx.semiCircle ? '100%' : '50%', "font-weight": _ctx.valueFontWeight, "font-size": _ctx.valueFontSize, fill: _ctx.valueTextColor, dy: _ctx.semiCircle ? _ctx.labelText ? -_ctx.labelFontSize - 15 : -5 : 0, "text-anchor": "middle", "dominant-baseline": !_ctx.semiCircle ? 'middle' : null }, (0, _vue.toDisplayString)(_ctx.valueText), 9, ["y", "font-weight", "font-size", "fill", "dy", "dominant-baseline"])) : (0, _vue.createCommentVNode)("", true), _ctx.labelText ? ((0, _vue.openBlock)(), (0, _vue.createBlock)("text", { key: 5, class: "gauge-label-text", x: "50%", y: _ctx.semiCircle ? '100%' : '50%', "font-weight": _ctx.labelFontWeight, "font-size": _ctx.labelFontSize, fill: _ctx.labelTextColor, dy: _ctx.semiCircle ? -5 : _ctx.valueText ? _ctx.valueFontSize / 2 + 10 : 0, "text-anchor": "middle", "dominant-baseline": !_ctx.semiCircle ? 'middle' : null }, (0, _vue.toDisplayString)(_ctx.labelText), 9, ["y", "font-weight", "font-size", "fill", "dy", "dominant-baseline"])) : (0, _vue.createCommentVNode)("", true)], 8, ["width", "height", "viewBox"]))]); } var _default = { name: 'zmp-gauge', render: render, props: { type: { type: String, default: 'circle' }, value: { type: [Number, String], default: 0 }, size: { type: [Number, String], default: 200 }, bgColor: { type: String, default: 'transparent' }, borderBgColor: { type: String, default: '#eeeeee' }, borderColor: { type: String, default: '#000000' }, borderWidth: { type: [Number, String], default: 10 }, valueText: [Number, String], valueTextColor: { type: String, default: '#000000' }, valueFontSize: { type: [Number, String], default: 31 }, valueFontWeight: { type: [Number, String], default: 500 }, labelText: String, labelTextColor: { type: String, default: '#888888' }, labelFontSize: { type: [Number, String], default: 14 }, labelFontWeight: { type: [Number, String], default: 400 } }, setup: function setup(props) { var semiCircle = (0, _vue.computed)(function () { return props.type === 'semicircle'; }); var radius = (0, _vue.computed)(function () { return props.size / 2 - props.borderWidth / 2; }); var length = (0, _vue.computed)(function () { return 2 * Math.PI * radius.value; }); var progress = (0, _vue.computed)(function () { return Math.max(Math.min(props.value, 1), 0); }); return { semiCircle: semiCircle, radius: radius, length: length, progress: progress }; } }; exports.default = _default;