@antv/g2plot 2.4.32 → 2.4.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/g2plot.min.js +2 -2
- package/dist/g2plot.min.js.map +1 -1
- package/esm/adaptor/geometries/base.d.ts +2 -0
- package/esm/adaptor/geometries/base.js +2 -2
- package/esm/adaptor/geometries/base.js.map +1 -1
- package/esm/index.d.ts +1 -1
- package/esm/index.js +1 -1
- package/esm/index.js.map +1 -1
- package/esm/plots/dual-axes/util/render-sider.js +2 -2
- package/esm/plots/dual-axes/util/render-sider.js.map +1 -1
- package/esm/plots/facet/adaptor.js +26 -4
- package/esm/plots/facet/adaptor.js.map +1 -1
- package/esm/plots/facet/types.d.ts +26 -1
- package/esm/plots/facet/types.js.map +1 -1
- package/lib/adaptor/geometries/base.d.ts +2 -0
- package/lib/adaptor/geometries/base.js +2 -2
- package/lib/adaptor/geometries/base.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/plots/dual-axes/util/render-sider.js +2 -2
- package/lib/plots/dual-axes/util/render-sider.js.map +1 -1
- package/lib/plots/facet/adaptor.js +26 -4
- package/lib/plots/facet/adaptor.js.map +1 -1
- package/lib/plots/facet/types.d.ts +26 -1
- package/lib/plots/facet/types.js.map +1 -1
- package/package.json +2 -1
- package/src/adaptor/geometries/base.ts +4 -1
- package/src/index.ts +1 -1
- package/src/plots/dual-axes/util/render-sider.ts +2 -2
- package/src/plots/facet/adaptor.ts +38 -1
- package/src/plots/facet/types.ts +26 -1
|
@@ -35,20 +35,26 @@ function facetAdaptor(params) {
|
|
|
35
35
|
}
|
|
36
36
|
else {
|
|
37
37
|
var plot = viewOptions;
|
|
38
|
-
var
|
|
38
|
+
var plotOptions_1 = plot.options;
|
|
39
|
+
// 如果 view 内部没有指定映射字段,则使用 options 内指定的映射字段
|
|
40
|
+
['seriesField', 'colorField', 'shapeField', 'sizeField', 'groupField'].forEach(function (key) {
|
|
41
|
+
if (options[key] && typeof plotOptions_1[key] === 'undefined') {
|
|
42
|
+
plotOptions_1[key] = options[key];
|
|
43
|
+
}
|
|
44
|
+
});
|
|
39
45
|
// @ts-ignore 仪表盘没 tooltip
|
|
40
|
-
if (
|
|
46
|
+
if (plotOptions_1.tooltip) {
|
|
41
47
|
// 配置 tooltip 交互
|
|
42
48
|
viewOfG2.interaction('tooltip');
|
|
43
49
|
}
|
|
44
|
-
(0, utils_2.execPlotAdaptor)(plot.type, viewOfG2,
|
|
50
|
+
(0, utils_2.execPlotAdaptor)(plot.type, viewOfG2, plotOptions_1);
|
|
45
51
|
}
|
|
46
52
|
} }));
|
|
47
53
|
return params;
|
|
48
54
|
}
|
|
49
55
|
function component(params) {
|
|
50
56
|
var chart = params.chart, options = params.options;
|
|
51
|
-
var axes = options.axes, meta = options.meta, tooltip = options.tooltip, coordinate = options.coordinate, theme = options.theme, legend = options.legend, interactions = options.interactions, annotations = options.annotations;
|
|
57
|
+
var axes = options.axes, meta = options.meta, tooltip = options.tooltip, coordinate = options.coordinate, theme = options.theme, legend = options.legend, interactions = options.interactions, annotations = options.annotations, shapeField = options.shapeField, sizeField = options.sizeField, shapeLegend = options.shapeLegend, sizeLegend = options.sizeLegend;
|
|
52
58
|
// 3. meta 配置
|
|
53
59
|
var scales = {};
|
|
54
60
|
if (axes) {
|
|
@@ -79,6 +85,22 @@ function component(params) {
|
|
|
79
85
|
}
|
|
80
86
|
// 7. legend 配置(默认展示)
|
|
81
87
|
chart.legend(legend);
|
|
88
|
+
var showLegend = legend !== false;
|
|
89
|
+
if (shapeField) {
|
|
90
|
+
if (shapeLegend) {
|
|
91
|
+
chart.legend(shapeField, shapeLegend);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
chart.legend(shapeField, shapeLegend === false ? false : legend);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (sizeField) {
|
|
98
|
+
chart.legend(sizeField, sizeLegend ? sizeLegend : false);
|
|
99
|
+
}
|
|
100
|
+
// /** 默认不展示 shape 图例,当 shapeLegend 为 undefined 也不展示图例 */
|
|
101
|
+
if (!showLegend && !shapeLegend && !sizeLegend) {
|
|
102
|
+
chart.legend(false);
|
|
103
|
+
}
|
|
82
104
|
// theme 配置
|
|
83
105
|
if (theme) {
|
|
84
106
|
chart.theme(theme);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adaptor.js","sourceRoot":"","sources":["../../../src/plots/facet/adaptor.ts"],"names":[],"mappings":";;;;AAAA,mCAAwC;AACxC,+CAA6C;AAC7C,2CAAuD;AAGvD,qCAAqD;AACrD,sCAA+C;AAE/C,iCAA0C;AAE1C,SAAS,YAAY,CAAC,MAA4B;IACxC,IAAA,KAAK,GAAc,MAAM,MAApB,EAAE,OAAO,GAAK,MAAM,QAAX,CAAY;IAC1B,IAAM,SAAS,GAA6B,OAAO,KAApC,EAAE,IAAI,GAAuB,OAAO,KAA9B,EAAE,MAAM,GAAe,OAAO,OAAtB,EAAE,QAAQ,GAAK,OAAO,SAAZ,CAAa;IAE5D,IAAM,YAAY,GAAG,IAAA,WAAI,EAAC,OAAc,EAAE;QACxC,MAAM;QACN,MAAM;QACN,QAAQ;QACR,UAAU;QACV,MAAM;QACN,MAAM;QACN,SAAS;QACT,YAAY;QACZ,OAAO;QACP,QAAQ;QACR,cAAc;QACd,aAAa;KACd,CAAC,CAAC;IAEH,UAAU;IACV,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEjB,WAAW;IACX,KAAK,CAAC,KAAK,CAAC,SAAS,wCAChB,YAAY,KACf,MAAM,QAAA,EACN,QAAQ,EAAE,UAAC,QAAQ,EAAE,KAAK;YACxB,IAAM,WAAW,GAAG,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;YAC9C,IAAK,WAAqB,CAAC,UAAU,EAAE;gBACrC,IAAA,uBAAe,EAAC,QAAQ,EAAE,WAAoB,CAAC,CAAC;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AW,IAAI,CAAC,UAAU,EAAE;QAC9C,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;KACrB;IAED,WAAW;IACX,IAAI,KAAK,EAAE;QACT,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;KACpB;IAED,kBAAkB;IAClB,IAAA,WAAI,EAAC,YAAY,EAAE,UAAC,WAAwB;QAC1C,IAAI,WAAW,CAAC,MAAM,KAAK,KAAK,EAAE;YAChC,KAAK,CAAC,iBAAiB,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;SAC3C;aAAM;YACL,KAAK,CAAC,WAAW,CAAC,WAAW,CAAC,IAAI,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC;SACtD;IACH,CAAC,CAAC,CAAC;IAEH,iBAAiB;IACjB,IAAA,WAAI,EAAC,WAAW,EAAE,UAAC,UAAU;QAC3B,KAAK,CAAC,UAAU,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,sBAC9B,UAAU,EACb,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;GAIG;AACH,SAAgB,OAAO,CAAC,MAA4B;IAClD,0BAA0B;IAC1B,OAAO,IAAA,YAAI,EAAC,cAAK,EAAE,YAAY,EAAE,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC;AACtD,CAAC;AAHD,0BAGC","sourcesContent":["import { each, omit } from '@antv/util';\nimport { theme } from '../../adaptor/common';\nimport { AXIS_META_CONFIG_KEYS } from '../../constant';\nimport { Params } from '../../core/adaptor';\nimport { Axis, Interaction } from '../../types';\nimport { deepAssign, flow, pick } from '../../utils';\nimport { execPlotAdaptor } from '../mix/utils';\nimport { FacetOptions, IPlot, IView } from './types';\nimport { execViewAdaptor } from './utils';\n\nfunction facetAdaptor(params: Params<FacetOptions>): Params<FacetOptions> {\n const { chart, options } = params;\n const { type: facetType, data, fields, eachView } = options;\n\n const restFacetCfg = omit(options as any, [\n 'type',\n 'data',\n 'fields',\n 'eachView',\n 'axes',\n 'meta',\n 'tooltip',\n 'coordinate',\n 'theme',\n 'legend',\n 'interactions',\n 'annotations',\n ]);\n\n // 1. data\n chart.data(data);\n\n // 2. facet\n chart.facet(facetType, {\n ...restFacetCfg,\n fields,\n eachView: (viewOfG2, facet) => {\n const viewOptions = eachView(viewOfG2, facet);\n if ((viewOptions as IView).geometries) {\n execViewAdaptor(viewOfG2, viewOptions as IView);\n } else {\n const plot = viewOptions as IPlot;\n const plotOptions = plot.options;\n\n // 如果 view 内部没有指定映射字段,则使用 options 内指定的映射字段\n ['seriesField', 'colorField', 'shapeField', 'sizeField', 'groupField'].forEach((key) => {\n if (options[key] && typeof plotOptions[key] === 'undefined') {\n plotOptions[key] = options[key];\n }\n });\n\n // @ts-ignore 仪表盘没 tooltip\n if (plotOptions.tooltip) {\n // 配置 tooltip 交互\n viewOfG2.interaction('tooltip');\n }\n execPlotAdaptor(plot.type, viewOfG2, plotOptions);\n }\n },\n });\n\n return params;\n}\n\nfunction component(params: Params<FacetOptions>): Params<FacetOptions> {\n const { chart, options } = params;\n const {\n axes,\n meta,\n tooltip,\n coordinate,\n theme,\n legend,\n interactions,\n annotations,\n shapeField,\n sizeField,\n shapeLegend,\n sizeLegend,\n } = options;\n\n // 3. meta 配置\n let scales: Record<string, any> = {};\n if (axes) {\n each(axes, (axis: Axis, field: string) => {\n scales[field] = pick(axis, AXIS_META_CONFIG_KEYS);\n });\n }\n\n scales = deepAssign({}, meta, scales);\n chart.scale(scales);\n\n // 4. coordinate 配置\n chart.coordinate(coordinate);\n\n // 5. axis 轴配置 (默认不展示)\n if (!axes) {\n chart.axis(false);\n } else {\n each(axes, (axis: Axis, field: string) => {\n chart.axis(field, axis);\n });\n }\n\n // 6. tooltip 配置\n if (tooltip) {\n chart.interaction('tooltip');\n chart.tooltip(tooltip);\n } else if (tooltip === false) {\n chart.removeInteraction('tooltip');\n }\n\n // 7. legend 配置(默认展示)\n chart.legend(legend);\n const showLegend = legend !== false;\n if (shapeField) {\n if (shapeLegend) {\n chart.legend(shapeField, shapeLegend);\n } else {\n chart.legend(shapeField, shapeLegend === false ? false : legend);\n }\n }\n\n if (sizeField) {\n chart.legend(sizeField, sizeLegend ? sizeLegend : false);\n }\n // /** 默认不展示 shape 图例,当 shapeLegend 为 undefined 也不展示图例 */\n if (!showLegend && !shapeLegend && !sizeLegend) {\n chart.legend(false);\n }\n\n // theme 配置\n if (theme) {\n chart.theme(theme);\n }\n\n // 8. interactions\n each(interactions, (interaction: Interaction) => {\n if (interaction.enable === false) {\n chart.removeInteraction(interaction.type);\n } else {\n chart.interaction(interaction.type, interaction.cfg);\n }\n });\n\n // 9. annotations\n each(annotations, (annotation) => {\n chart.annotation()[annotation.type]({\n ...annotation,\n });\n });\n\n return params;\n}\n\n/**\n * 分面图适配器\n * @param chart\n * @param options\n */\nexport function adaptor(params: Params<FacetOptions>) {\n // flow 的方式处理所有的配置到 G2 API\n return flow(theme, facetAdaptor, component)(params);\n}\n"]}
|
|
@@ -141,8 +141,33 @@ export interface FacetOptions<T extends keyof Types.FacetCfgMap = keyof Types.Fa
|
|
|
141
141
|
*/
|
|
142
142
|
readonly legend?: Legend;
|
|
143
143
|
/**
|
|
144
|
-
* @title
|
|
144
|
+
* @title 交互配置
|
|
145
145
|
*/
|
|
146
146
|
readonly interactions?: Interaction[];
|
|
147
|
+
/**
|
|
148
|
+
* @title 形状字段
|
|
149
|
+
* @description 形状映射字段
|
|
150
|
+
*/
|
|
151
|
+
readonly shapeField?: string;
|
|
152
|
+
/**
|
|
153
|
+
* @title 颜色字段
|
|
154
|
+
* @description 颜色映射字段
|
|
155
|
+
*/
|
|
156
|
+
readonly colorField?: string;
|
|
157
|
+
/**
|
|
158
|
+
* @title 大小字段
|
|
159
|
+
* @description 大小映射字段
|
|
160
|
+
*/
|
|
161
|
+
readonly sizeField?: string;
|
|
162
|
+
/**
|
|
163
|
+
* @title 形状图例配置
|
|
164
|
+
* @description 形状图例的配置项
|
|
165
|
+
*/
|
|
166
|
+
readonly shapeLegend?: Legend | false;
|
|
167
|
+
/**
|
|
168
|
+
* @title 大小图例配置
|
|
169
|
+
* @description 大小图例的配置项
|
|
170
|
+
*/
|
|
171
|
+
readonly sizeLegend?: Legend | false;
|
|
147
172
|
}
|
|
148
173
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/plots/facet/types.ts"],"names":[],"mappings":"","sourcesContent":["import { Types, View } from '@antv/g2';\nimport { Geometry } from '../../adaptor/geometries/base';\nimport { Data, Meta, Options, Tooltip } from '../../types';\nimport { Annotation } from '../../types/annotation';\nimport { Axis } from '../../types/axis';\nimport { Interaction } from '../../types/interaction';\nimport { Legend } from '../../types/legend';\nimport { IPlotTypes } from '../mix/utils';\n\n/**\n * @title geometry 映射信息\n */\nexport type IGeometry = Geometry & {\n adjust?: Types.AdjustOption;\n};\n\n/**\n * @title 子 view 的配置\n * @description 1. 暂时不开嵌套 view 的情况 2. 暂不开放 分面子 view 的 meta 独立设置\n */\nexport type IView = {\n /**\n * @title 图形\n * @description geometry 及映射配置\n */\n readonly geometries: IGeometry[];\n /**\n * @title 数据\n * @description optional,view 中的数据\n */\n readonly data?: Data;\n /**\n * @title meta\n */\n readonly meta?: Record<string, Axis>;\n /**\n * @title 坐标系的配置\n * @description 每一个 view 具有相同的坐标系\n */\n readonly coordinate?: Types.CoordinateOption;\n /**\n * @title 坐标轴配置\n */\n readonly axes?: false | Record<string, Axis>;\n /**\n * @title interactions 配置\n */\n readonly interactions?: Interaction[];\n /**\n * @title annotation 配置\n */\n readonly annotations?: Annotation[];\n /**\n * @title animation 配置\n */\n readonly animation?: Options['animation'];\n /**\n * @title tooltip 配置\n */\n readonly tooltip?: Tooltip;\n};\n\n/**\n * @title 子 plot 的配置\n */\nexport type IPlot = IPlotTypes;\n/**\n * @title facetData map\n */\ntype FacetDataMap = {\n /**\n * @title rect 类型分面配置\n */\n readonly rect: Types.RectData;\n /**\n * @title mirror 类型分面配置\n */\n readonly mirror: Types.MirrorData;\n /**\n * @title list 类型分面配置\n */\n readonly list: Types.ListData;\n /**\n * @title matrix 类型分面配置\n */\n readonly matrix: Types.MatrixData;\n /**\n * @title circle 类型分面配置\n */\n readonly circle: Types.CircleData;\n /**\n * @title tree 类型分面配置\n */\n readonly tree: Types.TreeData;\n};\n\ntype FacetCfg = Types.MirrorCfg & Types.RectCfg & Types.TreeCfg & Types.ListCfg & Types.CircleCfg & Types.MatrixCfg;\n\n/**\n * @title 分面图的配置类型定义\n */\nexport interface FacetOptions<T extends keyof Types.FacetCfgMap = keyof Types.FacetCfgMap> extends Options, FacetCfg {\n /**\n * @title 分面类型\n * @description G2 内置了六种分面: rect、list、circle、tree、mirror 和 matrix\n */\n readonly type: T;\n /**\n * @title 数据划分维度\n */\n readonly fields: string[];\n /**\n * @title 分面数据\n */\n readonly data: Data;\n /**\n * @title 绘图\n * @description 每个分面 view 中的具体绘图表现 回调的方式\n */\n readonly eachView: (innerView: View, facet?: FacetDataMap[T]) => IView | IPlot;\n /**\n * @title 是否展示分面标题\n * @default false\n */\n readonly showTitle?: boolean;\n /**\n * @title meta 字段\n * @description facet 中对应的 meta 字段配置\n */\n readonly meta?: Record<string, Meta>;\n /**\n * @title 坐标系的配置\n * @description 每一个 view 具有相同的坐标系\n */\n readonly coordinate?: Types.CoordinateOption;\n /**\n * @title 轴配置\n */\n readonly axes?: false | Record<string, Axis>;\n /**\n * @title tooltip 配置\n */\n readonly tooltip?: Tooltip;\n /**\n * @title 图例配置\n */\n readonly legend?: Legend;\n /**\n * @title
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/plots/facet/types.ts"],"names":[],"mappings":"","sourcesContent":["import { Types, View } from '@antv/g2';\nimport { Geometry } from '../../adaptor/geometries/base';\nimport { Data, Meta, Options, Tooltip } from '../../types';\nimport { Annotation } from '../../types/annotation';\nimport { Axis } from '../../types/axis';\nimport { Interaction } from '../../types/interaction';\nimport { Legend } from '../../types/legend';\nimport { IPlotTypes } from '../mix/utils';\n\n/**\n * @title geometry 映射信息\n */\nexport type IGeometry = Geometry & {\n adjust?: Types.AdjustOption;\n};\n\n/**\n * @title 子 view 的配置\n * @description 1. 暂时不开嵌套 view 的情况 2. 暂不开放 分面子 view 的 meta 独立设置\n */\nexport type IView = {\n /**\n * @title 图形\n * @description geometry 及映射配置\n */\n readonly geometries: IGeometry[];\n /**\n * @title 数据\n * @description optional,view 中的数据\n */\n readonly data?: Data;\n /**\n * @title meta\n */\n readonly meta?: Record<string, Axis>;\n /**\n * @title 坐标系的配置\n * @description 每一个 view 具有相同的坐标系\n */\n readonly coordinate?: Types.CoordinateOption;\n /**\n * @title 坐标轴配置\n */\n readonly axes?: false | Record<string, Axis>;\n /**\n * @title interactions 配置\n */\n readonly interactions?: Interaction[];\n /**\n * @title annotation 配置\n */\n readonly annotations?: Annotation[];\n /**\n * @title animation 配置\n */\n readonly animation?: Options['animation'];\n /**\n * @title tooltip 配置\n */\n readonly tooltip?: Tooltip;\n};\n\n/**\n * @title 子 plot 的配置\n */\nexport type IPlot = IPlotTypes;\n/**\n * @title facetData map\n */\ntype FacetDataMap = {\n /**\n * @title rect 类型分面配置\n */\n readonly rect: Types.RectData;\n /**\n * @title mirror 类型分面配置\n */\n readonly mirror: Types.MirrorData;\n /**\n * @title list 类型分面配置\n */\n readonly list: Types.ListData;\n /**\n * @title matrix 类型分面配置\n */\n readonly matrix: Types.MatrixData;\n /**\n * @title circle 类型分面配置\n */\n readonly circle: Types.CircleData;\n /**\n * @title tree 类型分面配置\n */\n readonly tree: Types.TreeData;\n};\n\ntype FacetCfg = Types.MirrorCfg & Types.RectCfg & Types.TreeCfg & Types.ListCfg & Types.CircleCfg & Types.MatrixCfg;\n\n/**\n * @title 分面图的配置类型定义\n */\nexport interface FacetOptions<T extends keyof Types.FacetCfgMap = keyof Types.FacetCfgMap> extends Options, FacetCfg {\n /**\n * @title 分面类型\n * @description G2 内置了六种分面: rect、list、circle、tree、mirror 和 matrix\n */\n readonly type: T;\n /**\n * @title 数据划分维度\n */\n readonly fields: string[];\n /**\n * @title 分面数据\n */\n readonly data: Data;\n /**\n * @title 绘图\n * @description 每个分面 view 中的具体绘图表现 回调的方式\n */\n readonly eachView: (innerView: View, facet?: FacetDataMap[T]) => IView | IPlot;\n /**\n * @title 是否展示分面标题\n * @default false\n */\n readonly showTitle?: boolean;\n /**\n * @title meta 字段\n * @description facet 中对应的 meta 字段配置\n */\n readonly meta?: Record<string, Meta>;\n /**\n * @title 坐标系的配置\n * @description 每一个 view 具有相同的坐标系\n */\n readonly coordinate?: Types.CoordinateOption;\n /**\n * @title 轴配置\n */\n readonly axes?: false | Record<string, Axis>;\n /**\n * @title tooltip 配置\n */\n readonly tooltip?: Tooltip;\n /**\n * @title 图例配置\n */\n readonly legend?: Legend;\n /**\n * @title 交互配置\n */\n readonly interactions?: Interaction[];\n /**\n * @title 形状字段\n * @description 形状映射字段\n */\n readonly shapeField?: string;\n /**\n * @title 颜色字段\n * @description 颜色映射字段\n */\n readonly colorField?: string;\n /**\n * @title 大小字段\n * @description 大小映射字段\n */\n readonly sizeField?: string;\n /**\n * @title 形状图例配置\n * @description 形状图例的配置项\n */\n readonly shapeLegend?: Legend | false;\n /**\n * @title 大小图例配置\n * @description 大小图例的配置项\n */\n readonly sizeLegend?: Legend | false;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antv/g2plot",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.34",
|
|
4
4
|
"description": "An interactive and responsive charting library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chart",
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"coverage": "jest -c jest.config.js -w 16 --coverage",
|
|
40
40
|
"ci": "run-s lint coverage build",
|
|
41
41
|
"changelog": "generate-changelog",
|
|
42
|
+
"prepublishOnly": "run-s lint test build",
|
|
42
43
|
"analyze": "webpack --profile --json > dist/stats.json && webpack-bundle-analyzer ./dist/stats.json"
|
|
43
44
|
},
|
|
44
45
|
"husky": {
|
|
@@ -46,6 +46,8 @@ export type Geometry = {
|
|
|
46
46
|
readonly rawFields?: RawFields;
|
|
47
47
|
/** 图形映射规则 */
|
|
48
48
|
readonly mapping?: MappingOptions;
|
|
49
|
+
/** 自定义映射字段 */
|
|
50
|
+
readonly customMappingField?: string;
|
|
49
51
|
/** label 映射通道,因为历史原因导致实现略有区别 */
|
|
50
52
|
readonly label?: Label;
|
|
51
53
|
/** 不同状态的样式 */
|
|
@@ -156,6 +158,7 @@ export function geometry<O extends GeometryOptions>(params: Params<O>): Params<O
|
|
|
156
158
|
label,
|
|
157
159
|
state,
|
|
158
160
|
customInfo,
|
|
161
|
+
customMappingField,
|
|
159
162
|
} = options;
|
|
160
163
|
|
|
161
164
|
// 如果没有 mapping 信息,那么直接返回
|
|
@@ -179,7 +182,7 @@ export function geometry<O extends GeometryOptions>(params: Params<O>): Params<O
|
|
|
179
182
|
colorField ? geometry.color(colorField, color) : geometry.color(color);
|
|
180
183
|
} else if (isFunction(color)) {
|
|
181
184
|
const { mappingFields, tileMappingField } = getMappingField(options, 'color');
|
|
182
|
-
geometry.color(tileMappingField, getMappingFunction(mappingFields, color));
|
|
185
|
+
geometry.color(customMappingField || tileMappingField, getMappingFunction(mappingFields, color));
|
|
183
186
|
} else {
|
|
184
187
|
colorField && geometry.color(colorField, color);
|
|
185
188
|
}
|
package/src/index.ts
CHANGED
|
@@ -21,8 +21,8 @@ export const doSliderFilter = (view: View, sliderValue: [number, number]) => {
|
|
|
21
21
|
const values = valuesOfKey(data, xScale.field);
|
|
22
22
|
const xValues = isHorizontal ? values : values.reverse();
|
|
23
23
|
const xTickCount = size(xValues);
|
|
24
|
-
const minIndex = Math.
|
|
25
|
-
const maxIndex = Math.
|
|
24
|
+
const minIndex = Math.round(min * (xTickCount - 1));
|
|
25
|
+
const maxIndex = Math.round(max * (xTickCount - 1));
|
|
26
26
|
|
|
27
27
|
// 增加 x 轴的过滤器
|
|
28
28
|
view.filter(xScale.field, (value: any) => {
|
|
@@ -41,6 +41,14 @@ function facetAdaptor(params: Params<FacetOptions>): Params<FacetOptions> {
|
|
|
41
41
|
} else {
|
|
42
42
|
const plot = viewOptions as IPlot;
|
|
43
43
|
const plotOptions = plot.options;
|
|
44
|
+
|
|
45
|
+
// 如果 view 内部没有指定映射字段,则使用 options 内指定的映射字段
|
|
46
|
+
['seriesField', 'colorField', 'shapeField', 'sizeField', 'groupField'].forEach((key) => {
|
|
47
|
+
if (options[key] && typeof plotOptions[key] === 'undefined') {
|
|
48
|
+
plotOptions[key] = options[key];
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
44
52
|
// @ts-ignore 仪表盘没 tooltip
|
|
45
53
|
if (plotOptions.tooltip) {
|
|
46
54
|
// 配置 tooltip 交互
|
|
@@ -56,7 +64,20 @@ function facetAdaptor(params: Params<FacetOptions>): Params<FacetOptions> {
|
|
|
56
64
|
|
|
57
65
|
function component(params: Params<FacetOptions>): Params<FacetOptions> {
|
|
58
66
|
const { chart, options } = params;
|
|
59
|
-
const {
|
|
67
|
+
const {
|
|
68
|
+
axes,
|
|
69
|
+
meta,
|
|
70
|
+
tooltip,
|
|
71
|
+
coordinate,
|
|
72
|
+
theme,
|
|
73
|
+
legend,
|
|
74
|
+
interactions,
|
|
75
|
+
annotations,
|
|
76
|
+
shapeField,
|
|
77
|
+
sizeField,
|
|
78
|
+
shapeLegend,
|
|
79
|
+
sizeLegend,
|
|
80
|
+
} = options;
|
|
60
81
|
|
|
61
82
|
// 3. meta 配置
|
|
62
83
|
let scales: Record<string, any> = {};
|
|
@@ -91,6 +112,22 @@ function component(params: Params<FacetOptions>): Params<FacetOptions> {
|
|
|
91
112
|
|
|
92
113
|
// 7. legend 配置(默认展示)
|
|
93
114
|
chart.legend(legend);
|
|
115
|
+
const showLegend = legend !== false;
|
|
116
|
+
if (shapeField) {
|
|
117
|
+
if (shapeLegend) {
|
|
118
|
+
chart.legend(shapeField, shapeLegend);
|
|
119
|
+
} else {
|
|
120
|
+
chart.legend(shapeField, shapeLegend === false ? false : legend);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (sizeField) {
|
|
125
|
+
chart.legend(sizeField, sizeLegend ? sizeLegend : false);
|
|
126
|
+
}
|
|
127
|
+
// /** 默认不展示 shape 图例,当 shapeLegend 为 undefined 也不展示图例 */
|
|
128
|
+
if (!showLegend && !shapeLegend && !sizeLegend) {
|
|
129
|
+
chart.legend(false);
|
|
130
|
+
}
|
|
94
131
|
|
|
95
132
|
// theme 配置
|
|
96
133
|
if (theme) {
|
package/src/plots/facet/types.ts
CHANGED
|
@@ -146,7 +146,32 @@ export interface FacetOptions<T extends keyof Types.FacetCfgMap = keyof Types.Fa
|
|
|
146
146
|
*/
|
|
147
147
|
readonly legend?: Legend;
|
|
148
148
|
/**
|
|
149
|
-
* @title
|
|
149
|
+
* @title 交互配置
|
|
150
150
|
*/
|
|
151
151
|
readonly interactions?: Interaction[];
|
|
152
|
+
/**
|
|
153
|
+
* @title 形状字段
|
|
154
|
+
* @description 形状映射字段
|
|
155
|
+
*/
|
|
156
|
+
readonly shapeField?: string;
|
|
157
|
+
/**
|
|
158
|
+
* @title 颜色字段
|
|
159
|
+
* @description 颜色映射字段
|
|
160
|
+
*/
|
|
161
|
+
readonly colorField?: string;
|
|
162
|
+
/**
|
|
163
|
+
* @title 大小字段
|
|
164
|
+
* @description 大小映射字段
|
|
165
|
+
*/
|
|
166
|
+
readonly sizeField?: string;
|
|
167
|
+
/**
|
|
168
|
+
* @title 形状图例配置
|
|
169
|
+
* @description 形状图例的配置项
|
|
170
|
+
*/
|
|
171
|
+
readonly shapeLegend?: Legend | false;
|
|
172
|
+
/**
|
|
173
|
+
* @title 大小图例配置
|
|
174
|
+
* @description 大小图例的配置项
|
|
175
|
+
*/
|
|
176
|
+
readonly sizeLegend?: Legend | false;
|
|
152
177
|
}
|