Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(builtinlib): move some components from core to builtinlib #5485

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions __tests__/unit/lib/core.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
Transpose,
Parallel,
Fisheye,
Helix,
Theta,
Radial,
Radar,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.', () => {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
22 changes: 0 additions & 22 deletions __tests__/unit/lib/std.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
Transpose,
Parallel,
Fisheye,
Helix,
Theta,
Radial,
Radar,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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.', () => {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion src/api/extend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@ type CompositionOf<Library> = Of<
CompositionOf<Library>
>;

type BuiltinComposition = {
'composition.mark': any;
'composition.view': any;
};

export type API<Spec, Library> = Runtime<Spec> &
MarkOf<Library, (composite?) => MarkNode> &
CompositionOf<Library>;
CompositionOf<Library & BuiltinComposition>;

export function extend<
Spec extends G2Spec = G2Spec,
Expand Down
9 changes: 6 additions & 3 deletions src/api/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,12 @@ export class Runtime<Spec extends G2Spec = G2Spec> 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();
Expand Down
28 changes: 28 additions & 0 deletions src/lib/builtinlib.ts
Original file line number Diff line number Diff line change
@@ -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;
}
22 changes: 0 additions & 22 deletions src/lib/core.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
Cartesian,
Polar,
Helix,
Transpose,
Theta,
Parallel,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -106,14 +99,11 @@ import {
BrushYFilter,
SliderFilter,
Poptip,
Event,
ScrollbarFilter,
} from '../interaction';
import {
SpaceLayer,
SpaceFlex,
Mark,
View,
FacetRect,
FacetCircle,
RepeatMatrix,
Expand Down Expand Up @@ -167,7 +157,6 @@ import {
ContrastReverse,
OverlapHide,
} from '../label-transform';
import { LabelShape } from '../shape';

export function corelib() {
return {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion src/runtime/library.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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}`;
Expand Down