@visactor/vgrammar-core 0.8.0 → 0.8.2
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/cjs/component/axis.js +9 -9
- package/cjs/component/axis.js.map +1 -1
- package/cjs/component/datazoom.js +9 -9
- package/cjs/component/datazoom.js.map +1 -1
- package/cjs/component/grid.js +18 -18
- package/cjs/component/grid.js.map +1 -1
- package/cjs/component/label.js +27 -22
- package/cjs/component/label.js.map +1 -1
- package/cjs/component/legend.js +13 -13
- package/cjs/component/legend.js.map +1 -1
- package/cjs/component/scrollbar.js +7 -7
- package/cjs/component/scrollbar.js.map +1 -1
- package/cjs/component/slider.js +5 -5
- package/cjs/component/slider.js.map +1 -1
- package/cjs/component/title.js +5 -5
- package/cjs/component/title.js.map +1 -1
- package/cjs/core/factory.d.ts +5 -1
- package/cjs/core/factory.js +13 -3
- package/cjs/core/factory.js.map +1 -1
- package/cjs/graph/animation/animate.d.ts +1 -0
- package/cjs/graph/animation/animate.js +4 -0
- package/cjs/graph/animation/animate.js.map +1 -1
- package/cjs/graph/animation/animation/move.js +10 -8
- package/cjs/graph/animation/animation/move.js.map +1 -1
- package/cjs/graph/attributes/common.js +2 -10
- package/cjs/graph/attributes/common.js.map +1 -1
- package/cjs/graph/attributes/helpers.d.ts +2 -2
- package/cjs/graph/attributes/helpers.js +50 -17
- package/cjs/graph/attributes/helpers.js.map +1 -1
- package/cjs/graph/attributes/index.d.ts +4 -10
- package/cjs/graph/attributes/index.js +16 -251
- package/cjs/graph/attributes/index.js.map +1 -1
- package/cjs/graph/attributes/line.d.ts +3 -0
- package/cjs/graph/attributes/line.js +46 -0
- package/cjs/graph/attributes/line.js.map +1 -0
- package/cjs/graph/attributes/transform.d.ts +5 -0
- package/cjs/graph/attributes/transform.js +167 -0
- package/cjs/graph/attributes/transform.js.map +1 -0
- package/cjs/graph/canvas-renderer.js +1 -1
- package/cjs/graph/canvas-renderer.js.map +1 -1
- package/cjs/graph/constants.d.ts +0 -1
- package/cjs/graph/constants.js +2 -3
- package/cjs/graph/constants.js.map +1 -1
- package/cjs/graph/element.js +12 -14
- package/cjs/graph/element.js.map +1 -1
- package/cjs/graph/glyph-element.js +6 -7
- package/cjs/graph/glyph-element.js.map +1 -1
- package/cjs/graph/layout/relative.js.map +1 -1
- package/cjs/graph/mark/encode.js +4 -4
- package/cjs/graph/mark/encode.js.map +1 -1
- package/cjs/index.d.ts +3 -1
- package/cjs/index.js +3 -2
- package/cjs/index.js.map +1 -1
- package/cjs/interactions/base.js.map +1 -1
- package/cjs/interactions/brush-base.js +2 -2
- package/cjs/interactions/brush-base.js.map +1 -1
- package/cjs/interactions/brush-filter.js +2 -2
- package/cjs/interactions/brush-filter.js.map +1 -1
- package/cjs/interactions/crosshair.d.ts +1 -1
- package/cjs/interactions/crosshair.js +15 -15
- package/cjs/interactions/crosshair.js.map +1 -1
- package/cjs/interactions/datazoom-filter.js +3 -3
- package/cjs/interactions/datazoom-filter.js.map +1 -1
- package/cjs/interactions/drill-down.js +2 -2
- package/cjs/interactions/drill-down.js.map +1 -1
- package/cjs/interactions/legend-filter.js +3 -3
- package/cjs/interactions/legend-filter.js.map +1 -1
- package/cjs/interactions/player-filter.js +3 -3
- package/cjs/interactions/player-filter.js.map +1 -1
- package/cjs/interactions/roll-up.js +2 -2
- package/cjs/interactions/roll-up.js.map +1 -1
- package/cjs/interactions/scrollbar-filter.js +3 -3
- package/cjs/interactions/scrollbar-filter.js.map +1 -1
- package/cjs/interactions/slider-filter.js +3 -3
- package/cjs/interactions/slider-filter.js.map +1 -1
- package/cjs/parse/view.js +1 -1
- package/cjs/parse/view.js.map +1 -1
- package/cjs/semantic-marks/cell.d.ts +3 -1
- package/cjs/semantic-marks/cell.js +10 -4
- package/cjs/semantic-marks/cell.js.map +1 -1
- package/cjs/semantic-marks/interval.d.ts +2 -0
- package/cjs/semantic-marks/interval.js +10 -4
- package/cjs/semantic-marks/interval.js.map +1 -1
- package/cjs/semantic-marks/text.d.ts +1 -0
- package/cjs/semantic-marks/text.js +3 -3
- package/cjs/semantic-marks/text.js.map +1 -1
- package/cjs/theme/common/component.d.ts +2 -1
- package/cjs/theme/common/component.js +13 -1
- package/cjs/theme/common/component.js.map +1 -1
- package/cjs/theme/dark.js.map +1 -1
- package/cjs/transforms/data/sampling.d.ts +2 -0
- package/cjs/transforms/data/sampling.js +111 -0
- package/cjs/transforms/data/sampling.js.map +1 -0
- package/cjs/transforms/index.d.ts +1 -1
- package/cjs/transforms/index.js +6 -6
- package/cjs/transforms/index.js.map +1 -1
- package/cjs/transforms/util/util.d.ts +4 -0
- package/cjs/transforms/util/util.js +20 -2
- package/cjs/transforms/util/util.js.map +1 -1
- package/cjs/types/animate.d.ts +6 -1
- package/cjs/types/animate.js.map +1 -1
- package/cjs/types/grammar.d.ts +1 -1
- package/cjs/types/grammar.js.map +1 -1
- package/cjs/types/mark.d.ts +5 -1
- package/cjs/types/mark.js.map +1 -1
- package/cjs/types/theme.d.ts +2 -1
- package/cjs/types/theme.js.map +1 -1
- package/cjs/types/transform.d.ts +5 -5
- package/cjs/types/transform.js.map +1 -1
- package/cjs/types/view.d.ts +2 -0
- package/cjs/types/view.js.map +1 -1
- package/cjs/view/View.d.ts +0 -1
- package/cjs/view/View.js +18 -27
- package/cjs/view/View.js.map +1 -1
- package/cjs/view/animate.d.ts +1 -0
- package/cjs/view/animate.js +12 -12
- package/cjs/view/animate.js.map +1 -1
- package/cjs/view/constants.d.ts +0 -3
- package/cjs/view/constants.js +2 -3
- package/cjs/view/constants.js.map +1 -1
- package/cjs/view/dataflow.d.ts +1 -0
- package/cjs/view/dataflow.js +9 -4
- package/cjs/view/dataflow.js.map +1 -1
- package/cjs/view/grammar-record.js +5 -5
- package/cjs/view/grammar-record.js.map +1 -1
- package/cjs/view/mark.js +1 -1
- package/cjs/view/mark.js.map +1 -1
- package/es/component/axis.js +1 -1
- package/es/component/axis.js.map +1 -1
- package/es/component/datazoom.js +5 -5
- package/es/component/datazoom.js.map +1 -1
- package/es/component/grid.js +1 -1
- package/es/component/grid.js.map +1 -1
- package/es/component/label.js +13 -8
- package/es/component/label.js.map +1 -1
- package/es/component/legend.js +1 -1
- package/es/component/legend.js.map +1 -1
- package/es/component/scrollbar.js +1 -1
- package/es/component/scrollbar.js.map +1 -1
- package/es/component/slider.js +1 -1
- package/es/component/slider.js.map +1 -1
- package/es/component/title.js +1 -1
- package/es/component/title.js.map +1 -1
- package/es/core/factory.d.ts +5 -1
- package/es/core/factory.js +11 -1
- package/es/core/factory.js.map +1 -1
- package/es/graph/animation/animate.d.ts +1 -0
- package/es/graph/animation/animate.js +4 -0
- package/es/graph/animation/animate.js.map +1 -1
- package/es/graph/animation/animation/move.js +5 -5
- package/es/graph/animation/animation/move.js.map +1 -1
- package/es/graph/attributes/common.js +2 -7
- package/es/graph/attributes/common.js.map +1 -1
- package/es/graph/attributes/helpers.d.ts +2 -2
- package/es/graph/attributes/helpers.js +46 -12
- package/es/graph/attributes/helpers.js.map +1 -1
- package/es/graph/attributes/index.d.ts +4 -10
- package/es/graph/attributes/index.js +4 -227
- package/es/graph/attributes/index.js.map +1 -1
- package/es/graph/attributes/line.d.ts +3 -0
- package/es/graph/attributes/line.js +42 -0
- package/es/graph/attributes/line.js.map +1 -0
- package/es/graph/attributes/transform.d.ts +5 -0
- package/es/graph/attributes/transform.js +153 -0
- package/es/graph/attributes/transform.js.map +1 -0
- package/es/graph/canvas-renderer.js +1 -1
- package/es/graph/canvas-renderer.js.map +1 -1
- package/es/graph/constants.d.ts +0 -1
- package/es/graph/constants.js +0 -2
- package/es/graph/constants.js.map +1 -1
- package/es/graph/element.js +11 -11
- package/es/graph/element.js.map +1 -1
- package/es/graph/glyph-element.js +3 -4
- package/es/graph/glyph-element.js.map +1 -1
- package/es/graph/layout/relative.js.map +1 -1
- package/es/graph/mark/encode.js +1 -1
- package/es/graph/mark/encode.js.map +1 -1
- package/es/index.d.ts +3 -1
- package/es/index.js +5 -1
- package/es/index.js.map +1 -1
- package/es/interactions/base.js.map +1 -1
- package/es/interactions/brush-base.js +1 -1
- package/es/interactions/brush-base.js.map +1 -1
- package/es/interactions/brush-filter.js +2 -3
- package/es/interactions/brush-filter.js.map +1 -1
- package/es/interactions/crosshair.d.ts +1 -1
- package/es/interactions/crosshair.js +1 -1
- package/es/interactions/crosshair.js.map +1 -1
- package/es/interactions/datazoom-filter.js +1 -1
- package/es/interactions/datazoom-filter.js.map +1 -1
- package/es/interactions/drill-down.js +1 -1
- package/es/interactions/drill-down.js.map +1 -1
- package/es/interactions/element-highlight-by-group.js +2 -1
- package/es/interactions/index.js +1 -2
- package/es/interactions/legend-filter.js +2 -2
- package/es/interactions/legend-filter.js.map +1 -1
- package/es/interactions/player-filter.js +2 -2
- package/es/interactions/player-filter.js.map +1 -1
- package/es/interactions/roll-up.js +2 -2
- package/es/interactions/roll-up.js.map +1 -1
- package/es/interactions/scrollbar-filter.js +2 -2
- package/es/interactions/scrollbar-filter.js.map +1 -1
- package/es/interactions/slider-filter.js +2 -2
- package/es/interactions/slider-filter.js.map +1 -1
- package/es/interactions/tooltip.js +1 -1
- package/es/interactions/view-drag-mixin.js +1 -1
- package/es/parse/coordinate.js +1 -1
- package/es/parse/event.js +1 -1
- package/es/parse/mark.js +1 -1
- package/es/parse/option.js +1 -1
- package/es/parse/scale.js +2 -1
- package/es/parse/transform.js +1 -1
- package/es/parse/util.js +1 -1
- package/es/parse/view.js +2 -2
- package/es/parse/view.js.map +1 -1
- package/es/semantic-marks/cell.d.ts +3 -1
- package/es/semantic-marks/cell.js +11 -1
- package/es/semantic-marks/cell.js.map +1 -1
- package/es/semantic-marks/interval.d.ts +2 -0
- package/es/semantic-marks/interval.js +9 -1
- package/es/semantic-marks/interval.js.map +1 -1
- package/es/semantic-marks/text.d.ts +1 -0
- package/es/semantic-marks/text.js +3 -1
- package/es/semantic-marks/text.js.map +1 -1
- package/es/theme/common/component.d.ts +2 -1
- package/es/theme/common/component.js +14 -0
- package/es/theme/common/component.js.map +1 -1
- package/es/theme/dark.js.map +1 -1
- package/es/transforms/data/sampling.d.ts +2 -0
- package/es/transforms/data/sampling.js +105 -0
- package/es/transforms/data/sampling.js.map +1 -0
- package/es/transforms/index.d.ts +1 -1
- package/es/transforms/index.js +4 -4
- package/es/transforms/index.js.map +1 -1
- package/es/transforms/util/util.d.ts +4 -0
- package/es/transforms/util/util.js +17 -0
- package/es/transforms/util/util.js.map +1 -1
- package/es/types/animate.d.ts +6 -1
- package/es/types/animate.js.map +1 -1
- package/es/types/grammar.d.ts +1 -1
- package/es/types/grammar.js.map +1 -1
- package/es/types/mark.d.ts +5 -1
- package/es/types/mark.js.map +1 -1
- package/es/types/theme.d.ts +2 -1
- package/es/types/theme.js.map +1 -1
- package/es/types/transform.d.ts +5 -5
- package/es/types/transform.js.map +1 -1
- package/es/types/view.d.ts +2 -0
- package/es/types/view.js.map +1 -1
- package/es/view/View.d.ts +0 -1
- package/es/view/View.js +15 -29
- package/es/view/View.js.map +1 -1
- package/es/view/animate.d.ts +1 -0
- package/es/view/animate.js +6 -6
- package/es/view/animate.js.map +1 -1
- package/es/view/constants.d.ts +0 -3
- package/es/view/constants.js +0 -6
- package/es/view/constants.js.map +1 -1
- package/es/view/dataflow.d.ts +1 -0
- package/es/view/dataflow.js +9 -4
- package/es/view/dataflow.js.map +1 -1
- package/es/view/grammar-record.js +1 -1
- package/es/view/grammar-record.js.map +1 -1
- package/es/view/mark.js +1 -1
- package/es/view/mark.js.map +1 -1
- package/package.json +9 -9
- package/cjs/transforms/mark/lttb-sample.d.ts +0 -2
- package/cjs/transforms/mark/lttb-sample.js +0 -68
- package/cjs/transforms/mark/lttb-sample.js.map +0 -1
- package/es/transforms/mark/lttb-sample.d.ts +0 -2
- package/es/transforms/mark/lttb-sample.js +0 -60
- package/es/transforms/mark/lttb-sample.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/component/label.ts"],"names":[],"mappings":";;;AAAA,6CAAiE;AAIjE,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C,CAAC;AACxD,CAAC,CAAC;AAPW,QAAA,aAAa,iBAOxB","file":"label.js","sourcesContent":["import { array, isNil, isString, merge } from '@visactor/vutils';\nimport type { IGraphic } from '@visactor/vrender-core';\nimport type { BaseLabelAttrs, DataLabelAttrs } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport { DataLabel } from '@visactor/vrender-components';\nimport type {\n BaseSignleEncodeSpec,\n IElement,\n IGroupMark,\n IMark,\n ITheme,\n IView,\n MarkFunctionType,\n Nil,\n StateEncodeSpec\n} from '../types';\nimport { ComponentEnum, GrammarMarkType } from '../graph';\nimport type { ILabel, LabelSpec } from '../types/component';\nimport { Component } from '../view/component';\nimport { invokeEncoder } from '../graph/mark/encode';\nimport { invokeFunctionType } from '../parse/util';\nimport { Factory } from '../core/factory';\n\nexport const generateLabelAttributes = (\n marks: IMark[],\n groupSize: { width: number; height: number },\n encoder: BaseSignleEncodeSpec,\n labelStyle: MarkFunctionType<Partial<BaseLabelAttrs>>,\n parameters: any,\n theme?: ITheme\n): DataLabelAttrs => {\n const labelTheme = theme?.components?.dataLabel;\n const dataLabels = marks\n .map((mark, index) => {\n const labelParameters = { ...parameters, labelIndex: index };\n let currentTheme: any = {};\n switch (mark.markType) {\n case GrammarMarkType.line:\n currentTheme = theme?.components?.lineLabel;\n break;\n case GrammarMarkType.rect:\n case GrammarMarkType.interval:\n currentTheme = theme?.components?.rectLabel;\n break;\n case GrammarMarkType.symbol:\n case GrammarMarkType.circle:\n case GrammarMarkType.cell:\n currentTheme = theme?.components?.symbolLabel;\n break;\n case GrammarMarkType.arc:\n case GrammarMarkType.arc3d:\n currentTheme = theme?.components?.arcLabel;\n break;\n case GrammarMarkType.polygon:\n case GrammarMarkType.path:\n default:\n currentTheme = theme?.components?.pointLabel;\n break;\n }\n const data: any[] = [];\n // process by order of elements\n mark.elements.forEach(element => {\n const graphicItem = element.getGraphicItem();\n if ((graphicItem as any).releaseStatus !== 'willRelease') {\n const attributes = invokeEncoder(encoder, element.getDatum(), element, labelParameters);\n const datum = merge({}, currentTheme?.data?.[0] ?? {}, attributes);\n data.push(datum);\n }\n });\n const addition = invokeFunctionType(labelStyle, labelParameters, mark);\n const graphicItemName = mark.graphicItem?.name;\n return merge(\n {},\n currentTheme,\n {\n data,\n baseMarkGroupName: graphicItemName,\n // FIXME: hack\n // 标签是对数据顺序有强要求的场景,因为顺序会影响标签躲避结果;而目前没有机制保证 vrender 图元顺序与数据顺序一致。\n // 这里目前只能通过自定义方法来 hack\n getBaseMarks: () => mark.elements.map(element => element.getGraphicItem())\n },\n addition ?? {}\n );\n })\n .filter(label => !isNil(label));\n return merge({}, labelTheme, { size: groupSize, dataLabels });\n};\n\nexport class Label extends Component implements ILabel {\n static readonly componentType: string = ComponentEnum.label;\n protected declare spec: LabelSpec;\n\n constructor(view: IView, group?: IGroupMark) {\n super(view, ComponentEnum.label, group);\n this.spec.componentType = ComponentEnum.label;\n }\n\n protected parseAddition(spec: LabelSpec) {\n super.parseAddition(spec);\n this.labelStyle(spec.labelStyle);\n this.size(spec.size);\n this.target(spec.target);\n return this;\n }\n\n labelStyle(style: MarkFunctionType<Partial<BaseLabelAttrs>>) {\n return this.setFunctionSpec(style, 'labelStyle');\n }\n\n size(size: LabelSpec['size']) {\n return this.setFunctionSpec(size, 'size');\n }\n\n target(mark: IMark | IMark[] | string | string[] | Nil): this {\n if (this.spec.target) {\n const prevMarks = array(this.spec.target).map(m => (isString(m) ? this.view.getMarkById(m) : m));\n this.detach(prevMarks);\n }\n this.spec.target = mark;\n if (mark) {\n const nextMarks = array(mark).map(m => (isString(m) ? this.view.getMarkById(m) : m));\n this.attach(nextMarks);\n }\n this.commit();\n return this;\n }\n\n protected _updateComponentEncoders() {\n const encoders = Object.assign({ update: {} }, this.spec.encode);\n const componentEncoders: StateEncodeSpec = Object.keys(encoders).reduce((res, state) => {\n const encoder = encoders[state];\n if (encoder) {\n res[state] = {\n callback: (datum: any, element: IElement, parameters: any) => {\n const marks = array(this.spec.target).map(m => (isString(m) ? this.view.getMarkById(m) : m));\n const groupGraphicItem = this.group?.getGroupGraphicItem?.();\n let size = invokeFunctionType(this.spec.size, parameters);\n if (!size) {\n size = groupGraphicItem\n ? {\n width: groupGraphicItem.attribute.width ?? groupGraphicItem.AABBBounds.width(),\n height: groupGraphicItem.attribute.height ?? groupGraphicItem.AABBBounds.height()\n }\n : { width: Infinity, height: Infinity };\n }\n const theme = this.view.getCurrentTheme();\n\n return generateLabelAttributes(\n marks,\n size,\n encoder as BaseSignleEncodeSpec,\n this.spec.labelStyle,\n parameters,\n theme\n );\n }\n };\n }\n return res;\n }, {});\n this._encoders = componentEncoders;\n }\n}\n\nexport const registerLabel = () => {\n Factory.registerGraphicComponent(\n ComponentEnum.label,\n (attrs: DataLabelAttrs) => new DataLabel(attrs) as unknown as IGraphic\n );\n\n Factory.registerComponent(ComponentEnum.label, Label);\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/component/label.ts"],"names":[],"mappings":";;;AAAA,6CAAiE;AAIjE,qEAAyD;AAYzD,0CAAgE;AAEhE,iDAA8C;AAC9C,iDAAqD;AACrD,wCAAmD;AACnD,6CAA0C;AAEnC,MAAM,uBAAuB,GAAG,CACrC,KAAc,EACd,SAA4C,EAC5C,OAA6B,EAC7B,UAAqD,EACrD,UAAe,EACf,KAAc,EACE,EAAE;;IAClB,MAAM,UAAU,GAAG,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,UAAU,0CAAE,SAAS,CAAC;IAChD,MAAM,UAAU,GAAG,KAAK;SACrB,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;;QACnB,MAAM,eAAe,mCAAQ,UAAU,KAAE,UAAU,EAAE,KAAK,GAAE,CAAC;QAC7D,IAAI,YAAY,GAAQ,EAAE,CAAC;QAC3B,QAAQ,IAAI,CAAC,QAAQ,EAAE;YACrB,KAAK,uBAAe,CAAC,IAAI,CAAC;YAC1B,KAAK,uBAAe,CAAC,IAAI;gB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visactor/vrender-core';\nimport type { BaseLabelAttrs, DataLabelAttrs } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport { DataLabel } from '@visactor/vrender-components';\nimport type {\n BaseSignleEncodeSpec,\n IElement,\n IGroupMark,\n IMark,\n ITheme,\n IView,\n MarkFunctionType,\n Nil,\n StateEncodeSpec\n} from '../types';\nimport { ComponentEnum, GrammarMarkType } from '../graph/enums';\nimport type { ILabel, LabelSpec } from '../types/component';\nimport { Component } from '../view/component';\nimport { invokeEncoder } from '../graph/mark/encode';\nimport { invokeFunctionType } from '../parse/util';\nimport { Factory } from '../core/factory';\n\nexport const generateLabelAttributes = (\n marks: IMark[],\n groupSize: { width: number; height: number },\n encoder: BaseSignleEncodeSpec,\n labelStyle: MarkFunctionType<Partial<BaseLabelAttrs>>,\n parameters: any,\n theme?: ITheme\n): DataLabelAttrs => {\n const labelTheme = theme?.components?.dataLabel;\n const dataLabels = marks\n .map((mark, index) => {\n const labelParameters = { ...parameters, labelIndex: index };\n let currentTheme: any = {};\n switch (mark.markType) {\n case GrammarMarkType.line:\n case GrammarMarkType.area:\n currentTheme = theme?.components?.lineDataLabel;\n break;\n case GrammarMarkType.rect:\n case GrammarMarkType.interval:\n currentTheme = theme?.components?.rectLabel;\n break;\n case GrammarMarkType.symbol:\n case GrammarMarkType.circle:\n case GrammarMarkType.cell:\n currentTheme = theme?.components?.symbolLabel;\n break;\n case GrammarMarkType.arc:\n case GrammarMarkType.arc3d:\n currentTheme = theme?.components?.arcLabel;\n break;\n case GrammarMarkType.polygon:\n case GrammarMarkType.path:\n default:\n currentTheme = theme?.components?.pointLabel;\n break;\n }\n const data: any[] = [];\n const themeDatum = currentTheme?.data?.[0] ?? {};\n // process by order of elements\n mark.elements.forEach(element => {\n const graphicItem = element.getGraphicItem();\n if ((graphicItem as any).releaseStatus !== 'willRelease') {\n if (mark.isCollectionMark()) {\n const datum = element.getDatum();\n\n datum.forEach((entry: any) => {\n const attributes = invokeEncoder(encoder, entry, element, labelParameters);\n data.push(merge({}, themeDatum, attributes));\n });\n } else {\n const attributes = invokeEncoder(encoder, element.getDatum(), element, labelParameters);\n const datum = merge({}, themeDatum, attributes);\n data.push(datum);\n }\n }\n });\n const addition = invokeFunctionType(labelStyle, labelParameters, mark);\n const graphicItemName = mark.graphicItem?.name;\n return merge(\n {},\n currentTheme,\n {\n data,\n baseMarkGroupName: graphicItemName,\n // FIXME: hack\n // 标签是对数据顺序有强要求的场景,因为顺序会影响标签躲避结果;而目前没有机制保证 vrender 图元顺序与数据顺序一致。\n // 这里目前只能通过自定义方法来 hack\n getBaseMarks: () => mark.elements.map(element => element.getGraphicItem())\n },\n addition ?? {}\n );\n })\n .filter(label => !isNil(label));\n\n return merge({}, labelTheme, { size: groupSize, dataLabels });\n};\n\nexport class Label extends Component implements ILabel {\n static readonly componentType: string = ComponentEnum.label;\n protected declare spec: LabelSpec;\n\n constructor(view: IView, group?: IGroupMark) {\n super(view, ComponentEnum.label, group);\n this.spec.componentType = ComponentEnum.label;\n }\n\n protected parseAddition(spec: LabelSpec) {\n super.parseAddition(spec);\n this.labelStyle(spec.labelStyle);\n this.size(spec.size);\n this.target(spec.target);\n return this;\n }\n\n labelStyle(style: MarkFunctionType<Partial<BaseLabelAttrs>>) {\n return this.setFunctionSpec(style, 'labelStyle');\n }\n\n size(size: LabelSpec['size']) {\n return this.setFunctionSpec(size, 'size');\n }\n\n target(mark: IMark | IMark[] | string | string[] | Nil): this {\n if (this.spec.target) {\n const prevMarks = array(this.spec.target).map(m => (isString(m) ? this.view.getMarkById(m) : m));\n this.detach(prevMarks);\n }\n this.spec.target = mark;\n if (mark) {\n const nextMarks = array(mark).map(m => (isString(m) ? this.view.getMarkById(m) : m));\n this.attach(nextMarks);\n }\n this.commit();\n return this;\n }\n\n protected _updateComponentEncoders() {\n const encoders = Object.assign({ update: {} }, this.spec.encode);\n const componentEncoders: StateEncodeSpec = Object.keys(encoders).reduce((res, state) => {\n const encoder = encoders[state];\n if (encoder) {\n res[state] = {\n callback: (datum: any, element: IElement, parameters: any) => {\n const marks = array(this.spec.target).map(m => (isString(m) ? this.view.getMarkById(m) : m));\n const groupGraphicItem = this.group?.getGroupGraphicItem?.();\n let size = invokeFunctionType(this.spec.size, parameters);\n if (!size) {\n size = groupGraphicItem\n ? {\n width: groupGraphicItem.attribute.width ?? groupGraphicItem.AABBBounds.width(),\n height: groupGraphicItem.attribute.height ?? groupGraphicItem.AABBBounds.height()\n }\n : { width: Infinity, height: Infinity };\n }\n const theme = this.view.getCurrentTheme();\n\n return generateLabelAttributes(\n marks,\n size,\n encoder as BaseSignleEncodeSpec,\n this.spec.labelStyle,\n parameters,\n theme\n );\n }\n };\n }\n return res;\n }, {});\n this._encoders = componentEncoders;\n }\n}\n\nexport const registerLabel = () => {\n Factory.registerGraphicComponent(\n ComponentEnum.label,\n (attrs: DataLabelAttrs) => new DataLabel(attrs) as unknown as IGraphic\n );\n\n Factory.registerComponent(ComponentEnum.label, Label);\n};\n"]}
|
package/cjs/component/legend.js
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: !0
|
|
5
5
|
}), exports.registerLegend = exports.Legend = exports.generateSizeLegendAttributes = exports.generateColorLegendAttributes = exports.generateDiscreteLegendAttributes = void 0;
|
|
6
6
|
|
|
7
|
-
const vscale_1 = require("@visactor/vscale"), vrender_components_1 = require("@visactor/vrender-components"), vutils_1 = require("@visactor/vutils"),
|
|
7
|
+
const vscale_1 = require("@visactor/vscale"), vrender_components_1 = require("@visactor/vrender-components"), vutils_1 = require("@visactor/vutils"), enums_1 = require("../graph/enums"), util_1 = require("../parse/util"), scale_1 = require("./scale"), encode_1 = require("../graph/mark/encode"), factory_1 = require("../core/factory"), legend_filter_1 = require("../interactions/legend-filter"), filter_1 = require("../interactions/filter"), generateDiscreteLegendAttributes = (scale, theme, addition, shapeScale) => {
|
|
8
8
|
var _a;
|
|
9
9
|
const legendTheme = null === (_a = null == theme ? void 0 : theme.components) || void 0 === _a ? void 0 : _a.discreteLegend;
|
|
10
10
|
if (!scale) return (0, vutils_1.merge)({}, legendTheme, null != addition ? addition : {});
|
|
@@ -60,7 +60,7 @@ exports.generateSizeLegendAttributes = generateSizeLegendAttributes;
|
|
|
60
60
|
|
|
61
61
|
class Legend extends scale_1.ScaleComponent {
|
|
62
62
|
constructor(view, group) {
|
|
63
|
-
super(view,
|
|
63
|
+
super(view, enums_1.ComponentEnum.legend, group), this.spec.componentType = enums_1.ComponentEnum.legend,
|
|
64
64
|
this.spec.legendType = "auto";
|
|
65
65
|
}
|
|
66
66
|
parseAddition(spec) {
|
|
@@ -84,7 +84,7 @@ class Legend extends scale_1.ScaleComponent {
|
|
|
84
84
|
this.commit(), this;
|
|
85
85
|
}
|
|
86
86
|
isContinuousLegend() {
|
|
87
|
-
return this._getLegendComponentType() !==
|
|
87
|
+
return this._getLegendComponentType() !== enums_1.LegendEnum.discreteLegend;
|
|
88
88
|
}
|
|
89
89
|
setSelected(selectedValues) {
|
|
90
90
|
var _a, _b;
|
|
@@ -106,13 +106,13 @@ class Legend extends scale_1.ScaleComponent {
|
|
|
106
106
|
var _a, _b;
|
|
107
107
|
const theme = this.view.getCurrentTheme(), addition = (0, encode_1.invokeEncoder)(encoder, datum, element, parameters), scale = null === (_a = null == scaleGrammar ? void 0 : scaleGrammar.getScale) || void 0 === _a ? void 0 : _a.call(scaleGrammar);
|
|
108
108
|
switch (this._getLegendComponentType()) {
|
|
109
|
-
case
|
|
109
|
+
case enums_1.LegendEnum.discreteLegend:
|
|
110
110
|
return (0, exports.generateDiscreteLegendAttributes)(scale, theme, addition, null === (_b = null == shapeScaleGrammar ? void 0 : shapeScaleGrammar.getScale) || void 0 === _b ? void 0 : _b.call(shapeScaleGrammar));
|
|
111
111
|
|
|
112
|
-
case
|
|
112
|
+
case enums_1.LegendEnum.colorLegend:
|
|
113
113
|
return (0, exports.generateColorLegendAttributes)(scale, theme, addition);
|
|
114
114
|
|
|
115
|
-
case
|
|
115
|
+
case enums_1.LegendEnum.sizeLegend:
|
|
116
116
|
return (0, exports.generateSizeLegendAttributes)(scale, theme, addition);
|
|
117
117
|
}
|
|
118
118
|
return addition;
|
|
@@ -128,20 +128,20 @@ class Legend extends scale_1.ScaleComponent {
|
|
|
128
128
|
const scaleGrammar = (0, vutils_1.isString)(this.spec.scale) ? this.view.getScaleById(this.spec.scale) : this.spec.scale, scaleType = null === (_a = null == scaleGrammar ? void 0 : scaleGrammar.getScaleType) || void 0 === _a ? void 0 : _a.call(scaleGrammar);
|
|
129
129
|
if (scaleType && (0, vscale_1.isContinuous)(scaleType)) {
|
|
130
130
|
const range = scaleGrammar.getScale().range();
|
|
131
|
-
(0, util_1.parseColor)(null == range ? void 0 : range[0]) ? this._legendComponentType =
|
|
132
|
-
} else this._legendComponentType =
|
|
131
|
+
(0, util_1.parseColor)(null == range ? void 0 : range[0]) ? this._legendComponentType = enums_1.LegendEnum.colorLegend : this._legendComponentType = enums_1.LegendEnum.sizeLegend;
|
|
132
|
+
} else this._legendComponentType = enums_1.LegendEnum.discreteLegend;
|
|
133
133
|
}
|
|
134
134
|
return this._legendComponentType;
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
exports.Legend = Legend, Legend.componentType =
|
|
138
|
+
exports.Legend = Legend, Legend.componentType = enums_1.ComponentEnum.legend;
|
|
139
139
|
|
|
140
140
|
const registerLegend = () => {
|
|
141
|
-
factory_1.Factory.registerGraphicComponent(
|
|
142
|
-
factory_1.Factory.registerGraphicComponent(
|
|
143
|
-
factory_1.Factory.registerGraphicComponent(
|
|
144
|
-
factory_1.Factory.registerComponent(
|
|
141
|
+
factory_1.Factory.registerGraphicComponent(enums_1.LegendEnum.discreteLegend, (attrs => new vrender_components_1.DiscreteLegend(attrs))),
|
|
142
|
+
factory_1.Factory.registerGraphicComponent(enums_1.LegendEnum.colorLegend, (attrs => new vrender_components_1.ColorContinuousLegend(attrs))),
|
|
143
|
+
factory_1.Factory.registerGraphicComponent(enums_1.LegendEnum.sizeLegend, (attrs => new vrender_components_1.SizeContinuousLegend(attrs))),
|
|
144
|
+
factory_1.Factory.registerComponent(enums_1.ComponentEnum.legend, Legend), (0, vutils_1.mixin)(filter_1.Filter, filter_1.FilterMixin),
|
|
145
145
|
factory_1.Factory.registerInteraction(legend_filter_1.LegendFilter.type, legend_filter_1.LegendFilter);
|
|
146
146
|
};
|
|
147
147
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/component/legend.ts"],"names":[],"mappings":";;;AAGA,6CAAgD;AAGhD,qEAA2G;AAC3G,6CAAuE;AACvE,oCAAqD;AAarD,wCAA2C;AAC3C,mCAAyC;AACzC,iDAAqD;AACrD,6CAA0C;AAC1C,iEAA6D;AAC7D,mDAA6D;AAEtD,MAAM,gCAAgC,GAAG,CAC9C,KAAiB,EACjB,KAAc,EACd,QAAgD,EAChD,UAAuB,EACF,EAAE;;IACvB,MAAM,WAAW,GAAG,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,UAAU,0CAAE,cAAc,CAAC;IACtD,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,IAAA,cAAK,EAAC,EAAE,EAAE,WAAW,EAAE,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,EAAE,CAAC,CAAC;KAC/C;IAED,MAAM,WAAW,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,IAAA,cAAK,EAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;IAC/D,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;;QAC5C,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAChC,MAAM,KAAK,GAAG,IAAA,iBAAU,EAAC,KAAK,CAAC,CAAC;QAChC,MAAM,KAAK,GAAG,KAAK;YACjB,CAAC,iCACM,CAAC,MAAA,M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CAAC,UAAU,KAAK,MAAM;wBACjC,CAAC,CAAC,YAAY;wBACd,CAAC,CAAC,gBAAgB,CAAC;SACxB;QACD,OAAO,IAAI,CAAC,oBAAoB,CAAC;IACnC,CAAC;;AA7HH,wBA8HC;AA7HiB,oBAAa,GAAW,qBAAa,CAAC,MAAM,CAAC;AA+HxD,MAAM,cAAc,GAAG,GAAG,EAAE;IACjC,iBAAO,CAAC,wBAAwB,CAC9B,kBAAU,CAAC,cAAc,EACzB,CAAC,KAA0B,EAAE,EAAE,CAAC,IAAI,mCAAc,CAAC,KAAK,CAAwB,CACjF,CAAC;IACF,iBAAO,CAAC,wBAAwB,CAC9B,kBAAU,CAAC,WAAW,EACtB,CAAC,KAA4B,EAAE,EAAE,CAAC,IAAI,0CAAqB,CAAC,KAAK,CAAwB,CAC1F,CAAC;IACF,iBAAO,CAAC,wBAAwB,CAC9B,kBAAU,CAAC,UAAU,EACrB,CAAC,KAA2B,EAAE,EAAE,CAAC,IAAI,yCAAoB,CAAC,KAAK,CAAwB,CACxF,CAAC;IAEF,iBAAO,CAAC,iBAAiB,CAAC,qBAAa,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAExD,IAAA,cAAK,EAAC,eAAM,EAAE,oBAAW,CAAC,CAAC;IAC3B,iBAAO,CAAC,mBAAmB,CAAC,4BAAY,CAAC,IAAI,EAAE,4BAAY,CAAC,CAAC;AAC/D,CAAC,CAAC;AAlBW,QAAA,cAAc,kBAkBzB","file":"legend.js","sourcesContent":["import type { IGraphic } from '@visactor/vrender-core';\nimport type { IBaseScale } from '@visactor/vscale';\n// eslint-disable-next-line no-duplicate-imports\nimport { isContinuous } from '@visactor/vscale';\nimport type { DiscreteLegendAttrs, ColorLegendAttributes, SizeLegendAttributes } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport { DiscreteLegend, ColorContinuousLegend, SizeContinuousLegend } from '@visactor/vrender-components';\nimport { array, isString, merge, last, mixin } from '@visactor/vutils';\nimport { ComponentEnum, LegendEnum } from '../graph';\nimport type {\n BaseSignleEncodeSpec,\n IElement,\n IGroupMark,\n IScale,\n ITheme,\n IView,\n Nil,\n RecursivePartial,\n StateEncodeSpec\n} from '../types';\nimport type { ILegend, LegendSpec, LegendType } from '../types/component';\nimport { parseColor } from '../parse/util';\nimport { ScaleComponent } from './scale';\nimport { invokeEncoder } from '../graph/mark/encode';\nimport { Factory } from '../core/factory';\nimport { LegendFilter } from '../interactions/legend-filter';\nimport { Filter, FilterMixin } from '../interactions/filter';\n\nexport const generateDiscreteLegendAttributes = (\n scale: IBaseScale,\n theme?: ITheme,\n addition?: RecursivePartial<DiscreteLegendAttrs>,\n shapeScale?: IBaseScale\n): DiscreteLegendAttrs => {\n const legendTheme = theme?.components?.discreteLegend;\n if (!scale) {\n return merge({}, legendTheme, addition ?? {});\n }\n // get domain items without repetitions\n const domainItems = Array.from(new Set(array(scale.domain())));\n const items = domainItems.map((item, index) => {\n const value = scale.scale(item);\n const color = parseColor(value);\n const shape = color\n ? {\n ...(theme?.components?.discreteLegend?.items?.[0]?.shape ?? {}),\n fill: color,\n stroke: color\n }\n : theme?.components?.discreteLegend?.items?.[0]?.shape ?? {};\n\n if (shapeScale) {\n Object.assign(shape, { symbolType: shapeScale.scale(item) });\n }\n\n return {\n label: item.toString(),\n id: item,\n shape,\n index\n };\n });\n return merge({}, legendTheme, { items }, addition ?? {});\n};\n\nexport const generateColorLegendAttributes = (\n scale: IBaseScale,\n theme?: ITheme,\n addition?: RecursivePartial<ColorLegendAttributes>\n): ColorLegendAttributes => {\n const legendTheme = theme?.components?.colorLegend;\n if (!scale) {\n return merge({}, legendTheme, addition ?? {});\n }\n const domain = scale.domain();\n return merge({}, legendTheme, { colors: scale.range().slice(), min: domain[0], max: last(domain) }, addition ?? {});\n};\n\nexport const generateSizeLegendAttributes = (\n scale: IBaseScale,\n theme?: ITheme,\n addition?: RecursivePartial<SizeLegendAttributes>\n): SizeLegendAttributes => {\n const legendTheme = theme?.components?.sizeLegend;\n if (!scale) {\n return merge({}, legendTheme, addition ?? {});\n }\n const domain = scale.domain();\n const attributes = {\n min: domain[0],\n max: domain[domain.length - 1],\n value: [domain[0], domain[domain.length - 1]]\n };\n return merge({}, legendTheme, attributes, addition ?? {});\n};\n\nexport class Legend extends ScaleComponent implements ILegend {\n static readonly componentType: string = ComponentEnum.legend;\n protected declare spec: LegendSpec;\n\n private _legendComponentType: keyof typeof LegendEnum;\n\n constructor(view: IView, group?: IGroupMark) {\n super(view, ComponentEnum.legend, group);\n this.spec.componentType = ComponentEnum.legend;\n this.spec.legendType = 'auto';\n }\n\n protected parseAddition(spec: LegendSpec) {\n this.shapeScale(spec.shapeScale);\n super.parseAddition(spec);\n this.legendType(spec.legendType);\n return this;\n }\n\n scale(scale?: IScale | string | Nil) {\n super.scale(scale);\n this._legendComponentType = null;\n return this;\n }\n\n shapeScale(shapeScale: LegendSpec['shapeScale']) {\n if (this.spec.shapeScale) {\n const lastScaleGrammar = isString(this.spec.shapeScale)\n ? this.view.getScaleById(this.spec.shapeScale)\n : this.spec.shapeScale;\n this.detach(lastScaleGrammar);\n this.spec.shapeScale = undefined;\n }\n const scaleGrammar = isString(shapeScale) ? this.view.getScaleById(shapeScale) : shapeScale;\n this.spec.shapeScale = scaleGrammar;\n this.attach(scaleGrammar);\n\n this.commit();\n return this;\n }\n\n legendType(legendType: LegendType | Nil) {\n this.spec.legendType = legendType;\n // clear legend type when spec is changed\n this._legendComponentType = null;\n this._prepareRejoin();\n this.commit();\n return this;\n }\n\n isContinuousLegend() {\n return this._getLegendComponentType() !== LegendEnum.discreteLegend;\n }\n\n setSelected(selectedValues: any[]) {\n // FIXME: provide ILegend interface in vis-component\n const legend = this.elements[0]?.getGraphicItem?.() as unknown as DiscreteLegend;\n legend.setSelected(selectedValues);\n return this;\n }\n\n addGraphicItem(attrs: any, groupKey?: string) {\n const graphicItem = Factory.createGraphicComponent(this._getLegendComponentType(), attrs);\n return super.addGraphicItem(attrs, groupKey, graphicItem);\n }\n\n protected _updateComponentEncoders() {\n const scaleGrammar = isString(this.spec.scale) ? this.view.getScaleById(this.spec.scale) : this.spec.scale;\n const shapeScaleGrammar = isString(this.spec.shapeScale)\n ? this.view.getScaleById(this.spec.shapeScale)\n : this.spec.shapeScale;\n const encoders = Object.assign({ update: {} }, this.spec.encode);\n const componentEncoders: StateEncodeSpec = Object.keys(encoders).reduce((res, state) => {\n const encoder = encoders[state];\n if (encoder) {\n res[state] = {\n callback: (datum: any, element: IElement, parameters: any) => {\n const theme = this.view.getCurrentTheme();\n const addition = invokeEncoder(encoder as BaseSignleEncodeSpec, datum, element, parameters);\n const scale = scaleGrammar?.getScale?.();\n switch (this._getLegendComponentType()) {\n case LegendEnum.discreteLegend:\n return generateDiscreteLegendAttributes(scale, theme, addition, shapeScaleGrammar?.getScale?.());\n case LegendEnum.colorLegend:\n return generateColorLegendAttributes(scale, theme, addition);\n case LegendEnum.sizeLegend:\n return generateSizeLegendAttributes(scale, theme, addition);\n }\n return addition;\n }\n };\n }\n return res;\n }, {});\n this._encoders = componentEncoders;\n }\n\n private _getLegendComponentType() {\n if (this._legendComponentType) {\n return this._legendComponentType;\n }\n\n // compute legend component type when needed\n if (!this.spec.legendType || this.spec.legendType === 'auto') {\n const scaleGrammar = isString(this.spec.scale) ? this.view.getScaleById(this.spec.scale) : this.spec.scale;\n const scaleType = scaleGrammar?.getScaleType?.();\n if (scaleType && isContinuous(scaleType)) {\n const range: any[] = scaleGrammar.getScale().range();\n if (parseColor(range?.[0])) {\n this._legendComponentType = LegendEnum.colorLegend;\n } else {\n this._legendComponentType = LegendEnum.sizeLegend;\n }\n } else {\n this._legendComponentType = LegendEnum.discreteLegend;\n }\n } else {\n this._legendComponentType =\n this.spec.legendType === 'color'\n ? 'colorLegend'\n : this.spec.legendType === 'size'\n ? 'sizeLegend'\n : 'discreteLegend';\n }\n return this._legendComponentType;\n }\n}\n\nexport const registerLegend = () => {\n Factory.registerGraphicComponent(\n LegendEnum.discreteLegend,\n (attrs: DiscreteLegendAttrs) => new DiscreteLegend(attrs) as unknown as IGraphic\n );\n Factory.registerGraphicComponent(\n LegendEnum.colorLegend,\n (attrs: ColorLegendAttributes) => new ColorContinuousLegend(attrs) as unknown as IGraphic\n );\n Factory.registerGraphicComponent(\n LegendEnum.sizeLegend,\n (attrs: SizeLegendAttributes) => new SizeContinuousLegend(attrs) as unknown as IGraphic\n );\n\n Factory.registerComponent(ComponentEnum.legend, Legend);\n\n mixin(Filter, FilterMixin);\n Factory.registerInteraction(LegendFilter.type, LegendFilter);\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/component/legend.ts"],"names":[],"mappings":";;;AAGA,6CAAgD;AAGhD,qEAA2G;AAC3G,6CAAuE;AACvE,0CAA2D;AAa3D,wCAA2C;AAC3C,mCAAyC;AACzC,iDAAqD;AACrD,6CAA0C;AAC1C,iEAA6D;AAC7D,mDAA6D;AAEtD,MAAM,gCAAgC,GAAG,CAC9C,KAAiB,EACjB,KAAc,EACd,QAAgD,EAChD,UAAuB,EACF,EAAE;;IACvB,MAAM,WAAW,GAAG,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,UAAU,0CAAE,cAAc,CAAC;IACtD,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,IAAA,cAAK,EAAC,EAAE,EAAE,WAAW,EAAE,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,EAAE,CAAC,CAAC;KAC/C;IAED,MAAM,WAAW,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,IAAA,cAAK,EAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;IAC/D,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;;QAC5C,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAChC,MAAM,KAAK,GAAG,IAAA,iBAAU,EAAC,KAAK,CAAC,CAAC;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BAC9B,CAAC,CAAC,aAAa;oBACf,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,KAAK,MAAM;wBACjC,CAAC,CAAC,YAAY;wBACd,CAAC,CAAC,gBAAgB,CAAC;SACxB;QACD,OAAO,IAAI,CAAC,oBAAoB,CAAC;IACnC,CAAC;;AA7HH,wBA8HC;AA7HiB,oBAAa,GAAW,qBAAa,CAAC,MAAM,CAAC;AA+HxD,MAAM,cAAc,GAAG,GAAG,EAAE;IACjC,iBAAO,CAAC,wBAAwB,CAC9B,kBAAU,CAAC,cAAc,EACzB,CAAC,KAA0B,EAAE,EAAE,CAAC,IAAI,mCAAc,CAAC,KAAK,CAAwB,CACjF,CAAC;IACF,iBAAO,CAAC,wBAAwB,CAC9B,kBAAU,CAAC,WAAW,EACtB,CAAC,KAA4B,EAAE,EAAE,CAAC,IAAI,0CAAqB,CAAC,KAAK,CAAwB,CAC1F,CAAC;IACF,iBAAO,CAAC,wBAAwB,CAC9B,kBAAU,CAAC,UAAU,EACrB,CAAC,KAA2B,EAAE,EAAE,CAAC,IAAI,yCAAoB,CAAC,KAAK,CAAwB,CACxF,CAAC;IAEF,iBAAO,CAAC,iBAAiB,CAAC,qBAAa,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAExD,IAAA,cAAK,EAAC,eAAM,EAAE,oBAAW,CAAC,CAAC;IAC3B,iBAAO,CAAC,mBAAmB,CAAC,4BAAY,CAAC,IAAI,EAAE,4BAAY,CAAC,CAAC;AAC/D,CAAC,CAAC;AAlBW,QAAA,cAAc,kBAkBzB","file":"legend.js","sourcesContent":["import type { IGraphic } from '@visactor/vrender-core';\nimport type { IBaseScale } from '@visactor/vscale';\n// eslint-disable-next-line no-duplicate-imports\nimport { isContinuous } from '@visactor/vscale';\nimport type { DiscreteLegendAttrs, ColorLegendAttributes, SizeLegendAttributes } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport { DiscreteLegend, ColorContinuousLegend, SizeContinuousLegend } from '@visactor/vrender-components';\nimport { array, isString, merge, last, mixin } from '@visactor/vutils';\nimport { ComponentEnum, LegendEnum } from '../graph/enums';\nimport type {\n BaseSignleEncodeSpec,\n IElement,\n IGroupMark,\n IScale,\n ITheme,\n IView,\n Nil,\n RecursivePartial,\n StateEncodeSpec\n} from '../types';\nimport type { ILegend, LegendSpec, LegendType } from '../types/component';\nimport { parseColor } from '../parse/util';\nimport { ScaleComponent } from './scale';\nimport { invokeEncoder } from '../graph/mark/encode';\nimport { Factory } from '../core/factory';\nimport { LegendFilter } from '../interactions/legend-filter';\nimport { Filter, FilterMixin } from '../interactions/filter';\n\nexport const generateDiscreteLegendAttributes = (\n scale: IBaseScale,\n theme?: ITheme,\n addition?: RecursivePartial<DiscreteLegendAttrs>,\n shapeScale?: IBaseScale\n): DiscreteLegendAttrs => {\n const legendTheme = theme?.components?.discreteLegend;\n if (!scale) {\n return merge({}, legendTheme, addition ?? {});\n }\n // get domain items without repetitions\n const domainItems = Array.from(new Set(array(scale.domain())));\n const items = domainItems.map((item, index) => {\n const value = scale.scale(item);\n const color = parseColor(value);\n const shape = color\n ? {\n ...(theme?.components?.discreteLegend?.items?.[0]?.shape ?? {}),\n fill: color,\n stroke: color\n }\n : theme?.components?.discreteLegend?.items?.[0]?.shape ?? {};\n\n if (shapeScale) {\n Object.assign(shape, { symbolType: shapeScale.scale(item) });\n }\n\n return {\n label: item.toString(),\n id: item,\n shape,\n index\n };\n });\n return merge({}, legendTheme, { items }, addition ?? {});\n};\n\nexport const generateColorLegendAttributes = (\n scale: IBaseScale,\n theme?: ITheme,\n addition?: RecursivePartial<ColorLegendAttributes>\n): ColorLegendAttributes => {\n const legendTheme = theme?.components?.colorLegend;\n if (!scale) {\n return merge({}, legendTheme, addition ?? {});\n }\n const domain = scale.domain();\n return merge({}, legendTheme, { colors: scale.range().slice(), min: domain[0], max: last(domain) }, addition ?? {});\n};\n\nexport const generateSizeLegendAttributes = (\n scale: IBaseScale,\n theme?: ITheme,\n addition?: RecursivePartial<SizeLegendAttributes>\n): SizeLegendAttributes => {\n const legendTheme = theme?.components?.sizeLegend;\n if (!scale) {\n return merge({}, legendTheme, addition ?? {});\n }\n const domain = scale.domain();\n const attributes = {\n min: domain[0],\n max: domain[domain.length - 1],\n value: [domain[0], domain[domain.length - 1]]\n };\n return merge({}, legendTheme, attributes, addition ?? {});\n};\n\nexport class Legend extends ScaleComponent implements ILegend {\n static readonly componentType: string = ComponentEnum.legend;\n protected declare spec: LegendSpec;\n\n private _legendComponentType: keyof typeof LegendEnum;\n\n constructor(view: IView, group?: IGroupMark) {\n super(view, ComponentEnum.legend, group);\n this.spec.componentType = ComponentEnum.legend;\n this.spec.legendType = 'auto';\n }\n\n protected parseAddition(spec: LegendSpec) {\n this.shapeScale(spec.shapeScale);\n super.parseAddition(spec);\n this.legendType(spec.legendType);\n return this;\n }\n\n scale(scale?: IScale | string | Nil) {\n super.scale(scale);\n this._legendComponentType = null;\n return this;\n }\n\n shapeScale(shapeScale: LegendSpec['shapeScale']) {\n if (this.spec.shapeScale) {\n const lastScaleGrammar = isString(this.spec.shapeScale)\n ? this.view.getScaleById(this.spec.shapeScale)\n : this.spec.shapeScale;\n this.detach(lastScaleGrammar);\n this.spec.shapeScale = undefined;\n }\n const scaleGrammar = isString(shapeScale) ? this.view.getScaleById(shapeScale) : shapeScale;\n this.spec.shapeScale = scaleGrammar;\n this.attach(scaleGrammar);\n\n this.commit();\n return this;\n }\n\n legendType(legendType: LegendType | Nil) {\n this.spec.legendType = legendType;\n // clear legend type when spec is changed\n this._legendComponentType = null;\n this._prepareRejoin();\n this.commit();\n return this;\n }\n\n isContinuousLegend() {\n return this._getLegendComponentType() !== LegendEnum.discreteLegend;\n }\n\n setSelected(selectedValues: any[]) {\n // FIXME: provide ILegend interface in vis-component\n const legend = this.elements[0]?.getGraphicItem?.() as unknown as DiscreteLegend;\n legend.setSelected(selectedValues);\n return this;\n }\n\n addGraphicItem(attrs: any, groupKey?: string) {\n const graphicItem = Factory.createGraphicComponent(this._getLegendComponentType(), attrs);\n return super.addGraphicItem(attrs, groupKey, graphicItem);\n }\n\n protected _updateComponentEncoders() {\n const scaleGrammar = isString(this.spec.scale) ? this.view.getScaleById(this.spec.scale) : this.spec.scale;\n const shapeScaleGrammar = isString(this.spec.shapeScale)\n ? this.view.getScaleById(this.spec.shapeScale)\n : this.spec.shapeScale;\n const encoders = Object.assign({ update: {} }, this.spec.encode);\n const componentEncoders: StateEncodeSpec = Object.keys(encoders).reduce((res, state) => {\n const encoder = encoders[state];\n if (encoder) {\n res[state] = {\n callback: (datum: any, element: IElement, parameters: any) => {\n const theme = this.view.getCurrentTheme();\n const addition = invokeEncoder(encoder as BaseSignleEncodeSpec, datum, element, parameters);\n const scale = scaleGrammar?.getScale?.();\n switch (this._getLegendComponentType()) {\n case LegendEnum.discreteLegend:\n return generateDiscreteLegendAttributes(scale, theme, addition, shapeScaleGrammar?.getScale?.());\n case LegendEnum.colorLegend:\n return generateColorLegendAttributes(scale, theme, addition);\n case LegendEnum.sizeLegend:\n return generateSizeLegendAttributes(scale, theme, addition);\n }\n return addition;\n }\n };\n }\n return res;\n }, {});\n this._encoders = componentEncoders;\n }\n\n private _getLegendComponentType() {\n if (this._legendComponentType) {\n return this._legendComponentType;\n }\n\n // compute legend component type when needed\n if (!this.spec.legendType || this.spec.legendType === 'auto') {\n const scaleGrammar = isString(this.spec.scale) ? this.view.getScaleById(this.spec.scale) : this.spec.scale;\n const scaleType = scaleGrammar?.getScaleType?.();\n if (scaleType && isContinuous(scaleType)) {\n const range: any[] = scaleGrammar.getScale().range();\n if (parseColor(range?.[0])) {\n this._legendComponentType = LegendEnum.colorLegend;\n } else {\n this._legendComponentType = LegendEnum.sizeLegend;\n }\n } else {\n this._legendComponentType = LegendEnum.discreteLegend;\n }\n } else {\n this._legendComponentType =\n this.spec.legendType === 'color'\n ? 'colorLegend'\n : this.spec.legendType === 'size'\n ? 'sizeLegend'\n : 'discreteLegend';\n }\n return this._legendComponentType;\n }\n}\n\nexport const registerLegend = () => {\n Factory.registerGraphicComponent(\n LegendEnum.discreteLegend,\n (attrs: DiscreteLegendAttrs) => new DiscreteLegend(attrs) as unknown as IGraphic\n );\n Factory.registerGraphicComponent(\n LegendEnum.colorLegend,\n (attrs: ColorLegendAttributes) => new ColorContinuousLegend(attrs) as unknown as IGraphic\n );\n Factory.registerGraphicComponent(\n LegendEnum.sizeLegend,\n (attrs: SizeLegendAttributes) => new SizeContinuousLegend(attrs) as unknown as IGraphic\n );\n\n Factory.registerComponent(ComponentEnum.legend, Legend);\n\n mixin(Filter, FilterMixin);\n Factory.registerInteraction(LegendFilter.type, LegendFilter);\n};\n"]}
|
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: !0
|
|
5
5
|
}), exports.registerScrollbar = exports.Scrollbar = exports.generateScrollbarAttributes = void 0;
|
|
6
6
|
|
|
7
|
-
const vutils_1 = require("@visactor/vutils"), vrender_components_1 = require("@visactor/vrender-components"),
|
|
7
|
+
const vutils_1 = require("@visactor/vutils"), vrender_components_1 = require("@visactor/vrender-components"), enums_1 = require("../graph/enums"), encode_1 = require("../graph/mark/encode"), util_1 = require("../parse/util"), factory_1 = require("../core/factory"), scale_1 = require("./scale"), scrollbar_filter_1 = require("../interactions/scrollbar-filter"), filter_1 = require("../interactions/filter");
|
|
8
8
|
|
|
9
9
|
function isValidDirection(direction) {
|
|
10
10
|
return "vertical" === direction || "horizontal" === direction;
|
|
@@ -64,7 +64,7 @@ exports.generateScrollbarAttributes = generateScrollbarAttributes;
|
|
|
64
64
|
|
|
65
65
|
class Scrollbar extends scale_1.ScaleComponent {
|
|
66
66
|
constructor(view, group) {
|
|
67
|
-
super(view,
|
|
67
|
+
super(view, enums_1.ComponentEnum.scrollbar, group), this.spec.componentType = enums_1.ComponentEnum.scrollbar;
|
|
68
68
|
}
|
|
69
69
|
parseAddition(spec) {
|
|
70
70
|
return super.parseAddition(spec), this.container(spec.container), this.direction(spec.direction),
|
|
@@ -104,7 +104,7 @@ class Scrollbar extends scale_1.ScaleComponent {
|
|
|
104
104
|
addGraphicItem(attrs, groupKey) {
|
|
105
105
|
const initialAttributes = (0, vutils_1.merge)({
|
|
106
106
|
range: [ 0, 1 ]
|
|
107
|
-
}, attrs), graphicItem = factory_1.Factory.createGraphicComponent(
|
|
107
|
+
}, attrs), graphicItem = factory_1.Factory.createGraphicComponent(enums_1.ComponentEnum.scrollbar, initialAttributes);
|
|
108
108
|
return super.addGraphicItem(initialAttributes, groupKey, graphicItem);
|
|
109
109
|
}
|
|
110
110
|
_updateComponentEncoders() {
|
|
@@ -118,7 +118,7 @@ class Scrollbar extends scale_1.ScaleComponent {
|
|
|
118
118
|
const theme = this.view.getCurrentTheme(), direction = (0, util_1.invokeFunctionType)(this.spec.direction, parameters, datum, element), position = (0,
|
|
119
119
|
util_1.invokeFunctionType)(this.spec.position, parameters, datum, element), addition = (0,
|
|
120
120
|
encode_1.invokeEncoder)(encoder, datum, element, parameters), targetMark = this.spec.container ? (0,
|
|
121
|
-
vutils_1.isString)(this.spec.container) ? this.view.getMarkById(this.spec.container) : this.spec.container : null, groupGraphicItem = (targetMark && targetMark.markType ===
|
|
121
|
+
vutils_1.isString)(this.spec.container) ? this.view.getMarkById(this.spec.container) : this.spec.container : null, groupGraphicItem = (targetMark && targetMark.markType === enums_1.GrammarMarkType.group ? targetMark : this.group).getGroupGraphicItem(), size = groupGraphicItem ? {
|
|
122
122
|
width: null !== (_a = groupGraphicItem.attribute.width) && void 0 !== _a ? _a : groupGraphicItem.AABBBounds.width(),
|
|
123
123
|
height: null !== (_b = groupGraphicItem.attribute.height) && void 0 !== _b ? _b : groupGraphicItem.AABBBounds.height()
|
|
124
124
|
} : {
|
|
@@ -133,11 +133,11 @@ class Scrollbar extends scale_1.ScaleComponent {
|
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
exports.Scrollbar = Scrollbar, Scrollbar.componentType =
|
|
136
|
+
exports.Scrollbar = Scrollbar, Scrollbar.componentType = enums_1.ComponentEnum.scrollbar;
|
|
137
137
|
|
|
138
138
|
const registerScrollbar = () => {
|
|
139
|
-
factory_1.Factory.registerGraphicComponent(
|
|
140
|
-
factory_1.Factory.registerComponent(
|
|
139
|
+
factory_1.Factory.registerGraphicComponent(enums_1.ComponentEnum.scrollbar, (attrs => new vrender_components_1.ScrollBar(attrs))),
|
|
140
|
+
factory_1.Factory.registerComponent(enums_1.ComponentEnum.scrollbar, Scrollbar),
|
|
141
141
|
(0, vutils_1.mixin)(filter_1.Filter, filter_1.FilterMixin), factory_1.Factory.registerInteraction(scrollbar_filter_1.ScrollbarFilter.type, scrollbar_filter_1.ScrollbarFilter);
|
|
142
142
|
};
|
|
143
143
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/component/scrollbar.ts"],"names":[],"mappings":";;;AAAA,6CAA0D;AAI1D,qEAA+E;AAY/E,oCAA0D;AAE1D,iDAAqD;AACrD,wCAAmD;AACnD,6CAA0C;AAC1C,mCAAyC;AACzC,uEAAmE;AACnE,mDAA6D;AAE7D,SAAS,gBAAgB,CAAC,SAAoB;IAC5C,OAAO,SAAS,KAAK,UAAU,IAAI,SAAS,KAAK,YAAY,CAAC;AAChE,CAAC;AAED,SAAS,eAAe,CAAC,QAAoB;IAC3C,OAAO,QAAQ,KAAK,KAAK,IAAI,QAAQ,KAAK,QAAQ,IAAI,QAAQ,KAAK,MAAM,IAAI,QAAQ,KAAK,OAAO,CAAC;AACpG,CAAC;AAED,SAAS,oBAAoB,CAAC,QAAoB;IAChD,OAAO,QAAQ,KAAK,KAAK,IAAI,QAAQ,KAAK,QAAQ,CAAC;AACrD,CAAC;AAEM,MAAM,2BAA2B,GAAG,CACzC,SAA4C,EAC5C,SAAqB,EACrB,QAAqB,EACrB,KAAc,EACd,QAAgD,EAC3B,EAAE;;IACvB,MAAM,cAAc,GAAG,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,UAAU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ge, mixin } from '@visactor/vutils';\nimport type { IGraphic } from '@visactor/vrender-core';\nimport type { Direction, OrientType, ScrollBarAttributes } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport { ScrollBar as ScrollbarComponent } from '@visactor/vrender-components';\nimport type {\n BaseSignleEncodeSpec,\n IElement,\n IGroupMark,\n ITheme,\n IView,\n MarkFunctionType,\n Nil,\n RecursivePartial,\n StateEncodeSpec\n} from '../types';\nimport { ComponentEnum, GrammarMarkType } from '../graph';\nimport type { IScrollbar, ScrollbarSpec } from '../types/component';\nimport { invokeEncoder } from '../graph/mark/encode';\nimport { invokeFunctionType } from '../parse/util';\nimport { Factory } from '../core/factory';\nimport { ScaleComponent } from './scale';\nimport { ScrollbarFilter } from '../interactions/scrollbar-filter';\nimport { Filter, FilterMixin } from '../interactions/filter';\n\nfunction isValidDirection(direction: Direction) {\n return direction === 'vertical' || direction === 'horizontal';\n}\n\nfunction isValidPosition(position: OrientType) {\n return position === 'top' || position === 'bottom' || position === 'left' || position === 'right';\n}\n\nfunction isHorizontalPosition(position: OrientType) {\n return position === 'top' || position === 'bottom';\n}\n\nexport const generateScrollbarAttributes = (\n groupSize: { width: number; height: number },\n direction?: Direction,\n position?: OrientType,\n theme?: ITheme,\n addition?: RecursivePartial<ScrollBarAttributes>\n): ScrollBarAttributes => {\n const scrollbarTheme = theme?.components?.scrollbar;\n\n let finalDirection: Direction = 'horizontal';\n let finalPosition: OrientType = 'bottom';\n if (!isValidDirection(direction) && !isValidPosition(position)) {\n finalDirection = 'horizontal';\n finalPosition = 'bottom';\n } else if (!isValidDirection(direction) && isValidPosition(position)) {\n finalDirection = isHorizontalPosition(position) ? 'horizontal' : 'vertical';\n finalPosition = position;\n } else if (isValidDirection(direction) && !isValidPosition(position)) {\n finalDirection = direction;\n finalPosition = direction === 'horizontal' ? 'bottom' : 'right';\n } else {\n finalDirection = direction;\n finalPosition =\n direction === 'horizontal' && !isHorizontalPosition(position)\n ? 'bottom'\n : direction === 'vertical' && isHorizontalPosition(position)\n ? 'right'\n : position;\n }\n\n const attributes: RecursivePartial<ScrollBarAttributes> = { direction: finalDirection };\n if (finalDirection === 'horizontal') {\n const size = addition.height ?? scrollbarTheme?.height ?? 12;\n\n // top or bottom\n if (finalPosition === 'top') {\n Object.assign(attributes, {\n width: groupSize.width,\n height: size,\n x: 0,\n y: 0\n });\n } else {\n Object.assign(attributes, {\n width: groupSize.width,\n height: size,\n x: 0,\n y: groupSize.height - size\n });\n }\n } else {\n const size = addition.width ?? scrollbarTheme?.width ?? 12;\n\n // left or right\n if (finalPosition === 'left') {\n Object.assign(attributes, {\n width: size,\n height: groupSize.height,\n x: 0,\n y: 0\n });\n } else {\n Object.assign(attributes, {\n width: size,\n height: groupSize.height,\n x: groupSize.width - size,\n y: 0\n });\n }\n }\n\n return merge({}, scrollbarTheme, attributes, addition ?? {});\n};\n\nexport class Scrollbar extends ScaleComponent implements IScrollbar {\n static readonly componentType: string = ComponentEnum.scrollbar;\n protected declare spec: ScrollbarSpec;\n\n constructor(view: IView, group?: IGroupMark) {\n super(view, ComponentEnum.scrollbar, group);\n this.spec.componentType = ComponentEnum.scrollbar;\n }\n\n protected parseAddition(spec: ScrollbarSpec) {\n super.parseAddition(spec);\n this.container(spec.container);\n this.direction(spec.direction);\n this.position(spec.position);\n return this;\n }\n\n container(container: IGroupMark | string | Nil): this {\n if (this.spec.container) {\n const prevContainer = isString(this.spec.container)\n ? this.view.getMarkById(this.spec.container)\n : this.spec.container;\n this.detach(prevContainer);\n }\n this.spec.container = container;\n if (container) {\n const nextContainer = isString(container) ? this.view.getMarkById(container) : container;\n this.attach(nextContainer);\n }\n this.commit();\n return this;\n }\n\n direction(direction: MarkFunctionType<Direction> | Nil) {\n return this.setFunctionSpec(direction, 'direction');\n }\n\n position(position: MarkFunctionType<OrientType> | Nil) {\n return this.setFunctionSpec(position, 'position');\n }\n\n setScrollStart(start: number) {\n const scrollbar = this.elements[0]?.getGraphicItem?.() as unknown as ScrollbarComponent;\n const range = scrollbar?.attribute?.range;\n if (scrollbar && range) {\n const nextRange: [number, number] = [start, range[1] - range[0] + start];\n scrollbar.setScrollRange(nextRange);\n }\n return this;\n }\n\n getScrollRange() {\n const scrollbar = this.elements[0]?.getGraphicItem?.() as unknown as ScrollbarComponent;\n\n if (scrollbar) {\n return scrollbar.getScrollRange();\n }\n }\n\n addGraphicItem(attrs: any, groupKey?: string) {\n const defaultAttributes = { range: [0, 1] };\n const initialAttributes = merge(defaultAttributes, attrs);\n const graphicItem = Factory.createGraphicComponent(ComponentEnum.scrollbar, initialAttributes);\n return super.addGraphicItem(initialAttributes, groupKey, graphicItem);\n }\n\n protected _updateComponentEncoders() {\n const encoders = Object.assign({ update: {} }, this.spec.encode);\n const componentEncoders: StateEncodeSpec = Object.keys(encoders).reduce((res, state) => {\n const encoder = encoders[state];\n if (encoder) {\n res[state] = {\n callback: (datum: any, element: IElement, parameters: any) => {\n const theme = this.view.getCurrentTheme();\n const direction = invokeFunctionType(this.spec.direction, parameters, datum, element);\n const position = invokeFunctionType(this.spec.position, parameters, datum, element);\n const addition = invokeEncoder(encoder as BaseSignleEncodeSpec, datum, element, parameters);\n const targetMark = this.spec.container\n ? isString(this.spec.container)\n ? this.view.getMarkById(this.spec.container)\n : this.spec.container\n : null;\n const groupMark = targetMark && targetMark.markType === GrammarMarkType.group ? targetMark : this.group;\n const groupGraphicItem = groupMark.getGroupGraphicItem();\n const size = groupGraphicItem\n ? {\n width: groupGraphicItem.attribute.width ?? groupGraphicItem.AABBBounds.width(),\n height: groupGraphicItem.attribute.height ?? groupGraphicItem.AABBBounds.height()\n }\n : { width: this.view.width(), height: this.view.height() };\n return generateScrollbarAttributes(size, direction, position, theme, addition);\n }\n };\n }\n return res;\n }, {});\n this._encoders = componentEncoders;\n }\n}\n\nexport const registerScrollbar = () => {\n Factory.registerGraphicComponent(\n ComponentEnum.scrollbar,\n (attrs: ScrollBarAttributes) => new ScrollbarComponent(attrs) as unknown as IGraphic\n );\n\n Factory.registerComponent(ComponentEnum.scrollbar, Scrollbar);\n\n mixin(Filter, FilterMixin);\n Factory.registerInteraction(ScrollbarFilter.type, ScrollbarFilter);\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/component/scrollbar.ts"],"names":[],"mappings":";;;AAAA,6CAA0D;AAI1D,qEAA+E;AAY/E,0CAAgE;AAEhE,iDAAqD;AACrD,wCAAmD;AACnD,6CAA0C;AAC1C,mCAAyC;AACzC,uEAAmE;AACnE,mDAA6D;AAE7D,SAAS,gBAAgB,CAAC,SAAoB;IAC5C,OAAO,SAAS,KAAK,UAAU,IAAI,SAAS,KAAK,YAAY,CAAC;AAChE,CAAC;AAED,SAAS,eAAe,CAAC,QAAoB;IAC3C,OAAO,QAAQ,KAAK,KAAK,IAAI,QAAQ,KAAK,QAAQ,IAAI,QAAQ,KAAK,MAAM,IAAI,QAAQ,KAAK,OAAO,CAAC;AACpG,CAAC;AAED,SAAS,oBAAoB,CAAC,QAAoB;IAChD,OAAO,QAAQ,KAAK,KAAK,IAAI,QAAQ,KAAK,QAAQ,CAAC;AACrD,CAAC;AAEM,MAAM,2BAA2B,GAAG,CACzC,SAA4C,EAC5C,SAAqB,EACrB,QAAqB,EACrB,KAAc,EACd,QAAgD,EAC3B,EAAE;;IACvB,MAAM,cAAc,GAAG,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,UAAU,0CAAE,SAAS,CAAC;IAEpD,IAAI,cAAc,GAAc,YAAY,CAAC;IAC7C,IAAI,aAAa,GAAe,QAAQ,CAAC;IACzC,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,EAAE;QAC9D,cAAc,GAAG,YAAY,CAAC;QAC9B,aAAa,GAAG,QAAQ,CAAC;KAC1B;SAAM,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,IAAI,eAAe,CAAC,QAAQ,CAAC,EAAE;QACpE,cAAc,GAAG,oBAAoB,CAAC,QAA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C,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;wBAC7D,OAAO,IAAA,mCAA2B,EAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;oBACjF,CAAC;iBACF,CAAC;aACH;YACD,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAAE,CAAC,CAAC;QACP,IAAI,CAAC,SAAS,GAAG,iBAAiB,CAAC;IACrC,CAAC;;AAjGH,8BAkGC;AAjGiB,uBAAa,GAAW,qBAAa,CAAC,SAAS,CAAC;AAmG3D,MAAM,iBAAiB,GAAG,GAAG,EAAE;IACpC,iBAAO,CAAC,wBAAwB,CAC9B,qBAAa,CAAC,SAAS,EACvB,CAAC,KAA0B,EAAE,EAAE,CAAC,IAAI,8BAAkB,CAAC,KAAK,CAAwB,CACrF,CAAC;IAEF,iBAAO,CAAC,iBAAiB,CAAC,qBAAa,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IAE9D,IAAA,cAAK,EAAC,eAAM,EAAE,oBAAW,CAAC,CAAC;IAC3B,iBAAO,CAAC,mBAAmB,CAAC,kCAAe,CAAC,IAAI,EAAE,kCAAe,CAAC,CAAC;AACrE,CAAC,CAAC;AAVW,QAAA,iBAAiB,qBAU5B","file":"scrollbar.js","sourcesContent":["import { isString, merge, mixin } from '@visactor/vutils';\nimport type { IGraphic } from '@visactor/vrender-core';\nimport type { Direction, OrientType, ScrollBarAttributes } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport { ScrollBar as ScrollbarComponent } from '@visactor/vrender-components';\nimport type {\n BaseSignleEncodeSpec,\n IElement,\n IGroupMark,\n ITheme,\n IView,\n MarkFunctionType,\n Nil,\n RecursivePartial,\n StateEncodeSpec\n} from '../types';\nimport { ComponentEnum, GrammarMarkType } from '../graph/enums';\nimport type { IScrollbar, ScrollbarSpec } from '../types/component';\nimport { invokeEncoder } from '../graph/mark/encode';\nimport { invokeFunctionType } from '../parse/util';\nimport { Factory } from '../core/factory';\nimport { ScaleComponent } from './scale';\nimport { ScrollbarFilter } from '../interactions/scrollbar-filter';\nimport { Filter, FilterMixin } from '../interactions/filter';\n\nfunction isValidDirection(direction: Direction) {\n return direction === 'vertical' || direction === 'horizontal';\n}\n\nfunction isValidPosition(position: OrientType) {\n return position === 'top' || position === 'bottom' || position === 'left' || position === 'right';\n}\n\nfunction isHorizontalPosition(position: OrientType) {\n return position === 'top' || position === 'bottom';\n}\n\nexport const generateScrollbarAttributes = (\n groupSize: { width: number; height: number },\n direction?: Direction,\n position?: OrientType,\n theme?: ITheme,\n addition?: RecursivePartial<ScrollBarAttributes>\n): ScrollBarAttributes => {\n const scrollbarTheme = theme?.components?.scrollbar;\n\n let finalDirection: Direction = 'horizontal';\n let finalPosition: OrientType = 'bottom';\n if (!isValidDirection(direction) && !isValidPosition(position)) {\n finalDirection = 'horizontal';\n finalPosition = 'bottom';\n } else if (!isValidDirection(direction) && isValidPosition(position)) {\n finalDirection = isHorizontalPosition(position) ? 'horizontal' : 'vertical';\n finalPosition = position;\n } else if (isValidDirection(direction) && !isValidPosition(position)) {\n finalDirection = direction;\n finalPosition = direction === 'horizontal' ? 'bottom' : 'right';\n } else {\n finalDirection = direction;\n finalPosition =\n direction === 'horizontal' && !isHorizontalPosition(position)\n ? 'bottom'\n : direction === 'vertical' && isHorizontalPosition(position)\n ? 'right'\n : position;\n }\n\n const attributes: RecursivePartial<ScrollBarAttributes> = { direction: finalDirection };\n if (finalDirection === 'horizontal') {\n const size = addition.height ?? scrollbarTheme?.height ?? 12;\n\n // top or bottom\n if (finalPosition === 'top') {\n Object.assign(attributes, {\n width: groupSize.width,\n height: size,\n x: 0,\n y: 0\n });\n } else {\n Object.assign(attributes, {\n width: groupSize.width,\n height: size,\n x: 0,\n y: groupSize.height - size\n });\n }\n } else {\n const size = addition.width ?? scrollbarTheme?.width ?? 12;\n\n // left or right\n if (finalPosition === 'left') {\n Object.assign(attributes, {\n width: size,\n height: groupSize.height,\n x: 0,\n y: 0\n });\n } else {\n Object.assign(attributes, {\n width: size,\n height: groupSize.height,\n x: groupSize.width - size,\n y: 0\n });\n }\n }\n\n return merge({}, scrollbarTheme, attributes, addition ?? {});\n};\n\nexport class Scrollbar extends ScaleComponent implements IScrollbar {\n static readonly componentType: string = ComponentEnum.scrollbar;\n protected declare spec: ScrollbarSpec;\n\n constructor(view: IView, group?: IGroupMark) {\n super(view, ComponentEnum.scrollbar, group);\n this.spec.componentType = ComponentEnum.scrollbar;\n }\n\n protected parseAddition(spec: ScrollbarSpec) {\n super.parseAddition(spec);\n this.container(spec.container);\n this.direction(spec.direction);\n this.position(spec.position);\n return this;\n }\n\n container(container: IGroupMark | string | Nil): this {\n if (this.spec.container) {\n const prevContainer = isString(this.spec.container)\n ? this.view.getMarkById(this.spec.container)\n : this.spec.container;\n this.detach(prevContainer);\n }\n this.spec.container = container;\n if (container) {\n const nextContainer = isString(container) ? this.view.getMarkById(container) : container;\n this.attach(nextContainer);\n }\n this.commit();\n return this;\n }\n\n direction(direction: MarkFunctionType<Direction> | Nil) {\n return this.setFunctionSpec(direction, 'direction');\n }\n\n position(position: MarkFunctionType<OrientType> | Nil) {\n return this.setFunctionSpec(position, 'position');\n }\n\n setScrollStart(start: number) {\n const scrollbar = this.elements[0]?.getGraphicItem?.() as unknown as ScrollbarComponent;\n const range = scrollbar?.attribute?.range;\n if (scrollbar && range) {\n const nextRange: [number, number] = [start, range[1] - range[0] + start];\n scrollbar.setScrollRange(nextRange);\n }\n return this;\n }\n\n getScrollRange() {\n const scrollbar = this.elements[0]?.getGraphicItem?.() as unknown as ScrollbarComponent;\n\n if (scrollbar) {\n return scrollbar.getScrollRange();\n }\n }\n\n addGraphicItem(attrs: any, groupKey?: string) {\n const defaultAttributes = { range: [0, 1] };\n const initialAttributes = merge(defaultAttributes, attrs);\n const graphicItem = Factory.createGraphicComponent(ComponentEnum.scrollbar, initialAttributes);\n return super.addGraphicItem(initialAttributes, groupKey, graphicItem);\n }\n\n protected _updateComponentEncoders() {\n const encoders = Object.assign({ update: {} }, this.spec.encode);\n const componentEncoders: StateEncodeSpec = Object.keys(encoders).reduce((res, state) => {\n const encoder = encoders[state];\n if (encoder) {\n res[state] = {\n callback: (datum: any, element: IElement, parameters: any) => {\n const theme = this.view.getCurrentTheme();\n const direction = invokeFunctionType(this.spec.direction, parameters, datum, element);\n const position = invokeFunctionType(this.spec.position, parameters, datum, element);\n const addition = invokeEncoder(encoder as BaseSignleEncodeSpec, datum, element, parameters);\n const targetMark = this.spec.container\n ? isString(this.spec.container)\n ? this.view.getMarkById(this.spec.container)\n : this.spec.container\n : null;\n const groupMark = targetMark && targetMark.markType === GrammarMarkType.group ? targetMark : this.group;\n const groupGraphicItem = groupMark.getGroupGraphicItem();\n const size = groupGraphicItem\n ? {\n width: groupGraphicItem.attribute.width ?? groupGraphicItem.AABBBounds.width(),\n height: groupGraphicItem.attribute.height ?? groupGraphicItem.AABBBounds.height()\n }\n : { width: this.view.width(), height: this.view.height() };\n return generateScrollbarAttributes(size, direction, position, theme, addition);\n }\n };\n }\n return res;\n }, {});\n this._encoders = componentEncoders;\n }\n}\n\nexport const registerScrollbar = () => {\n Factory.registerGraphicComponent(\n ComponentEnum.scrollbar,\n (attrs: ScrollBarAttributes) => new ScrollbarComponent(attrs) as unknown as IGraphic\n );\n\n Factory.registerComponent(ComponentEnum.scrollbar, Scrollbar);\n\n mixin(Filter, FilterMixin);\n Factory.registerInteraction(ScrollbarFilter.type, ScrollbarFilter);\n};\n"]}
|
package/cjs/component/slider.js
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: !0
|
|
5
5
|
}), exports.registerSlider = exports.Slider = exports.generateSliderAttributes = void 0;
|
|
6
6
|
|
|
7
|
-
const vutils_1 = require("@visactor/vutils"), vrender_components_1 = require("@visactor/vrender-components"),
|
|
7
|
+
const vutils_1 = require("@visactor/vutils"), vrender_components_1 = require("@visactor/vrender-components"), enums_1 = require("../graph/enums"), component_1 = require("../view/component"), encode_1 = require("../graph/mark/encode"), util_1 = require("../parse/util"), factory_1 = require("../core/factory"), slider_filter_1 = require("../interactions/slider-filter"), filter_1 = require("../interactions/filter"), generateSliderAttributes = (min, max, theme, addition) => {
|
|
8
8
|
var _a;
|
|
9
9
|
const sliderTheme = null === (_a = null == theme ? void 0 : theme.components) || void 0 === _a ? void 0 : _a.slider;
|
|
10
10
|
return (0, vutils_1.merge)({}, sliderTheme, {
|
|
@@ -18,7 +18,7 @@ exports.generateSliderAttributes = generateSliderAttributes;
|
|
|
18
18
|
|
|
19
19
|
class Slider extends component_1.Component {
|
|
20
20
|
constructor(view, group) {
|
|
21
|
-
super(view,
|
|
21
|
+
super(view, enums_1.ComponentEnum.slider, group), this.spec.componentType = enums_1.ComponentEnum.slider;
|
|
22
22
|
}
|
|
23
23
|
parseAddition(spec) {
|
|
24
24
|
return super.parseAddition(spec), this.min(spec.min), this.max(spec.max), this;
|
|
@@ -52,11 +52,11 @@ class Slider extends component_1.Component {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
exports.Slider = Slider, Slider.componentType =
|
|
55
|
+
exports.Slider = Slider, Slider.componentType = enums_1.ComponentEnum.slider;
|
|
56
56
|
|
|
57
57
|
const registerSlider = () => {
|
|
58
|
-
factory_1.Factory.registerGraphicComponent(
|
|
59
|
-
factory_1.Factory.registerComponent(
|
|
58
|
+
factory_1.Factory.registerGraphicComponent(enums_1.ComponentEnum.slider, (attrs => new vrender_components_1.Slider(attrs))),
|
|
59
|
+
factory_1.Factory.registerComponent(enums_1.ComponentEnum.slider, Slider), (0, vutils_1.mixin)(filter_1.Filter, filter_1.FilterMixin),
|
|
60
60
|
factory_1.Factory.registerInteraction(slider_filter_1.SliderFilter.type, slider_filter_1.SliderFilter);
|
|
61
61
|
};
|
|
62
62
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":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AAC,CAAC,CAAC,CAAC,CAAC;wBACtG,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC;wBAC1C,MAAM,QAAQ,GAAG,IAAA,sBAAa,EAAC,OAA+B,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;wBAC5F,OAAO,IAAA,gCAAwB,EAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;oBAC7D,CAAC;iBACF,CAAC;aACH;YACD,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAAE,CAAC,CAAC;QACP,IAAI,CAAC,SAAS,GAAG,iBAAiB,CAAC;IACrC,CAAC;;AAhDH,wBAiDC;AAhDiB,oBAAa,GAAW,qBAAa,CAAC,MAAM,CAAC;AAkDxD,MAAM,cAAc,GAAG,GAAG,EAAE;IACjC,iBAAO,CAAC,wBAAwB,CAC9B,qBAAa,CAAC,MAAM,EACpB,CAAC,KAAuB,EAAE,EAAE,CAAC,IAAI,2BAAe,CAAC,KAAK,CAAwB,CAC/E,CAAC;IAEF,iBAAO,CAAC,iBAAiB,CAAC,qBAAa,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAExD,IAAA,cAAK,EAAC,eAAM,EAAE,oBAAW,CAAC,CAAC;IAC3B,iBAAO,CAAC,mBAAmB,CAAC,4BAAY,CAAC,IAAI,EAAE,4BAAY,CAAC,CAAC;AAC/D,CAAC,CAAC;AAVW,QAAA,cAAc,kBAUzB","file":"slider.js","sourcesContent":["import { isNil, merge, mixin } from '@visactor/vutils';\nimport type { IGraphic } from '@visactor/vrender-core';\nimport type { SliderAttributes } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport { Slider as SliderComponent } from '@visactor/vrender-components';\nimport type {\n BaseSignleEncodeSpec,\n IElement,\n IGroupMark,\n ITheme,\n IView,\n MarkFunctionType,\n Nil,\n RecursivePartial,\n StateEncodeSpec\n} from '../types';\nimport { ComponentEnum } from '../graph/enums';\nimport type { ISlider, SliderSpec } from '../types/component';\nimport { Component } from '../view/component';\nimport { invokeEncoder } from '../graph/mark/encode';\nimport { invokeFunctionType } from '../parse/util';\nimport { Factory } from '../core/factory';\nimport { SliderFilter } from '../interactions/slider-filter';\nimport { Filter, FilterMixin } from '../interactions/filter';\n\nexport const generateSliderAttributes = (\n min: number,\n max: number,\n theme?: ITheme,\n addition?: RecursivePartial<SliderAttributes>\n): SliderAttributes => {\n const sliderTheme = theme?.components?.slider;\n return merge({}, sliderTheme, { min, max, value: [min, max] }, addition ?? {});\n};\n\nexport class Slider extends Component implements ISlider {\n static readonly componentType: string = ComponentEnum.slider;\n protected declare spec: SliderSpec;\n\n constructor(view: IView, group?: IGroupMark) {\n super(view, ComponentEnum.slider, group);\n this.spec.componentType = ComponentEnum.slider;\n }\n\n protected parseAddition(spec: SliderSpec) {\n super.parseAddition(spec);\n this.min(spec.min);\n this.max(spec.max);\n return this;\n }\n\n min(min: MarkFunctionType<number> | Nil) {\n return this.setFunctionSpec(min, 'min');\n }\n\n max(max: MarkFunctionType<number> | Nil) {\n return this.setFunctionSpec(max, 'max');\n }\n\n setStartEndValue(start?: number, end?: number) {\n const slider = this.elements[0]?.getGraphicItem?.() as unknown as SliderComponent;\n slider.setValue([start, end]);\n return this;\n }\n\n protected _updateComponentEncoders() {\n const encoders = Object.assign({ update: {} }, this.spec.encode);\n const componentEncoders: StateEncodeSpec = Object.keys(encoders).reduce((res, state) => {\n const encoder = encoders[state];\n if (encoder) {\n res[state] = {\n callback: (datum: any, element: IElement, parameters: any) => {\n const min = !isNil(this.spec.min) ? invokeFunctionType(this.spec.min, parameters, datum, element) : 0;\n const max = !isNil(this.spec.max) ? invokeFunctionType(this.spec.max, parameters, datum, element) : 1;\n const theme = this.view.getCurrentTheme();\n const addition = invokeEncoder(encoder as BaseSignleEncodeSpec, datum, element, parameters);\n return generateSliderAttributes(min, max, theme, addition);\n }\n };\n }\n return res;\n }, {});\n this._encoders = componentEncoders;\n }\n}\n\nexport const registerSlider = () => {\n Factory.registerGraphicComponent(\n ComponentEnum.slider,\n (attrs: SliderAttributes) => new SliderComponent(attrs) as unknown as IGraphic\n );\n\n Factory.registerComponent(ComponentEnum.slider, Slider);\n\n mixin(Filter, FilterMixin);\n Factory.registerInteraction(SliderFilter.type, SliderFilter);\n};\n"]}
|
package/cjs/component/title.js
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: !0
|
|
5
5
|
}), exports.registerTitle = exports.Title = exports.generateTitleAttributes = void 0;
|
|
6
6
|
|
|
7
|
-
const vutils_1 = require("@visactor/vutils"), vrender_components_1 = require("@visactor/vrender-components"),
|
|
7
|
+
const vutils_1 = require("@visactor/vutils"), vrender_components_1 = require("@visactor/vrender-components"), enums_1 = require("../graph/enums"), component_1 = require("../view/component"), encode_1 = require("../graph/mark/encode"), util_1 = require("../parse/util"), factory_1 = require("../core/factory"), generateTitleAttributes = (title, subTitle, theme, addition) => {
|
|
8
8
|
var _a;
|
|
9
9
|
const titleTheme = null === (_a = null == theme ? void 0 : theme.components) || void 0 === _a ? void 0 : _a.title, attributes = {};
|
|
10
10
|
return (0, vutils_1.isValid)(title) && (attributes.text = title), (0, vutils_1.isValid)(subTitle) && (attributes.subtext = subTitle),
|
|
@@ -15,7 +15,7 @@ exports.generateTitleAttributes = generateTitleAttributes;
|
|
|
15
15
|
|
|
16
16
|
class Title extends component_1.Component {
|
|
17
17
|
constructor(view, group) {
|
|
18
|
-
super(view,
|
|
18
|
+
super(view, enums_1.ComponentEnum.title, group), this.spec.componentType = enums_1.ComponentEnum.title;
|
|
19
19
|
}
|
|
20
20
|
parseAddition(spec) {
|
|
21
21
|
return super.parseAddition(spec), this.title(spec.title), this.subTitle(spec.subTitle),
|
|
@@ -45,11 +45,11 @@ class Title extends component_1.Component {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
exports.Title = Title, Title.componentType =
|
|
48
|
+
exports.Title = Title, Title.componentType = enums_1.ComponentEnum.title;
|
|
49
49
|
|
|
50
50
|
const registerTitle = () => {
|
|
51
|
-
factory_1.Factory.registerGraphicComponent(
|
|
52
|
-
factory_1.Factory.registerComponent(
|
|
51
|
+
factory_1.Factory.registerGraphicComponent(enums_1.ComponentEnum.title, (attrs => new vrender_components_1.Title(attrs))),
|
|
52
|
+
factory_1.Factory.registerComponent(enums_1.ComponentEnum.title, Title);
|
|
53
53
|
};
|
|
54
54
|
|
|
55
55
|
exports.registerTitle = registerTitle;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/component/title.ts"],"names":[],"mappings":";;;AAAA,6CAAkD;AAIlD,qEAAuE;AAYvE,
|
|
1
|
+
{"version":3,"sources":["../src/component/title.ts"],"names":[],"mappings":";;;AAAA,6CAAkD;AAIlD,qEAAuE;AAYvE,0CAA+C;AAE/C,iDAA8C;AAC9C,iDAAqD;AACrD,wCAAmD;AACnD,6CAA0C;AAEnC,MAAM,uBAAuB,GAAG,CACrC,KAA6C,EAC7C,QAAgD,EAChD,KAAc,EACd,QAAuC,EAC3B,EAAE;;IACd,MAAM,UAAU,GAAG,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,UAAU,0CAAE,KAAK,CAAC;IAC5C,MAAM,UAAU,GAAiC,EAAE,CAAC;IACpD,IAAI,IAAA,gBAAO,EAAC,KAAK,CAAC,EAAE;QAClB,UAAU,CAAC,IAAI,GAAG,KAAK,CAAC;KACzB;IACD,IAAI,IAAA,gBAAO,EAAC,QAAQ,CAAC,EAAE;QACrB,UAAU,CAAC,OAAO,GAAG,QAAQ,CAAC;KAC/B;IACD,OAAO,IAAA,cAAK,EAAC,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,EAAE,CAAC,CAAC;AAC3D,CAAC,CAAC;AAfW,QAAA,uBAAuB,2BAelC;AAEF,MAAa,KAAM,SAAQ,q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EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;wBAC9E,MAAM,QAAQ,GAAG,IAAA,yBAAkB,EAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;wBACpF,MAAM,QAAQ,GAAG,IAAA,sBAAa,EAAC,OAA+B,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;wBAC5F,OAAO,IAAA,+BAAuB,EAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;oBACnE,CAAC;iBACF,CAAC;aACH;YACD,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAAE,CAAC,CAAC;QACP,IAAI,CAAC,SAAS,GAAG,iBAAiB,CAAC;IACrC,CAAC;;AA1CH,sBA2CC;AA1CiB,mBAAa,GAAW,qBAAa,CAAC,KAAK,CAAC;AA4CvD,MAAM,aAAa,GAAG,GAAG,EAAE;IAChC,iBAAO,CAAC,wBAAwB,CAC9B,qBAAa,CAAC,KAAK,EACnB,CAAC,KAAiB,EAAE,EAAE,CAAC,IAAI,0BAAc,CAAC,KAAK,CAAwB,CACxE,CAAC;IAEF,iBAAO,CAAC,iBAAiB,CAAC,qBAAa,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AACxD,CAAC,CAAC;AAPW,QAAA,aAAa,iBAOxB","file":"title.js","sourcesContent":["import { isValid, merge } from '@visactor/vutils';\nimport type { IGraphic } from '@visactor/vrender-core';\nimport type { TitleAttrs } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport { Title as TitleComponent } from '@visactor/vrender-components';\nimport type {\n BaseSignleEncodeSpec,\n IElement,\n IGroupMark,\n ITheme,\n IView,\n MarkFunctionType,\n Nil,\n RecursivePartial,\n StateEncodeSpec\n} from '../types';\nimport { ComponentEnum } from '../graph/enums';\nimport type { ITitle, TitleSpec } from '../types/component';\nimport { Component } from '../view/component';\nimport { invokeEncoder } from '../graph/mark/encode';\nimport { invokeFunctionType } from '../parse/util';\nimport { Factory } from '../core/factory';\n\nexport const generateTitleAttributes = (\n title?: string | number | number[] | string[],\n subTitle?: string | number | number[] | string[],\n theme?: ITheme,\n addition?: RecursivePartial<TitleAttrs>\n): TitleAttrs => {\n const titleTheme = theme?.components?.title;\n const attributes: RecursivePartial<TitleAttrs> = {};\n if (isValid(title)) {\n attributes.text = title;\n }\n if (isValid(subTitle)) {\n attributes.subtext = subTitle;\n }\n return merge({}, titleTheme, attributes, addition ?? {});\n};\n\nexport class Title extends Component implements ITitle {\n static readonly componentType: string = ComponentEnum.title;\n protected declare spec: TitleSpec;\n\n constructor(view: IView, group?: IGroupMark) {\n super(view, ComponentEnum.title, group);\n this.spec.componentType = ComponentEnum.title;\n }\n\n protected parseAddition(spec: TitleSpec) {\n super.parseAddition(spec);\n this.title(spec.title);\n this.subTitle(spec.subTitle);\n return this;\n }\n\n title(text: MarkFunctionType<string | number | number[] | string[]> | Nil) {\n return this.setFunctionSpec(text, 'title');\n }\n\n subTitle(text: MarkFunctionType<string | number | number[] | string[]> | Nil) {\n return this.setFunctionSpec(text, 'subTitle');\n }\n\n protected _updateComponentEncoders() {\n const encoders = Object.assign({ update: {} }, this.spec.encode);\n const componentEncoders: StateEncodeSpec = Object.keys(encoders).reduce((res, state) => {\n const encoder = encoders[state];\n if (encoder) {\n res[state] = {\n callback: (datum: any, element: IElement, parameters: any) => {\n const theme = this.view.getCurrentTheme();\n const title = invokeFunctionType(this.spec.title, parameters, datum, element);\n const subTitle = invokeFunctionType(this.spec.subTitle, parameters, datum, element);\n const addition = invokeEncoder(encoder as BaseSignleEncodeSpec, datum, element, parameters);\n return generateTitleAttributes(title, subTitle, theme, addition);\n }\n };\n }\n return res;\n }, {});\n this._encoders = componentEncoders;\n }\n}\n\nexport const registerTitle = () => {\n Factory.registerGraphicComponent(\n ComponentEnum.title,\n (attrs: TitleAttrs) => new TitleComponent(attrs) as unknown as IGraphic\n );\n\n Factory.registerComponent(ComponentEnum.title, Title);\n};\n"]}
|
package/cjs/core/factory.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { IGraphic } from '@visactor/vrender-core';
|
|
2
|
-
import type { GlyphChannelEncoder, GlyphDefaultEncoder, IComponentConstructor, IElement, IGlyphElement, IGlyphMeta, IGrammarBaseConstructor, IGroupMark, IInteractionConstructor, IPlotMarkConstructor, ISemanticMark, ITransform, IView, MarkType, TypeAnimation } from '../types';
|
|
2
|
+
import type { GlyphChannelEncoder, GlyphDefaultEncoder, IComponentConstructor, IElement, IGlyphElement, IGlyphMeta, IGrammarBaseConstructor, IGroupMark, IInteractionConstructor, IMark, IMarkConstructor, IPlotMarkConstructor, ISemanticMark, ITransform, IView, MarkType, TypeAnimation } from '../types';
|
|
3
3
|
export declare class Factory {
|
|
4
4
|
private static _plotMarks;
|
|
5
|
+
private static _marks;
|
|
5
6
|
private static _components;
|
|
6
7
|
private static _graphicComponents;
|
|
7
8
|
private static _transforms;
|
|
@@ -11,6 +12,9 @@ export declare class Factory {
|
|
|
11
12
|
private static _interactions;
|
|
12
13
|
static registerPlotMarks(key: string, mark: IPlotMarkConstructor): void;
|
|
13
14
|
static createPlotMark(type: string, id?: string): ISemanticMark<any, any> | null;
|
|
15
|
+
static registerMark(key: string, mark: IMarkConstructor): void;
|
|
16
|
+
static createMark(type: string, view: IView, group?: IGroupMark): IMark | null;
|
|
17
|
+
static hasMark(type: string): boolean;
|
|
14
18
|
static registerComponent(key: string, component: IComponentConstructor): void;
|
|
15
19
|
static createComponent(componentType: string, view: IView, group?: IGroupMark, mode?: '2d' | '3d'): import("../types").IComponent;
|
|
16
20
|
static hasComponent(componentType: string): boolean;
|
package/cjs/core/factory.js
CHANGED
|
@@ -14,6 +14,16 @@ class Factory {
|
|
|
14
14
|
if (!Factory._plotMarks[type]) return null;
|
|
15
15
|
return new (0, Factory._plotMarks[type])(id);
|
|
16
16
|
}
|
|
17
|
+
static registerMark(key, mark) {
|
|
18
|
+
Factory._marks[key] = mark;
|
|
19
|
+
}
|
|
20
|
+
static createMark(type, view, group) {
|
|
21
|
+
if (!Factory._marks[type]) return null;
|
|
22
|
+
return new (0, Factory._marks[type])(view, type, group);
|
|
23
|
+
}
|
|
24
|
+
static hasMark(type) {
|
|
25
|
+
return !!Factory._marks[type];
|
|
26
|
+
}
|
|
17
27
|
static registerComponent(key, component) {
|
|
18
28
|
Factory._components[key] = component;
|
|
19
29
|
}
|
|
@@ -68,9 +78,9 @@ class Factory {
|
|
|
68
78
|
}
|
|
69
79
|
}
|
|
70
80
|
|
|
71
|
-
exports.Factory = Factory, Factory._plotMarks = {}, Factory.
|
|
72
|
-
Factory.
|
|
73
|
-
Factory._interactions = {}, Factory.registerGlyph = (glyphType, marks, encoders, defaultEncoder, progressiveChannels) => (Factory._glyphs[glyphType] = new glyph_meta_1.GlyphMeta(marks, encoders, defaultEncoder, progressiveChannels),
|
|
81
|
+
exports.Factory = Factory, Factory._plotMarks = {}, Factory._marks = {}, Factory._components = {},
|
|
82
|
+
Factory._graphicComponents = {}, Factory._transforms = {}, Factory._grammars = {},
|
|
83
|
+
Factory._glyphs = {}, Factory._animations = {}, Factory._interactions = {}, Factory.registerGlyph = (glyphType, marks, encoders, defaultEncoder, progressiveChannels) => (Factory._glyphs[glyphType] = new glyph_meta_1.GlyphMeta(marks, encoders, defaultEncoder, progressiveChannels),
|
|
74
84
|
Factory._glyphs[glyphType]), Factory.registerAnimationType = (animationType, animation) => {
|
|
75
85
|
Factory._animations[animationType] = animation;
|
|
76
86
|
}, Factory.getAnimationType = animationType => Factory._animations[animationType],
|
package/cjs/core/factory.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/core/factory.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"sources":["../src/core/factory.ts"],"names":[],"mappings":";;;AAoBA,mDAA+C;AAE/C,MAAa,OAAO;IAWlB,MAAM,CAAC,iBAAiB,CAAC,GAAW,EAA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rB,SAAiB,EACjB,KAAuC,EACvC,QAA8F,EAC9F,cAAoC,EACpC,mBAAuC,EACQ,EAAE;IACjD,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,IAAI,sBAAS,CACxC,KAAK,EACL,QAAQ,EACR,cAAc,EACd,mBAAmB,CACpB,CAAC;IACF,OAAO,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AACpC,CAAC,CAAC;AAMK,6BAAqB,GAAG,CAC7B,aAAqB,EACrB,SAAiE,EAC3D,EAAE;IACR,OAAO,CAAC,WAAW,CAAC,aAAa,CAAC,GAAG,SAAS,CAAC;AACjD,CAAC,CAAC;AAEK,wBAAgB,GAAG,CAAC,aAAqB,EAAE,EAAE;IAClD,OAAO,OAAO,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;AAC5C,CAAC,CAAC;AAEK,2BAAmB,GAAG,CAAC,eAAuB,EAAE,WAAoC,EAAE,EAAE;IAC7F,OAAO,CAAC,aAAa,CAAC,eAAe,CAAC,GAAG,WAAW,CAAC;AACvD,CAAC,CAAC","file":"factory.js","sourcesContent":["import type { IGraphic } from '@visactor/vrender-core';\nimport type {\n GlyphChannelEncoder,\n GlyphDefaultEncoder,\n IComponentConstructor,\n IElement,\n IGlyphElement,\n IGlyphMeta,\n IGrammarBaseConstructor,\n IGroupMark,\n IInteractionConstructor,\n IMark,\n IMarkConstructor,\n IPlotMarkConstructor,\n ISemanticMark,\n ITransform,\n IView,\n MarkType,\n TypeAnimation\n} from '../types';\nimport { GlyphMeta } from '../view/glyph-meta';\n\nexport class Factory {\n private static _plotMarks: Record<string, IPlotMarkConstructor> = {};\n private static _marks: Record<string, IMarkConstructor> = {};\n private static _components: Record<string, IComponentConstructor> = {};\n private static _graphicComponents: Record<string, (attrs: any, mode?: '2d' | '3d') => IGraphic> = {};\n private static _transforms: Record<string, ITransform> = {};\n private static _grammars: Record<string, { grammarClass: IGrammarBaseConstructor; specKey: string }> = {};\n private static _glyphs: Record<string, IGlyphMeta<any, any>> = {};\n private static _animations: Record<string, TypeAnimation<IGlyphElement> | TypeAnimation<IElement>> = {};\n private static _interactions: Record<string, IInteractionConstructor> = {};\n\n static registerPlotMarks(key: string, mark: IPlotMarkConstructor) {\n Factory._plotMarks[key] = mark;\n }\n\n static createPlotMark(type: string, id?: string): ISemanticMark<any, any> | null {\n if (!Factory._plotMarks[type]) {\n return null;\n }\n const MarkConstructor = Factory._plotMarks[type];\n return new MarkConstructor(id);\n }\n\n static registerMark(key: string, mark: IMarkConstructor) {\n Factory._marks[key] = mark;\n }\n\n static createMark(type: string, view: IView, group?: IGroupMark): IMark | null {\n if (!Factory._marks[type]) {\n return null;\n }\n const MarkConstructor = Factory._marks[type];\n return new MarkConstructor(view, type, group);\n }\n\n static hasMark(type: string) {\n return !!Factory._marks[type];\n }\n\n static registerComponent(key: string, component: IComponentConstructor) {\n Factory._components[key] = component;\n }\n\n static createComponent(componentType: string, view: IView, group?: IGroupMark, mode?: '2d' | '3d') {\n const Ctor = Factory._components[componentType];\n if (!Ctor) {\n return null;\n }\n\n return new Ctor(view, group, mode);\n }\n\n static hasComponent(componentType: string) {\n return !!Factory._components[componentType];\n }\n\n static registerGraphicComponent(key: string, creator: (attrs: any, mode?: '2d' | '3d') => IGraphic) {\n Factory._graphicComponents[key] = creator;\n }\n\n static createGraphicComponent(componentType: string, attrs: any, mode?: '2d' | '3d') {\n const compCreator = Factory._graphicComponents[componentType];\n\n if (!compCreator) {\n return null;\n }\n\n return compCreator(attrs, mode);\n }\n\n static registerTransform(type: string, transform: Omit<ITransform, 'type'>, isBuiltIn?: boolean) {\n Factory._transforms[type] = Object.assign(transform, { type, isBuiltIn: !!isBuiltIn });\n }\n\n static getTransform(type: string) {\n return Factory._transforms[type];\n }\n\n static unregisterRuntimeTransforms() {\n Object.keys(Factory._transforms).forEach(type => {\n if (Factory._transforms[type] && !Factory._transforms[type].isBuiltIn) {\n Factory._transforms[type] = null;\n }\n });\n }\n\n static registerGrammar(type: string, grammarClass: IGrammarBaseConstructor, specKey?: string) {\n Factory._grammars[type] = {\n grammarClass: grammarClass,\n specKey: specKey ?? type\n };\n }\n\n static createGrammar(type: string, view: IView) {\n const Ctor = Factory._grammars[type]?.grammarClass;\n\n if (!Ctor) {\n return null;\n }\n\n return new Ctor(view);\n }\n\n static getGrammars() {\n return this._grammars;\n }\n\n static registerGlyph = <EncodeValuesType = any, GlyphConfigType = any>(\n glyphType: string,\n marks: { [markName: string]: MarkType },\n encoders?: { [markName: string]: GlyphChannelEncoder<any, EncodeValuesType, GlyphConfigType> },\n defaultEncoder?: GlyphDefaultEncoder,\n progressiveChannels?: string | string[]\n ): IGlyphMeta<EncodeValuesType, GlyphConfigType> => {\n Factory._glyphs[glyphType] = new GlyphMeta<EncodeValuesType, GlyphConfigType>(\n marks,\n encoders,\n defaultEncoder,\n progressiveChannels\n );\n return Factory._glyphs[glyphType];\n };\n\n static getGlyph(glyphType: string): IGlyphMeta {\n return Factory._glyphs[glyphType];\n }\n\n static registerAnimationType = (\n animationType: string,\n animation: TypeAnimation<IGlyphElement> | TypeAnimation<IElement>\n ): void => {\n Factory._animations[animationType] = animation;\n };\n\n static getAnimationType = (animationType: string) => {\n return Factory._animations[animationType];\n };\n\n static registerInteraction = (interactionType: string, interaction: IInteractionConstructor) => {\n Factory._interactions[interactionType] = interaction;\n };\n\n static createInteraction(interactionType: string, view: IView, options?: any) {\n const Ctor = Factory._interactions[interactionType];\n if (!Ctor) {\n return null;\n }\n\n return new Ctor(view, options);\n }\n}\n"]}
|
|
@@ -12,6 +12,7 @@ export declare class Animate implements IAnimate {
|
|
|
12
12
|
private elementRecorder;
|
|
13
13
|
private timelineCount;
|
|
14
14
|
constructor(mark: IMark, config: Record<string, IAnimationConfig | IAnimationConfig[]>);
|
|
15
|
+
getAnimationConfigs(animationState: string): IParsedAnimationConfig[];
|
|
15
16
|
updateConfig(config: Record<string, IAnimationConfig | IAnimationConfig[]>): void;
|
|
16
17
|
updateState(state: MarkFunctionType<string> | null): void;
|
|
17
18
|
animate(): this;
|
|
@@ -12,6 +12,10 @@ class Animate {
|
|
|
12
12
|
this.animators = new Map, this.elementRecorder = new WeakMap, this.timelineCount = {},
|
|
13
13
|
this.mark = mark, this.configs = (0, config_1.normalizeAnimationConfig)(null != config ? config : {});
|
|
14
14
|
}
|
|
15
|
+
getAnimationConfigs(animationState) {
|
|
16
|
+
var _a;
|
|
17
|
+
return this.isEnabled ? (null !== (_a = this.configs) && void 0 !== _a ? _a : []).filter((config => config.state === animationState)) : [];
|
|
18
|
+
}
|
|
15
19
|
updateConfig(config) {
|
|
16
20
|
this.configs = (0, config_1.normalizeAnimationConfig)(null != config ? config : {});
|
|
17
21
|
}
|