@antv/scale

  • Version 0.3.18
  • Published
  • 331 kB
  • 3 dependencies
  • MIT license

Install

npm i @antv/scale
yarn add @antv/scale
pnpm add @antv/scale

Overview

The scale module for G2

Index

Functions

function getScale

getScale: (key: string) => ScaleConstructor;

    function getTickMethod

    getTickMethod: (key: string) => TickMethod;
    • 获取计算 ticks 的方法

      Parameter key

      键值

      Returns

      计算 ticks 的方法

    function registerScale

    registerScale: (key: string, cls: ScaleConstructor) => void;

      function registerTickMethod

      registerTickMethod: (key: string, method: TickMethod) => void;
      • 注册计算 ticks 的方法

        Parameter key

        键值

        Parameter method

        方法

      Classes

      class Category

      class Category extends Base {}
      • 分类度量

      property isCategory

      readonly isCategory: boolean;

        property type

        readonly type: string;

          method getText

          getText: (value: any, ...args: any[]) => string;

            method initCfg

            protected initCfg: () => void;

              method invert

              invert: (scaledValue: number) => any;

                method scale

                scale: (value: any) => number;

                  method setDomain

                  protected setDomain: () => void;

                    method translate

                    translate: (value: any) => number;

                      class Identity

                      class Identity extends Base {}
                      • identity scale原则上是定义域和值域一致,scale/invert方法也是一致的 参考R的实现:https://github.com/r-lib/scales/blob/master/R/pal-identity.r 参考d3的实现(做了下转型):https://github.com/d3/d3-scale/blob/master/src/identity.js

                      property isIdentity

                      readonly isIdentity: boolean;

                        property type

                        readonly type: ScaleType;

                          method calculateTicks

                          calculateTicks: () => any[];

                            method invert

                            invert: (value?: number) => number;

                              method scale

                              scale: (value: any) => number;

                                class Linear

                                class Linear extends Continuous {}
                                • 线性度量

                                property isLinear

                                readonly isLinear: boolean;

                                  property minTickInterval

                                  minTickInterval: number;

                                    property type

                                    type: string;

                                      method initCfg

                                      protected initCfg: () => void;

                                        method invert

                                        invert: (value: number) => any;

                                          class Log

                                          class Log extends Continuous {}
                                          • Log 度量,处理非均匀分布

                                          property base

                                          base: number;

                                            property type

                                            readonly type: string;

                                              method getScalePercent

                                              protected getScalePercent: (value: number) => any;

                                                method initCfg

                                                protected initCfg: () => void;

                                                  method invert

                                                  invert: (value: number) => number;
                                                  • Modifiers

                                                    • @override

                                                  method setDomain

                                                  protected setDomain: () => void;

                                                    class Pow

                                                    class Pow extends Continuous {}
                                                    • Pow 度量,处理非均匀分布

                                                    property exponent

                                                    exponent: number;
                                                    • 指数

                                                    property type

                                                    readonly type: string;

                                                      method getScalePercent

                                                      protected getScalePercent: (value: number) => number;

                                                        method initCfg

                                                        protected initCfg: () => void;

                                                          method invert

                                                          invert: (value: number) => number;
                                                          • Modifiers

                                                            • @override

                                                          class Quantile

                                                          class Quantile extends Quantize {}

                                                            property type

                                                            type: string;

                                                              method initCfg

                                                              protected initCfg: () => void;

                                                                class Quantize

                                                                class Quantize extends Continuous {}
                                                                • 分段度量

                                                                property type

                                                                type: string;

                                                                  method calculateTicks

                                                                  protected calculateTicks: () => any[];

                                                                    method getScalePercent

                                                                    protected getScalePercent: (value: any) => number;

                                                                      method initCfg

                                                                      protected initCfg: () => void;

                                                                        method invert

                                                                        invert: (value: any) => number;

                                                                          class Scale

                                                                          abstract class Scale {}

                                                                            constructor

                                                                            constructor(
                                                                            cfg: Partial<{
                                                                            field: string;
                                                                            values: any[];
                                                                            min: any;
                                                                            max: any;
                                                                            minLimit?: any;
                                                                            maxLimit?: any;
                                                                            alias: string;
                                                                            range: number[];
                                                                            base: number;
                                                                            exponent: number;
                                                                            nice: boolean;
                                                                            ticks: any[];
                                                                            tickInterval: number;
                                                                            minTickInterval: number;
                                                                            tickCount: number;
                                                                            maxTickCount: number;
                                                                            formatter: (value: any, index?: number) => any;
                                                                            tickMethod: string | TickMethod;
                                                                            mask?: string;
                                                                            showLast?: boolean;
                                                                            }>
                                                                            );

                                                                              property alias

                                                                              alias?: string;

                                                                                property field

                                                                                field?: string;

                                                                                  property formatter

                                                                                  formatter?: (value: any, index?: number) => any;

                                                                                    property isCategory

                                                                                    isCategory?: boolean;
                                                                                    • 是否分类类型的度量

                                                                                    property isContinuous

                                                                                    isContinuous?: boolean;
                                                                                    • 是否连续类型的度量,linear,time,log, pow, quantile, quantize 都支持

                                                                                    property isIdentity

                                                                                    isIdentity: boolean;
                                                                                    • 是否是常量的度量,传入和传出一致

                                                                                    property isLinear

                                                                                    isLinear?: boolean;
                                                                                    • 是否线性度量,有linear, time 度量

                                                                                    property max

                                                                                    max?: any;

                                                                                      property maxLimit

                                                                                      maxLimit?: any;

                                                                                        property min

                                                                                        min?: any;

                                                                                          property minLimit

                                                                                          minLimit?: any;

                                                                                            property range

                                                                                            range: number[];

                                                                                              property tickCount

                                                                                              tickCount: number;

                                                                                                property tickInterval

                                                                                                tickInterval: number;

                                                                                                  property tickMethod

                                                                                                  tickMethod?: string | TickMethod;

                                                                                                    property ticks

                                                                                                    ticks: any[];

                                                                                                      property type

                                                                                                      type: string;
                                                                                                      • 度量的类型

                                                                                                      property values

                                                                                                      values: any[];

                                                                                                        method calcPercent

                                                                                                        protected calcPercent: (value: any, min: number, max: number) => number;
                                                                                                        • 定义域转 0~1

                                                                                                        method calculateTicks

                                                                                                        protected calculateTicks: () => any[];

                                                                                                          method calcValue

                                                                                                          protected calcValue: (percent: number, min: number, max: number) => number;
                                                                                                          • 0~1转定义域

                                                                                                          method change

                                                                                                          change: (cfg: ScaleConfig) => void;
                                                                                                          • 重新初始化

                                                                                                          method clone

                                                                                                          clone: () => Scale;

                                                                                                            method getConfig

                                                                                                            protected getConfig: (key: any) => any;

                                                                                                              method getText

                                                                                                              getText: (value: any, key?: number) => string;
                                                                                                              • 获取Tick的格式化结果

                                                                                                              method getTicks

                                                                                                              getTicks: () => Tick[];
                                                                                                              • 获取坐标轴需要的ticks

                                                                                                              method init

                                                                                                              protected init: () => void;

                                                                                                                method initCfg

                                                                                                                protected initCfg: () => void;

                                                                                                                  method invert

                                                                                                                  abstract invert: (scaled: number) => any;
                                                                                                                  • 将值域转换为定义域

                                                                                                                  method rangeMax

                                                                                                                  protected rangeMax: () => number;

                                                                                                                    method rangeMin

                                                                                                                    protected rangeMin: () => number;

                                                                                                                      method scale

                                                                                                                      abstract scale: (value: any) => number;
                                                                                                                      • 将定义域转换为值域

                                                                                                                      method setDomain

                                                                                                                      protected setDomain: () => void;

                                                                                                                        method translate

                                                                                                                        translate: (v: any) => any;

                                                                                                                          class Time

                                                                                                                          class Time extends Linear {}
                                                                                                                          • 时间度量

                                                                                                                          property mask

                                                                                                                          mask: string;

                                                                                                                            property type

                                                                                                                            readonly type: string;

                                                                                                                              method getText

                                                                                                                              getText: (value: string | number | Date, index?: number) => any;
                                                                                                                              • Modifiers

                                                                                                                                • @override

                                                                                                                              method initCfg

                                                                                                                              protected initCfg: () => void;

                                                                                                                                method scale

                                                                                                                                scale: (value: any) => number;
                                                                                                                                • Modifiers

                                                                                                                                  • @override

                                                                                                                                method setDomain

                                                                                                                                protected setDomain: () => void;

                                                                                                                                  method translate

                                                                                                                                  translate: (v: any) => number;
                                                                                                                                  • 将时间转换成数字

                                                                                                                                    Modifiers

                                                                                                                                    • @override

                                                                                                                                  class TimeCat

                                                                                                                                  class TimeCat extends Category {}
                                                                                                                                  • 时间分类度量

                                                                                                                                  property mask

                                                                                                                                  mask: any;

                                                                                                                                    property type

                                                                                                                                    readonly type: string;

                                                                                                                                      method getText

                                                                                                                                      getText: (value: string | number, tickIndex?: number) => any;
                                                                                                                                      • 由于时间类型数据需要转换一下,所以复写 getText

                                                                                                                                        Modifiers

                                                                                                                                        • @override

                                                                                                                                      method initCfg

                                                                                                                                      protected initCfg: () => void;

                                                                                                                                        method setDomain

                                                                                                                                        protected setDomain: () => void;

                                                                                                                                          method translate

                                                                                                                                          translate: (value: any) => number;
                                                                                                                                          • Modifiers

                                                                                                                                            • @override

                                                                                                                                          Interfaces

                                                                                                                                          interface Tick

                                                                                                                                          interface Tick {}

                                                                                                                                            property text

                                                                                                                                            text: string;
                                                                                                                                            • 展示名

                                                                                                                                            property tickValue

                                                                                                                                            tickValue: string | number;
                                                                                                                                            • 定义域值

                                                                                                                                            property value

                                                                                                                                            value: number;
                                                                                                                                            • 值域值

                                                                                                                                            Type Aliases

                                                                                                                                            type ScaleConfig

                                                                                                                                            type ScaleConfig = Partial<{
                                                                                                                                            /** 对应的字段id */
                                                                                                                                            field: string;
                                                                                                                                            /** 输入域、定义域 */
                                                                                                                                            values: any[];
                                                                                                                                            /** 定义域的最小值,d3为domain,ggplot2为limits,分类型下无效 */
                                                                                                                                            min: any;
                                                                                                                                            /** 定义域的最大值,分类型下无效 */
                                                                                                                                            max: any;
                                                                                                                                            /** 严格模式下的定义域最小值,设置后会强制 ticks 从最小值开始 */
                                                                                                                                            minLimit?: any;
                                                                                                                                            /** 严格模式下的定义域最大值,设置后会强制 ticks 已最大值结束 */
                                                                                                                                            maxLimit?: any;
                                                                                                                                            /** 数据字段的显示别名,scale内部不感知,外部注入 */
                                                                                                                                            alias: string;
                                                                                                                                            /** 输出域、值域,默认值为[0, 1] */
                                                                                                                                            range: number[];
                                                                                                                                            /** Log有效,底数 */
                                                                                                                                            base: number;
                                                                                                                                            /** Pow有效,指数 */
                                                                                                                                            exponent: number;
                                                                                                                                            /** 自动调整min、max */
                                                                                                                                            nice: boolean;
                                                                                                                                            /** 用于指定tick,优先级最高 */
                                                                                                                                            ticks: any[];
                                                                                                                                            /** tick间隔,只对分类型和时间型适用,优先级高于tickCount */
                                                                                                                                            tickInterval: number;
                                                                                                                                            /** tick最小间隔,只对线型适用 */
                                                                                                                                            minTickInterval: number;
                                                                                                                                            /** tick个数,默认值为5 */
                                                                                                                                            tickCount: number;
                                                                                                                                            /** ticks最大值,默认值为10 */
                                                                                                                                            maxTickCount: number;
                                                                                                                                            /** tick格式化函数,会影响数据在坐标轴 axis、图例 legend、tooltip 上的显示 */
                                                                                                                                            formatter: (value: any, index?: number) => any;
                                                                                                                                            /** 计算 ticks 的算法 */
                                                                                                                                            tickMethod: string | TickMethod;
                                                                                                                                            /** 时间度量 time, timeCat 时有效 */
                                                                                                                                            mask?: string;
                                                                                                                                            /** 是否始终保留最后一个 tick */
                                                                                                                                            showLast?: boolean;
                                                                                                                                            }>;

                                                                                                                                              Package Files (14)

                                                                                                                                              Dependencies (3)

                                                                                                                                              Dev Dependencies (16)

                                                                                                                                              Peer Dependencies (0)

                                                                                                                                              No peer dependencies.

                                                                                                                                              Badge

                                                                                                                                              To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                                                                              You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@antv/scale.

                                                                                                                                              • Markdown
                                                                                                                                                [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@antv/scale)
                                                                                                                                              • HTML
                                                                                                                                                <a href="https://www.jsdocs.io/package/@antv/scale"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>