@visactor/vchart 1.12.6 → 1.12.7-alpha.0
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/build/es5/index.js +1 -1
- package/build/index.js +18 -12
- package/build/index.min.js +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/cjs/compile/compilable-base.js +2 -1
- package/cjs/compile/util.js +1 -2
- package/cjs/component/legend/continuous/legend.js +2 -1
- package/cjs/component/legend/continuous/legend.js.map +1 -1
- package/cjs/component/legend/discrete/legend.js +2 -1
- package/cjs/component/legend/discrete/legend.js.map +1 -1
- package/cjs/component/legend/interface.d.ts +1 -0
- package/cjs/component/legend/interface.js.map +1 -1
- package/cjs/constant/correlation.js +2 -1
- package/cjs/constant/layout.js +1 -2
- package/cjs/core/index.d.ts +1 -1
- package/cjs/core/index.js +1 -1
- package/cjs/core/index.js.map +1 -1
- package/cjs/data/transforms/legend-data/continuous/continuous.d.ts +1 -1
- package/cjs/data/transforms/legend-data/continuous/continuous.js +3 -2
- package/cjs/data/transforms/legend-data/continuous/continuous.js.map +1 -1
- package/cjs/data/transforms/legend-data/continuous/interface.d.ts +1 -0
- package/cjs/data/transforms/legend-data/continuous/interface.js.map +1 -1
- package/cjs/data/transforms/legend-data/discrete/discrete.d.ts +1 -1
- package/cjs/data/transforms/legend-data/discrete/discrete.js +3 -3
- package/cjs/data/transforms/legend-data/discrete/discrete.js.map +1 -1
- package/cjs/data/transforms/legend-data/discrete/interface.d.ts +1 -0
- package/cjs/data/transforms/legend-data/discrete/interface.js.map +1 -1
- package/esm/compile/compilable-base.js +2 -1
- package/esm/compile/util.js +1 -2
- package/esm/component/legend/continuous/legend.js +2 -1
- package/esm/component/legend/continuous/legend.js.map +1 -1
- package/esm/component/legend/discrete/legend.js +2 -1
- package/esm/component/legend/discrete/legend.js.map +1 -1
- package/esm/component/legend/interface.d.ts +1 -0
- package/esm/component/legend/interface.js.map +1 -1
- package/esm/constant/correlation.js +2 -1
- package/esm/constant/layout.js +1 -2
- package/esm/core/index.d.ts +1 -1
- package/esm/core/index.js +1 -1
- package/esm/core/index.js.map +1 -1
- package/esm/data/transforms/legend-data/continuous/continuous.d.ts +1 -1
- package/esm/data/transforms/legend-data/continuous/continuous.js +2 -2
- package/esm/data/transforms/legend-data/continuous/continuous.js.map +1 -1
- package/esm/data/transforms/legend-data/continuous/interface.d.ts +1 -0
- package/esm/data/transforms/legend-data/continuous/interface.js.map +1 -1
- package/esm/data/transforms/legend-data/discrete/discrete.d.ts +1 -1
- package/esm/data/transforms/legend-data/discrete/discrete.js +3 -3
- package/esm/data/transforms/legend-data/discrete/discrete.js.map +1 -1
- package/esm/data/transforms/legend-data/discrete/interface.d.ts +1 -0
- package/esm/data/transforms/legend-data/discrete/interface.js.map +1 -1
- package/package.json +5 -5
package/cjs/compile/util.js
CHANGED
|
@@ -30,7 +30,8 @@ class ContinuousLegend extends base_legend_1.BaseLegend {
|
|
|
30
30
|
selected: () => this._selectedData,
|
|
31
31
|
field: () => this._field,
|
|
32
32
|
data: () => this._legendData.getLatestData(),
|
|
33
|
-
isHierarchyData: s.isHierarchyData
|
|
33
|
+
isHierarchyData: s.isHierarchyData,
|
|
34
|
+
customFilter: this._spec.customFilter
|
|
34
35
|
},
|
|
35
36
|
level: initialize_1.TransformLevel.legendFilter
|
|
36
37
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/component/legend/continuous/legend.ts"],"names":[],"mappings":";;;AAKA,6CAAiE;AACjE,iDAA8C;AAK9C,+CAAyD;AAEzD,qDAA0E;AAC1E,+CAA4D;AAC5D,6CAAmD;AACnD,6CAAsD;AAEtD,2FAGoE;AACpE,iCAAgG;AAChG,gDAA4C;AAC5C,mDAAqD;AACrD,mDAAgD;AAChD,yDAA0D;AAE1D,qCAAyC;AAEzC,MAAM,eAAe,GAAG,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,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C,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,EAAE,kBAAkB,IACxE,IAAA,oCAA6B,EAAC,IAAI,CAAC,KAAK,CAAC,CAC7C,CAAC;QACF,IAAI,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC;QACjC,OAAO,KAAK,CAAC;IACf,CAAC;IAES,qBAAqB;QAC7B,OAAO,0BAAmB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC/C,CAAC;IAES,UAAU;QAClB,IAAI,IAAI,CAAC,gBAAgB,EAAE;YACzB,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,KAAK,CAAC;YAC7C,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,CACpC,QAAQ,EACR,IAAA,iBAAQ,EAAC,CAAC,CAAM,EAAE,EAAE;gBAClB,MAAM,YAAY,GAAG,IAAA,YAAG,EAAC,CAAC,EAAE,cAAc,CAAC,CAAC;gBAC5C,IAAI,QAAQ,EAAE;oBACZ,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;iBACpC;gBACD,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,kBAAU,CAAC,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;YAC3F,CAAC,EAAE,EAAE,CAAC,CACP,CAAC;SACH;IACH,CAAC;;AA/LH,4CAgMC;AA7LQ,wBAAO,GAAG,SAAS,CAAC;AAEpB,qBAAI,GAAG,wBAAiB,CAAC,gBAAgB,CAAC;AA6L5C,MAAM,wBAAwB,GAAG,GAAG,EAAE;IAC3C,iBAAO,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC;AACrE,CAAC,CAAC;AAFW,QAAA,wBAAwB,4BAEnC","file":"legend.js","sourcesContent":["/**\n * @description color legend component\n */\nimport type { Maybe } from '@visactor/vutils';\n// eslint-disable-next-line no-duplicate-imports\nimport { debounce, isEmpty, isNil, get } from '@visactor/vutils';\nimport { DataView } from '@visactor/vdataset';\n// eslint-disable-next-line no-duplicate-imports\nimport type { IModelInitOption, IModelSpecInfo } from '../../../model/interface';\nimport type { IComponentOption } from '../../interface';\n// eslint-disable-next-line no-duplicate-imports\nimport { ComponentTypeEnum } from '../../interface/type';\n// eslint-disable-next-line no-duplicate-imports\nimport { registerDataSetInstanceTransform } from '../../../data/register';\nimport { eachSeries, getSeries } from '../../../util/model';\nimport { getFieldAlias } from '../../../util/data';\nimport { isDataDomainSpec } from '../../../util/type';\nimport type { IColorLegendSpec, ISizeLegendSpec } from './interface';\nimport {\n continuousLegendDataMake,\n continuousLegendFilter\n} from '../../../data/transforms/legend-data/continuous/continuous';\nimport { ContinuousLegendMap, getContinuousLegendAttributes, isContinuousLegend } from './util';\nimport { BaseLegend } from '../base-legend';\nimport { ChartEvent } from '../../../constant/event';\nimport { Factory } from '../../../core/factory';\nimport { TransformLevel } from '../../../data/initialize';\nimport type { ILayoutRect } from '../../../typings/layout';\nimport { getSpecInfo } from '../../util';\n\nconst SINGLE_SEQUENCE = ['#C4E7FF', '#98CAFF', '#75ACFF', '#518FF9', '#2775DC', '#005CBE', '#00429F', '#00287E'];\nconst SIZE = [2, 10];\n\nexport class ContinuousLegend<\n T extends IColorLegendSpec | ISizeLegendSpec = IColorLegendSpec | ISizeLegendSpec\n> extends BaseLegend<T> {\n static specKey = 'legends';\n\n static type = ComponentTypeEnum.continuousLegend;\n type = ComponentTypeEnum.colorLegend;\n name: string = ComponentTypeEnum.colorLegend;\n\n private _field: string | undefined;\n private _legendType: string;\n\n static getSpecInfo(chartSpec: any): Maybe<IModelSpecInfo[]> {\n const infos = getSpecInfo<IColorLegendSpec | ISizeLegendSpec>(\n chartSpec,\n this.specKey,\n this.type,\n (s: IColorLegendSpec | ISizeLegendSpec) => {\n return isContinuousLegend(s.type);\n }\n );\n\n if (infos) {\n infos.forEach(info => {\n info.type = info.spec.type === 'color' ? ComponentTypeEnum.colorLegend : ComponentTypeEnum.sizeLegend;\n });\n }\n\n return infos;\n }\n\n constructor(spec: T, options: IComponentOption) {\n super(spec, options);\n\n // 这里需要区分下是 colorLegend 还是 sizeLegend\n const legendName = this._spec.type === 'color' ? ComponentTypeEnum.colorLegend : ComponentTypeEnum.sizeLegend;\n this.type = legendName;\n this.name = legendName;\n }\n\n setAttrFromSpec() {\n super.setAttrFromSpec();\n this._field = this._spec.field;\n this._legendType = this._spec.type;\n }\n\n init(option: IModelInitOption): void {\n super.init(option);\n eachSeries(\n this._regions,\n s => {\n s.addViewDataFilter({\n type: 'continuousLegendFilter',\n options: {\n selected: () => this._selectedData,\n field: () => this._field,\n data: () => this._legendData.getLatestData(),\n isHierarchyData: s.isHierarchyData\n },\n level: TransformLevel.legendFilter\n });\n },\n {\n userId: this._seriesUserId,\n specIndex: this._seriesIndex\n }\n );\n }\n\n private _getScaleInGlobal() {\n const globalScale = this._option.globalScale;\n let scaleKey = this._spec.scale;\n if (!scaleKey) {\n scaleKey = this._legendType;\n }\n return globalScale.getScale(scaleKey);\n }\n\n protected _initLegendData(): DataView {\n registerDataSetInstanceTransform(this._option.dataSet, 'continuousLegendFilter', continuousLegendFilter);\n registerDataSetInstanceTransform(this._option.dataSet, 'continuousLegendDataMake', continuousLegendDataMake);\n const legendData = new DataView(this._option.dataSet, { name: `${this.type}_${this.id}_data` });\n legendData.transform({\n type: 'continuousLegendDataMake',\n options: {\n series: () => {\n return getSeries(this._regions, {\n userId: this._seriesUserId,\n specIndex: this._seriesIndex\n });\n },\n field: () => this._field,\n scale: this._getScaleInGlobal.bind(this)\n }\n });\n return legendData;\n }\n\n protected _initSelectedData(): void {\n if (this._spec.defaultSelected) {\n this._selectedData = this._spec.defaultSelected.slice();\n } else {\n this._selectedData = this._legendData.getLatestData();\n }\n }\n\n private _addDefaultTitleText(attrs: any) {\n if (attrs.title?.visible && isNil(attrs.title.text) && isNil(attrs.title.style?.text)) {\n const field = this._field;\n if (field) {\n // 默认使用第0个系列的对应别名\n const series = this._regions?.[0]?.getSeries()[0];\n if (!series) {\n return;\n }\n // 如果没有别名继续保持 空字符串\n attrs.title.text = getFieldAlias(series.getRawData(), field);\n return;\n }\n let scaleKey = this._spec.scale;\n if (!scaleKey) {\n scaleKey = this._legendType;\n }\n const scaleSpec = this._option.globalScale.getScaleSpec(scaleKey);\n if (!isDataDomainSpec(scaleSpec?.domain)) {\n return;\n }\n const dataInfo = scaleSpec.domain[0];\n if (dataInfo.fields.length === 0) {\n return;\n }\n // 如果没有别名继续保持 空字符串\n attrs.title.text = getFieldAlias(this._option.dataSet.getDataView(dataInfo.dataId), dataInfo.fields[0]);\n return;\n }\n }\n\n protected _getLegendAttributes(rect: ILayoutRect) {\n const layout = this.layoutOrient === 'bottom' || this.layoutOrient === 'top' ? 'horizontal' : 'vertical';\n const align = layout === 'horizontal' ? 'bottom' : this.layoutOrient;\n\n // 获取关联的 scale 以获取 colors / size\n let visualMappingRange = [];\n const scale = this._getScaleInGlobal();\n if (scale && scale.type === 'linear') {\n visualMappingRange = scale.range();\n }\n if (isEmpty(visualMappingRange)) {\n visualMappingRange = this._legendType === 'color' ? SINGLE_SEQUENCE : SIZE;\n }\n let min = this._legendData.getLatestData()[0] ?? 0;\n let max = this._legendData.getLatestData()[1] ?? 1;\n\n const isSame = this._legendData.getLatestData()[0] === this._legendData.getLatestData()[1];\n if (isSame) {\n min = Math.min(0, this._legendData.getLatestData()[0]);\n max = this._legendData.getLatestData()[0] === 0 ? 1 : Math.max(0, this._legendData.getLatestData()[0]);\n }\n\n const attrs: any = {\n layout,\n align,\n zIndex: this.layoutZIndex,\n min,\n max,\n value: this._spec.defaultSelected,\n [this._legendType === 'color' ? 'colors' : 'sizeRange']: visualMappingRange,\n ...getContinuousLegendAttributes(this._spec)\n };\n this._addDefaultTitleText(attrs);\n return attrs;\n }\n\n protected _getLegendConstructor() {\n return ContinuousLegendMap[this._legendType];\n }\n\n protected _initEvent() {\n if (this._legendComponent) {\n const doFilter = this._spec.filter !== false;\n this._legendComponent.addEventListener(\n 'change',\n debounce((e: any) => {\n const selectedData = get(e, 'detail.value');\n if (doFilter) {\n this.setSelectedData(selectedData);\n }\n this.event.emit(ChartEvent.legendFilter, { model: this, value: selectedData, event: e });\n }, 30)\n );\n }\n }\n}\n\nexport const registerContinuousLegend = () => {\n Factory.registerComponent(ContinuousLegend.type, ContinuousLegend);\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/component/legend/continuous/legend.ts"],"names":[],"mappings":";;;AAKA,6CAAiE;AACjE,iDAA8C;AAK9C,+CAAyD;AAEzD,qDAA0E;AAC1E,+CAA4D;AAC5D,6CAAmD;AACnD,6CAAsD;AAEtD,2FAGoE;AACpE,iCAAgG;AAChG,gDAA4C;AAC5C,mDAAqD;AACrD,mDAAgD;AAChD,yDAA0D;AAE1D,qCAAyC;AAEzC,MAAM,eAAe,GAAG,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;AACjH,MAAM,IAAI,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAErB,MAAa,gBAEX,SAAQ,wBAAa;IAUrB,MAAM,CAAC,WAAW,CAAC,SAAc;QAC/B,MAAM,KAAK,GAAG,IAAA,kBAAW,EACvB,SAAS,EACT,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,IAAI,EACT,CAAC,CAAqC,EAAE,EAAE;YACxC,OAAO,IAAA,yBAAkB,EAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACpC,CAAC,CACF,CAAC;QAEF,IAAI,KAAK,EAAE;YACT,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;gBACnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,wBAAiB,CAAC,WAAW,CAAC,CAAC,CAAC,wBAAiB,C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AA,YAAG,EAAC,CAAC,EAAE,cAAc,CAAC,CAAC;gBAC5C,IAAI,QAAQ,EAAE;oBACZ,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;iBACpC;gBACD,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,kBAAU,CAAC,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;YAC3F,CAAC,EAAE,EAAE,CAAC,CACP,CAAC;SACH;IACH,CAAC;;AAhMH,4CAiMC;AA9LQ,wBAAO,GAAG,SAAS,CAAC;AAEpB,qBAAI,GAAG,wBAAiB,CAAC,gBAAgB,CAAC;AA8L5C,MAAM,wBAAwB,GAAG,GAAG,EAAE;IAC3C,iBAAO,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC;AACrE,CAAC,CAAC;AAFW,QAAA,wBAAwB,4BAEnC","file":"legend.js","sourcesContent":["/**\n * @description color legend component\n */\nimport type { Maybe } from '@visactor/vutils';\n// eslint-disable-next-line no-duplicate-imports\nimport { debounce, isEmpty, isNil, get } from '@visactor/vutils';\nimport { DataView } from '@visactor/vdataset';\n// eslint-disable-next-line no-duplicate-imports\nimport type { IModelInitOption, IModelSpecInfo } from '../../../model/interface';\nimport type { IComponentOption } from '../../interface';\n// eslint-disable-next-line no-duplicate-imports\nimport { ComponentTypeEnum } from '../../interface/type';\n// eslint-disable-next-line no-duplicate-imports\nimport { registerDataSetInstanceTransform } from '../../../data/register';\nimport { eachSeries, getSeries } from '../../../util/model';\nimport { getFieldAlias } from '../../../util/data';\nimport { isDataDomainSpec } from '../../../util/type';\nimport type { IColorLegendSpec, ISizeLegendSpec } from './interface';\nimport {\n continuousLegendDataMake,\n continuousLegendFilter\n} from '../../../data/transforms/legend-data/continuous/continuous';\nimport { ContinuousLegendMap, getContinuousLegendAttributes, isContinuousLegend } from './util';\nimport { BaseLegend } from '../base-legend';\nimport { ChartEvent } from '../../../constant/event';\nimport { Factory } from '../../../core/factory';\nimport { TransformLevel } from '../../../data/initialize';\nimport type { ILayoutRect } from '../../../typings/layout';\nimport { getSpecInfo } from '../../util';\n\nconst SINGLE_SEQUENCE = ['#C4E7FF', '#98CAFF', '#75ACFF', '#518FF9', '#2775DC', '#005CBE', '#00429F', '#00287E'];\nconst SIZE = [2, 10];\n\nexport class ContinuousLegend<\n T extends IColorLegendSpec | ISizeLegendSpec = IColorLegendSpec | ISizeLegendSpec\n> extends BaseLegend<T> {\n static specKey = 'legends';\n\n static type = ComponentTypeEnum.continuousLegend;\n type = ComponentTypeEnum.colorLegend;\n name: string = ComponentTypeEnum.colorLegend;\n\n private _field: string | undefined;\n private _legendType: string;\n\n static getSpecInfo(chartSpec: any): Maybe<IModelSpecInfo[]> {\n const infos = getSpecInfo<IColorLegendSpec | ISizeLegendSpec>(\n chartSpec,\n this.specKey,\n this.type,\n (s: IColorLegendSpec | ISizeLegendSpec) => {\n return isContinuousLegend(s.type);\n }\n );\n\n if (infos) {\n infos.forEach(info => {\n info.type = info.spec.type === 'color' ? ComponentTypeEnum.colorLegend : ComponentTypeEnum.sizeLegend;\n });\n }\n\n return infos;\n }\n\n constructor(spec: T, options: IComponentOption) {\n super(spec, options);\n\n // 这里需要区分下是 colorLegend 还是 sizeLegend\n const legendName = this._spec.type === 'color' ? ComponentTypeEnum.colorLegend : ComponentTypeEnum.sizeLegend;\n this.type = legendName;\n this.name = legendName;\n }\n\n setAttrFromSpec() {\n super.setAttrFromSpec();\n this._field = this._spec.field;\n this._legendType = this._spec.type;\n }\n\n init(option: IModelInitOption): void {\n super.init(option);\n eachSeries(\n this._regions,\n s => {\n s.addViewDataFilter({\n type: 'continuousLegendFilter',\n options: {\n selected: () => this._selectedData,\n field: () => this._field,\n data: () => this._legendData.getLatestData(),\n isHierarchyData: s.isHierarchyData,\n customFilter: this._spec.customFilter\n },\n level: TransformLevel.legendFilter\n });\n },\n {\n userId: this._seriesUserId,\n specIndex: this._seriesIndex\n }\n );\n }\n\n private _getScaleInGlobal() {\n const globalScale = this._option.globalScale;\n let scaleKey = this._spec.scale;\n if (!scaleKey) {\n scaleKey = this._legendType;\n }\n return globalScale.getScale(scaleKey);\n }\n\n protected _initLegendData(): DataView {\n registerDataSetInstanceTransform(this._option.dataSet, 'continuousLegendFilter', continuousLegendFilter);\n registerDataSetInstanceTransform(this._option.dataSet, 'continuousLegendDataMake', continuousLegendDataMake);\n const legendData = new DataView(this._option.dataSet, { name: `${this.type}_${this.id}_data` });\n legendData.transform({\n type: 'continuousLegendDataMake',\n options: {\n series: () => {\n return getSeries(this._regions, {\n userId: this._seriesUserId,\n specIndex: this._seriesIndex\n });\n },\n field: () => this._field,\n scale: this._getScaleInGlobal.bind(this)\n }\n });\n return legendData;\n }\n\n protected _initSelectedData(): void {\n if (this._spec.defaultSelected) {\n this._selectedData = this._spec.defaultSelected.slice();\n } else {\n this._selectedData = this._legendData.getLatestData();\n }\n }\n\n private _addDefaultTitleText(attrs: any) {\n if (attrs.title?.visible && isNil(attrs.title.text) && isNil(attrs.title.style?.text)) {\n const field = this._field;\n if (field) {\n // 默认使用第0个系列的对应别名\n const series = this._regions?.[0]?.getSeries()[0];\n if (!series) {\n return;\n }\n // 如果没有别名继续保持 空字符串\n attrs.title.text = getFieldAlias(series.getRawData(), field);\n return;\n }\n let scaleKey = this._spec.scale;\n if (!scaleKey) {\n scaleKey = this._legendType;\n }\n const scaleSpec = this._option.globalScale.getScaleSpec(scaleKey);\n if (!isDataDomainSpec(scaleSpec?.domain)) {\n return;\n }\n const dataInfo = scaleSpec.domain[0];\n if (dataInfo.fields.length === 0) {\n return;\n }\n // 如果没有别名继续保持 空字符串\n attrs.title.text = getFieldAlias(this._option.dataSet.getDataView(dataInfo.dataId), dataInfo.fields[0]);\n return;\n }\n }\n\n protected _getLegendAttributes(rect: ILayoutRect) {\n const layout = this.layoutOrient === 'bottom' || this.layoutOrient === 'top' ? 'horizontal' : 'vertical';\n const align = layout === 'horizontal' ? 'bottom' : this.layoutOrient;\n\n // 获取关联的 scale 以获取 colors / size\n let visualMappingRange = [];\n const scale = this._getScaleInGlobal();\n if (scale && scale.type === 'linear') {\n visualMappingRange = scale.range();\n }\n if (isEmpty(visualMappingRange)) {\n visualMappingRange = this._legendType === 'color' ? SINGLE_SEQUENCE : SIZE;\n }\n let min = this._legendData.getLatestData()[0] ?? 0;\n let max = this._legendData.getLatestData()[1] ?? 1;\n\n const isSame = this._legendData.getLatestData()[0] === this._legendData.getLatestData()[1];\n if (isSame) {\n min = Math.min(0, this._legendData.getLatestData()[0]);\n max = this._legendData.getLatestData()[0] === 0 ? 1 : Math.max(0, this._legendData.getLatestData()[0]);\n }\n\n const attrs: any = {\n layout,\n align,\n zIndex: this.layoutZIndex,\n min,\n max,\n value: this._spec.defaultSelected,\n [this._legendType === 'color' ? 'colors' : 'sizeRange']: visualMappingRange,\n ...getContinuousLegendAttributes(this._spec)\n };\n this._addDefaultTitleText(attrs);\n return attrs;\n }\n\n protected _getLegendConstructor() {\n return ContinuousLegendMap[this._legendType];\n }\n\n protected _initEvent() {\n if (this._legendComponent) {\n const doFilter = this._spec.filter !== false;\n this._legendComponent.addEventListener(\n 'change',\n debounce((e: any) => {\n const selectedData = get(e, 'detail.value');\n if (doFilter) {\n this.setSelectedData(selectedData);\n }\n this.event.emit(ChartEvent.legendFilter, { model: this, value: selectedData, event: e });\n }, 30)\n );\n }\n }\n}\n\nexport const registerContinuousLegend = () => {\n Factory.registerComponent(ContinuousLegend.type, ContinuousLegend);\n};\n"]}
|
|
@@ -21,7 +21,8 @@ class DiscreteLegend extends base_legend_1.BaseLegend {
|
|
|
21
21
|
series: s,
|
|
22
22
|
selected: () => this._selectedData,
|
|
23
23
|
field: () => this._getSeriesLegendField(s),
|
|
24
|
-
data: () => this.getLegendDefaultData()
|
|
24
|
+
data: () => this.getLegendDefaultData(),
|
|
25
|
+
customFilter: this._spec.customFilter
|
|
25
26
|
},
|
|
26
27
|
level: initialize_1.TransformLevel.legendFilter
|
|
27
28
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/component/legend/discrete/legend.ts"],"names":[],"mappings":";;;AAEA,6CAAyE;AACzE,iDAA8C;AAM9C,+CAAyD;AAEzD,iCAA6C;AAC7C,qDAA0E;AAC1E,+CAAiD;AACjD,6CAAmD;AACnD,6CAAsD;AAItD,qEAA2D;AAE3D,qEAAiF;AACjF,qFAAsH;AACtH,gDAA4C;AAC5C,mDAAqD;AACrD,mDAAgD;AAChD,yDAA0D;AAG1D,qCAA4D;AAG5D,MAAa,cAAe,SAAQ,wBAA+B;IAAnE;;QAIE,SAAI,GAAG,wBAAiB,CAAC,cAAc,CAAC;QACxC,SAAI,GAAW,wBAAiB,CAAC,cAAc,CAAC;IA8OlD,CAAC;IA1OC,MAAM,CAAC,WAAW,CAAC,SAAc;QAC/B,OAAO,IAAA,kBAAW,EAAsB,SAAS,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAsB,EAAE,EAAE;YACrG,OAAO,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,KAAK,UAAU,CAAC;QAC1C,CAAC,CAAC,CAAC;IACL,CAAC;IAED,IAAI,CAAC,MAAwB;QAC3B,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACnB,IAAA,kBAAU,EACR,IAAI,CAAC,QAAQ,EACb,CAAC,CAAC,EAAE;YACF,CAAC,CAAC,iBAAiB,CAAC;gBAClB,IAAI,EAAE,sBAAsB;gBAC5B,OAAO,EAAE;oBACP,MAAM,EAAE,CAAC;oBACT,QAAQ,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,aAAa;oBAClC,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC,CAAC;oBAC1C,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,oBAAoB,EAAE;i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E,cAAc,CAAC,CAAC;QAC7F,IAAI,cAAc,IAAI,CAAC,iBAAiB,IAAI,eAAe,EAAE;YAC3D,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,GAAG,CAAC,KAAa,EAAE,KAAU,EAAE,EAAE;gBAC5D,OAAO,eAAe,CAAC,cAAc,EAAE,KAAK,EAAE,KAAK,EAAE,cAAc,CAAC,CAAC;YACvE,CAAC,CAAC;SACH;IACH,CAAC;;AAlPH,wCAmPC;AAlPQ,sBAAO,GAAG,SAAS,CAAC;AAEpB,mBAAI,GAAG,wBAAiB,CAAC,cAAc,CAAC;AAkP1C,MAAM,sBAAsB,GAAG,GAAG,EAAE;IACzC,iBAAO,CAAC,iBAAiB,CAAC,cAAc,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;AACjE,CAAC,CAAC;AAFW,QAAA,sBAAsB,0BAEjC","file":"legend.js","sourcesContent":["import type { Maybe } from '@visactor/vutils';\n// eslint-disable-next-line no-duplicate-imports\nimport { isFunction, isNil, isValidNumber, get } from '@visactor/vutils';\nimport { DataView } from '@visactor/vdataset';\nimport type { IDiscreteLegendSpec } from './interface';\n// eslint-disable-next-line no-duplicate-imports\nimport type { ISeries } from '../../../series/interface';\nimport type { IModelInitOption, IModelSpecInfo } from '../../../model/interface';\n// eslint-disable-next-line no-duplicate-imports\nimport { ComponentTypeEnum } from '../../interface/type';\n// eslint-disable-next-line no-duplicate-imports\nimport { getLegendAttributes } from './util';\nimport { registerDataSetInstanceTransform } from '../../../data/register';\nimport { eachSeries } from '../../../util/model';\nimport { getFieldAlias } from '../../../util/data';\nimport { isDataDomainSpec } from '../../../util/type';\n// eslint-disable-next-line no-duplicate-imports\nimport type { LegendItemDatum } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport { LegendEvent } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport { DiscreteLegend as LegendComponent } from '@visactor/vrender-components';\nimport { discreteLegendDataMake, discreteLegendFilter } from '../../../data/transforms/legend-data/discrete/discrete';\nimport { BaseLegend } from '../base-legend';\nimport { ChartEvent } from '../../../constant/event';\nimport { Factory } from '../../../core/factory';\nimport { TransformLevel } from '../../../data/initialize';\nimport type { ILayoutRect } from '../../../typings/layout';\nimport type { StringOrNumber } from '../../../typings';\nimport { getFormatFunction, getSpecInfo } from '../../util';\nimport type { IDiscreteLegendData } from '../../../data/transforms/legend-data/discrete';\n\nexport class DiscreteLegend extends BaseLegend<IDiscreteLegendSpec> {\n static specKey = 'legends';\n\n static type = ComponentTypeEnum.discreteLegend;\n type = ComponentTypeEnum.discreteLegend;\n name: string = ComponentTypeEnum.discreteLegend;\n\n protected _unselectedData: StringOrNumber[];\n\n static getSpecInfo(chartSpec: any): Maybe<IModelSpecInfo[]> {\n return getSpecInfo<IDiscreteLegendSpec>(chartSpec, this.specKey, this.type, (s: IDiscreteLegendSpec) => {\n return !s.type || s.type === 'discrete';\n });\n }\n\n init(option: IModelInitOption): void {\n super.init(option);\n eachSeries(\n this._regions,\n s => {\n s.addViewDataFilter({\n type: 'discreteLegendFilter',\n options: {\n series: s,\n selected: () => this._selectedData,\n field: () => this._getSeriesLegendField(s),\n data: () => this.getLegendDefaultData()\n },\n level: TransformLevel.legendFilter\n });\n },\n {\n userId: this._seriesUserId,\n specIndex: this._seriesIndex\n }\n );\n }\n\n protected _initLegendData(): DataView {\n registerDataSetInstanceTransform(this._option.dataSet, 'discreteLegendFilter', discreteLegendFilter);\n registerDataSetInstanceTransform(this._option.dataSet, 'discreteLegendDataMake', discreteLegendDataMake);\n const legendData = new DataView(this._option.dataSet, { name: `${this.type}_${this.id}_data` });\n legendData.transform({\n type: 'discreteLegendDataMake',\n options: {\n series: () => {\n const result: ISeries[] = [];\n eachSeries(\n this._regions,\n s => {\n result.push(s);\n },\n {\n specIndex: this._spec.seriesIndex,\n userId: this._spec.seriesId\n }\n );\n return result;\n },\n seriesField: (s: ISeries) => this._getSeriesLegendField(s)\n }\n });\n\n return legendData;\n }\n\n protected _getSeriesLegendField(s: ISeries) {\n const defaultField = s.getSeriesField();\n const specifyScaleId = this._spec.scaleName ?? this._spec.scale;\n\n if (isNil(specifyScaleId)) {\n return defaultField;\n }\n if (!s.getRawData()) {\n return defaultField;\n }\n const scaleSpec = this._option.globalScale.getScaleSpec(specifyScaleId);\n if (!scaleSpec) {\n return defaultField;\n }\n\n // field是只在图例指定了scale的情况下生效\n if (this._spec.field) {\n return this._spec.field;\n }\n\n if (!isDataDomainSpec(scaleSpec.domain)) {\n return defaultField;\n }\n const seriesData = scaleSpec.domain.find(d => d.dataId === s.getRawData().name);\n if (!seriesData) {\n return defaultField;\n }\n return seriesData.fields?.[0] ?? defaultField;\n }\n\n protected _initSelectedData(): void {\n const fullSelectedData = this.getLegendDefaultData();\n\n if (this._unselectedData) {\n const selected: StringOrNumber[] = [];\n const unselected: StringOrNumber[] = [];\n\n fullSelectedData.forEach((entry: StringOrNumber) => {\n if (this._unselectedData.includes(entry)) {\n unselected.push(entry);\n } else {\n selected.push(entry);\n }\n });\n this._selectedData = selected;\n this._unselectedData = unselected;\n } else if (this._spec.defaultSelected) {\n this._selectedData = [...this._spec.defaultSelected];\n } else {\n this._selectedData = fullSelectedData;\n }\n }\n\n getLegendDefaultData(originalData?: boolean) {\n if (isFunction(this._spec.data)) {\n return this._getLegendItems().map((obj: LegendItemDatum) => obj.label);\n }\n\n return this._legendData\n .getLatestData()\n .map(originalData ? (obj: IDiscreteLegendData) => obj.originalKey : (obj: IDiscreteLegendData) => obj.key);\n }\n\n private _addDefaultTitleText(attrs: any) {\n if (attrs.title?.visible && isNil(attrs.title.text) && isNil(attrs.title.style?.text)) {\n // 默认使用第0个系列的 seriesField 别名\n const series = this._regions?.[0]?.getSeries()[0];\n if (!series) {\n return;\n }\n // 如果没有别名继续保持 空字符串\n attrs.title.text = getFieldAlias(series.getRawData(), series.getSeriesField());\n }\n }\n\n protected _getLegendAttributes(rect: ILayoutRect) {\n const layout = this.layoutOrient === 'bottom' || this.layoutOrient === 'top' ? 'horizontal' : 'vertical';\n const attrs = {\n layout,\n items: this._getLegendItems(),\n zIndex: this.layoutZIndex,\n ...getLegendAttributes(this._spec, rect),\n // maxWidth 和 maxHeight 已经在布局模块处理了,所以 rect 的优先级最高\n maxWidth: rect.width,\n maxHeight: rect.height\n };\n this._addDefaultTitleText(attrs);\n this._addLegendItemFormatMethods(attrs);\n return attrs;\n }\n\n protected _getLegendConstructor() {\n return LegendComponent;\n }\n\n setSelectedData(selectedData: StringOrNumber[]) {\n if (selectedData) {\n this._unselectedData = this.getLegendDefaultData().filter(\n (entry: StringOrNumber) => !selectedData.includes(entry)\n );\n }\n\n super.setSelectedData(selectedData);\n }\n\n protected _initEvent() {\n if (this._legendComponent) {\n const doFilter = this._spec.filter !== false;\n this._legendComponent.addEventListener(LegendEvent.legendItemClick, (e: any) => {\n const selectedData = get(e, 'detail.currentSelected');\n doFilter && this.setSelectedData(selectedData);\n this.event.emit(ChartEvent.legendItemClick, { model: this, value: selectedData, event: e });\n });\n\n this._legendComponent.addEventListener(LegendEvent.legendItemHover, (e: any) => {\n const detail = get(e, 'detail');\n this.event.emit(ChartEvent.legendItemHover, { model: this, value: detail, event: e });\n });\n\n this._legendComponent.addEventListener(LegendEvent.legendItemUnHover, (e: any) => {\n const detail = get(e, 'detail');\n this.event.emit(ChartEvent.legendItemUnHover, { model: this, value: detail, event: e });\n });\n }\n }\n\n private _getLegendItems() {\n const originData = (this._legendData.getLatestData() || []).map((datum: any) => {\n const fillOpacity = datum.style('fillOpacity');\n const strokeOpacity = datum.style('strokeOpacity');\n const opacity = datum.style('opacity');\n const texture = datum.style('texture');\n\n return {\n label: datum.key,\n shape: {\n symbolType: datum.style('symbolType') ?? datum.shapeType ?? 'circle',\n fillOpacity: isValidNumber(fillOpacity) ? fillOpacity : 1,\n strokeOpacity: isValidNumber(strokeOpacity) ? strokeOpacity : 1,\n opacity: isValidNumber(opacity) ? opacity : 1,\n texturePadding: texture ? 1 : null,\n textureSize: texture ? 4 : null,\n texture,\n fill: datum.style('fill'),\n stroke: datum.style('stroke'),\n textureColor: datum.style('textureColor'),\n innerBorder: datum.style('innerBorder'),\n outerBorder: datum.style('outerBorder'),\n lineDash: datum.style('lineDash'),\n lineDashOffset: datum.style('lineDashOffset'),\n lineWidth: datum.style('lineWidth')\n }\n };\n });\n const legendItems = isFunction(this._spec.data)\n ? this._spec.data(originData, this._option.globalScale.getScale('color'), this._option.globalScale)\n : originData;\n return legendItems;\n }\n\n private _addLegendItemFormatMethods(attrs: any) {\n const { formatMethod: labelFormatMethod, formatter: labelFormatter } = this._spec.item?.label ?? {};\n const { formatMethod: valueFormatMethod, formatter: valueFormatter } = this._spec.item?.value ?? {};\n\n const { formatFunc: labelFormatFunc } = getFormatFunction(labelFormatMethod, labelFormatter);\n if (labelFormatter && !labelFormatMethod && labelFormatFunc) {\n attrs.item.label.formatMethod = (value: string, datum: any) => {\n return labelFormatFunc(value, datum, labelFormatter);\n };\n }\n const { formatFunc: valueFormatFunc } = getFormatFunction(valueFormatMethod, valueFormatter);\n if (valueFormatter && !valueFormatMethod && valueFormatFunc) {\n attrs.item.value.formatMethod = (value: string, datum: any) => {\n return valueFormatFunc(valueFormatter, value, datum, labelFormatter);\n };\n }\n }\n}\n\nexport const registerDiscreteLegend = () => {\n Factory.registerComponent(DiscreteLegend.type, DiscreteLegend);\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/component/legend/discrete/legend.ts"],"names":[],"mappings":";;;AAEA,6CAAyE;AACzE,iDAA8C;AAM9C,+CAAyD;AAEzD,iCAA6C;AAC7C,qDAA0E;AAC1E,+CAAiD;AACjD,6CAAmD;AACnD,6CAAsD;AAItD,qEAA2D;AAE3D,qEAAiF;AACjF,qFAAsH;AACtH,gDAA4C;AAC5C,mDAAqD;AACrD,mDAAgD;AAChD,yDAA0D;AAG1D,qCAA4D;AAG5D,MAAa,cAAe,SAAQ,wBAA+B;IAAnE;;QAIE,SAAI,GAAG,wBAAiB,CAAC,cAA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GAAG,GAAG,EAAE;IACzC,iBAAO,CAAC,iBAAiB,CAAC,cAAc,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;AACjE,CAAC,CAAC;AAFW,QAAA,sBAAsB,0BAEjC","file":"legend.js","sourcesContent":["import type { Maybe } from '@visactor/vutils';\n// eslint-disable-next-line no-duplicate-imports\nimport { isFunction, isNil, isValidNumber, get } from '@visactor/vutils';\nimport { DataView } from '@visactor/vdataset';\nimport type { IDiscreteLegendSpec } from './interface';\n// eslint-disable-next-line no-duplicate-imports\nimport type { ISeries } from '../../../series/interface';\nimport type { IModelInitOption, IModelSpecInfo } from '../../../model/interface';\n// eslint-disable-next-line no-duplicate-imports\nimport { ComponentTypeEnum } from '../../interface/type';\n// eslint-disable-next-line no-duplicate-imports\nimport { getLegendAttributes } from './util';\nimport { registerDataSetInstanceTransform } from '../../../data/register';\nimport { eachSeries } from '../../../util/model';\nimport { getFieldAlias } from '../../../util/data';\nimport { isDataDomainSpec } from '../../../util/type';\n// eslint-disable-next-line no-duplicate-imports\nimport type { LegendItemDatum } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport { LegendEvent } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport { DiscreteLegend as LegendComponent } from '@visactor/vrender-components';\nimport { discreteLegendDataMake, discreteLegendFilter } from '../../../data/transforms/legend-data/discrete/discrete';\nimport { BaseLegend } from '../base-legend';\nimport { ChartEvent } from '../../../constant/event';\nimport { Factory } from '../../../core/factory';\nimport { TransformLevel } from '../../../data/initialize';\nimport type { ILayoutRect } from '../../../typings/layout';\nimport type { StringOrNumber } from '../../../typings';\nimport { getFormatFunction, getSpecInfo } from '../../util';\nimport type { IDiscreteLegendData } from '../../../data/transforms/legend-data/discrete';\n\nexport class DiscreteLegend extends BaseLegend<IDiscreteLegendSpec> {\n static specKey = 'legends';\n\n static type = ComponentTypeEnum.discreteLegend;\n type = ComponentTypeEnum.discreteLegend;\n name: string = ComponentTypeEnum.discreteLegend;\n\n protected _unselectedData: StringOrNumber[];\n\n static getSpecInfo(chartSpec: any): Maybe<IModelSpecInfo[]> {\n return getSpecInfo<IDiscreteLegendSpec>(chartSpec, this.specKey, this.type, (s: IDiscreteLegendSpec) => {\n return !s.type || s.type === 'discrete';\n });\n }\n\n init(option: IModelInitOption): void {\n super.init(option);\n eachSeries(\n this._regions,\n s => {\n s.addViewDataFilter({\n type: 'discreteLegendFilter',\n options: {\n series: s,\n selected: () => this._selectedData,\n field: () => this._getSeriesLegendField(s),\n data: () => this.getLegendDefaultData(),\n customFilter: this._spec.customFilter\n },\n level: TransformLevel.legendFilter\n });\n },\n {\n userId: this._seriesUserId,\n specIndex: this._seriesIndex\n }\n );\n }\n\n protected _initLegendData(): DataView {\n registerDataSetInstanceTransform(this._option.dataSet, 'discreteLegendFilter', discreteLegendFilter);\n registerDataSetInstanceTransform(this._option.dataSet, 'discreteLegendDataMake', discreteLegendDataMake);\n const legendData = new DataView(this._option.dataSet, { name: `${this.type}_${this.id}_data` });\n legendData.transform({\n type: 'discreteLegendDataMake',\n options: {\n series: () => {\n const result: ISeries[] = [];\n eachSeries(\n this._regions,\n s => {\n result.push(s);\n },\n {\n specIndex: this._spec.seriesIndex,\n userId: this._spec.seriesId\n }\n );\n return result;\n },\n seriesField: (s: ISeries) => this._getSeriesLegendField(s)\n }\n });\n\n return legendData;\n }\n\n protected _getSeriesLegendField(s: ISeries) {\n const defaultField = s.getSeriesField();\n const specifyScaleId = this._spec.scaleName ?? this._spec.scale;\n\n if (isNil(specifyScaleId)) {\n return defaultField;\n }\n if (!s.getRawData()) {\n return defaultField;\n }\n const scaleSpec = this._option.globalScale.getScaleSpec(specifyScaleId);\n if (!scaleSpec) {\n return defaultField;\n }\n\n // field是只在图例指定了scale的情况下生效\n if (this._spec.field) {\n return this._spec.field;\n }\n\n if (!isDataDomainSpec(scaleSpec.domain)) {\n return defaultField;\n }\n const seriesData = scaleSpec.domain.find(d => d.dataId === s.getRawData().name);\n if (!seriesData) {\n return defaultField;\n }\n return seriesData.fields?.[0] ?? defaultField;\n }\n\n protected _initSelectedData(): void {\n const fullSelectedData = this.getLegendDefaultData();\n\n if (this._unselectedData) {\n const selected: StringOrNumber[] = [];\n const unselected: StringOrNumber[] = [];\n\n fullSelectedData.forEach((entry: StringOrNumber) => {\n if (this._unselectedData.includes(entry)) {\n unselected.push(entry);\n } else {\n selected.push(entry);\n }\n });\n this._selectedData = selected;\n this._unselectedData = unselected;\n } else if (this._spec.defaultSelected) {\n this._selectedData = [...this._spec.defaultSelected];\n } else {\n this._selectedData = fullSelectedData;\n }\n }\n\n getLegendDefaultData(originalData?: boolean) {\n if (isFunction(this._spec.data)) {\n return this._getLegendItems().map((obj: LegendItemDatum) => obj.label);\n }\n\n return this._legendData\n .getLatestData()\n .map(originalData ? (obj: IDiscreteLegendData) => obj.originalKey : (obj: IDiscreteLegendData) => obj.key);\n }\n\n private _addDefaultTitleText(attrs: any) {\n if (attrs.title?.visible && isNil(attrs.title.text) && isNil(attrs.title.style?.text)) {\n // 默认使用第0个系列的 seriesField 别名\n const series = this._regions?.[0]?.getSeries()[0];\n if (!series) {\n return;\n }\n // 如果没有别名继续保持 空字符串\n attrs.title.text = getFieldAlias(series.getRawData(), series.getSeriesField());\n }\n }\n\n protected _getLegendAttributes(rect: ILayoutRect) {\n const layout = this.layoutOrient === 'bottom' || this.layoutOrient === 'top' ? 'horizontal' : 'vertical';\n const attrs = {\n layout,\n items: this._getLegendItems(),\n zIndex: this.layoutZIndex,\n ...getLegendAttributes(this._spec, rect),\n // maxWidth 和 maxHeight 已经在布局模块处理了,所以 rect 的优先级最高\n maxWidth: rect.width,\n maxHeight: rect.height\n };\n this._addDefaultTitleText(attrs);\n this._addLegendItemFormatMethods(attrs);\n return attrs;\n }\n\n protected _getLegendConstructor() {\n return LegendComponent;\n }\n\n setSelectedData(selectedData: StringOrNumber[]) {\n if (selectedData) {\n this._unselectedData = this.getLegendDefaultData().filter(\n (entry: StringOrNumber) => !selectedData.includes(entry)\n );\n }\n\n super.setSelectedData(selectedData);\n }\n\n protected _initEvent() {\n if (this._legendComponent) {\n const doFilter = this._spec.filter !== false;\n this._legendComponent.addEventListener(LegendEvent.legendItemClick, (e: any) => {\n const selectedData = get(e, 'detail.currentSelected');\n doFilter && this.setSelectedData(selectedData);\n this.event.emit(ChartEvent.legendItemClick, { model: this, value: selectedData, event: e });\n });\n\n this._legendComponent.addEventListener(LegendEvent.legendItemHover, (e: any) => {\n const detail = get(e, 'detail');\n this.event.emit(ChartEvent.legendItemHover, { model: this, value: detail, event: e });\n });\n\n this._legendComponent.addEventListener(LegendEvent.legendItemUnHover, (e: any) => {\n const detail = get(e, 'detail');\n this.event.emit(ChartEvent.legendItemUnHover, { model: this, value: detail, event: e });\n });\n }\n }\n\n private _getLegendItems() {\n const originData = (this._legendData.getLatestData() || []).map((datum: any) => {\n const fillOpacity = datum.style('fillOpacity');\n const strokeOpacity = datum.style('strokeOpacity');\n const opacity = datum.style('opacity');\n const texture = datum.style('texture');\n\n return {\n label: datum.key,\n shape: {\n symbolType: datum.style('symbolType') ?? datum.shapeType ?? 'circle',\n fillOpacity: isValidNumber(fillOpacity) ? fillOpacity : 1,\n strokeOpacity: isValidNumber(strokeOpacity) ? strokeOpacity : 1,\n opacity: isValidNumber(opacity) ? opacity : 1,\n texturePadding: texture ? 1 : null,\n textureSize: texture ? 4 : null,\n texture,\n fill: datum.style('fill'),\n stroke: datum.style('stroke'),\n textureColor: datum.style('textureColor'),\n innerBorder: datum.style('innerBorder'),\n outerBorder: datum.style('outerBorder'),\n lineDash: datum.style('lineDash'),\n lineDashOffset: datum.style('lineDashOffset'),\n lineWidth: datum.style('lineWidth')\n }\n };\n });\n const legendItems = isFunction(this._spec.data)\n ? this._spec.data(originData, this._option.globalScale.getScale('color'), this._option.globalScale)\n : originData;\n return legendItems;\n }\n\n private _addLegendItemFormatMethods(attrs: any) {\n const { formatMethod: labelFormatMethod, formatter: labelFormatter } = this._spec.item?.label ?? {};\n const { formatMethod: valueFormatMethod, formatter: valueFormatter } = this._spec.item?.value ?? {};\n\n const { formatFunc: labelFormatFunc } = getFormatFunction(labelFormatMethod, labelFormatter);\n if (labelFormatter && !labelFormatMethod && labelFormatFunc) {\n attrs.item.label.formatMethod = (value: string, datum: any) => {\n return labelFormatFunc(value, datum, labelFormatter);\n };\n }\n const { formatFunc: valueFormatFunc } = getFormatFunction(valueFormatMethod, valueFormatter);\n if (valueFormatter && !valueFormatMethod && valueFormatFunc) {\n attrs.item.value.formatMethod = (value: string, datum: any) => {\n return valueFormatFunc(valueFormatter, value, datum, labelFormatter);\n };\n }\n }\n}\n\nexport const registerDiscreteLegend = () => {\n Factory.registerComponent(DiscreteLegend.type, DiscreteLegend);\n};\n"]}
|
|
@@ -29,6 +29,7 @@ export type ILegendCommonSpec = {
|
|
|
29
29
|
position?: 'start' | 'middle' | 'end';
|
|
30
30
|
layout?: 'horizontal' | 'vertical';
|
|
31
31
|
filter?: boolean;
|
|
32
|
+
customFilter?: (data: any, selectedRange: StringOrNumber[], datumField: string) => any;
|
|
32
33
|
title?: ITitle;
|
|
33
34
|
background?: {
|
|
34
35
|
visible?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/component/legend/interface.ts"],"names":[],"mappings":"","file":"interface.js","sourcesContent":["import type { LegendTitle } from '@visactor/vrender-components';\nimport type {\n Datum,\n IOrientType,\n IPadding,\n IRectMarkSpec,\n ISymbolMarkSpec,\n ITextMarkSpec,\n StringOrNumber\n} from '../../typings';\nimport type { IComponent } from '../interface';\nimport type { IComponentSpec } from '../base/interface';\nimport type { IDiscreteLegendSpec } from './discrete';\nimport type { IColorLegendSpec, ISizeLegendSpec } from './continuous';\n\nexport type ILegend = IComponent & {\n getLegendData: () => Datum[];\n getSelectedData: () => StringOrNumber[];\n setSelectedData: (d: StringOrNumber[]) => void;\n};\n\nexport type NoVisibleMarkStyle<T> = Omit<T, 'visible'>;\n\nexport type ITitle = {\n /** 标题文本样式 */\n textStyle?: NoVisibleMarkStyle<ITextMarkSpec>;\n /**\n * @deprecated 请使用 textStyle 配置文本样式\n */\n style?: NoVisibleMarkStyle<ITextMarkSpec>;\n /** 文本前 mark 图元 */\n shape?: {\n /**\n * 是否展示 shape\n */\n visible?: boolean;\n /**\n * shape 同 文本的间距\n */\n space?: number;\n style?: NoVisibleMarkStyle<ISymbolMarkSpec>;\n };\n /**\n * 标题的背景面板配置\n */\n background?: {\n /**\n * 是否绘制背景层\n */\n visible?: boolean;\n /**\n * 背景层样式\n */\n style?: Omit<NoVisibleMarkStyle<IRectMarkSpec>, 'visible' | 'width' | 'height'>;\n };\n} & Omit<LegendTitle, 'textStyle' | 'style' | 'background'>;\n\n// 图例组件通用配置\nexport type ILegendCommonSpec = {\n /**\n * 是否显示图例\n * @default true\n */\n visible?: boolean;\n /**\n * 图例位置\n * @default 'left'\n */\n orient?: IOrientType;\n /**\n * 图例在当前行列的对齐方式,起始 | 居中 | 末尾\n * @default 'middle'\n */\n position?: 'start' | 'middle' | 'end';\n /**\n * 图例组件的布局配置,默认自动跟随显示位置进行调整。\n * 1. `orient` 为 'top' 或者 'bottom' 时,默认为 'horizontal' 水平布局\n * 2. `orient` 为 'left' 或者 'right' 时,默认为 'vertical' 垂直布局\n */\n layout?: 'horizontal' | 'vertical';\n\n /**\n * 是否进行数据筛选,默认为 true\n */\n filter?: boolean;\n\n /**\n * 图例标题配置\n */\n title?: ITitle;\n\n /**\n * 图例背景配置\n */\n background?: {\n /**\n * 是否绘制背景层\n */\n visible?: boolean;\n /**\n * 背景内边距\n */\n padding?: IPadding | number | number[];\n /**\n * 背景层样式\n */\n style?: Omit<NoVisibleMarkStyle<IRectMarkSpec>, 'visible' | 'width' | 'height'>;\n };\n /**\n * 是否允许交互\n * @default true\n */\n interactive?: boolean;\n} & Omit<IComponentSpec, 'orient'>;\n\nexport type ILegendSpec = IDiscreteLegendSpec | IColorLegendSpec | ISizeLegendSpec;\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/component/legend/interface.ts"],"names":[],"mappings":"","file":"interface.js","sourcesContent":["import type { LegendTitle } from '@visactor/vrender-components';\nimport type {\n Datum,\n IOrientType,\n IPadding,\n IRectMarkSpec,\n ISymbolMarkSpec,\n ITextMarkSpec,\n StringOrNumber\n} from '../../typings';\nimport type { IComponent } from '../interface';\nimport type { IComponentSpec } from '../base/interface';\nimport type { IDiscreteLegendSpec } from './discrete';\nimport type { IColorLegendSpec, ISizeLegendSpec } from './continuous';\n\nexport type ILegend = IComponent & {\n getLegendData: () => Datum[];\n getSelectedData: () => StringOrNumber[];\n setSelectedData: (d: StringOrNumber[]) => void;\n};\n\nexport type NoVisibleMarkStyle<T> = Omit<T, 'visible'>;\n\nexport type ITitle = {\n /** 标题文本样式 */\n textStyle?: NoVisibleMarkStyle<ITextMarkSpec>;\n /**\n * @deprecated 请使用 textStyle 配置文本样式\n */\n style?: NoVisibleMarkStyle<ITextMarkSpec>;\n /** 文本前 mark 图元 */\n shape?: {\n /**\n * 是否展示 shape\n */\n visible?: boolean;\n /**\n * shape 同 文本的间距\n */\n space?: number;\n style?: NoVisibleMarkStyle<ISymbolMarkSpec>;\n };\n /**\n * 标题的背景面板配置\n */\n background?: {\n /**\n * 是否绘制背景层\n */\n visible?: boolean;\n /**\n * 背景层样式\n */\n style?: Omit<NoVisibleMarkStyle<IRectMarkSpec>, 'visible' | 'width' | 'height'>;\n };\n} & Omit<LegendTitle, 'textStyle' | 'style' | 'background'>;\n\n// 图例组件通用配置\nexport type ILegendCommonSpec = {\n /**\n * 是否显示图例\n * @default true\n */\n visible?: boolean;\n /**\n * 图例位置\n * @default 'left'\n */\n orient?: IOrientType;\n /**\n * 图例在当前行列的对齐方式,起始 | 居中 | 末尾\n * @default 'middle'\n */\n position?: 'start' | 'middle' | 'end';\n /**\n * 图例组件的布局配置,默认自动跟随显示位置进行调整。\n * 1. `orient` 为 'top' 或者 'bottom' 时,默认为 'horizontal' 水平布局\n * 2. `orient` 为 'left' 或者 'right' 时,默认为 'vertical' 垂直布局\n */\n layout?: 'horizontal' | 'vertical';\n\n /**\n * 是否进行数据筛选,默认为 true\n */\n filter?: boolean;\n /**\n * 自定义筛选函数\n * @since 1.13.1\n * @param data 当前数据\n * @param selectedRange 选中的数据范围\n * @param datumField 筛选数据对应的字段\n * @returns 最终展示的数据\n */\n customFilter?: (data: any, selectedRange: StringOrNumber[], datumField: string) => any;\n\n /**\n * 图例标题配置\n */\n title?: ITitle;\n\n /**\n * 图例背景配置\n */\n background?: {\n /**\n * 是否绘制背景层\n */\n visible?: boolean;\n /**\n * 背景内边距\n */\n padding?: IPadding | number | number[];\n /**\n * 背景层样式\n */\n style?: Omit<NoVisibleMarkStyle<IRectMarkSpec>, 'visible' | 'width' | 'height'>;\n };\n /**\n * 是否允许交互\n * @default true\n */\n interactive?: boolean;\n} & Omit<IComponentSpec, 'orient'>;\n\nexport type ILegendSpec = IDiscreteLegendSpec | IColorLegendSpec | ISizeLegendSpec;\n"]}
|
|
@@ -7,4 +7,5 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
const base_1 = require("./base");
|
|
8
8
|
|
|
9
9
|
exports.CORRELATION_X = `${base_1.PREFIX}_CORRELATION_X`, exports.CORRELATION_Y = `${base_1.PREFIX}_CORRELATION_Y`,
|
|
10
|
-
exports.CORRELATION_SIZE = `${base_1.PREFIX}_CORRELATION_SIZE`;
|
|
10
|
+
exports.CORRELATION_SIZE = `${base_1.PREFIX}_CORRELATION_SIZE`;
|
|
11
|
+
//# sourceMappingURL=correlation.js.map
|
package/cjs/constant/layout.js
CHANGED
|
@@ -24,5 +24,4 @@ function(LayoutZIndex) {
|
|
|
24
24
|
LayoutLevel[LayoutLevel.Player = 40] = "Player", LayoutLevel[LayoutLevel.ScrollBar = 40] = "ScrollBar",
|
|
25
25
|
LayoutLevel[LayoutLevel.Legend = 50] = "Legend", LayoutLevel[LayoutLevel.Title = 70] = "Title",
|
|
26
26
|
LayoutLevel[LayoutLevel.CustomMark = 70] = "CustomMark";
|
|
27
|
-
}(LayoutLevel = exports.LayoutLevel || (exports.LayoutLevel = {}));
|
|
28
|
-
//# sourceMappingURL=layout.js.map
|
|
27
|
+
}(LayoutLevel = exports.LayoutLevel || (exports.LayoutLevel = {}));
|
package/cjs/core/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { VChart } from './vchart';
|
|
2
2
|
import { Factory } from './factory';
|
|
3
3
|
export { VChart, Factory };
|
|
4
|
-
export declare const version = "1.12.
|
|
4
|
+
export declare const version = "1.12.7-alpha.0";
|
|
5
5
|
export type { IVChart } from './interface';
|
|
6
6
|
export type { IStateSpec, StateValueType } from '../compile/mark';
|
|
7
7
|
export * from '../typings/spec/common';
|
package/cjs/core/index.js
CHANGED
|
@@ -35,7 +35,7 @@ Object.defineProperty(exports, "Factory", {
|
|
|
35
35
|
get: function() {
|
|
36
36
|
return factory_1.Factory;
|
|
37
37
|
}
|
|
38
|
-
}), exports.version = "1.12.
|
|
38
|
+
}), exports.version = "1.12.7-alpha.0", __exportStar(require("../typings/spec/common"), exports),
|
|
39
39
|
__exportStar(require("../event/interface"), exports), __exportStar(require("../theme/interface"), exports),
|
|
40
40
|
__exportStar(require("./interface"), exports), __exportStar(require("../constant/base"), exports),
|
|
41
41
|
__exportStar(require("../typings/spec/index"), exports), __exportStar(require("../typings/tooltip"), exports),
|
package/cjs/core/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/core/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAIA,qCAAkC;AAGzB,uFAHA,eAAM,OAGA;AAFf,uCAAoC;AAEnB,wFAFR,iBAAO,OAEQ;AAGX,QAAA,OAAO,GAAG,
|
|
1
|
+
{"version":3,"sources":["../src/core/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAIA,qCAAkC;AAGzB,uFAHA,eAAM,OAGA;AAFf,uCAAoC;AAEnB,wFAFR,iBAAO,OAEQ;AAGX,QAAA,OAAO,GAAG,gBAAgB,CAAC;AAMxC,yDAAuC;AACvC,qDAAmC;AACnC,qDAAmC;AACnC,8CAA4B;AAG5B,mDAAiC;AAKjC,wDAAsC;AAGtC,qDAAmC;AAGnC,iDAA+B;AAG/B,uDAAiD;AAAxC,uGAAA,OAAO,OAAA","file":"index.js","sourcesContent":["/**\n * @description The core module of VChart, containing the necessary interfaces for using VChart.\n */\n\nimport { VChart } from './vchart';\nimport { Factory } from './factory';\n\nexport { VChart, Factory };\n\n// export the version\nexport const version = \"1.12.7-alpha.0\";\n\n// export necessary types\nexport type { IVChart } from './interface';\nexport type { IStateSpec, StateValueType } from '../compile/mark';\n\nexport * from '../typings/spec/common';\nexport * from '../event/interface';\nexport * from '../theme/interface';\nexport * from './interface';\n\n// some constants\nexport * from '../constant/base';\n\n/**\n * spec\n */\nexport * from '../typings/spec/index';\n\n// tooltip\nexport * from '../typings/tooltip';\n\n// theme\nexport * from '../theme/index';\n\n// vrender\nexport { vglobal } from '@visactor/vrender-core';\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { ISeries } from '../../../../series/interface';
|
|
2
2
|
import type { IContinuousLegendDataMakeOption, IContinuousLegendFilterOption } from './interface';
|
|
3
3
|
export declare const continuousLegendDataMake: (data: Array<ISeries>, op: IContinuousLegendDataMakeOption) => any;
|
|
4
|
-
export declare const continuousLegendFilter: (data: Array<any>, op: IContinuousLegendFilterOption) => any
|
|
4
|
+
export declare const continuousLegendFilter: (data: Array<any>, op: IContinuousLegendFilterOption) => any;
|
|
@@ -24,12 +24,13 @@ const vutils_1 = require("@visactor/vutils"), util_1 = require("../../../../util
|
|
|
24
24
|
exports.continuousLegendDataMake = continuousLegendDataMake;
|
|
25
25
|
|
|
26
26
|
const continuousLegendFilter = (data, op) => {
|
|
27
|
-
const {selected: selected, field: field, data: legendData, isHierarchyData: isHierarchyData} = op, selectedRange = selected(), datumField = field(), isHierarchy = isHierarchyData || (data => data && data.some((d => d && (0,
|
|
27
|
+
const {selected: selected, field: field, data: legendData, isHierarchyData: isHierarchyData, customFilter: customFilter} = op, selectedRange = selected(), datumField = field(), isHierarchy = isHierarchyData || (data => data && data.some((d => d && (0,
|
|
28
28
|
util_1.isHierarchyItem)(d))));
|
|
29
29
|
if (selectedRange === legendData()) return data;
|
|
30
30
|
if (datumField && !(0, vutils_1.isEmpty)(selectedRange)) {
|
|
31
31
|
const [min, max] = selectedRange;
|
|
32
|
-
return
|
|
32
|
+
return customFilter ? customFilter(data, selectedRange, datumField) : isHierarchy(data) ? (0,
|
|
33
|
+
util_1.filterHierarchyDataByRange)(data, +min, +max, datumField) : data.filter((datum => datum[datumField] >= min && datum[datumField] <= max));
|
|
33
34
|
}
|
|
34
35
|
return data;
|
|
35
36
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/data/transforms/legend-data/continuous/continuous.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"sources":["../src/data/transforms/legend-data/continuous/continuous.ts"],"names":[],"mappings":";;;AAAA,6CAA0D;AAG1D,2CAA+E;AAGxE,MAAM,wBAAwB,GAAG,CAAC,IAAoB,EAAE,EAAmC,EAAE,EAAE;IACpG,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;IACpC,MAAM,UAAU,GAAG,KAAK,EAAE,CAAC;IAC3B,IAAI,KAAK,IAAI,UAAU,EAAE;QACvB,IAAI,GAAG,GAAW,QAAQ,CAAC;QAC3B,IAAI,GAAG,GAAW,CAAC,QAAQ,CAAC;QAC5B,MAAM,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;YACnB,MAAM,aAAa,GAAG,CAAC,CAAC,2BAA2B,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;YACtE,MAAM,SAAS,GAAG,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,GAAG,CAAC;YACrC,MAAM,SAAS,GAAG,aAAa,aAAb,aAAa,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,gBAAO,EAAC,aAAa,CAAC,EAAE;QACzC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,aAAa,CAAC;QAEjC,IAAI,YAAY,EAAE;YAChB,OAAO,YAAY,CAAC,IAAI,EAAE,aAAa,EAAE,UAAU,CAAC,CAAC;SACtD;aAAM,IAAI,WAAW,CAAC,IAAI,CAAC,EAAE;YAC5B,OAAO,IAAA,iCAA0B,EAAC,IAAI,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;SACjE;QACD,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;YACzB,OAAO,KAAK,CAAC,UAAU,CAAC,IAAI,GAAG,IAAI,KAAK,CAAC,UAAU,CAAC,IAAI,GAAG,CAAC;QAC9D,CAAC,CAAC,CAAC;KACJ;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AA3BW,QAAA,sBAAsB,0BA2BjC","file":"continuous.js","sourcesContent":["import { isEmpty, isValidNumber } from '@visactor/vutils';\nimport type { ISeries } from '../../../../series/interface';\nimport type { IContinuousLegendDataMakeOption, IContinuousLegendFilterOption } from './interface';\nimport { filterHierarchyDataByRange, isHierarchyItem } from '../../../../util';\n\n// 获取数值范围\nexport const continuousLegendDataMake = (data: Array<ISeries>, op: IContinuousLegendDataMakeOption) => {\n const { series, field, scale } = op;\n const datumField = field();\n if (field && datumField) {\n let min: number = Infinity;\n let max: number = -Infinity;\n series().forEach(s => {\n const statisticData = s.getRawDataStatisticsByField(datumField, true);\n const seriesMin = statisticData?.min;\n const seriesMax = statisticData?.max;\n if (isValidNumber(seriesMin)) {\n min = Math.min(seriesMin, min);\n }\n if (isValidNumber(seriesMax)) {\n max = Math.max(seriesMax, max);\n }\n });\n return [min, max];\n }\n if (scale) {\n const _scale = scale();\n if (!_scale) {\n return [];\n }\n return _scale.domain();\n }\n return [];\n};\n\n// 连续数据过滤\nexport const continuousLegendFilter = (data: Array<any>, op: IContinuousLegendFilterOption) => {\n const { selected, field, data: legendData, isHierarchyData, customFilter } = op;\n const selectedRange = selected();\n const datumField = field();\n const dataRange = legendData();\n const isHierarchy = isHierarchyData\n ? isHierarchyData\n : (data: Array<any>) => data && data.some(d => d && isHierarchyItem(d));\n\n // 如果数值范围相等,就不进行返回 data,不需要进行过滤\n if (selectedRange === dataRange) {\n return data;\n }\n if (datumField && !isEmpty(selectedRange)) {\n const [min, max] = selectedRange;\n\n if (customFilter) {\n return customFilter(data, selectedRange, datumField);\n } else if (isHierarchy(data)) {\n return filterHierarchyDataByRange(data, +min, +max, datumField);\n }\n return data.filter(datum => {\n return datum[datumField] >= min && datum[datumField] <= max;\n });\n }\n\n return data;\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/data/transforms/legend-data/continuous/interface.ts"],"names":[],"mappings":"","file":"interface.js","sourcesContent":["import type { IBaseScale } from '@visactor/vscale';\nimport type { ISeries } from '../../../../series/interface';\nimport type { StringOrNumber } from '../../../../typings';\n\nexport interface IContinuousLegendDataMakeOption {\n series: () => ISeries[];\n field: () => string | undefined;\n scale?: () => IBaseScale;\n}\n\nexport interface IContinuousLegendFilterOption {\n selected: () => StringOrNumber[];\n field: () => string | undefined;\n data: () => StringOrNumber[];\n isHierarchyData?: () => boolean;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/data/transforms/legend-data/continuous/interface.ts"],"names":[],"mappings":"","file":"interface.js","sourcesContent":["import type { IBaseScale } from '@visactor/vscale';\nimport type { ISeries } from '../../../../series/interface';\nimport type { StringOrNumber } from '../../../../typings';\n\nexport interface IContinuousLegendDataMakeOption {\n series: () => ISeries[];\n field: () => string | undefined;\n scale?: () => IBaseScale;\n}\n\nexport interface IContinuousLegendFilterOption {\n selected: () => StringOrNumber[];\n field: () => string | undefined;\n data: () => StringOrNumber[];\n isHierarchyData?: () => boolean;\n customFilter?: (data: any, selectedRange: StringOrNumber[], datumField: string) => any;\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { ISeries } from '../../../../series/interface';
|
|
2
2
|
import type { IDiscreteLegendData, IDiscreteLegendDataMakeOption, IDiscreteLegendFilterOption } from './interface';
|
|
3
3
|
export declare const discreteLegendDataMake: (data: Array<ISeries>, op: IDiscreteLegendDataMakeOption) => IDiscreteLegendData[];
|
|
4
|
-
export declare const discreteLegendFilter: (data: Array<any>, op: IDiscreteLegendFilterOption) => any
|
|
4
|
+
export declare const discreteLegendFilter: (data: Array<any>, op: IDiscreteLegendFilterOption) => any;
|
|
@@ -20,7 +20,7 @@ exports.discreteLegendDataMake = discreteLegendDataMake;
|
|
|
20
20
|
|
|
21
21
|
const discreteLegendFilter = (data, op) => {
|
|
22
22
|
var _a, _b, _c;
|
|
23
|
-
const {series: series, selected: selected, field: field, data: legendData} = op, selectedData = selected(), legendKeys = legendData();
|
|
23
|
+
const {series: series, selected: selected, field: field, data: legendData, customFilter: customFilter} = op, selectedData = selected(), legendKeys = legendData();
|
|
24
24
|
if (0 === selectedData.length && legendKeys.length) return [];
|
|
25
25
|
if (selectedData.length === legendKeys.length) return data;
|
|
26
26
|
const selectedFilter = {};
|
|
@@ -28,10 +28,10 @@ const discreteLegendFilter = (data, op) => {
|
|
|
28
28
|
selectedFilter[s] = !0;
|
|
29
29
|
}));
|
|
30
30
|
const datumField = null !== (_a = field()) && void 0 !== _a ? _a : data_1.DEFAULT_DATA_SERIES_FIELD;
|
|
31
|
-
return (0, vutils_1.isArray)(data) && (null === (_b = data[0]) || void 0 === _b ? void 0 : _b.nodes) ? (data[0].nodes = data[0].nodes.filter((d => !0 === selectedFilter[d.key])),
|
|
31
|
+
return customFilter ? customFilter(data, selectedData, datumField) : ((0, vutils_1.isArray)(data) && (null === (_b = data[0]) || void 0 === _b ? void 0 : _b.nodes) ? (data[0].nodes = data[0].nodes.filter((d => !0 === selectedFilter[d.key])),
|
|
32
32
|
(null === (_c = data[0]) || void 0 === _c ? void 0 : _c.links) && (data[0].links = data[0].links.filter((d => !0 === selectedFilter[d.source] && !0 === selectedFilter[d.target])))) : (0,
|
|
33
33
|
vutils_1.isValid)(datumField) && (data = data.filter((d => !0 === selectedFilter[series.getSeriesFieldValue(d, datumField)]))),
|
|
34
|
-
data;
|
|
34
|
+
data);
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
exports.discreteLegendFilter = discreteLegendFilter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/data/transforms/legend-data/discrete/discrete.ts"],"names":[],"mappings":";;;AAAA,6CAAoD;AAGpD,oDAAsE;AAE/D,MAAM,sBAAsB,GAAG,CAAC,IAAoB,EAAE,EAAiC,EAAE,EAAE;IAChG,MAAM,MAAM,GAA0B,EAAE,CAAC;IACzC,MAAM,OAAO,GAAiC,EAAE,CAAC;IACjD,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,EAAE,CAAC;IACnC,MAAM,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;QACnB,MAAM,KAAK,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;QAC7B,IAAI,QAAQ,CAAC;QACb,IAAI,KAAK,KAAK,CAAC,CAAC,cAAc,EAAE,EAAE;YAChC,QAAQ,GAAG,CAAC,CAAC,iBAAiB,EAAE,CAAC;SAClC;aAAM;YACL,QAAQ,GAAG,CAAC,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC;SAC1C;QACD,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YACtB,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;gBACrB,OAAO;aACR;YACD,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;YACzB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACpB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AArBW,QAAA,sBAAsB,0BAqBjC;AAEK,MA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,MAAM,CAAC,KAAK,IAAI,CACnF,CAAC;SACH;KACF;SAAM;QACL,IAAI,IAAA,gBAAO,EAAC,UAAU,CAAC,EAAE;YACvB,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,cAAc,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC;SAC7F;KACF;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AApCW,QAAA,oBAAoB,wBAoC/B","file":"discrete.js","sourcesContent":["import { isValid, isArray } from '@visactor/vutils';\nimport type { ISeries } from '../../../../series/interface';\nimport type { IDiscreteLegendData, IDiscreteLegendDataMakeOption, IDiscreteLegendFilterOption } from './interface';\nimport { DEFAULT_DATA_SERIES_FIELD } from '../../../../constant/data';\n\nexport const discreteLegendDataMake = (data: Array<ISeries>, op: IDiscreteLegendDataMakeOption) => {\n const result: IDiscreteLegendData[] = [];\n const tempKey: { [key in string]: boolean } = {};\n const { series, seriesField } = op;\n series().forEach(s => {\n const field = seriesField(s);\n let infoList;\n if (field === s.getSeriesField()) {\n infoList = s.getSeriesInfoList();\n } else {\n infoList = s.getSeriesInfoInField(field);\n }\n infoList.forEach(info => {\n if (tempKey[info.key]) {\n return;\n }\n tempKey[info.key] = true;\n result.push(info);\n });\n });\n return result;\n};\n\nexport const discreteLegendFilter = (data: Array<any>, op: IDiscreteLegendFilterOption) => {\n const { series, selected, field, data: legendData, customFilter } = op;\n const selectedData = selected();\n const legendKeys = legendData(); // 全量的图例项\n if (selectedData.length === 0 && legendKeys.length) {\n return [];\n }\n\n if (selectedData.length === legendKeys.length) {\n return data;\n }\n\n const selectedFilter = {};\n selectedData.forEach(s => {\n selectedFilter[s] = true;\n });\n\n const datumField = field() ?? DEFAULT_DATA_SERIES_FIELD;\n\n if (customFilter) {\n return customFilter(data, selectedData, datumField);\n } else if (isArray(data) && data[0]?.nodes) {\n // data silter for sankey chart\n data[0].nodes = data[0].nodes.filter((d: any) => selectedFilter[d.key] === true);\n if (data[0]?.links) {\n data[0].links = data[0].links.filter(\n (d: any) => selectedFilter[d.source] === true && selectedFilter[d.target] === true\n );\n }\n } else {\n if (isValid(datumField)) {\n data = data.filter(d => selectedFilter[series.getSeriesFieldValue(d, datumField)] === true);\n }\n }\n\n return data;\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/data/transforms/legend-data/discrete/interface.ts"],"names":[],"mappings":"","file":"interface.js","sourcesContent":["import type { ISeries } from '../../../../series/interface';\nimport type { StringOrNumber } from '../../../../typings';\n\nexport interface IDiscreteLegendData {\n key: string;\n /** 图例的原始 key,直接取 datum 里的原始值 */\n originalKey: any;\n style: (attribute: string) => any;\n}\n\nexport interface IDiscreteLegendDataMakeOption {\n series: () => ISeries[];\n seriesField: (s: ISeries) => string;\n}\n\nexport interface IDiscreteLegendFilterOption {\n series: ISeries;\n selected: () => StringOrNumber[];\n field: () => string;\n data: () => StringOrNumber[];\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/data/transforms/legend-data/discrete/interface.ts"],"names":[],"mappings":"","file":"interface.js","sourcesContent":["import type { ISeries } from '../../../../series/interface';\nimport type { StringOrNumber } from '../../../../typings';\n\nexport interface IDiscreteLegendData {\n key: string;\n /** 图例的原始 key,直接取 datum 里的原始值 */\n originalKey: any;\n style: (attribute: string) => any;\n}\n\nexport interface IDiscreteLegendDataMakeOption {\n series: () => ISeries[];\n seriesField: (s: ISeries) => string;\n}\n\nexport interface IDiscreteLegendFilterOption {\n series: ISeries;\n selected: () => StringOrNumber[];\n field: () => string;\n data: () => StringOrNumber[];\n customFilter?: (data: any, selectedRange: StringOrNumber[], datumField: string) => any;\n}\n"]}
|
package/esm/compile/util.js
CHANGED
|
@@ -51,7 +51,8 @@ export class ContinuousLegend extends BaseLegend {
|
|
|
51
51
|
selected: () => this._selectedData,
|
|
52
52
|
field: () => this._field,
|
|
53
53
|
data: () => this._legendData.getLatestData(),
|
|
54
|
-
isHierarchyData: s.isHierarchyData
|
|
54
|
+
isHierarchyData: s.isHierarchyData,
|
|
55
|
+
customFilter: this._spec.customFilter
|
|
55
56
|
},
|
|
56
57
|
level: TransformLevel.legendFilter
|
|
57
58
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/component/legend/continuous/legend.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAK9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD,OAAO,EAAE,gCAAgC,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,EACL,wBAAwB,EACxB,sBAAsB,EACvB,MAAM,4DAA4D,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,6BAA6B,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AAChG,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE1D,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,MAAM,eAAe,GAAG,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;AACjH,MAAM,IAAI,GAAG,C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AAC,KAAK,CAAC,CAAC;QACjC,OAAO,KAAK,CAAC;IACf,CAAC;IAES,qBAAqB;QAC7B,OAAO,mBAAmB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC/C,CAAC;IAES,UAAU;QAClB,IAAI,IAAI,CAAC,gBAAgB,EAAE;YACzB,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,KAAK,CAAC;YAC7C,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,CACpC,QAAQ,EACR,QAAQ,CAAC,CAAC,CAAM,EAAE,EAAE;gBAClB,MAAM,YAAY,GAAG,GAAG,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC;gBAC5C,IAAI,QAAQ,EAAE;oBACZ,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;iBACpC;gBACD,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;YAC3F,CAAC,EAAE,EAAE,CAAC,CACP,CAAC;SACH;IACH,CAAC;;AA5LM,wBAAO,GAAG,SAAS,CAAC;AAEpB,qBAAI,GAAG,iBAAiB,CAAC,gBAAgB,CAAC;AA6LnD,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,EAAE;IAC3C,OAAO,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC;AACrE,CAAC,CAAC","file":"legend.js","sourcesContent":["/**\n * @description color legend component\n */\nimport type { Maybe } from '@visactor/vutils';\n// eslint-disable-next-line no-duplicate-imports\nimport { debounce, isEmpty, isNil, get } from '@visactor/vutils';\nimport { DataView } from '@visactor/vdataset';\n// eslint-disable-next-line no-duplicate-imports\nimport type { IModelInitOption, IModelSpecInfo } from '../../../model/interface';\nimport type { IComponentOption } from '../../interface';\n// eslint-disable-next-line no-duplicate-imports\nimport { ComponentTypeEnum } from '../../interface/type';\n// eslint-disable-next-line no-duplicate-imports\nimport { registerDataSetInstanceTransform } from '../../../data/register';\nimport { eachSeries, getSeries } from '../../../util/model';\nimport { getFieldAlias } from '../../../util/data';\nimport { isDataDomainSpec } from '../../../util/type';\nimport type { IColorLegendSpec, ISizeLegendSpec } from './interface';\nimport {\n continuousLegendDataMake,\n continuousLegendFilter\n} from '../../../data/transforms/legend-data/continuous/continuous';\nimport { ContinuousLegendMap, getContinuousLegendAttributes, isContinuousLegend } from './util';\nimport { BaseLegend } from '../base-legend';\nimport { ChartEvent } from '../../../constant/event';\nimport { Factory } from '../../../core/factory';\nimport { TransformLevel } from '../../../data/initialize';\nimport type { ILayoutRect } from '../../../typings/layout';\nimport { getSpecInfo } from '../../util';\n\nconst SINGLE_SEQUENCE = ['#C4E7FF', '#98CAFF', '#75ACFF', '#518FF9', '#2775DC', '#005CBE', '#00429F', '#00287E'];\nconst SIZE = [2, 10];\n\nexport class ContinuousLegend<\n T extends IColorLegendSpec | ISizeLegendSpec = IColorLegendSpec | ISizeLegendSpec\n> extends BaseLegend<T> {\n static specKey = 'legends';\n\n static type = ComponentTypeEnum.continuousLegend;\n type = ComponentTypeEnum.colorLegend;\n name: string = ComponentTypeEnum.colorLegend;\n\n private _field: string | undefined;\n private _legendType: string;\n\n static getSpecInfo(chartSpec: any): Maybe<IModelSpecInfo[]> {\n const infos = getSpecInfo<IColorLegendSpec | ISizeLegendSpec>(\n chartSpec,\n this.specKey,\n this.type,\n (s: IColorLegendSpec | ISizeLegendSpec) => {\n return isContinuousLegend(s.type);\n }\n );\n\n if (infos) {\n infos.forEach(info => {\n info.type = info.spec.type === 'color' ? ComponentTypeEnum.colorLegend : ComponentTypeEnum.sizeLegend;\n });\n }\n\n return infos;\n }\n\n constructor(spec: T, options: IComponentOption) {\n super(spec, options);\n\n // 这里需要区分下是 colorLegend 还是 sizeLegend\n const legendName = this._spec.type === 'color' ? ComponentTypeEnum.colorLegend : ComponentTypeEnum.sizeLegend;\n this.type = legendName;\n this.name = legendName;\n }\n\n setAttrFromSpec() {\n super.setAttrFromSpec();\n this._field = this._spec.field;\n this._legendType = this._spec.type;\n }\n\n init(option: IModelInitOption): void {\n super.init(option);\n eachSeries(\n this._regions,\n s => {\n s.addViewDataFilter({\n type: 'continuousLegendFilter',\n options: {\n selected: () => this._selectedData,\n field: () => this._field,\n data: () => this._legendData.getLatestData(),\n isHierarchyData: s.isHierarchyData\n },\n level: TransformLevel.legendFilter\n });\n },\n {\n userId: this._seriesUserId,\n specIndex: this._seriesIndex\n }\n );\n }\n\n private _getScaleInGlobal() {\n const globalScale = this._option.globalScale;\n let scaleKey = this._spec.scale;\n if (!scaleKey) {\n scaleKey = this._legendType;\n }\n return globalScale.getScale(scaleKey);\n }\n\n protected _initLegendData(): DataView {\n registerDataSetInstanceTransform(this._option.dataSet, 'continuousLegendFilter', continuousLegendFilter);\n registerDataSetInstanceTransform(this._option.dataSet, 'continuousLegendDataMake', continuousLegendDataMake);\n const legendData = new DataView(this._option.dataSet, { name: `${this.type}_${this.id}_data` });\n legendData.transform({\n type: 'continuousLegendDataMake',\n options: {\n series: () => {\n return getSeries(this._regions, {\n userId: this._seriesUserId,\n specIndex: this._seriesIndex\n });\n },\n field: () => this._field,\n scale: this._getScaleInGlobal.bind(this)\n }\n });\n return legendData;\n }\n\n protected _initSelectedData(): void {\n if (this._spec.defaultSelected) {\n this._selectedData = this._spec.defaultSelected.slice();\n } else {\n this._selectedData = this._legendData.getLatestData();\n }\n }\n\n private _addDefaultTitleText(attrs: any) {\n if (attrs.title?.visible && isNil(attrs.title.text) && isNil(attrs.title.style?.text)) {\n const field = this._field;\n if (field) {\n // 默认使用第0个系列的对应别名\n const series = this._regions?.[0]?.getSeries()[0];\n if (!series) {\n return;\n }\n // 如果没有别名继续保持 空字符串\n attrs.title.text = getFieldAlias(series.getRawData(), field);\n return;\n }\n let scaleKey = this._spec.scale;\n if (!scaleKey) {\n scaleKey = this._legendType;\n }\n const scaleSpec = this._option.globalScale.getScaleSpec(scaleKey);\n if (!isDataDomainSpec(scaleSpec?.domain)) {\n return;\n }\n const dataInfo = scaleSpec.domain[0];\n if (dataInfo.fields.length === 0) {\n return;\n }\n // 如果没有别名继续保持 空字符串\n attrs.title.text = getFieldAlias(this._option.dataSet.getDataView(dataInfo.dataId), dataInfo.fields[0]);\n return;\n }\n }\n\n protected _getLegendAttributes(rect: ILayoutRect) {\n const layout = this.layoutOrient === 'bottom' || this.layoutOrient === 'top' ? 'horizontal' : 'vertical';\n const align = layout === 'horizontal' ? 'bottom' : this.layoutOrient;\n\n // 获取关联的 scale 以获取 colors / size\n let visualMappingRange = [];\n const scale = this._getScaleInGlobal();\n if (scale && scale.type === 'linear') {\n visualMappingRange = scale.range();\n }\n if (isEmpty(visualMappingRange)) {\n visualMappingRange = this._legendType === 'color' ? SINGLE_SEQUENCE : SIZE;\n }\n let min = this._legendData.getLatestData()[0] ?? 0;\n let max = this._legendData.getLatestData()[1] ?? 1;\n\n const isSame = this._legendData.getLatestData()[0] === this._legendData.getLatestData()[1];\n if (isSame) {\n min = Math.min(0, this._legendData.getLatestData()[0]);\n max = this._legendData.getLatestData()[0] === 0 ? 1 : Math.max(0, this._legendData.getLatestData()[0]);\n }\n\n const attrs: any = {\n layout,\n align,\n zIndex: this.layoutZIndex,\n min,\n max,\n value: this._spec.defaultSelected,\n [this._legendType === 'color' ? 'colors' : 'sizeRange']: visualMappingRange,\n ...getContinuousLegendAttributes(this._spec)\n };\n this._addDefaultTitleText(attrs);\n return attrs;\n }\n\n protected _getLegendConstructor() {\n return ContinuousLegendMap[this._legendType];\n }\n\n protected _initEvent() {\n if (this._legendComponent) {\n const doFilter = this._spec.filter !== false;\n this._legendComponent.addEventListener(\n 'change',\n debounce((e: any) => {\n const selectedData = get(e, 'detail.value');\n if (doFilter) {\n this.setSelectedData(selectedData);\n }\n this.event.emit(ChartEvent.legendFilter, { model: this, value: selectedData, event: e });\n }, 30)\n );\n }\n }\n}\n\nexport const registerContinuousLegend = () => {\n Factory.registerComponent(ContinuousLegend.type, ContinuousLegend);\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/component/legend/continuous/legend.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAK9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD,OAAO,EAAE,gCAAgC,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,EACL,wBAAwB,EACxB,sBAAsB,EACvB,MAAM,4DAA4D,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,6BAA6B,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AAChG,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE1D,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,MAAM,eAAe,GAAG,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;AACjH,MAAM,IAAI,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAErB,MAAM,OAAO,gBAEX,SAAQ,UAAa;IAUrB,MAAM,CAAC,WAAW,CAAC,SAAc;QAC/B,M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;QAC7B,OAAO,mBAAmB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC/C,CAAC;IAES,UAAU;QAClB,IAAI,IAAI,CAAC,gBAAgB,EAAE;YACzB,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,KAAK,CAAC;YAC7C,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,CACpC,QAAQ,EACR,QAAQ,CAAC,CAAC,CAAM,EAAE,EAAE;gBAClB,MAAM,YAAY,GAAG,GAAG,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC;gBAC5C,IAAI,QAAQ,EAAE;oBACZ,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;iBACpC;gBACD,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;YAC3F,CAAC,EAAE,EAAE,CAAC,CACP,CAAC;SACH;IACH,CAAC;;AA7LM,wBAAO,GAAG,SAAS,CAAC;AAEpB,qBAAI,GAAG,iBAAiB,CAAC,gBAAgB,CAAC;AA8LnD,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,EAAE;IAC3C,OAAO,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC;AACrE,CAAC,CAAC","file":"legend.js","sourcesContent":["/**\n * @description color legend component\n */\nimport type { Maybe } from '@visactor/vutils';\n// eslint-disable-next-line no-duplicate-imports\nimport { debounce, isEmpty, isNil, get } from '@visactor/vutils';\nimport { DataView } from '@visactor/vdataset';\n// eslint-disable-next-line no-duplicate-imports\nimport type { IModelInitOption, IModelSpecInfo } from '../../../model/interface';\nimport type { IComponentOption } from '../../interface';\n// eslint-disable-next-line no-duplicate-imports\nimport { ComponentTypeEnum } from '../../interface/type';\n// eslint-disable-next-line no-duplicate-imports\nimport { registerDataSetInstanceTransform } from '../../../data/register';\nimport { eachSeries, getSeries } from '../../../util/model';\nimport { getFieldAlias } from '../../../util/data';\nimport { isDataDomainSpec } from '../../../util/type';\nimport type { IColorLegendSpec, ISizeLegendSpec } from './interface';\nimport {\n continuousLegendDataMake,\n continuousLegendFilter\n} from '../../../data/transforms/legend-data/continuous/continuous';\nimport { ContinuousLegendMap, getContinuousLegendAttributes, isContinuousLegend } from './util';\nimport { BaseLegend } from '../base-legend';\nimport { ChartEvent } from '../../../constant/event';\nimport { Factory } from '../../../core/factory';\nimport { TransformLevel } from '../../../data/initialize';\nimport type { ILayoutRect } from '../../../typings/layout';\nimport { getSpecInfo } from '../../util';\n\nconst SINGLE_SEQUENCE = ['#C4E7FF', '#98CAFF', '#75ACFF', '#518FF9', '#2775DC', '#005CBE', '#00429F', '#00287E'];\nconst SIZE = [2, 10];\n\nexport class ContinuousLegend<\n T extends IColorLegendSpec | ISizeLegendSpec = IColorLegendSpec | ISizeLegendSpec\n> extends BaseLegend<T> {\n static specKey = 'legends';\n\n static type = ComponentTypeEnum.continuousLegend;\n type = ComponentTypeEnum.colorLegend;\n name: string = ComponentTypeEnum.colorLegend;\n\n private _field: string | undefined;\n private _legendType: string;\n\n static getSpecInfo(chartSpec: any): Maybe<IModelSpecInfo[]> {\n const infos = getSpecInfo<IColorLegendSpec | ISizeLegendSpec>(\n chartSpec,\n this.specKey,\n this.type,\n (s: IColorLegendSpec | ISizeLegendSpec) => {\n return isContinuousLegend(s.type);\n }\n );\n\n if (infos) {\n infos.forEach(info => {\n info.type = info.spec.type === 'color' ? ComponentTypeEnum.colorLegend : ComponentTypeEnum.sizeLegend;\n });\n }\n\n return infos;\n }\n\n constructor(spec: T, options: IComponentOption) {\n super(spec, options);\n\n // 这里需要区分下是 colorLegend 还是 sizeLegend\n const legendName = this._spec.type === 'color' ? ComponentTypeEnum.colorLegend : ComponentTypeEnum.sizeLegend;\n this.type = legendName;\n this.name = legendName;\n }\n\n setAttrFromSpec() {\n super.setAttrFromSpec();\n this._field = this._spec.field;\n this._legendType = this._spec.type;\n }\n\n init(option: IModelInitOption): void {\n super.init(option);\n eachSeries(\n this._regions,\n s => {\n s.addViewDataFilter({\n type: 'continuousLegendFilter',\n options: {\n selected: () => this._selectedData,\n field: () => this._field,\n data: () => this._legendData.getLatestData(),\n isHierarchyData: s.isHierarchyData,\n customFilter: this._spec.customFilter\n },\n level: TransformLevel.legendFilter\n });\n },\n {\n userId: this._seriesUserId,\n specIndex: this._seriesIndex\n }\n );\n }\n\n private _getScaleInGlobal() {\n const globalScale = this._option.globalScale;\n let scaleKey = this._spec.scale;\n if (!scaleKey) {\n scaleKey = this._legendType;\n }\n return globalScale.getScale(scaleKey);\n }\n\n protected _initLegendData(): DataView {\n registerDataSetInstanceTransform(this._option.dataSet, 'continuousLegendFilter', continuousLegendFilter);\n registerDataSetInstanceTransform(this._option.dataSet, 'continuousLegendDataMake', continuousLegendDataMake);\n const legendData = new DataView(this._option.dataSet, { name: `${this.type}_${this.id}_data` });\n legendData.transform({\n type: 'continuousLegendDataMake',\n options: {\n series: () => {\n return getSeries(this._regions, {\n userId: this._seriesUserId,\n specIndex: this._seriesIndex\n });\n },\n field: () => this._field,\n scale: this._getScaleInGlobal.bind(this)\n }\n });\n return legendData;\n }\n\n protected _initSelectedData(): void {\n if (this._spec.defaultSelected) {\n this._selectedData = this._spec.defaultSelected.slice();\n } else {\n this._selectedData = this._legendData.getLatestData();\n }\n }\n\n private _addDefaultTitleText(attrs: any) {\n if (attrs.title?.visible && isNil(attrs.title.text) && isNil(attrs.title.style?.text)) {\n const field = this._field;\n if (field) {\n // 默认使用第0个系列的对应别名\n const series = this._regions?.[0]?.getSeries()[0];\n if (!series) {\n return;\n }\n // 如果没有别名继续保持 空字符串\n attrs.title.text = getFieldAlias(series.getRawData(), field);\n return;\n }\n let scaleKey = this._spec.scale;\n if (!scaleKey) {\n scaleKey = this._legendType;\n }\n const scaleSpec = this._option.globalScale.getScaleSpec(scaleKey);\n if (!isDataDomainSpec(scaleSpec?.domain)) {\n return;\n }\n const dataInfo = scaleSpec.domain[0];\n if (dataInfo.fields.length === 0) {\n return;\n }\n // 如果没有别名继续保持 空字符串\n attrs.title.text = getFieldAlias(this._option.dataSet.getDataView(dataInfo.dataId), dataInfo.fields[0]);\n return;\n }\n }\n\n protected _getLegendAttributes(rect: ILayoutRect) {\n const layout = this.layoutOrient === 'bottom' || this.layoutOrient === 'top' ? 'horizontal' : 'vertical';\n const align = layout === 'horizontal' ? 'bottom' : this.layoutOrient;\n\n // 获取关联的 scale 以获取 colors / size\n let visualMappingRange = [];\n const scale = this._getScaleInGlobal();\n if (scale && scale.type === 'linear') {\n visualMappingRange = scale.range();\n }\n if (isEmpty(visualMappingRange)) {\n visualMappingRange = this._legendType === 'color' ? SINGLE_SEQUENCE : SIZE;\n }\n let min = this._legendData.getLatestData()[0] ?? 0;\n let max = this._legendData.getLatestData()[1] ?? 1;\n\n const isSame = this._legendData.getLatestData()[0] === this._legendData.getLatestData()[1];\n if (isSame) {\n min = Math.min(0, this._legendData.getLatestData()[0]);\n max = this._legendData.getLatestData()[0] === 0 ? 1 : Math.max(0, this._legendData.getLatestData()[0]);\n }\n\n const attrs: any = {\n layout,\n align,\n zIndex: this.layoutZIndex,\n min,\n max,\n value: this._spec.defaultSelected,\n [this._legendType === 'color' ? 'colors' : 'sizeRange']: visualMappingRange,\n ...getContinuousLegendAttributes(this._spec)\n };\n this._addDefaultTitleText(attrs);\n return attrs;\n }\n\n protected _getLegendConstructor() {\n return ContinuousLegendMap[this._legendType];\n }\n\n protected _initEvent() {\n if (this._legendComponent) {\n const doFilter = this._spec.filter !== false;\n this._legendComponent.addEventListener(\n 'change',\n debounce((e: any) => {\n const selectedData = get(e, 'detail.value');\n if (doFilter) {\n this.setSelectedData(selectedData);\n }\n this.event.emit(ChartEvent.legendFilter, { model: this, value: selectedData, event: e });\n }, 30)\n );\n }\n }\n}\n\nexport const registerContinuousLegend = () => {\n Factory.registerComponent(ContinuousLegend.type, ContinuousLegend);\n};\n"]}
|
|
@@ -45,7 +45,8 @@ export class DiscreteLegend extends BaseLegend {
|
|
|
45
45
|
series: s,
|
|
46
46
|
selected: () => this._selectedData,
|
|
47
47
|
field: () => this._getSeriesLegendField(s),
|
|
48
|
-
data: () => this.getLegendDefaultData()
|
|
48
|
+
data: () => this.getLegendDefaultData(),
|
|
49
|
+
customFilter: this._spec.customFilter
|
|
49
50
|
},
|
|
50
51
|
level: TransformLevel.legendFilter
|
|
51
52
|
});
|