Skip to content

Commit

Permalink
chore: split lib for demand loading
Browse files Browse the repository at this point in the history
  • Loading branch information
pearmini committed Aug 11, 2023
1 parent 40cc5b6 commit dc99901
Show file tree
Hide file tree
Showing 45 changed files with 15,388 additions and 170 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@ site/.dumi/tmp-production

# Bundle analyzer
analyse.html

# Other
!/src/lib
!/__tests__/unit/lib
4 changes: 2 additions & 2 deletions __tests__/integration/utils/renderSpec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Canvas } from '@antv/g';
import { createCanvas } from 'canvas';
import { G2Context, G2Spec, createLibrary, render } from '../../../src';
import { G2Context, G2Spec, stdlib, render } from '../../../src';
import { renderToMountedElement } from '../../utils/renderToMountedElement';
import { createNodeGCanvas } from './createNodeGCanvas';

Expand All @@ -15,7 +15,7 @@ export async function renderSpec(
const renderFunction = mounted ? renderToMountedElement : render;
const options = preprocess({ ...raw, width, height });
context.canvas = gCanvas;
context.library = createLibrary();
context.library = stdlib();
context.createCanvas = () => {
// The width attribute defaults to 300, and the height attribute defaults to 150.
// @see https://stackoverflow.com/a/12019582
Expand Down
4 changes: 2 additions & 2 deletions __tests__/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Plugin as ControlPlugin } from '@antv/g-plugin-control';
import { Plugin as ThreeDPlugin } from '@antv/g-plugin-3d';
import { Renderer as SVGRenderer } from '@antv/g-svg';
import { Renderer as WebGLRenderer } from '@antv/g-webgl';
import { createLibrary, render } from '../src';
import { stdlib, render } from '../src';
import { renderToMountedElement } from './utils/renderToMountedElement';
import * as statics from './plots/static';
import * as interactions from './plots/interaction';
Expand Down Expand Up @@ -169,7 +169,7 @@ function createSpecRender(object) {
const node = renderChart(
{ theme: 'classic', ...options },
// @ts-ignore
{ canvas, library: createLibrary() },
{ canvas, library: stdlib() },
() => after?.(),
);

Expand Down
19 changes: 0 additions & 19 deletions __tests__/treeshaking/main.ts

This file was deleted.

328 changes: 328 additions & 0 deletions __tests__/unit/lib/core.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,328 @@
import { corelib } from '../../../src/lib';
import {
Cartesian,
Polar,
Transpose,
Parallel,
Fisheye,
Helix,
Theta,
Radial,
Radar,
} from '../../../src/coordinate';
import { Constant, Field, Transform, Column } from '../../../src/encode';
import {
Interval,
Rect,
Line,
Point as PointGeometry,
Text as TextGeometry,
Cell,
Area as AreaGeometry,
Image as ImageGeometry,
Polygon as PolygonGeometry,
Box as BoxGeometry,
Vector as VectorGeometry,
Link as LinkGeometry,
LineX,
LineY,
Range,
RangeX,
RangeY,
Connector,
Path,
Shape,
} from '../../../src/mark';
import { Category10, Category20 } from '../../../src/palette';
import {
Linear,
Ordinal,
Band,
Identity,
Point,
Time,
Log,
Pow,
Threshold,
Quantile,
Quantize,
Sqrt,
Sequential,
Constant as ConstantScale,
} from '../../../src/scale';
import { Classic, ClassicDark, Academy } from '../../../src/theme';
import {
AxisX,
AxisY,
AxisArc,
AxisLinear,
AxisRadar,
LegendCategory,
LegendContinuous,
LegendContinuousBlock,
LegendContinuousBlockSize,
LegendContinuousSize,
SliderX,
SliderY,
ScrollbarX,
ScrollbarY,
TitleComponent,
Legends,
} from '../../../src/component';
import {
ScaleInX,
ScaleOutX,
ScaleInY,
ScaleOutY,
FadeIn,
FadeOut,
Morphing,
WaveIn,
ZoomIn,
ZoomOut,
PathIn,
GrowInX,
GrowInY,
} from '../../../src/animation';
import {
ElementHighlight,
ElementHighlightByColor,
ElementHighlightByX,
ElementSelect,
ElementSelectByColor,
ElementSelectByX,
Fisheye as ChartFisheye,
ChartIndex,
Tooltip,
LegendFilter,
BrushXHighlight,
BrushYHighlight,
BrushHighlight,
BrushAxisHighlight,
BrushFilter,
BrushYFilter,
BrushXFilter,
SliderFilter,
ScrollbarFilter,
LegendHighlight,
Poptip,
Event,
} from '../../../src/interaction';
import {
SpaceLayer,
SpaceFlex,
RepeatMatrix,
View,
FacetCircle,
FacetRect,
TimingKeyframe,
Mark,
} from '../../../src/composition';
import {
StackY,
DodgeX,
StackEnter,
NormalizeY,
Jitter,
JitterX,
SymmetryY,
DiffY,
Select,
SelectX,
SelectY,
GroupX,
SortX,
FlexX,
SortColor,
SortY,
Group,
GroupY,
GroupColor,
Pack,
Bin,
BinX,
Sample,
Filter as FilterTransform,
} from '../../../src/transform';
import {
Fetch,
SortBy,
Sort,
Filter,
Map,
Pick,
Rename,
Fold,
Slice,
Inline,
Custom,
Join,
KDE,
} from '../../../src/data';
import {
OverflowHide,
ContrastReverse,
OverlapHide,
OverlapDodgeY,
} from '../../../src/label-transform';
import { LabelShape } from '../../../src/shape';

describe('corelib', () => {
it('corelib() should returns expected basic marks and components.', () => {
expect(corelib()).toEqual({
'data.fetch': Fetch,
'data.inline': Inline,
'data.sortBy': SortBy,
'data.sort': Sort,
'data.filter': Filter,
'data.pick': Pick,
'data.rename': Rename,
'data.fold': Fold,
'data.slice': Slice,
'data.custom': Custom,
'data.map': Map,
'data.join': Join,
'data.kde': KDE,
'transform.stackY': StackY,
'transform.binX': BinX,
'transform.bin': Bin,
'transform.dodgeX': DodgeX,
'transform.jitter': Jitter,
'transform.jitterX': JitterX,
'transform.symmetryY': SymmetryY,
'transform.diffY': DiffY,
'transform.stackEnter': StackEnter,
'transform.normalizeY': NormalizeY,
'transform.select': Select,
'transform.selectX': SelectX,
'transform.selectY': SelectY,
'transform.groupX': GroupX,
'transform.groupY': GroupY,
'transform.groupColor': GroupColor,
'transform.group': Group,
'transform.sortX': SortX,
'transform.sortY': SortY,
'transform.sortColor': SortColor,
'transform.flexX': FlexX,
'transform.pack': Pack,
'transform.sample': Sample,
'transform.filter': FilterTransform,
'coordinate.cartesian': Cartesian,
'coordinate.polar': Polar,
'coordinate.helix': Helix,
'coordinate.transpose': Transpose,
'coordinate.theta': Theta,
'coordinate.parallel': Parallel,
'coordinate.radar': Radar,
'coordinate.fisheye': Fisheye,
'coordinate.radial': Radial,
'encode.constant': Constant,
'encode.field': Field,
'encode.transform': Transform,
'encode.column': Column,
'mark.interval': Interval,
'mark.rect': Rect,
'mark.line': Line,
'mark.point': PointGeometry,
'mark.text': TextGeometry,
'mark.cell': Cell,
'mark.area': AreaGeometry,
'mark.link': LinkGeometry,
'mark.image': ImageGeometry,
'mark.polygon': PolygonGeometry,
'mark.box': BoxGeometry,
'mark.vector': VectorGeometry,
'mark.lineX': LineX,
'mark.lineY': LineY,
'mark.connector': Connector,
'mark.range': Range,
'mark.rangeX': RangeX,
'mark.rangeY': RangeY,
'mark.path': Path,
'mark.shape': Shape,
'shape.label.label': LabelShape,
'palette.category10': Category10,
'palette.category20': Category20,
'scale.linear': Linear,
'scale.ordinal': Ordinal,
'scale.band': Band,
'scale.identity': Identity,
'scale.point': Point,
'scale.time': Time,
'scale.log': Log,
'scale.pow': Pow,
'scale.sqrt': Sqrt,
'scale.threshold': Threshold,
'scale.quantile': Quantile,
'scale.quantize': Quantize,
'scale.sequential': Sequential,
'scale.constant': ConstantScale,
'theme.classic': Classic,
'theme.classicDark': ClassicDark,
'theme.academy': Academy,
'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,
'component.sliderY': SliderY,
'component.scrollbarX': ScrollbarX,
'component.scrollbarY': ScrollbarY,
'animation.scaleInX': ScaleInX,
'animation.scaleOutX': ScaleOutX,
'animation.scaleInY': ScaleInY,
'animation.scaleOutY': ScaleOutY,
'animation.waveIn': WaveIn,
'animation.fadeIn': FadeIn,
'animation.fadeOut': FadeOut,
'animation.zoomIn': ZoomIn,
'animation.zoomOut': ZoomOut,
'animation.pathIn': PathIn,
'animation.morphing': Morphing,
'animation.growInX': GrowInX,
'animation.growInY': GrowInY,
'interaction.elementHighlight': ElementHighlight,
'interaction.elementHighlightByX': ElementHighlightByX,
'interaction.elementHighlightByColor': ElementHighlightByColor,
'interaction.elementSelect': ElementSelect,
'interaction.elementSelectByX': ElementSelectByX,
'interaction.elementSelectByColor': ElementSelectByColor,
'interaction.fisheye': ChartFisheye,
'interaction.chartIndex': ChartIndex,
'interaction.tooltip': Tooltip,
'interaction.legendFilter': LegendFilter,
'interaction.legendHighlight': LegendHighlight,
'interaction.brushXHighlight': BrushXHighlight,
'interaction.brushYHighlight': BrushYHighlight,
'interaction.brushHighlight': BrushHighlight,
'interaction.brushAxisHighlight': BrushAxisHighlight,
'interaction.brushYFilter': BrushYFilter,
'interaction.brushXFilter': BrushXFilter,
'interaction.brushFilter': BrushFilter,
'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,
'composition.timingKeyframe': TimingKeyframe,
'labelTransform.overlapHide': OverlapHide,
'labelTransform.overlapDodgeY': OverlapDodgeY,
'labelTransform.overflowHide': OverflowHide,
'labelTransform.contrastReverse': ContrastReverse,
});
});
});
Loading

0 comments on commit dc99901

Please sign in to comment.