@antv/scale
Advanced tools
Comparing version 0.3.6 to 0.3.7
@@ -9,2 +9,3 @@ import Base from '../base'; | ||
readonly isCategory: boolean; | ||
private cache; | ||
translate(value: any): number; | ||
@@ -11,0 +12,0 @@ scale(value: any): number; |
@@ -14,9 +14,15 @@ import { __extends, __spreadArrays } from "tslib"; | ||
_this.isCategory = true; | ||
// 用于缓存 translate 函数 | ||
_this.cache = new Map(); | ||
return _this; | ||
} | ||
Category.prototype.translate = function (value) { | ||
if (this.cache.has(value)) { | ||
return this.cache.get(value); | ||
} | ||
var index = indexOf(this.values, value); | ||
if (index === -1) { | ||
return isNumber(value) ? value : NaN; | ||
index = isNumber(value) ? value : NaN; | ||
} | ||
this.cache.set(value, index); | ||
return index; | ||
@@ -68,2 +74,6 @@ }; | ||
} | ||
// domain 改变时清除缓存 | ||
if (this.cache) { | ||
this.cache.clear(); | ||
} | ||
}; | ||
@@ -70,0 +80,0 @@ return Category; |
@@ -9,2 +9,3 @@ import Base from '../base'; | ||
readonly isCategory: boolean; | ||
private cache; | ||
translate(value: any): number; | ||
@@ -11,0 +12,0 @@ scale(value: any): number; |
@@ -16,9 +16,15 @@ "use strict"; | ||
_this.isCategory = true; | ||
// 用于缓存 translate 函数 | ||
_this.cache = new Map(); | ||
return _this; | ||
} | ||
Category.prototype.translate = function (value) { | ||
if (this.cache.has(value)) { | ||
return this.cache.get(value); | ||
} | ||
var index = util_1.indexOf(this.values, value); | ||
if (index === -1) { | ||
return util_1.isNumber(value) ? value : NaN; | ||
index = util_1.isNumber(value) ? value : NaN; | ||
} | ||
this.cache.set(value, index); | ||
return index; | ||
@@ -70,2 +76,6 @@ }; | ||
} | ||
// domain 改变时清除缓存 | ||
if (this.cache) { | ||
this.cache.clear(); | ||
} | ||
}; | ||
@@ -72,0 +82,0 @@ return Category; |
{ | ||
"name": "@antv/scale", | ||
"version": "0.3.6", | ||
"version": "0.3.7", | ||
"description": "The scale module for G2", | ||
@@ -5,0 +5,0 @@ "author": "https://github.com/orgs/antvis/people", |
@@ -12,7 +12,14 @@ import { indexOf, isNil, isNumber } from '@antv/util'; | ||
// 用于缓存 translate 函数 | ||
private cache = new Map(); | ||
public translate(value: any): number { | ||
const index = indexOf(this.values, value); | ||
if (this.cache.has(value)) { | ||
return this.cache.get(value); | ||
} | ||
let index = indexOf(this.values, value); | ||
if (index === -1) { | ||
return isNumber(value) ? value : NaN; | ||
index = isNumber(value) ? value : NaN; | ||
} | ||
this.cache.set(value, index); | ||
return index; | ||
@@ -63,2 +70,7 @@ } | ||
} | ||
// domain 改变时清除缓存 | ||
if (this.cache) { | ||
this.cache.clear(); | ||
} | ||
} | ||
@@ -65,0 +77,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
319715
5954