diff --git a/__tests__/unit/lib/core.spec.ts b/__tests__/unit/lib/core.spec.ts index 1aaa79aab9..24ca1b51a1 100644 --- a/__tests__/unit/lib/core.spec.ts +++ b/__tests__/unit/lib/core.spec.ts @@ -5,7 +5,6 @@ import { Transpose, Parallel, Fisheye, - Helix, Theta, Radial, Radar, @@ -56,14 +55,8 @@ import { Classic, ClassicDark, Academy, Light } from '../../../src/theme'; import { AxisX, AxisY, - AxisArc, - AxisLinear, - AxisRadar, LegendCategory, LegendContinuous, - LegendContinuousBlock, - LegendContinuousBlockSize, - LegendContinuousSize, SliderX, SliderY, ScrollbarX, @@ -108,17 +101,14 @@ import { ScrollbarFilter, LegendHighlight, Poptip, - Event, } from '../../../src/interaction'; import { SpaceLayer, SpaceFlex, RepeatMatrix, - View, FacetCircle, FacetRect, TimingKeyframe, - Mark, } from '../../../src/composition'; import { StackY, @@ -168,7 +158,6 @@ import { OverlapHide, OverlapDodgeY, } from '../../../src/label-transform'; -import { LabelShape } from '../../../src/shape'; describe('corelib', () => { it('corelib() should returns expected basic marks and components.', () => { @@ -213,7 +202,6 @@ describe('corelib', () => { 'transform.filter': FilterTransform, 'coordinate.cartesian': Cartesian, 'coordinate.polar': Polar, - 'coordinate.helix': Helix, 'coordinate.transpose': Transpose, 'coordinate.theta': Theta, 'coordinate.parallel': Parallel, @@ -246,7 +234,6 @@ describe('corelib', () => { 'mark.shape': Shape, 'mark.density': Density, 'mark.heatmap': Heatmap, - 'shape.label.label': LabelShape, 'palette.category10': Category10, 'palette.category20': Category20, 'scale.linear': Linear, @@ -269,14 +256,8 @@ describe('corelib', () => { 'theme.light': Light, 'component.axisX': AxisX, 'component.axisY': AxisY, - 'component.axisArc': AxisArc, - 'component.axisLinear': AxisLinear, - 'component.axisRadar': AxisRadar, 'component.legendCategory': LegendCategory, 'component.legendContinuous': LegendContinuous, - 'component.legendContinuousBlock': LegendContinuousBlock, - 'component.legendContinuousBlockSize': LegendContinuousBlockSize, - 'component.legendContinuousSize': LegendContinuousSize, 'component.legends': Legends, 'component.title': TitleComponent, 'component.sliderX': SliderX, @@ -317,11 +298,8 @@ describe('corelib', () => { 'interaction.sliderFilter': SliderFilter, 'interaction.scrollbarFilter': ScrollbarFilter, 'interaction.poptip': Poptip, - 'interaction.event': Event, 'composition.spaceLayer': SpaceLayer, 'composition.spaceFlex': SpaceFlex, - 'composition.mark': Mark, - 'composition.view': View, 'composition.facetRect': FacetRect, 'composition.repeatMatrix': RepeatMatrix, 'composition.facetCircle': FacetCircle, diff --git a/__tests__/unit/lib/std.spec.ts b/__tests__/unit/lib/std.spec.ts index 62c8817586..7d8cd59926 100644 --- a/__tests__/unit/lib/std.spec.ts +++ b/__tests__/unit/lib/std.spec.ts @@ -5,7 +5,6 @@ import { Transpose, Parallel, Fisheye, - Helix, Theta, Radial, Radar, @@ -64,14 +63,8 @@ import { Classic, ClassicDark, Academy, Light } from '../../../src/theme'; import { AxisX, AxisY, - AxisArc, - AxisLinear, - AxisRadar, LegendCategory, LegendContinuous, - LegendContinuousBlock, - LegendContinuousBlockSize, - LegendContinuousSize, SliderX, SliderY, ScrollbarX, @@ -116,17 +109,14 @@ import { ScrollbarFilter, LegendHighlight, Poptip, - Event, } from '../../../src/interaction'; import { SpaceLayer, SpaceFlex, RepeatMatrix, - View, FacetCircle, FacetRect, TimingKeyframe, - Mark, GeoView, GeoPath, } from '../../../src/composition'; @@ -181,7 +171,6 @@ import { OverlapHide, OverlapDodgeY, } from '../../../src/label-transform'; -import { LabelShape } from '../../../src/shape'; describe('stdlib', () => { it('stdlib() should returns expected all components.', () => { @@ -229,7 +218,6 @@ describe('stdlib', () => { 'transform.filter': FilterTransform, 'coordinate.cartesian': Cartesian, 'coordinate.polar': Polar, - 'coordinate.helix': Helix, 'coordinate.transpose': Transpose, 'coordinate.theta': Theta, 'coordinate.parallel': Parallel, @@ -270,7 +258,6 @@ describe('stdlib', () => { 'mark.density': DensityGeometry, 'mark.gauge': Gauge, 'mark.heatmap': Heatmap, - 'shape.label.label': LabelShape, 'palette.category10': Category10, 'palette.category20': Category20, 'scale.linear': Linear, @@ -293,14 +280,8 @@ describe('stdlib', () => { 'theme.light': Light, 'component.axisX': AxisX, 'component.axisY': AxisY, - 'component.axisArc': AxisArc, - 'component.axisLinear': AxisLinear, - 'component.axisRadar': AxisRadar, 'component.legendCategory': LegendCategory, 'component.legendContinuous': LegendContinuous, - 'component.legendContinuousBlock': LegendContinuousBlock, - 'component.legendContinuousBlockSize': LegendContinuousBlockSize, - 'component.legendContinuousSize': LegendContinuousSize, 'component.legends': Legends, 'component.title': TitleComponent, 'component.sliderX': SliderX, @@ -341,11 +322,8 @@ describe('stdlib', () => { 'interaction.sliderFilter': SliderFilter, 'interaction.scrollbarFilter': ScrollbarFilter, 'interaction.poptip': Poptip, - 'interaction.event': Event, 'composition.spaceLayer': SpaceLayer, 'composition.spaceFlex': SpaceFlex, - 'composition.mark': Mark, - 'composition.view': View, 'composition.facetRect': FacetRect, 'composition.repeatMatrix': RepeatMatrix, 'composition.facetCircle': FacetCircle, diff --git a/src/api/extend.ts b/src/api/extend.ts index ea93f2c1b4..3f85c0f213 100644 --- a/src/api/extend.ts +++ b/src/api/extend.ts @@ -16,9 +16,14 @@ type CompositionOf = Of< CompositionOf >; +type BuiltinComposition = { + 'composition.mark': any; + 'composition.view': any; +}; + export type API = Runtime & MarkOf MarkNode> & - CompositionOf; + CompositionOf; export function extend< Spec extends G2Spec = G2Spec, diff --git a/src/api/runtime.ts b/src/api/runtime.ts index 1f6e4de39c..2f480727ee 100644 --- a/src/api/runtime.ts +++ b/src/api/runtime.ts @@ -222,9 +222,12 @@ export class Runtime extends CompositionNode { } // Create composition generators. - const compositions = Object.keys(library).filter( - (key) => key.startsWith('composition.') && key !== 'composition.mark', - ); + const compositions = [ + 'composition.view', // chat.view() + ...Object.keys(library).filter( + (key) => key.startsWith('composition.') && key !== 'composition.mark', + ), + ]; this._compositions = Object.fromEntries( compositions.map((key) => { const name = key.split('.').pop(); diff --git a/src/lib/builtinlib.ts b/src/lib/builtinlib.ts new file mode 100644 index 0000000000..17a6389924 --- /dev/null +++ b/src/lib/builtinlib.ts @@ -0,0 +1,28 @@ +import { + AxisLinear, + AxisArc, + AxisRadar, + LegendContinuousBlock, + LegendContinuousBlockSize, + LegendContinuousSize, +} from '../component'; +import { Mark, View } from '../composition'; +import { LabelShape } from '../shape'; +import { Event } from '../interaction/event'; + +// Some private visual components, they are not public to +// users, only for runtime. +export function builtinlib() { + return { + 'component.axisRadar': AxisRadar, + 'component.axisLinear': AxisLinear, + 'component.axisArc': AxisArc, + 'component.legendContinuousBlock': LegendContinuousBlock, + 'component.legendContinuousBlockSize': LegendContinuousBlockSize, + 'component.legendContinuousSize': LegendContinuousSize, + 'interaction.event': Event, + 'composition.mark': Mark, + 'composition.view': View, + 'shape.label.label': LabelShape, + } as const; +} diff --git a/src/lib/core.ts b/src/lib/core.ts index b878abfe1d..8261e3d04f 100644 --- a/src/lib/core.ts +++ b/src/lib/core.ts @@ -1,7 +1,6 @@ import { Cartesian, Polar, - Helix, Transpose, Theta, Parallel, @@ -53,16 +52,10 @@ import { } from '../scale'; import { Classic, ClassicDark, Academy, Light } from '../theme'; import { - AxisLinear, - AxisArc, AxisX, AxisY, - AxisRadar, LegendCategory, LegendContinuous, - LegendContinuousBlock, - LegendContinuousBlockSize, - LegendContinuousSize, TitleComponent, SliderX, SliderY, @@ -106,14 +99,11 @@ import { BrushYFilter, SliderFilter, Poptip, - Event, ScrollbarFilter, } from '../interaction'; import { SpaceLayer, SpaceFlex, - Mark, - View, FacetRect, FacetCircle, RepeatMatrix, @@ -167,7 +157,6 @@ import { ContrastReverse, OverlapHide, } from '../label-transform'; -import { LabelShape } from '../shape'; export function corelib() { return { @@ -211,7 +200,6 @@ export function corelib() { 'transform.filter': Filter, 'coordinate.cartesian': Cartesian, 'coordinate.polar': Polar, - 'coordinate.helix': Helix, 'coordinate.transpose': Transpose, 'coordinate.theta': Theta, 'coordinate.parallel': Parallel, @@ -244,7 +232,6 @@ export function corelib() { 'mark.shape': Shape, 'mark.density': Density, 'mark.heatmap': Heatmap, - 'shape.label.label': LabelShape, 'palette.category10': Category10, 'palette.category20': Category20, 'scale.linear': ScaleLinear, @@ -267,14 +254,8 @@ export function corelib() { 'theme.light': Light, 'component.axisX': AxisX, 'component.axisY': AxisY, - 'component.axisRadar': AxisRadar, - 'component.axisLinear': AxisLinear, - 'component.axisArc': AxisArc, 'component.legendCategory': LegendCategory, 'component.legendContinuous': LegendContinuous, - 'component.legendContinuousBlock': LegendContinuousBlock, - 'component.legendContinuousBlockSize': LegendContinuousBlockSize, - 'component.legendContinuousSize': LegendContinuousSize, 'component.legends': Legends, 'component.title': TitleComponent, 'component.sliderX': SliderX, @@ -315,11 +296,8 @@ export function corelib() { 'interaction.sliderFilter': SliderFilter, 'interaction.scrollbarFilter': ScrollbarFilter, 'interaction.poptip': Poptip, - 'interaction.event': Event, 'composition.spaceLayer': SpaceLayer, 'composition.spaceFlex': SpaceFlex, - 'composition.mark': Mark, - 'composition.view': View, 'composition.facetRect': FacetRect, 'composition.repeatMatrix': RepeatMatrix, 'composition.facetCircle': FacetCircle, diff --git a/src/runtime/library.ts b/src/runtime/library.ts index fcbc4bc241..4c2db349db 100644 --- a/src/runtime/library.ts +++ b/src/runtime/library.ts @@ -1,5 +1,6 @@ import { IDocument } from '@antv/g'; import { error } from '../utils/helper'; +import { builtinlib } from '../lib/builtinlib'; import { G2ComponentOptions, G2Context, G2Library } from './types/options'; import { G2Component, @@ -13,8 +14,10 @@ export function useLibrary< V extends G2ComponentValue, >( namespace: G2ComponentNamespaces, - library: G2Library, + publicLibrary: G2Library, ): [(options: O, context?) => V, (type: O['type']) => C] { + const library = { ...builtinlib(), ...publicLibrary }; + const create = (type: O['type']) => { if (typeof type !== 'string') return type; const key = `${namespace}.${type}`;