@visactor/vgrammar-core 0.10.1 → 0.10.3
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 +1 -1
- package/cjs/component/axis.js.map +1 -1
- package/cjs/component/datazoom.js +23 -30
- package/cjs/component/datazoom.js.map +1 -1
- package/cjs/component/label.js +11 -11
- package/cjs/component/label.js.map +1 -1
- package/cjs/component/legend.js +4 -6
- package/cjs/component/legend.js.map +1 -1
- package/cjs/component/player.js +4 -12
- package/cjs/component/player.js.map +1 -1
- package/cjs/component/scrollbar.js +12 -24
- package/cjs/component/scrollbar.js.map +1 -1
- package/cjs/component/slider.js +1 -3
- package/cjs/component/slider.js.map +1 -1
- package/cjs/glyph/boxplot.js +34 -20
- package/cjs/glyph/boxplot.js.map +1 -1
- package/cjs/glyph/violin.js +18 -11
- package/cjs/glyph/violin.js.map +1 -1
- package/cjs/graph/animation/animation/clip.js +2 -2
- package/cjs/graph/animation/animation/clip.js.map +1 -1
- package/cjs/graph/animation/animation/grow-cartesian.js +11 -11
- package/cjs/graph/animation/animation/grow-cartesian.js.map +1 -1
- package/cjs/graph/animation/animation/grow-interval.js +18 -18
- package/cjs/graph/animation/animation/grow-interval.js.map +1 -1
- package/cjs/graph/animation/animation/grow-points.js +3 -3
- package/cjs/graph/animation/animation/grow-points.js.map +1 -1
- package/cjs/graph/animation/animation/grow-polar.js +8 -8
- package/cjs/graph/animation/animation/grow-polar.js.map +1 -1
- package/cjs/graph/animation/animation/move.js +12 -14
- package/cjs/graph/animation/animation/move.js.map +1 -1
- package/cjs/graph/animation/animation/update.js +1 -1
- package/cjs/graph/animation/animation/update.js.map +1 -1
- package/cjs/graph/animation/attribute.js +2 -2
- package/cjs/graph/animation/attribute.js.map +1 -1
- package/cjs/graph/attributes/helpers.js +9 -11
- package/cjs/graph/attributes/helpers.js.map +1 -1
- package/cjs/graph/attributes/transform.js +1 -1
- package/cjs/graph/attributes/transform.js.map +1 -1
- package/cjs/graph/element.js +1 -1
- package/cjs/graph/element.js.map +1 -1
- package/cjs/graph/layout/grid.js +1 -1
- package/cjs/graph/layout/grid.js.map +1 -1
- package/cjs/graph/mark/graphic.js +2 -2
- package/cjs/graph/mark/graphic.js.map +1 -1
- package/cjs/index.d.ts +1 -1
- package/cjs/index.js +1 -1
- package/cjs/index.js.map +1 -1
- package/cjs/interactions/brush-base.js +3 -5
- package/cjs/interactions/brush-base.js.map +1 -1
- package/cjs/interactions/view-navigation-base.js +3 -3
- package/cjs/interactions/view-navigation-base.js.map +1 -1
- package/cjs/interactions/view-roam.js +10 -10
- package/cjs/interactions/view-roam.js.map +1 -1
- package/cjs/interactions/view-scroll-mixin.js +1 -1
- package/cjs/interactions/view-scroll-mixin.js.map +1 -1
- package/cjs/interactions/view-zoom-mixin.js +2 -2
- package/cjs/interactions/view-zoom-mixin.js.map +1 -1
- package/cjs/parse/event.js +1 -2
- package/cjs/parse/event.js.map +1 -1
- package/cjs/parse/scale.js +5 -4
- package/cjs/parse/scale.js.map +1 -1
- package/cjs/parse/view.js +11 -10
- package/cjs/parse/view.js.map +1 -1
- package/cjs/view/View.js +12 -13
- package/cjs/view/View.js.map +1 -1
- package/cjs/view/animate.js +11 -11
- package/cjs/view/animate.js.map +1 -1
- package/cjs/view/mark.js +6 -10
- 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 +23 -26
- package/es/component/datazoom.js.map +1 -1
- package/es/component/label.js +11 -11
- package/es/component/label.js.map +1 -1
- package/es/component/legend.js +4 -6
- package/es/component/legend.js.map +1 -1
- package/es/component/player.js +4 -12
- package/es/component/player.js.map +1 -1
- package/es/component/scrollbar.js +7 -18
- package/es/component/scrollbar.js.map +1 -1
- package/es/component/slider.js +1 -3
- package/es/component/slider.js.map +1 -1
- package/es/glyph/boxplot.js +22 -19
- package/es/glyph/boxplot.js.map +1 -1
- package/es/glyph/violin.js +12 -10
- package/es/glyph/violin.js.map +1 -1
- package/es/graph/animation/animation/clip.js +2 -2
- package/es/graph/animation/animation/clip.js.map +1 -1
- package/es/graph/animation/animation/grow-cartesian.js +11 -11
- package/es/graph/animation/animation/grow-cartesian.js.map +1 -1
- package/es/graph/animation/animation/grow-interval.js +18 -18
- package/es/graph/animation/animation/grow-interval.js.map +1 -1
- package/es/graph/animation/animation/grow-points.js +3 -3
- package/es/graph/animation/animation/grow-points.js.map +1 -1
- package/es/graph/animation/animation/grow-polar.js +8 -8
- package/es/graph/animation/animation/grow-polar.js.map +1 -1
- package/es/graph/animation/animation/move.js +9 -9
- package/es/graph/animation/animation/move.js.map +1 -1
- package/es/graph/animation/animation/update.js +1 -1
- package/es/graph/animation/animation/update.js.map +1 -1
- package/es/graph/animation/attribute.js +2 -2
- package/es/graph/animation/attribute.js.map +1 -1
- package/es/graph/attributes/helpers.js +8 -11
- package/es/graph/attributes/helpers.js.map +1 -1
- package/es/graph/attributes/transform.js +1 -1
- package/es/graph/attributes/transform.js.map +1 -1
- package/es/graph/element.js +1 -1
- package/es/graph/element.js.map +1 -1
- package/es/graph/layout/grid.js +1 -1
- package/es/graph/layout/grid.js.map +1 -1
- package/es/graph/mark/graphic.js +2 -2
- package/es/graph/mark/graphic.js.map +1 -1
- package/es/index.d.ts +1 -1
- package/es/index.js +1 -1
- package/es/index.js.map +1 -1
- package/es/interactions/brush-base.js +3 -5
- package/es/interactions/brush-base.js.map +1 -1
- package/es/interactions/view-navigation-base.js +3 -3
- package/es/interactions/view-navigation-base.js.map +1 -1
- package/es/interactions/view-roam.js +10 -10
- package/es/interactions/view-roam.js.map +1 -1
- package/es/interactions/view-scroll-mixin.js +1 -1
- package/es/interactions/view-scroll-mixin.js.map +1 -1
- package/es/interactions/view-zoom-mixin.js +2 -2
- package/es/interactions/view-zoom-mixin.js.map +1 -1
- package/es/parse/event.js +1 -1
- package/es/parse/event.js.map +1 -1
- package/es/parse/scale.js +4 -4
- package/es/parse/scale.js.map +1 -1
- package/es/parse/view.js +11 -10
- package/es/parse/view.js.map +1 -1
- package/es/view/View.js +12 -13
- package/es/view/View.js.map +1 -1
- package/es/view/animate.js +11 -11
- package/es/view/animate.js.map +1 -1
- package/es/view/mark.js +6 -10
- package/es/view/mark.js.map +1 -1
- package/package.json +6 -6
package/cjs/component/axis.js
CHANGED
|
@@ -41,7 +41,7 @@ exports.generateCircleAxisAttributes = generateCircleAxisAttributes;
|
|
|
41
41
|
const generateCoordinateAxisAttribute = (scale, coordinate, inside, baseValue, layout, isGrid) => {
|
|
42
42
|
var _a;
|
|
43
43
|
const axisPosition = scale.getCoordinateAxisPosition();
|
|
44
|
-
"auto" ===
|
|
44
|
+
layout && "auto" === layout.position && (layout.position = inside ? "content" : axisPosition);
|
|
45
45
|
const axisPoints = scale.getCoordinateAxisPoints(baseValue);
|
|
46
46
|
if (axisPoints) {
|
|
47
47
|
const res = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/component/axis.ts"],"names":[],"mappings":";;;AAAA,6CAA0D;AAI1D,qEAAgH;AAgBhH,0CAAyD;AAEzD,mCAAyC;AACzC,iDAAqD;AACrD,wCAAmD;AAEnD,6CAA0C;AAEnC,MAAM,0BAA0B,GAAG,CACxC,KAAiB,EACjB,KAAc,EACd,QAA+C,EAC/C,SAAkB,EACE,EAAE;;IACtB,MAAM,SAAS,GAAG,MAAA,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,UAAU,0CAAE,IAAI,mCAAI,EAAE,CAAC;IAChD,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,IAAA,cAAK,EAAC,EAAE,EAAE,SAAS,EAAE,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,EAAE,CAAC,CAAC;KAC7C;IACD,MAAM,QAAQ,GAAG,MAAA,MAAA,KAAK,CAAC,QAAQ,sDAAG,SAAS,CAAC,mCAAI,EAAE,CAAC;IAEnD,MAAM,KAAK,GAAG;QACZ,QAAQ,CAAC,GAAG,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C,UAAU,EACnB,CAAC,KAA2B,EAAE,EAAE,CAAC,IAAI,+BAAmB,CAAC,KAAK,CAAwB,CACvF,CAAC;IAEF,iBAAO,CAAC,iBAAiB,CAAC,qBAAa,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AACtD,CAAC,CAAC;AAZW,QAAA,YAAY,gBAYvB","file":"axis.js","sourcesContent":["import { isNil, isString, merge } from '@visactor/vutils';\nimport type { IGraphic } from '@visactor/vrender-core';\nimport type { CircleAxisAttributes, LineAxisAttributes, ComponentOptions } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport { CircleAxis as CircleAxisComponent, LineAxis as LineAxisComponent } from '@visactor/vrender-components';\nimport type { IBaseScale } from '@visactor/vscale';\nimport type {\n BaseSingleEncodeSpec,\n IElement,\n IGroupMark,\n IScale,\n ITheme,\n IView,\n MarkFunctionType,\n MarkRelativeItemSpec,\n Nil,\n RecursivePartial,\n SimpleSignalType,\n StateEncodeSpec\n} from '../types';\nimport { AxisEnum, ComponentEnum } from '../graph/enums';\nimport type { AxisSpec, AxisType, IAxis } from '../types/component';\nimport { ScaleComponent } from './scale';\nimport { invokeEncoder } from '../graph/mark/encode';\nimport { invokeFunctionType } from '../parse/util';\nimport type { IPolarCoordinate, IBaseCoordinate } from '@visactor/vgrammar-coordinate';\nimport { Factory } from '../core/factory';\n\nexport const generateLineAxisAttributes = (\n scale: IBaseScale,\n theme?: ITheme,\n addition?: RecursivePartial<LineAxisAttributes>,\n tickCount?: number\n): LineAxisAttributes => {\n const axisTheme = theme?.components?.axis ?? {};\n if (!scale) {\n return merge({}, axisTheme, addition ?? {});\n }\n const tickData = scale.tickData?.(tickCount) ?? [];\n\n const items = [\n tickData.map(tick => ({\n id: tick.index,\n label: tick.tick,\n value: tick.value,\n rawValue: tick.tick\n }))\n ];\n return merge({}, axisTheme, { items }, addition ?? {});\n};\n\nexport const generateCircleAxisAttributes = (\n scale: IBaseScale,\n theme?: ITheme,\n addition?: RecursivePartial<CircleAxisAttributes>,\n tickCount?: number\n): CircleAxisAttributes => {\n const axisTheme = theme?.components?.circleAxis ?? {};\n if (!scale) {\n return merge({}, axisTheme, addition ?? {});\n }\n const tickData = scale.tickData?.(tickCount) ?? [];\n const items = [\n tickData.map(tick => ({\n id: tick.index,\n label: tick.tick,\n value: tick.value,\n rawValue: tick.tick\n }))\n ];\n return merge({}, axisTheme, { items }, addition ?? {});\n};\n\nexport const generateCoordinateAxisAttribute = (\n scale: IScale,\n coordinate: IBaseCoordinate,\n inside: boolean,\n baseValue: number,\n layout: MarkRelativeItemSpec,\n isGrid?: boolean\n) => {\n const axisPosition = scale.getCoordinateAxisPosition();\n if (layout?.position === 'auto') {\n // FIXME: too hack\n layout.position = inside ? 'content' : axisPosition;\n }\n\n const axisPoints = scale.getCoordinateAxisPoints(baseValue);\n\n if (axisPoints) {\n const start = axisPoints[0];\n const end = axisPoints[1];\n const res: any = {\n start,\n end,\n verticalFactor:\n (axisPosition === 'top' || axisPosition === 'left' ? -1 : 1) *\n (inside ? -1 : 1) *\n (scale.getSpec().range?.reversed ? -1 : 1)\n };\n\n if (isGrid && coordinate.type === 'polar') {\n const angle = (coordinate as IPolarCoordinate).angle();\n\n res.center = (coordinate as IPolarCoordinate).origin();\n res.startAngle = angle[0];\n res.endAngle = angle[1];\n }\n\n return res;\n }\n\n const radius = (coordinate as IPolarCoordinate).radius();\n const angle = (coordinate as IPolarCoordinate).angle();\n return {\n center: (coordinate as IPolarCoordinate).origin(),\n radius: radius[1],\n innerRadius: radius[0],\n inside: inside,\n startAngle: angle[0],\n endAngle: angle[1]\n };\n};\n\nexport class Axis extends ScaleComponent implements IAxis {\n static readonly componentType: string = ComponentEnum.axis;\n\n protected declare spec: AxisSpec;\n\n private _axisComponentType: keyof typeof AxisEnum;\n\n constructor(view: IView, group?: IGroupMark, mode?: '2d' | '3d') {\n super(view, ComponentEnum.axis, group);\n this.spec.componentType = ComponentEnum.axis;\n this.mode = mode;\n }\n\n protected parseAddition(spec: AxisSpec) {\n super.parseAddition(spec);\n\n this.axisType(spec.axisType);\n this.tickCount(spec.tickCount);\n this.inside(spec.inside);\n this.baseValue(spec.baseValue);\n\n return this;\n }\n\n scale(scale?: IScale | string | Nil) {\n super.scale(scale);\n this._axisComponentType = null;\n return this;\n }\n\n axisType(axisType: AxisType | Nil) {\n this.spec.axisType = axisType;\n this._axisComponentType = null;\n this._prepareRejoin();\n this.commit();\n return this;\n }\n\n addGraphicItem(attrs: any, groupKey?: string) {\n const defaultAttributes = { x: 0, y: 0, start: { x: 0, y: 0 }, end: { x: 0, y: 0 } };\n const initialAttributes = merge(defaultAttributes, attrs);\n const graphicItem = Factory.createGraphicComponent(this._getAxisComponentType(), initialAttributes, {\n mode: this.mode,\n skipDefault: this.spec.skipTheme\n });\n return super.addGraphicItem(initialAttributes, groupKey, graphicItem);\n }\n\n tickCount(tickCount: SimpleSignalType<number> | Nil) {\n const scaleGrammar = isString(this.spec.scale) ? this.view.getScaleById(this.spec.scale) : this.spec.scale;\n\n if (scaleGrammar) {\n scaleGrammar.tickCount(tickCount);\n }\n\n return this.setFunctionSpec(tickCount, 'tickCount');\n }\n\n inside(inside: MarkFunctionType<boolean> | Nil) {\n return this.setFunctionSpec(inside, 'inside');\n }\n\n baseValue(baseValue: MarkFunctionType<number> | Nil) {\n return this.setFunctionSpec(baseValue, 'baseValue');\n }\n\n getAxisComponentType() {\n return this._axisComponentType;\n }\n\n protected _updateComponentEncoders() {\n const scaleGrammar = isString(this.spec.scale) ? this.view.getScaleById(this.spec.scale) : this.spec.scale;\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.spec.skipTheme ? null : this.view.getCurrentTheme();\n let addition = invokeEncoder(encoder as BaseSingleEncodeSpec, datum, element, parameters);\n const inside = invokeFunctionType(this.spec.inside, parameters, datum, element);\n const baseValue = invokeFunctionType(this.spec.baseValue, parameters, datum, element);\n\n const coordinate = scaleGrammar?.getCoordinate?.();\n if (coordinate) {\n addition = Object.assign(\n generateCoordinateAxisAttribute(\n scaleGrammar,\n coordinate,\n inside,\n baseValue,\n this.spec.layout as MarkRelativeItemSpec\n ),\n addition\n );\n }\n\n const scale = scaleGrammar?.getScale?.();\n const tickCount = invokeFunctionType(this.spec.tickCount, parameters, datum, element);\n\n switch (this._getAxisComponentType()) {\n case AxisEnum.lineAxis:\n return generateLineAxisAttributes(scale, theme, addition, tickCount);\n case AxisEnum.circleAxis:\n return generateCircleAxisAttributes(scale, theme, addition, tickCount);\n }\n return addition;\n }\n };\n }\n return res;\n }, {});\n this._encoders = componentEncoders;\n }\n\n private _getAxisComponentType() {\n if (this._axisComponentType) {\n return this._axisComponentType;\n }\n\n let type = this.spec.axisType;\n\n if (isNil(type)) {\n const scaleGrammar = isString(this.spec.scale) ? this.view.getScaleById(this.spec.scale) : this.spec.scale;\n\n type = scaleGrammar?.getCoordinate?.() ? (scaleGrammar.getCoordinateAxisPoints() ? 'line' : 'circle') : 'line';\n }\n\n this._axisComponentType = type === 'circle' ? AxisEnum.circleAxis : AxisEnum.lineAxis;\n\n return this._axisComponentType;\n }\n}\n\nexport const registerAxis = () => {\n Factory.registerGraphicComponent(\n AxisEnum.lineAxis,\n (attrs: LineAxisAttributes, options?: ComponentOptions) =>\n new LineAxisComponent(attrs, options) as unknown as IGraphic\n );\n Factory.registerGraphicComponent(\n AxisEnum.circleAxis,\n (attrs: CircleAxisAttributes) => new CircleAxisComponent(attrs) as unknown as IGraphic\n );\n\n Factory.registerComponent(ComponentEnum.axis, Axis);\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/component/axis.ts"],"names":[],"mappings":";;;AAAA,6CAA0D;AAI1D,qEAAgH;AAgBhH,0CAAyD;AAEzD,mCAAyC;AACzC,iDAAqD;AACrD,wCAAmD;AAEnD,6CAA0C;AAEnC,MAAM,0B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K,QAAQ,CAAC,CAAC,CAAC,gBAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,gBAAQ,CAAC,QAAQ,CAAC;QAEtF,OAAO,IAAI,CAAC,kBAAkB,CAAC;IACjC,CAAC;;AAnIH,oBAoIC;AAnIiB,kBAAa,GAAW,qBAAa,CAAC,IAAI,CAAC;AAqItD,MAAM,YAAY,GAAG,GAAG,EAAE;IAC/B,iBAAO,CAAC,wBAAwB,CAC9B,gBAAQ,CAAC,QAAQ,EACjB,CAAC,KAAyB,EAAE,OAA0B,EAAE,EAAE,CACxD,IAAI,6BAAiB,CAAC,KAAK,EAAE,OAAO,CAAwB,CAC/D,CAAC;IACF,iBAAO,CAAC,wBAAwB,CAC9B,gBAAQ,CAAC,UAAU,EACnB,CAAC,KAA2B,EAAE,EAAE,CAAC,IAAI,+BAAmB,CAAC,KAAK,CAAwB,CACvF,CAAC;IAEF,iBAAO,CAAC,iBAAiB,CAAC,qBAAa,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AACtD,CAAC,CAAC;AAZW,QAAA,YAAY,gBAYvB","file":"axis.js","sourcesContent":["import { isNil, isString, merge } from '@visactor/vutils';\nimport type { IGraphic } from '@visactor/vrender-core';\nimport type { CircleAxisAttributes, LineAxisAttributes, ComponentOptions } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport { CircleAxis as CircleAxisComponent, LineAxis as LineAxisComponent } from '@visactor/vrender-components';\nimport type { IBaseScale } from '@visactor/vscale';\nimport type {\n BaseSingleEncodeSpec,\n IElement,\n IGroupMark,\n IScale,\n ITheme,\n IView,\n MarkFunctionType,\n MarkRelativeItemSpec,\n Nil,\n RecursivePartial,\n SimpleSignalType,\n StateEncodeSpec\n} from '../types';\nimport { AxisEnum, ComponentEnum } from '../graph/enums';\nimport type { AxisSpec, AxisType, IAxis } from '../types/component';\nimport { ScaleComponent } from './scale';\nimport { invokeEncoder } from '../graph/mark/encode';\nimport { invokeFunctionType } from '../parse/util';\nimport type { IPolarCoordinate, IBaseCoordinate } from '@visactor/vgrammar-coordinate';\nimport { Factory } from '../core/factory';\n\nexport const generateLineAxisAttributes = (\n scale: IBaseScale,\n theme?: ITheme,\n addition?: RecursivePartial<LineAxisAttributes>,\n tickCount?: number\n): LineAxisAttributes => {\n const axisTheme = theme?.components?.axis ?? {};\n if (!scale) {\n return merge({}, axisTheme, addition ?? {});\n }\n const tickData = scale.tickData?.(tickCount) ?? [];\n\n const items = [\n tickData.map(tick => ({\n id: tick.index,\n label: tick.tick,\n value: tick.value,\n rawValue: tick.tick\n }))\n ];\n return merge({}, axisTheme, { items }, addition ?? {});\n};\n\nexport const generateCircleAxisAttributes = (\n scale: IBaseScale,\n theme?: ITheme,\n addition?: RecursivePartial<CircleAxisAttributes>,\n tickCount?: number\n): CircleAxisAttributes => {\n const axisTheme = theme?.components?.circleAxis ?? {};\n if (!scale) {\n return merge({}, axisTheme, addition ?? {});\n }\n const tickData = scale.tickData?.(tickCount) ?? [];\n const items = [\n tickData.map(tick => ({\n id: tick.index,\n label: tick.tick,\n value: tick.value,\n rawValue: tick.tick\n }))\n ];\n return merge({}, axisTheme, { items }, addition ?? {});\n};\n\nexport const generateCoordinateAxisAttribute = (\n scale: IScale,\n coordinate: IBaseCoordinate,\n inside: boolean,\n baseValue: number,\n layout: MarkRelativeItemSpec,\n isGrid?: boolean\n) => {\n const axisPosition = scale.getCoordinateAxisPosition();\n if (layout && layout.position === 'auto') {\n // FIXME: too hack\n layout.position = inside ? 'content' : axisPosition;\n }\n\n const axisPoints = scale.getCoordinateAxisPoints(baseValue);\n\n if (axisPoints) {\n const start = axisPoints[0];\n const end = axisPoints[1];\n const res: any = {\n start,\n end,\n verticalFactor:\n (axisPosition === 'top' || axisPosition === 'left' ? -1 : 1) *\n (inside ? -1 : 1) *\n (scale.getSpec().range?.reversed ? -1 : 1)\n };\n\n if (isGrid && coordinate.type === 'polar') {\n const angle = (coordinate as IPolarCoordinate).angle();\n\n res.center = (coordinate as IPolarCoordinate).origin();\n res.startAngle = angle[0];\n res.endAngle = angle[1];\n }\n\n return res;\n }\n\n const radius = (coordinate as IPolarCoordinate).radius();\n const angle = (coordinate as IPolarCoordinate).angle();\n return {\n center: (coordinate as IPolarCoordinate).origin(),\n radius: radius[1],\n innerRadius: radius[0],\n inside: inside,\n startAngle: angle[0],\n endAngle: angle[1]\n };\n};\n\nexport class Axis extends ScaleComponent implements IAxis {\n static readonly componentType: string = ComponentEnum.axis;\n\n protected declare spec: AxisSpec;\n\n private _axisComponentType: keyof typeof AxisEnum;\n\n constructor(view: IView, group?: IGroupMark, mode?: '2d' | '3d') {\n super(view, ComponentEnum.axis, group);\n this.spec.componentType = ComponentEnum.axis;\n this.mode = mode;\n }\n\n protected parseAddition(spec: AxisSpec) {\n super.parseAddition(spec);\n\n this.axisType(spec.axisType);\n this.tickCount(spec.tickCount);\n this.inside(spec.inside);\n this.baseValue(spec.baseValue);\n\n return this;\n }\n\n scale(scale?: IScale | string | Nil) {\n super.scale(scale);\n this._axisComponentType = null;\n return this;\n }\n\n axisType(axisType: AxisType | Nil) {\n this.spec.axisType = axisType;\n this._axisComponentType = null;\n this._prepareRejoin();\n this.commit();\n return this;\n }\n\n addGraphicItem(attrs: any, groupKey?: string) {\n const defaultAttributes = { x: 0, y: 0, start: { x: 0, y: 0 }, end: { x: 0, y: 0 } };\n const initialAttributes = merge(defaultAttributes, attrs);\n const graphicItem = Factory.createGraphicComponent(this._getAxisComponentType(), initialAttributes, {\n mode: this.mode,\n skipDefault: this.spec.skipTheme\n });\n return super.addGraphicItem(initialAttributes, groupKey, graphicItem);\n }\n\n tickCount(tickCount: SimpleSignalType<number> | Nil) {\n const scaleGrammar = isString(this.spec.scale) ? this.view.getScaleById(this.spec.scale) : this.spec.scale;\n\n if (scaleGrammar) {\n scaleGrammar.tickCount(tickCount);\n }\n\n return this.setFunctionSpec(tickCount, 'tickCount');\n }\n\n inside(inside: MarkFunctionType<boolean> | Nil) {\n return this.setFunctionSpec(inside, 'inside');\n }\n\n baseValue(baseValue: MarkFunctionType<number> | Nil) {\n return this.setFunctionSpec(baseValue, 'baseValue');\n }\n\n getAxisComponentType() {\n return this._axisComponentType;\n }\n\n protected _updateComponentEncoders() {\n const scaleGrammar = isString(this.spec.scale) ? this.view.getScaleById(this.spec.scale) : this.spec.scale;\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.spec.skipTheme ? null : this.view.getCurrentTheme();\n let addition = invokeEncoder(encoder as BaseSingleEncodeSpec, datum, element, parameters);\n const inside = invokeFunctionType(this.spec.inside, parameters, datum, element);\n const baseValue = invokeFunctionType(this.spec.baseValue, parameters, datum, element);\n\n const coordinate = scaleGrammar?.getCoordinate?.();\n if (coordinate) {\n addition = Object.assign(\n generateCoordinateAxisAttribute(\n scaleGrammar,\n coordinate,\n inside,\n baseValue,\n this.spec.layout as MarkRelativeItemSpec\n ),\n addition\n );\n }\n\n const scale = scaleGrammar?.getScale?.();\n const tickCount = invokeFunctionType(this.spec.tickCount, parameters, datum, element);\n\n switch (this._getAxisComponentType()) {\n case AxisEnum.lineAxis:\n return generateLineAxisAttributes(scale, theme, addition, tickCount);\n case AxisEnum.circleAxis:\n return generateCircleAxisAttributes(scale, theme, addition, tickCount);\n }\n return addition;\n }\n };\n }\n return res;\n }, {});\n this._encoders = componentEncoders;\n }\n\n private _getAxisComponentType() {\n if (this._axisComponentType) {\n return this._axisComponentType;\n }\n\n let type = this.spec.axisType;\n\n if (isNil(type)) {\n const scaleGrammar = isString(this.spec.scale) ? this.view.getScaleById(this.spec.scale) : this.spec.scale;\n\n type = scaleGrammar?.getCoordinate?.() ? (scaleGrammar.getCoordinateAxisPoints() ? 'line' : 'circle') : 'line';\n }\n\n this._axisComponentType = type === 'circle' ? AxisEnum.circleAxis : AxisEnum.lineAxis;\n\n return this._axisComponentType;\n }\n}\n\nexport const registerAxis = () => {\n Factory.registerGraphicComponent(\n AxisEnum.lineAxis,\n (attrs: LineAxisAttributes, options?: ComponentOptions) =>\n new LineAxisComponent(attrs, options) as unknown as IGraphic\n );\n Factory.registerGraphicComponent(\n AxisEnum.circleAxis,\n (attrs: CircleAxisAttributes) => new CircleAxisComponent(attrs) as unknown as IGraphic\n );\n\n Factory.registerComponent(ComponentEnum.axis, Axis);\n};\n"]}
|
|
@@ -19,9 +19,10 @@ class Datazoom extends component_1.Component {
|
|
|
19
19
|
super(view, enums_1.ComponentEnum.datazoom, group), this.spec.componentType = enums_1.ComponentEnum.datazoom;
|
|
20
20
|
}
|
|
21
21
|
parseAddition(spec) {
|
|
22
|
-
var _a
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
var _a;
|
|
23
|
+
super.parseAddition(spec);
|
|
24
|
+
const {data: data, x: x, y: y, x1: x1, y1: y1} = null !== (_a = spec.preview) && void 0 !== _a ? _a : {};
|
|
25
|
+
return this.preview(data, x, y, x1, y1), this._updateComponentEncoders(), this;
|
|
25
26
|
}
|
|
26
27
|
preview(data, x, y, x1, y1) {
|
|
27
28
|
if (!(0, vutils_1.isNil)(this.spec.preview)) {
|
|
@@ -46,14 +47,12 @@ class Datazoom extends component_1.Component {
|
|
|
46
47
|
return this._updateComponentEncoders(), this.commit(), this;
|
|
47
48
|
}
|
|
48
49
|
setStartEndValue(start, end) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return null === (_c = null == datazoom ? void 0 : datazoom.setStartAndEnd) || void 0 === _c || _c.call(datazoom, start, end),
|
|
50
|
+
const datazoom = this.getGroupGraphicItem();
|
|
51
|
+
return datazoom && datazoom.setStartAndEnd && datazoom.setStartAndEnd(start, end),
|
|
52
52
|
this;
|
|
53
53
|
}
|
|
54
54
|
getStartEndValue() {
|
|
55
|
-
|
|
56
|
-
const datazoom = null === (_b = null === (_a = this.elements[0]) || void 0 === _a ? void 0 : _a.getGraphicItem) || void 0 === _b ? void 0 : _b.call(_a);
|
|
55
|
+
const datazoom = this.getGroupGraphicItem();
|
|
57
56
|
if (datazoom) {
|
|
58
57
|
const state = datazoom.state;
|
|
59
58
|
return {
|
|
@@ -64,36 +63,30 @@ class Datazoom extends component_1.Component {
|
|
|
64
63
|
return null;
|
|
65
64
|
}
|
|
66
65
|
addGraphicItem(attrs, groupKey) {
|
|
67
|
-
var _a;
|
|
66
|
+
var _a, _b;
|
|
68
67
|
const theme = this.spec.skipTheme ? null : this.view.getCurrentTheme(), initialAttributes = Object.assign({}, null === (_a = null == theme ? void 0 : theme.components) || void 0 === _a ? void 0 : _a.datazoom, attrs), graphicItem = factory_1.Factory.createGraphicComponent(this.componentType, initialAttributes, {
|
|
69
68
|
skipDefault: this.spec.skipTheme
|
|
70
69
|
}), datazoom = graphicItem;
|
|
71
|
-
|
|
70
|
+
datazoom.setStatePointToData((state => {
|
|
72
71
|
var _a;
|
|
73
72
|
return this.spec.preview && null !== (_a = this.invertDatazoomRatio(state)) && void 0 !== _a ? _a : state;
|
|
74
|
-
}))
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
encode_1.invokeEncoder)({
|
|
78
|
-
x:
|
|
73
|
+
}));
|
|
74
|
+
const {data: data, x: x, y: y, x1: x1, y1: y1} = null !== (_b = this.spec.preview) && void 0 !== _b ? _b : {};
|
|
75
|
+
return datazoom.setPreviewPointsX((datum => {
|
|
76
|
+
if (x && data) return (0, encode_1.invokeEncoder)({
|
|
77
|
+
x: x
|
|
79
78
|
}, datum, this.elements[0], this.parameters()).x;
|
|
80
79
|
})), datazoom.setPreviewPointsY((datum => {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
encode_1.invokeEncoder)({
|
|
84
|
-
y: this.spec.preview.y
|
|
80
|
+
if (y && data) return (0, encode_1.invokeEncoder)({
|
|
81
|
+
y: y
|
|
85
82
|
}, datum, this.elements[0], this.parameters()).y;
|
|
86
83
|
})), datazoom.setPreviewPointsX1((datum => {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
encode_1.invokeEncoder)({
|
|
90
|
-
x1: this.spec.preview.x1
|
|
84
|
+
if (x1 && data) return (0, encode_1.invokeEncoder)({
|
|
85
|
+
x1: x1
|
|
91
86
|
}, datum, this.elements[0], this.parameters()).x1;
|
|
92
87
|
})), datazoom.setPreviewPointsY1((datum => {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
encode_1.invokeEncoder)({
|
|
96
|
-
y1: this.spec.preview.y1
|
|
88
|
+
if (y1 && data) return (0, encode_1.invokeEncoder)({
|
|
89
|
+
y1: y1
|
|
97
90
|
}, datum, this.elements[0], this.parameters()).y1;
|
|
98
91
|
})), super.addGraphicItem(initialAttributes, groupKey, graphicItem);
|
|
99
92
|
}
|
|
@@ -124,10 +117,10 @@ class Datazoom extends component_1.Component {
|
|
|
124
117
|
return null;
|
|
125
118
|
}
|
|
126
119
|
getDatazoomMainScale() {
|
|
127
|
-
var _a, _b
|
|
128
|
-
const datazoom =
|
|
120
|
+
var _a, _b;
|
|
121
|
+
const datazoom = this.getGroupGraphicItem();
|
|
129
122
|
if (datazoom && this.spec.preview) {
|
|
130
|
-
const scale = "top" === datazoom.attribute.orient || "bottom" === datazoom.attribute.orient ? null === (
|
|
123
|
+
const scale = "top" === datazoom.attribute.orient || "bottom" === datazoom.attribute.orient ? null === (_a = this.spec.preview.x) || void 0 === _a ? void 0 : _a.scale : null === (_b = this.spec.preview.y) || void 0 === _b ? void 0 : _b.scale, scaleGrammar = (0,
|
|
131
124
|
vutils_1.isString)(scale) ? this.view.getScaleById(scale) : scale;
|
|
132
125
|
return null == scaleGrammar ? void 0 : scaleGrammar.getScale();
|
|
133
126
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/component/datazoom.ts"],"names":[],"mappings":";;;AAGA,qEAA6E;AAC7E,6CAAiE;AACjE,0CAA+C;AAe/C,iDAAqD;AACrD,iDAA8C;AAC9C,wCAAgD;AAChD,6CAA0C;AAC1C,q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EAAE,CAAC;SACjC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;;AAxJH,4BAyJC;AAxJiB,sBAAa,GAAW,qBAAa,CAAC,QAAQ,CAAC;AA0J1D,MAAM,gBAAgB,GAAG,GAAG,EAAE;IACnC,iBAAO,CAAC,wBAAwB,CAC9B,qBAAa,CAAC,QAAQ,EACtB,CAAC,KAAyB,EAAE,EAAE,CAAC,IAAI,6BAAiB,CAAC,KAAK,CAAwB,CACnF,CAAC;IAEF,iBAAO,CAAC,iBAAiB,CAAC,qBAAa,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAE5D,IAAA,cAAK,EAAC,eAAM,EAAE,oBAAW,CAAC,CAAC;IAC3B,iBAAO,CAAC,mBAAmB,CAAC,gCAAc,CAAC,IAAI,EAAE,gCAAc,CAAC,CAAC;AACnE,CAAC,CAAC;AAVW,QAAA,gBAAgB,oBAU3B","file":"datazoom.js","sourcesContent":["import type { IGraphic } from '@visactor/vrender-core';\nimport type { DataZoomAttributes } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport { DataZoom as DatazoomComponent } from '@visactor/vrender-components';\nimport { isNil, isString, merge, mixin } from '@visactor/vutils';\nimport { ComponentEnum } from '../graph/enums';\nimport type {\n BaseSingleEncodeSpec,\n ChannelEncodeType,\n IData,\n IElement,\n IGroupMark,\n ITheme,\n IView,\n Nil,\n RecursivePartial,\n ScaleEncodeType,\n StateEncodeSpec\n} from '../types';\nimport type { DatazoomSpec, IDatazoom } from '../types/component';\nimport { invokeEncoder } from '../graph/mark/encode';\nimport { Component } from '../view/component';\nimport { parseEncodeType } from '../parse/mark';\nimport { Factory } from '../core/factory';\nimport { DatazoomFilter } from '../interactions/datazoom-filter';\nimport { Filter, FilterMixin } from '../interactions/filter';\n\nexport const generateDatazoomAttributes = (\n data: any[],\n theme?: ITheme,\n addition?: RecursivePartial<DataZoomAttributes>\n): DataZoomAttributes => {\n const datazoomTheme = theme?.components?.datazoom;\n if (!data) {\n return merge({}, datazoomTheme, addition ?? {});\n }\n\n return merge({}, datazoomTheme, { previewData: data }, addition ?? {});\n};\n\nexport class Datazoom extends Component implements IDatazoom {\n static readonly componentType: string = ComponentEnum.datazoom;\n protected declare spec: DatazoomSpec;\n\n constructor(view: IView, group?: IGroupMark) {\n super(view, ComponentEnum.datazoom, group);\n this.spec.componentType = ComponentEnum.datazoom;\n }\n\n protected parseAddition(spec: DatazoomSpec) {\n super.parseAddition(spec);\n this.preview(spec.preview?.data, spec.preview?.x, spec.preview?.y, spec.preview?.x1, spec.preview?.y1);\n this._updateComponentEncoders();\n return this;\n }\n\n preview(\n data: IData | string | Nil,\n x: ScaleEncodeType | Nil,\n y: ScaleEncodeType | Nil,\n x1?: ChannelEncodeType | Nil,\n y1?: ChannelEncodeType | Nil\n ) {\n if (!isNil(this.spec.preview)) {\n const lastData = this.spec.preview.data;\n const lastDataGrammar = isString(lastData) ? this.view.getDataById(lastData) : lastData;\n this.detach(lastDataGrammar);\n this.detach(parseEncodeType(this.spec.preview.x, this.view));\n this.detach(parseEncodeType(this.spec.preview.y, this.view));\n this.detach(parseEncodeType(this.spec.preview.x1, this.view));\n this.detach(parseEncodeType(this.spec.preview.y1, this.view));\n }\n this.spec.preview = undefined;\n if (data) {\n this.spec.preview = { data, x, y, x1, y1 };\n const dataGrammar = isString(data) ? this.view.getDataById(data) : data;\n this.attach(dataGrammar);\n this.attach(parseEncodeType(x, this.view));\n this.attach(parseEncodeType(y, this.view));\n this.attach(parseEncodeType(x1, this.view));\n this.attach(parseEncodeType(y1, this.view));\n }\n this._updateComponentEncoders();\n this.commit();\n return this;\n }\n\n setStartEndValue(start?: number, end?: number) {\n const datazoom = this.elements[0]?.getGraphicItem?.() as unknown as DatazoomComponent;\n datazoom?.setStartAndEnd?.(start, end);\n return this;\n }\n\n getStartEndValue() {\n const datazoom = this.elements[0]?.getGraphicItem?.() as unknown as DatazoomComponent;\n\n if (datazoom) {\n const state = datazoom.state;\n return {\n start: state.start,\n end: state.end\n };\n }\n\n return null;\n }\n\n addGraphicItem(attrs: any, groupKey?: string) {\n const theme = this.spec.skipTheme ? null : this.view.getCurrentTheme();\n const initialAttributes = Object.assign({}, theme?.components?.datazoom, attrs);\n const graphicItem = Factory.createGraphicComponent(this.componentType, initialAttributes, {\n skipDefault: this.spec.skipTheme\n });\n const datazoom = graphicItem as unknown as DatazoomComponent;\n datazoom.setStatePointToData(state => {\n if (this.spec.preview) {\n return this.invertDatazoomRatio(state) ?? state;\n }\n return state;\n });\n\n datazoom.setPreviewPointsX((datum: any) => {\n if (this.spec.preview?.x && this.spec.preview?.data) {\n return invokeEncoder({ x: this.spec.preview.x }, datum, this.elements[0], this.parameters()).x;\n }\n\n return undefined;\n });\n datazoom.setPreviewPointsY((datum: any) => {\n if (this.spec.preview?.y && this.spec.preview?.data) {\n return invokeEncoder({ y: this.spec.preview.y }, datum, this.elements[0], this.parameters()).y;\n }\n\n return undefined;\n });\n\n datazoom.setPreviewPointsX1((datum: any) => {\n if (this.spec.preview?.x1 && this.spec.preview?.data) {\n return invokeEncoder({ x1: this.spec.preview.x1 }, datum, this.elements[0], this.parameters()).x1;\n }\n\n return undefined;\n });\n datazoom.setPreviewPointsY1((datum: any) => {\n if (this.spec.preview?.y1 && this.spec.preview?.data) {\n return invokeEncoder({ y1: this.spec.preview.y1 }, datum, this.elements[0], this.parameters()).y1;\n }\n\n return undefined;\n });\n return super.addGraphicItem(initialAttributes, groupKey, graphicItem);\n }\n\n protected _updateComponentEncoders() {\n const data = this.spec.preview?.data;\n const dataGrammar = isString(data) ? this.view.getDataById(data) : data;\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.spec.skipTheme ? null : this.view.getCurrentTheme();\n const addition = invokeEncoder(encoder as BaseSingleEncodeSpec, datum, element, parameters);\n return generateDatazoomAttributes(dataGrammar?.getValue?.(), theme, addition);\n }\n };\n }\n return res;\n }, {});\n this._encoders = componentEncoders;\n }\n\n invertDatazoomRatio(ratio: number): any {\n const scale = this.getDatazoomMainScale();\n if (scale) {\n const range = scale.range();\n const scaledValue = (range[range.length - 1] - range[0]) * ratio + range[0];\n return scale.invert(scaledValue);\n }\n return null;\n }\n\n getDatazoomMainScale() {\n const datazoom = this.elements[0]?.getGraphicItem?.() as unknown as DatazoomComponent;\n if (datazoom && this.spec.preview) {\n const isHorizontal = datazoom.attribute.orient === 'top' || datazoom.attribute.orient === 'bottom';\n const scale = isHorizontal ? this.spec.preview.x?.scale : this.spec.preview.y?.scale;\n const scaleGrammar = isString(scale) ? this.view.getScaleById(scale) : scale;\n return scaleGrammar?.getScale();\n }\n return null;\n }\n}\n\nexport const registerDataZoom = () => {\n Factory.registerGraphicComponent(\n ComponentEnum.datazoom,\n (attrs: DataZoomAttributes) => new DatazoomComponent(attrs) as unknown as IGraphic\n );\n\n Factory.registerComponent(ComponentEnum.datazoom, Datazoom);\n\n mixin(Filter, FilterMixin);\n Factory.registerInteraction(DatazoomFilter.type, DatazoomFilter);\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/component/datazoom.ts"],"names":[],"mappings":";;;AAGA,qEAA6E;AAC7E,6CAAiE;AACjE,0CAA+C;AAe/C,iDAAqD;AACrD,iDAA8C;AAC9C,wCAAgD;AAChD,6CAA0C;AAC1C,qEAAiE;AACjE,mDAA6D;AAEtD,MAAM,0BAA0B,GAAG,CACxC,IAAW,EACX,KAAc,EACd,QAA+C,EAC3B,EAAE;;IACtB,MAAM,aAAa,GAAG,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,UAAU,0CAAE,QAAQ,CAAC;IAClD,IAAI,CAAC,IAAI,EAAE;QACT,OAAO,IAAA,cAAK,EAAC,EAAE,EAAE,aAAa,EAAE,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,EAAE,CAAC,CAAC;KACj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KAAK,CAAC,CAAC,CAAC,MAAA,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,0CAAE,KAAK,CAAC;YACrF,MAAM,YAAY,GAAG,IAAA,iBAAQ,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;YAC7E,OAAO,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,QAAQ,EAAE,CAAC;SACjC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;;AA3JH,4BA4JC;AA3JiB,sBAAa,GAAW,qBAAa,CAAC,QAAQ,CAAC;AA6J1D,MAAM,gBAAgB,GAAG,GAAG,EAAE;IACnC,iBAAO,CAAC,wBAAwB,CAC9B,qBAAa,CAAC,QAAQ,EACtB,CAAC,KAAyB,EAAE,EAAE,CAAC,IAAI,6BAAiB,CAAC,KAAK,CAAwB,CACnF,CAAC;IAEF,iBAAO,CAAC,iBAAiB,CAAC,qBAAa,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAE5D,IAAA,cAAK,EAAC,eAAM,EAAE,oBAAW,CAAC,CAAC;IAC3B,iBAAO,CAAC,mBAAmB,CAAC,gCAAc,CAAC,IAAI,EAAE,gCAAc,CAAC,CAAC;AACnE,CAAC,CAAC;AAVW,QAAA,gBAAgB,oBAU3B","file":"datazoom.js","sourcesContent":["import type { IGraphic } from '@visactor/vrender-core';\nimport type { DataZoomAttributes } from '@visactor/vrender-components';\n// eslint-disable-next-line no-duplicate-imports\nimport { DataZoom as DatazoomComponent } from '@visactor/vrender-components';\nimport { isNil, isString, merge, mixin } from '@visactor/vutils';\nimport { ComponentEnum } from '../graph/enums';\nimport type {\n BaseSingleEncodeSpec,\n ChannelEncodeType,\n IData,\n IElement,\n IGroupMark,\n ITheme,\n IView,\n Nil,\n RecursivePartial,\n ScaleEncodeType,\n StateEncodeSpec\n} from '../types';\nimport type { DatazoomSpec, IDatazoom } from '../types/component';\nimport { invokeEncoder } from '../graph/mark/encode';\nimport { Component } from '../view/component';\nimport { parseEncodeType } from '../parse/mark';\nimport { Factory } from '../core/factory';\nimport { DatazoomFilter } from '../interactions/datazoom-filter';\nimport { Filter, FilterMixin } from '../interactions/filter';\n\nexport const generateDatazoomAttributes = (\n data: any[],\n theme?: ITheme,\n addition?: RecursivePartial<DataZoomAttributes>\n): DataZoomAttributes => {\n const datazoomTheme = theme?.components?.datazoom;\n if (!data) {\n return merge({}, datazoomTheme, addition ?? {});\n }\n\n return merge({}, datazoomTheme, { previewData: data }, addition ?? {});\n};\n\nexport class Datazoom extends Component implements IDatazoom {\n static readonly componentType: string = ComponentEnum.datazoom;\n protected declare spec: DatazoomSpec;\n\n constructor(view: IView, group?: IGroupMark) {\n super(view, ComponentEnum.datazoom, group);\n this.spec.componentType = ComponentEnum.datazoom;\n }\n\n protected parseAddition(spec: DatazoomSpec) {\n super.parseAddition(spec);\n const { data, x, y, x1, y1 } = spec.preview ?? {};\n this.preview(data, x, y, x1, y1);\n this._updateComponentEncoders();\n return this;\n }\n\n preview(\n data: IData | string | Nil,\n x: ScaleEncodeType | Nil,\n y: ScaleEncodeType | Nil,\n x1?: ChannelEncodeType | Nil,\n y1?: ChannelEncodeType | Nil\n ) {\n if (!isNil(this.spec.preview)) {\n const lastData = this.spec.preview.data;\n const lastDataGrammar = isString(lastData) ? this.view.getDataById(lastData) : lastData;\n this.detach(lastDataGrammar);\n this.detach(parseEncodeType(this.spec.preview.x, this.view));\n this.detach(parseEncodeType(this.spec.preview.y, this.view));\n this.detach(parseEncodeType(this.spec.preview.x1, this.view));\n this.detach(parseEncodeType(this.spec.preview.y1, this.view));\n }\n this.spec.preview = undefined;\n if (data) {\n this.spec.preview = { data, x, y, x1, y1 };\n const dataGrammar = isString(data) ? this.view.getDataById(data) : data;\n this.attach(dataGrammar);\n this.attach(parseEncodeType(x, this.view));\n this.attach(parseEncodeType(y, this.view));\n this.attach(parseEncodeType(x1, this.view));\n this.attach(parseEncodeType(y1, this.view));\n }\n this._updateComponentEncoders();\n this.commit();\n return this;\n }\n\n setStartEndValue(start?: number, end?: number) {\n const datazoom = this.getGroupGraphicItem() as unknown as DatazoomComponent;\n if (datazoom && datazoom.setStartAndEnd) {\n datazoom.setStartAndEnd(start, end);\n }\n return this;\n }\n\n getStartEndValue() {\n const datazoom = this.getGroupGraphicItem() as unknown as DatazoomComponent;\n if (datazoom) {\n const state = datazoom.state;\n return {\n start: state.start,\n end: state.end\n };\n }\n\n return null;\n }\n\n addGraphicItem(attrs: any, groupKey?: string) {\n const theme = this.spec.skipTheme ? null : this.view.getCurrentTheme();\n const initialAttributes = Object.assign({}, theme?.components?.datazoom, attrs);\n const graphicItem = Factory.createGraphicComponent(this.componentType, initialAttributes, {\n skipDefault: this.spec.skipTheme\n });\n const datazoom = graphicItem as unknown as DatazoomComponent;\n datazoom.setStatePointToData(state => {\n if (this.spec.preview) {\n return this.invertDatazoomRatio(state) ?? state;\n }\n return state;\n });\n const { data, x, y, x1, y1 } = this.spec.preview ?? {};\n\n datazoom.setPreviewPointsX((datum: any) => {\n if (x && data) {\n return invokeEncoder({ x }, datum, this.elements[0], this.parameters()).x;\n }\n\n return undefined;\n });\n datazoom.setPreviewPointsY((datum: any) => {\n if (y && data) {\n return invokeEncoder({ y }, datum, this.elements[0], this.parameters()).y;\n }\n\n return undefined;\n });\n\n datazoom.setPreviewPointsX1((datum: any) => {\n if (x1 && data) {\n return invokeEncoder({ x1 }, datum, this.elements[0], this.parameters()).x1;\n }\n\n return undefined;\n });\n datazoom.setPreviewPointsY1((datum: any) => {\n if (y1 && data) {\n return invokeEncoder({ y1 }, datum, this.elements[0], this.parameters()).y1;\n }\n\n return undefined;\n });\n return super.addGraphicItem(initialAttributes, groupKey, graphicItem);\n }\n\n protected _updateComponentEncoders() {\n const data = this.spec.preview?.data;\n const dataGrammar = isString(data) ? this.view.getDataById(data) : data;\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.spec.skipTheme ? null : this.view.getCurrentTheme();\n const addition = invokeEncoder(encoder as BaseSingleEncodeSpec, datum, element, parameters);\n return generateDatazoomAttributes(dataGrammar?.getValue?.(), theme, addition);\n }\n };\n }\n return res;\n }, {});\n this._encoders = componentEncoders;\n }\n\n invertDatazoomRatio(ratio: number): any {\n const scale = this.getDatazoomMainScale();\n if (scale) {\n const range = scale.range();\n const scaledValue = (range[range.length - 1] - range[0]) * ratio + range[0];\n return scale.invert(scaledValue);\n }\n return null;\n }\n\n getDatazoomMainScale() {\n const datazoom = this.getGroupGraphicItem() as unknown as DatazoomComponent;\n if (datazoom && this.spec.preview) {\n const isHorizontal = datazoom.attribute.orient === 'top' || datazoom.attribute.orient === 'bottom';\n const scale = isHorizontal ? this.spec.preview.x?.scale : this.spec.preview.y?.scale;\n const scaleGrammar = isString(scale) ? this.view.getScaleById(scale) : scale;\n return scaleGrammar?.getScale();\n }\n return null;\n }\n}\n\nexport const registerDataZoom = () => {\n Factory.registerGraphicComponent(\n ComponentEnum.datazoom,\n (attrs: DataZoomAttributes) => new DatazoomComponent(attrs) as unknown as IGraphic\n );\n\n Factory.registerComponent(ComponentEnum.datazoom, Datazoom);\n\n mixin(Filter, FilterMixin);\n Factory.registerInteraction(DatazoomFilter.type, DatazoomFilter);\n};\n"]}
|
package/cjs/component/label.js
CHANGED
|
@@ -4,43 +4,43 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: !0
|
|
5
5
|
}), exports.registerLabel = exports.Label = exports.generateLabelAttributes = void 0;
|
|
6
6
|
|
|
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"), generateLabelAttributes = (marks, groupSize, encoder, labelStyle, parameters, theme) => {
|
|
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"), generateLabelAttributes = (marks, groupSize, encoder, labelStyle, parameters, theme = {}) => {
|
|
8
8
|
var _a;
|
|
9
|
-
const labelTheme = null === (_a =
|
|
10
|
-
var _a, _b, _c, _d, _e
|
|
9
|
+
const labelTheme = null === (_a = theme.components) || void 0 === _a ? void 0 : _a.dataLabel, dataLabels = marks.map(((mark, index) => {
|
|
10
|
+
var _a, _b, _c, _d, _e;
|
|
11
11
|
const labelParameters = Object.assign(Object.assign({}, parameters), {
|
|
12
12
|
labelIndex: index
|
|
13
|
-
}), addition = (0, util_1.invokeFunctionType)(labelStyle, labelParameters, mark);
|
|
13
|
+
}), addition = null !== (_a = (0, util_1.invokeFunctionType)(labelStyle, labelParameters, mark)) && void 0 !== _a ? _a : {}, {components: components = {}} = theme;
|
|
14
14
|
let currentTheme = {};
|
|
15
15
|
switch (mark.markType) {
|
|
16
16
|
case enums_1.GrammarMarkType.line:
|
|
17
17
|
case enums_1.GrammarMarkType.area:
|
|
18
|
-
currentTheme = "line" ===
|
|
18
|
+
currentTheme = "line" === addition.type ? components.lineLabel : "area" === addition.type ? components.areaLabel : components.lineDataLabel;
|
|
19
19
|
break;
|
|
20
20
|
|
|
21
21
|
case enums_1.GrammarMarkType.rect:
|
|
22
22
|
case enums_1.GrammarMarkType.rect3d:
|
|
23
23
|
case enums_1.GrammarMarkType.interval:
|
|
24
|
-
currentTheme =
|
|
24
|
+
currentTheme = components.rectLabel;
|
|
25
25
|
break;
|
|
26
26
|
|
|
27
27
|
case enums_1.GrammarMarkType.symbol:
|
|
28
28
|
case enums_1.GrammarMarkType.circle:
|
|
29
29
|
case enums_1.GrammarMarkType.cell:
|
|
30
|
-
currentTheme =
|
|
30
|
+
currentTheme = components.symbolLabel;
|
|
31
31
|
break;
|
|
32
32
|
|
|
33
33
|
case enums_1.GrammarMarkType.arc:
|
|
34
34
|
case enums_1.GrammarMarkType.arc3d:
|
|
35
|
-
currentTheme =
|
|
35
|
+
currentTheme = components.arcLabel;
|
|
36
36
|
break;
|
|
37
37
|
|
|
38
38
|
case enums_1.GrammarMarkType.polygon:
|
|
39
39
|
case enums_1.GrammarMarkType.path:
|
|
40
40
|
default:
|
|
41
|
-
currentTheme =
|
|
41
|
+
currentTheme = components.pointLabel;
|
|
42
42
|
}
|
|
43
|
-
const data = null !== (
|
|
43
|
+
const data = null !== (_b = addition.data) && void 0 !== _b ? _b : [], themeDatum = null !== (_d = null === (_c = null == currentTheme ? void 0 : currentTheme.data) || void 0 === _c ? void 0 : _c[0]) && void 0 !== _d ? _d : {};
|
|
44
44
|
data && data.length > 0 ? data.forEach(((d, index) => {
|
|
45
45
|
if (mark.elements[index]) {
|
|
46
46
|
const attributes = (0, encode_1.invokeEncoder)(encoder, d, mark.elements[index], labelParameters);
|
|
@@ -58,7 +58,7 @@ const vutils_1 = require("@visactor/vutils"), vrender_components_1 = require("@v
|
|
|
58
58
|
data.push(datum);
|
|
59
59
|
}
|
|
60
60
|
}));
|
|
61
|
-
const graphicItemName = null === (
|
|
61
|
+
const graphicItemName = null === (_e = mark.graphicItem) || void 0 === _e ? void 0 : _e.name;
|
|
62
62
|
return (0, vutils_1.merge)({}, currentTheme, {
|
|
63
63
|
data: data,
|
|
64
64
|
baseMarkGroupName: graphicItemName,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/component/label.ts"],"names":[],"mappings":";;;AACA,6CAAuE;AAIvE,qEAAyD;AAYzD,0CAAgE;AAEhE,iDAA8C;AAC9C,iDAAqD;AACrD,wCAAmD;AACnD,6CAA0C;AAEnC,MAAM,uBAAuB,GAAG,CACrC,KAAc,EACd,SAA4C,EAC5C,OAA6B,EAC7B,UAAqD,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AO,CAAC,iBAAiB,CAAC,qBAAa,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AACxD,CAAC,CAAC;AAPW,QAAA,aAAa,iBAOxB","file":"label.js","sourcesContent":["import { load } from './../util/data';\nimport { array, isNil, isString, merge, last } 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 BaseSingleEncodeSpec,\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: BaseSingleEncodeSpec,\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 const addition = invokeFunctionType(labelStyle, labelParameters, mark);\n let currentTheme: any = {};\n\n switch (mark.markType) {\n case GrammarMarkType.line:\n case GrammarMarkType.area:\n if (addition?.type === 'line') {\n currentTheme = theme?.components?.lineLabel;\n } else if (addition?.type === 'area') {\n currentTheme = theme?.components?.areaLabel;\n } else {\n currentTheme = theme?.components?.lineDataLabel;\n }\n break;\n case GrammarMarkType.rect:\n case GrammarMarkType.rect3d:\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\n const data: any[] = addition?.data ?? [];\n const themeDatum = currentTheme?.data?.[0] ?? {};\n\n if (data && data.length > 0) {\n data.forEach((d, index) => {\n if (mark.elements[index]) {\n const attributes = invokeEncoder(encoder, d, mark.elements[index], labelParameters);\n merge(d, themeDatum, attributes);\n }\n });\n } else {\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 }\n\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\n const theme = this.spec.skipTheme ? null : this.view.getCurrentTheme();\n\n return generateLabelAttributes(\n marks,\n size,\n encoder as BaseSingleEncodeSpec,\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":";;;AACA,6CAAuE;AAIvE,qEAAyD;AAYzD,0CAAgE;AAEhE,iDAA8C;AAC9C,iDAAqD;AAC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gCACrB,CAAC,CAAC;oCACE,KAAK,EAAE,MAAA,gBAAgB,CAAC,SAAS,CAAC,KAAK,mCAAI,gBAAgB,CAAC,UAAU,CAAC,KAAK,EAAE;oCAC9E,MAAM,EAAE,MAAA,gBAAgB,CAAC,SAAS,CAAC,MAAM,mCAAI,gBAAgB,CAAC,UAAU,CAAC,MAAM,EAAE;iCAClF;gCACH,CAAC,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;yBAC3C;wBAED,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC;wBAEvE,OAAO,IAAA,+BAAuB,EAC5B,KAAK,EACL,IAAI,EACJ,OAA+B,EAC/B,IAAI,CAAC,IAAI,CAAC,UAAU,EACpB,UAAU,EACV,KAAK,CACN,CAAC;oBACJ,CAAC;iBACF,CAAC;aACH;YACD,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAAE,CAAC,CAAC;QACP,IAAI,CAAC,SAAS,GAAG,iBAAiB,CAAC;IACrC,CAAC;;AA1EH,sBA2EC;AA1EiB,mBAAa,GAAW,qBAAa,CAAC,KAAK,CAAC;AA4EvD,MAAM,aAAa,GAAG,GAAG,EAAE;IAChC,iBAAO,CAAC,wBAAwB,CAC9B,qBAAa,CAAC,KAAK,EACnB,CAAC,KAAqB,EAAE,EAAE,CAAC,IAAI,8BAAS,CAAC,KAAK,CAAwB,CACvE,CAAC;IAEF,iBAAO,CAAC,iBAAiB,CAAC,qBAAa,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AACxD,CAAC,CAAC;AAPW,QAAA,aAAa,iBAOxB","file":"label.js","sourcesContent":["import { load } from './../util/data';\nimport { array, isNil, isString, merge, last } 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 BaseSingleEncodeSpec,\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: BaseSingleEncodeSpec,\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 const addition = invokeFunctionType(labelStyle, labelParameters, mark) ?? {};\n const { components = {} } = theme;\n let currentTheme: any = {};\n\n switch (mark.markType) {\n case GrammarMarkType.line:\n case GrammarMarkType.area:\n if (addition.type === 'line') {\n currentTheme = components.lineLabel;\n } else if (addition.type === 'area') {\n currentTheme = components.areaLabel;\n } else {\n currentTheme = components.lineDataLabel;\n }\n break;\n case GrammarMarkType.rect:\n case GrammarMarkType.rect3d:\n case GrammarMarkType.interval:\n currentTheme = components.rectLabel;\n break;\n case GrammarMarkType.symbol:\n case GrammarMarkType.circle:\n case GrammarMarkType.cell:\n currentTheme = components.symbolLabel;\n break;\n case GrammarMarkType.arc:\n case GrammarMarkType.arc3d:\n currentTheme = components.arcLabel;\n break;\n case GrammarMarkType.polygon:\n case GrammarMarkType.path:\n default:\n currentTheme = components.pointLabel;\n break;\n }\n\n const data: any[] = addition.data ?? [];\n const themeDatum = currentTheme?.data?.[0] ?? {};\n\n if (data && data.length > 0) {\n data.forEach((d, index) => {\n if (mark.elements[index]) {\n const attributes = invokeEncoder(encoder, d, mark.elements[index], labelParameters);\n merge(d, themeDatum, attributes);\n }\n });\n } else {\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 }\n\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\n const theme = this.spec.skipTheme ? null : this.view.getCurrentTheme();\n\n return generateLabelAttributes(\n marks,\n size,\n encoder as BaseSingleEncodeSpec,\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
|
@@ -9,11 +9,11 @@ const vscale_1 = require("@visactor/vscale"), vrender_components_1 = require("@v
|
|
|
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 : {});
|
|
11
11
|
const items = Array.from(new Set((0, vutils_1.array)(scale.domain()))).map(((item, index) => {
|
|
12
|
-
var _a, _b, _c, _d, _e, _f
|
|
13
|
-
const value = scale.scale(item), color = (0, util_1.parseColor)(value), shape = color ? Object.assign(Object.assign({}, null !== (
|
|
12
|
+
var _a, _b, _c, _d, _e, _f;
|
|
13
|
+
const value = scale.scale(item), color = (0, util_1.parseColor)(value), shape = color ? Object.assign(Object.assign({}, null !== (_c = null === (_b = null === (_a = null == legendTheme ? void 0 : legendTheme.items) || void 0 === _a ? void 0 : _a[0]) || void 0 === _b ? void 0 : _b.shape) && void 0 !== _c ? _c : {}), {
|
|
14
14
|
fill: color,
|
|
15
15
|
stroke: color
|
|
16
|
-
}) : null !== (
|
|
16
|
+
}) : null !== (_f = null === (_e = null === (_d = null == legendTheme ? void 0 : legendTheme.items) || void 0 === _d ? void 0 : _d[0]) || void 0 === _e ? void 0 : _e.shape) && void 0 !== _f ? _f : {};
|
|
17
17
|
return shapeScale && Object.assign(shape, {
|
|
18
18
|
symbolType: shapeScale.scale(item)
|
|
19
19
|
}), {
|
|
@@ -87,9 +87,7 @@ class Legend extends scale_1.ScaleComponent {
|
|
|
87
87
|
return this._getLegendComponentType() !== enums_1.LegendEnum.discreteLegend;
|
|
88
88
|
}
|
|
89
89
|
setSelected(selectedValues) {
|
|
90
|
-
|
|
91
|
-
return (null === (_b = null === (_a = this.elements[0]) || void 0 === _a ? void 0 : _a.getGraphicItem) || void 0 === _b ? void 0 : _b.call(_a)).setSelected(selectedValues),
|
|
92
|
-
this;
|
|
90
|
+
return this.getGroupGraphicItem().setSelected(selectedValues), this;
|
|
93
91
|
}
|
|
94
92
|
addGraphicItem(attrs, groupKey) {
|
|
95
93
|
const graphicItem = factory_1.Factory.createGraphicComponent(this._getLegendComponentType(), attrs, {
|
|
@@ -1 +1 @@
|
|
|
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,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AAU,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 BaseSingleEncodeSpec,\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 skipDefault: this.spec.skipTheme\n });\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.spec.skipTheme ? null : this.view.getCurrentTheme();\n const addition = invokeEncoder(encoder as BaseSingleEncodeSpec, 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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zB,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 BaseSingleEncodeSpec,\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 ...(legendTheme?.items?.[0]?.shape ?? {}),\n fill: color,\n stroke: color\n }\n : legendTheme?.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.getGroupGraphicItem() as unknown as DiscreteLegend;\n\n legend.setSelected(selectedValues);\n return this;\n }\n\n addGraphicItem(attrs: any, groupKey?: string) {\n const graphicItem = Factory.createGraphicComponent(this._getLegendComponentType(), attrs, {\n skipDefault: this.spec.skipTheme\n });\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.spec.skipTheme ? null : this.view.getCurrentTheme();\n const addition = invokeEncoder(encoder as BaseSingleEncodeSpec, 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"]}
|
package/cjs/component/player.js
CHANGED
|
@@ -51,24 +51,16 @@ class Player extends component_1.Component {
|
|
|
51
51
|
return this.attach(sourceDataGrammar), this.commit(), this;
|
|
52
52
|
}
|
|
53
53
|
play() {
|
|
54
|
-
|
|
55
|
-
return (null === (_b = null === (_a = this.elements[0]) || void 0 === _a ? void 0 : _a.getGraphicItem) || void 0 === _b ? void 0 : _b.call(_a)).play(),
|
|
56
|
-
this;
|
|
54
|
+
return this.getGroupGraphicItem().play(), this;
|
|
57
55
|
}
|
|
58
56
|
pause() {
|
|
59
|
-
|
|
60
|
-
return (null === (_b = null === (_a = this.elements[0]) || void 0 === _a ? void 0 : _a.getGraphicItem) || void 0 === _b ? void 0 : _b.call(_a)).pause(),
|
|
61
|
-
this;
|
|
57
|
+
return this.getGroupGraphicItem().pause(), this;
|
|
62
58
|
}
|
|
63
59
|
backward() {
|
|
64
|
-
|
|
65
|
-
return (null === (_b = null === (_a = this.elements[0]) || void 0 === _a ? void 0 : _a.getGraphicItem) || void 0 === _b ? void 0 : _b.call(_a)).backward(),
|
|
66
|
-
this;
|
|
60
|
+
return this.getGroupGraphicItem().backward(), this;
|
|
67
61
|
}
|
|
68
62
|
forward() {
|
|
69
|
-
|
|
70
|
-
return (null === (_b = null === (_a = this.elements[0]) || void 0 === _a ? void 0 : _a.getGraphicItem) || void 0 === _b ? void 0 : _b.call(_a)).forward(),
|
|
71
|
-
this;
|
|
63
|
+
return this.getGroupGraphicItem().forward(), this;
|
|
72
64
|
}
|
|
73
65
|
addGraphicItem(attrs, groupKey, newGraphicItem) {
|
|
74
66
|
const initialAttributes = (0, vutils_1.merge)({
|