UNPKG

2.88 kBJavaScriptView Raw
1"use strict";
2var __extends = (this && this.__extends) || (function () {
3 var extendStatics = Object.setPrototypeOf ||
4 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
6 return function (d, b) {
7 extendStatics(d, b);
8 function __() { this.constructor = d; }
9 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
10 };
11})();
12Object.defineProperty(exports, "__esModule", { value: true });
13var Graphic_1 = require("./../Graphic");
14var Tool_1 = require("./../Tool");
15var Progress = (function (_super) {
16 __extends(Progress, _super);
17 /* LIFECYCLE */
18 function Progress() {
19 var _this = _super.call(this) || this;
20 _this.setProps({
21 min: 0,
22 max: 100,
23 value: 0
24 });
25 _this.connect(_this.signals.propChange, ["min", "max", "value"], _this.onValueChange.bind(_this));
26 return _this;
27 }
28 Progress.prototype.initialize = function (props) {
29 _super.prototype.initialize.call(this, props);
30 this.shape("fill", {
31 width: this.getRatioWidth(),
32 height: this.props.height,
33 stroke: Tool_1.Color.transparent,
34 fill: Tool_1.Color.white,
35 fillAlpha: 1
36 }).shape("shape", {
37 width: this.props.width,
38 height: this.props.height,
39 fill: Tool_1.Color.transparent,
40 stroke: Tool_1.Color.cyan400
41 });
42 this.onValueChange();
43 };
44 /* METHODS */
45 /**
46 * Get the percentage of progression relative to the value and the max value
47 * @returns The percentage
48 */
49 Progress.prototype.getPercentage = function () {
50 var _a = this.props, min = _a.min, max = _a.max, value = Tool_1.Util.limit(this.props.value, min, max);
51 return (value / max) * 100;
52 };
53 /**
54 * Get the width relative to the Percentage of progression
55 * @returns The width rationed
56 */
57 Progress.prototype.getRatioWidth = function () {
58 return (this.props.width * this.getPercentage()) / 100;
59 };
60 /* EVENTS */
61 /**
62 * When width or height attributes has changed
63 */
64 Progress.prototype.onSizeChange = function () {
65 _super.prototype.onSizeChange.call(this);
66 this.onValueChange();
67 this.shape("shape", {
68 width: this.props.width,
69 height: this.props.height
70 });
71 };
72 /**
73 * When the ratio value has changed ("min", "max" or "value")
74 */
75 Progress.prototype.onValueChange = function () {
76 this.shape("fill", {
77 width: this.getRatioWidth(),
78 height: this.props.height
79 });
80 };
81 return Progress;
82}(Graphic_1.Graphic));
83exports.Progress = Progress;