Skip to content

Commit

Permalink
Merge branch 'main' into demo/custom-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
lvisei committed Dec 13, 2024
2 parents a54e568 + 24bb114 commit 4d1b690
Show file tree
Hide file tree
Showing 13 changed files with 175 additions and 77 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# @antv/gpt-vis

## 0.3.4

### Patch Changes

- [#56](https://github.com/antvis/GPT-Vis/pull/56) [`694773d`](https://github.com/antvis/GPT-Vis/commit/694773d504e55f4f7c248b30714e6f0a4ce72b60) Thanks [@yvonneyx](https://github.com/yvonneyx)! - refactor: adjust graph options priority

- [#53](https://github.com/antvis/GPT-Vis/pull/53) [`9965c16`](https://github.com/antvis/GPT-Vis/commit/9965c163eb963255a6438fced1aa12b7f5f9c2ee) Thanks [@lvisei](https://github.com/lvisei)! - fix: config plot axis

## 0.3.3

### Patch Changes

- [#51](https://github.com/antvis/GPT-Vis/pull/51) [`376c22b`](https://github.com/antvis/GPT-Vis/commit/376c22b9412b07fd4073cdb967ec4df1ed709720) Thanks [@lzxue](https://github.com/lzxue)! - feat: map support update

## 0.3.2

### Patch Changes
Expand Down
46 changes: 23 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/gpt-vis",
"version": "0.3.2",
"version": "0.3.4",
"description": "Components for GPTs, generative AI, and LLM projects. Not only UI Components.",
"keywords": [
"antv",
Expand Down Expand Up @@ -53,52 +53,52 @@
"publish-package": "pnpm build && changeset publish"
},
"dependencies": {
"@ant-design/graphs": "^2.0.1",
"@ant-design/icons": "^5.4.0",
"@ant-design/plots": "^2.2.5",
"@antv/l7": "^2.22.0",
"@ant-design/graphs": "^2.0.2",
"@ant-design/icons": "^5.5.2",
"@ant-design/plots": "^2.3.2",
"@antv/l7": "^2.22.3",
"@antv/larkmap": "^1.5.1",
"@babel/runtime": "^7.18.0",
"@babel/runtime": "^7.26.0",
"lodash": "^4.17.21",
"react-markdown": "^9.0.1",
"rehype-raw": "^7.0.0",
"remark-gfm": "^4.0.0",
"styled-components": "^6.0.7"
"styled-components": "^6.1.13"
},
"devDependencies": {
"@ant-design/x": "^1.0.1",
"@ant-design/x": "^1.0.2",
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.9",
"@commitlint/cli": "^19.5.0",
"@commitlint/config-conventional": "^19.5.0",
"@changesets/cli": "^2.27.10",
"@commitlint/cli": "^19.6.0",
"@commitlint/config-conventional": "^19.6.0",
"@types/jest": "^29.5.14",
"@types/lodash": "^4.17.13",
"@types/react": "^18.0.0",
"@types/react": "^18.3.16",
"@types/webpack-bundle-analyzer": "^4.7.0",
"antd": "^5.0.0",
"dumi": "^2.4.13",
"eslint": "^9.14.0",
"antd": "^5.22.4",
"dumi": "^2.4.16",
"eslint": "^9.16.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-jest": "^28.9.0",
"eslint-plugin-jsx-a11y": "^6.10.2",
"eslint-plugin-react": "^7.37.2",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-hooks": "^5.1.0",
"father": "^4.5.1",
"gh-pages": "^6.2.0",
"globals": "^15.12.0",
"husky": "^9.1.6",
"globals": "^15.13.0",
"husky": "^9.1.7",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"limit-size": "^0.1.4",
"lint-staged": "^15.2.10",
"lint-staged": "^15.2.11",
"npm-run-all": "^4.1.5",
"prettier": "^3.3.3",
"prettier": "^3.4.2",
"prettier-plugin-organize-imports": "^4.1.0",
"react": "^18.0.0",
"react": "^18.3.1",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"typescript": "^5.6.3",
"typescript-eslint": "^8.13.0",
"typescript": "^5.7.2",
"typescript-eslint": "^8.18.0",
"webpack-bundle-analyzer": "^4.10.2"
},
"peerDependencies": {
Expand Down
15 changes: 9 additions & 6 deletions src/ConfigProvider/hooks/useConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,15 @@ export function usePlotConfig<T extends CommonConfig>(
defaultConfig: Partial<T> | ((props: Partial<T>) => Partial<T>),
props: Partial<T>,
): Partial<T> {
const transformedProps = transform2ADCProps(props);
const globalConfig = usePlotGlobalConfig(name);
const mergedProps = { ...globalConfig, ...props };
const transformedProps = transform2ADCProps(mergedProps);

const _defaultConfig =
typeof defaultConfig === 'function' ? defaultConfig(transformedProps) : defaultConfig;

const globalConfig = usePlotGlobalConfig(name);

const config = {
..._defaultConfig,
...globalConfig,
...transformedProps,
};

Expand Down Expand Up @@ -86,8 +85,12 @@ function useGraphGlobalConfig(name: Charts) {
return mergeGraphOptions(graphConfig, componentConfig || {});
}

export function useGraphConfig<T extends GraphOptions>(name: Charts, ...configs: Partial<T>[]) {
export function useGraphConfig<T extends GraphOptions>(
name: Charts,
defaultConfig: Partial<T>,
props: Partial<T>,
) {
const globalConfig = useGraphGlobalConfig(name);

return mergeGraphOptions(globalConfig, ...configs);
return mergeGraphOptions(defaultConfig, globalConfig, props);
}
8 changes: 3 additions & 5 deletions src/FlowDiagram/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { FlowGraph as ADCFlowGraph, RCNode } from '@ant-design/graphs';
import React, { useMemo } from 'react';
import { useGraphConfig } from '../ConfigProvider/hooks';
import type { GraphProps } from '../types';
import { mergeGraphOptions } from '../utils/config';
import { visGraphData2GraphData } from '../utils/graph';
import { getGraphOptionsByData } from './helper';

Expand All @@ -12,7 +13,7 @@ export interface FlowDiagramProps extends GraphProps {}

const defaultConfig: FlowGraphOptions = {
autoResize: true,
autoFit: 'center',
autoFit: 'view',
node: {
style: {
component: (d: G6.NodeData) => {
Expand All @@ -32,7 +33,6 @@ const defaultConfig: FlowGraphOptions = {
},
size: [140, 32],
},
animation: { enter: false },
},
edge: {
style: {
Expand All @@ -49,7 +49,6 @@ const defaultConfig: FlowGraphOptions = {
stroke: '#001f98',
},
},
animation: { enter: false },
},
behaviors: (prev) => [
...prev,
Expand All @@ -72,8 +71,7 @@ const FlowDiagram: React.FC<FlowDiagramProps> = (props) => {

const config = useGraphConfig<FlowGraphOptions>(
'FlowDiagram',
defaultConfig,
getGraphOptionsByData(data),
mergeGraphOptions(defaultConfig, getGraphOptionsByData(data)),
restProps,
);

Expand Down
20 changes: 20 additions & 0 deletions src/Map/Component/MapView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useScene } from '@antv/larkmap';
import { useEffect } from 'react';
import type { Map } from '../../types/map';
import { fitBounds, setMapStatus, setMapView } from '../../utils/map';

// 更新地图视野
export default (props: Map) => {
const scene = useScene();
useEffect(() => {
setMapView(props, scene);
}, []);
useEffect(() => {
setMapStatus(props, scene);
}, [props.enableRotate, props.enableScroll, props.enableZoom]);
useEffect(() => {
fitBounds(props, scene);
}, [props.includePoints, props.markers, props.polyline, props.includePadding]);

return null;
};
33 changes: 33 additions & 0 deletions src/Map/Component/Marker.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { ILayer } from '@antv/l7';
import { useScene } from '@antv/larkmap';
import { useEffect, useState } from 'react';
import type { Map } from '../../types/map';
import { setMapContext, setMarkers } from '../../utils/map';
// 渲染标记点
export default (props: Map) => {
const scene = useScene();
const [layers, setLayers] = useState<ILayer[]>([]);
const removeLayers = () => {
layers.forEach((item) => {
scene.removeLayer(item);
});
};
useEffect(() => {
if (!props.markers) return;
// 异步调用
setMapContext(props, scene)?.then(() => {
// 初始化资源
const markerLayer = setMarkers(props.markers || []);
removeLayers();
markerLayer.forEach((item) => {
scene.addLayer(item);
});
setLayers(markerLayer);
});
return () => {
removeLayers();
};
}, [props.markers]);

return null;
};
30 changes: 30 additions & 0 deletions src/Map/Component/Polyline.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type { ILayer } from '@antv/l7';
import { useScene } from '@antv/larkmap';
import { useEffect, useState } from 'react';
import type { Map } from '../../types/map';
import { setPolyline } from '../../utils/map';
// 渲染线图层
export default (props: Map) => {
const scene = useScene();
const [layers, setLayers] = useState<ILayer[]>([]);
const removeLayers = () => {
layers.forEach((item) => {
scene.removeLayer(item);
});
};
useEffect(() => {
if (!props.polyline) return;
const lineLayers = setPolyline(props.polyline || []);
removeLayers();
lineLayers.forEach((item) => {
scene.addLayer(item);
});
setLayers(lineLayers);

return () => {
removeLayers();
};
}, [props.polyline]);

return null;
};
5 changes: 5 additions & 0 deletions src/Map/Component/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import MapView from './MapView';
import Marker from './Marker';
import Polyline from './Polyline';

export { MapView, Marker, Polyline };
40 changes: 14 additions & 26 deletions src/Map/index.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,18 @@
import type { ILayer, Scene } from '@antv/l7';
import { LarkMap } from '@antv/larkmap';
import React, { type FC } from 'react';
import React, { useMemo, type FC } from 'react';
import type { BaseMapProps } from '../types';
import { formatMapStyle, setMapContext, setMapView, setMarkers, setPolyline } from '../utils/map';
import { formatMapStyle } from '../utils/map';
import { MapView, Marker, Polyline } from './Component/';

export type MapProps = Omit<BaseMapProps<any>, 'data'>;

const Map: FC<MapProps> = (props) => {
const { className, containerStyle, children } = props;
const allLayers: ILayer[] = [];
const mapConfig = formatMapStyle(props);

const onSceneLoaded = async (scene: Scene) => {
// 初始地图视野
setMapView(props, scene);
// 初始化地图资源和状态
await setMapContext(props, scene);

// 添加线图层
if (props.polyline) {
const polylineLayer = setPolyline(props.polyline || []);
allLayers.push(...polylineLayer);
}

// 添加标记
if (props.markers) {
const markerLayer = setMarkers(props.markers || []);
allLayers.push(...markerLayer);
const mapConfig = useMemo(() => formatMapStyle(props), [props]);
const onSceneLoaded = async () => {
if (props.onInitComplete) {
props.onInitComplete();
}

allLayers.forEach((item) => {
scene.addLayer(item);
});
};

return (
Expand All @@ -41,6 +22,13 @@ const Map: FC<MapProps> = (props) => {
{...mapConfig}
onSceneLoaded={onSceneLoaded}
>
{/* 设置地图状态 */}
<MapView {...props} />
{/* 初始化图片,并加载 Marker */}
<Marker {...props} />
{/* 初始化线,并加载 Polyline */}
<Polyline {...props} />

{children}
</LarkMap>
);
Expand Down
3 changes: 3 additions & 0 deletions src/utils/map/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export function setMapContext(props: Map, scene: Scene) {
return Promise.all(
Array.from(icons.values()).map(async (url: string) => {
const id = urlToMarkerId(url);
if (scene.hasImage(id)) {
return;
}
return await scene.addImage(id, url);
}),
);
Expand Down
13 changes: 7 additions & 6 deletions src/utils/map/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ function fitIncludePoints(
}

export const setMapView = (props: Map, scene: Scene) => {
// 单个点,多个点
fitBounds(props, scene);
setMapStatus(props, scene);
};

export const fitBounds = (props: Map, scene: Scene) => {
if (props.includePoints) {
fitIncludePoints(props.includePoints, scene, props.includePadding);
} else {
Expand All @@ -53,7 +57,9 @@ export const setMapView = (props: Map, scene: Scene) => {
fitIncludePoints(points, scene, props.includePadding);
}
}
};

export const setMapStatus = (props: Map, scene: Scene) => {
if (props.enableZoom !== undefined) {
scene.setMapStatus({
zoomEnable: props.enableZoom,
Expand All @@ -69,9 +75,4 @@ export const setMapView = (props: Map, scene: Scene) => {
dragEnable: props.enableScroll,
});
}

if (props.onInitComplete) {
scene.off('loaded', props.onInitComplete);
scene.on('loaded', props.onInitComplete);
}
};
Loading

0 comments on commit 4d1b690

Please sign in to comment.