base.d.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { AttributeCfg, CallbackType, Scale } from '../interface';
  2. export type AttributeConstructor = new (cfg: any) => Attribute;
  3. /**
  4. * 所有视觉通道属性的基类
  5. * @class Base
  6. */
  7. export default class Attribute {
  8. type: string;
  9. names: string[];
  10. scales: Scale[];
  11. linear: boolean;
  12. values: any[];
  13. constructor(cfg: AttributeCfg);
  14. callback: CallbackType;
  15. /**
  16. * 映射的值组成的数组
  17. * @param params 对应 scale 顺序的值传入
  18. */
  19. mapping(...params: any[]): any[];
  20. /**
  21. * 如果进行线性映射,返回对应的映射值
  22. * @param percent
  23. */
  24. getLinearValue(percent: number): number | string;
  25. /**
  26. * 根据度量获取属性名
  27. */
  28. getNames(): any[];
  29. /**
  30. * 获取所有的维度名
  31. */
  32. getFields(): string[];
  33. /**
  34. * 根据名称获取度量
  35. * @param name
  36. */
  37. getScale(name: string): Scale;
  38. /**
  39. * 默认的回调函数(用户没有自定义 callback,或者用户自定义 callback 返回空的时候,使用 values 映射)
  40. * @param params
  41. */
  42. private defaultCallback;
  43. private _parseCfg;
  44. private _getAttributeValue;
  45. /**
  46. * 通过 scale 拿到数据对应的原始的参数
  47. * @param param
  48. * @param scale
  49. * @private
  50. */
  51. private _toOriginParam;
  52. }