Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const filtered = items.reduce((filtered, d) => {
// check for dates
const f = (utils.isDate(d[attr])) ? d[attr] : parseFloat(d[attr]);
// if it is a number
if (!isNaN(f)) {
filtered.push(f);
}
//filter
return filtered;
}, []); const formatter = function(n) { return utils.isDate(n) ? n : d3.round(n, 2); };_formatToDates: function() {
var date_attr = ["value", "start", "end"];
var fmts = [this.formatInput].concat(formatters);
for(var i = 0; i < date_attr.length; i++) {
var attr = date_attr[i];
if(!utils.isDate(this[attr])) {
for(var j = 0; j < fmts.length; j++) {
var formatter = d3.time.format(fmts[j]);
var date = formatter.parse(this[attr].toString());
if(utils.isDate(date)) {
this.set(attr, date);
break;
}
}
}
}
},validate() {
this._super();
//restore the correct object type for time values
if (this.scale && this.scaleType == "time") {
const obj = {};
if (this.zoomedMin != null && !utils.isDate(this.zoomedMin)) obj.zoomedMin = this._space.time.parse(this.zoomedMin.toString());
if (this.zoomedMax != null && !utils.isDate(this.zoomedMax)) obj.zoomedMax = this._space.time.parse(this.zoomedMax.toString());
this.set(obj);
}
},const formatter = function(n) {
if (!n && n !== 0) return n;
if (utils.isDate(n)) return _this.model.time.formatDate(n);
return d3.format(".2r")(n);
};_formatToDates() {
const persistentValues = ["value"];
const date_attr = ["value", "start", "end", "startSelected", "endSelected"];
for (let i = 0; i < date_attr.length; i++) {
const attr = date_attr[i];
if (!utils.isDate(this[attr])) {
const date = this.parse(this[attr]);
this.set(attr, date, null, (persistentValues.indexOf(attr) !== -1));
}
}
},validate: function() {
//unit has to be one of the available_time_units
if(time_units.indexOf(this.unit) === -1) {
this.unit = "year";
}
if(this.step < 1) {
this.step = "year";
}
//make sure dates are transformed into dates at all times
if(!utils.isDate(this.start) || !utils.isDate(this.end) || !utils.isDate(this.value)) {
this._formatToDates();
}
//end has to be >= than start
if(this.end < this.start) {
this.end = this.start;
}
//value has to be between start and end
if(this.value < this.start) {
this.value = this.start;
} else if(this.value > this.end) {
this.value = this.end;
}
if(this.playable === false && this.playing === true) {
this.playing = false;