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:新增打包图circle packing #2178

Merged
merged 4 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 10 additions & 0 deletions packages/plots/src/components/circlePacking/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import { CirclePackingOptions } from '../../core';
import { CommonConfig } from '../../interface';
import { BaseChart } from '../base';

export type CirclePackingConfig = CommonConfig<CirclePackingOptions>;

const CirclePackingChart = (props: CirclePackingConfig) => <BaseChart {...props} chartType="CirclePacking" />;

export default CirclePackingChart;
3 changes: 3 additions & 0 deletions packages/plots/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Gauge from './gauge';
import Liquid from './liquid';
import WordCloud from './wordCloud';
import Treemap from './treemap';
import CirclePacking from './circlePacking';

export type { AreaConfig } from './area';
export type { BarConfig } from './bar';
Expand All @@ -42,6 +43,7 @@ export type { GaugeConfig } from './gauge';
export type { LiquidConfig } from './liquid';
export type { WordCloudConfig } from './wordCloud';
export type { TreemapConfig } from './treemap';
export type { CirclePackingConfig } from './circlePacking';

export {
Base,
Expand All @@ -66,4 +68,5 @@ export {
Liquid,
WordCloud,
Treemap,
CirclePacking,
};
3 changes: 3 additions & 0 deletions packages/plots/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type { GaugeOptions } from './plots/gauge';
export type { LiquidOptions } from './plots/liquid';
export type { WordCloudOptions } from './plots/wordCloud';
export type { TreemapOptions } from './plots/treemap';
export type { CirclePackingOptions } from './plots/circlePacking';
export * from './types';

import { Base } from './plots/base';
Expand Down Expand Up @@ -52,6 +53,7 @@ import { Gauge } from './plots/gauge';
import { Liquid } from './plots/liquid';
import { WordCloud } from './plots/wordCloud';
import { Treemap } from './plots/treemap';
import { CirclePacking } from './plots/circlePacking';

export const Plots = {
Base,
Expand Down Expand Up @@ -80,4 +82,5 @@ export const Plots = {
Liquid,
WordCloud,
Treemap,
CirclePacking,
};
14 changes: 14 additions & 0 deletions packages/plots/src/core/plots/circlePacking/adaptor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { flow, transformOptions } from '../../utils';
import type { Adaptor } from '../../types';
import type { CirclePackingOptions } from './type';

type Params = Adaptor<CirclePackingOptions>;

/**
* @param chart
* @param options
*/
export function adaptor(params: Params) {

return flow(transformOptions)(params);
}
40 changes: 40 additions & 0 deletions packages/plots/src/core/plots/circlePacking/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Plot } from '../../base';
import { adaptor } from './adaptor';

import type { CirclePackingOptions } from './type';
import type { Adaptor } from '../../types';

export type { CirclePackingOptions };

export class CirclePacking extends Plot<CirclePackingOptions> {
/** 图表类型 */
public type = 'CirclePacking';

/**
* 获取 circle packing 默认配置项
* 供外部使用
*/
static getDefaultOptions(): Partial<CirclePackingOptions> {
return {
legend: false,
type: "view",
children: [{
type: "pack"
}]
};
}

/**
* 获取 打包图 默认配置
*/
protected getDefaultOptions() {
return CirclePacking.getDefaultOptions();
}

/**
* 打包图适配器
*/
protected getSchemaAdaptor(): (params: Adaptor<CirclePackingOptions>) => void {
return adaptor;
}
}
3 changes: 3 additions & 0 deletions packages/plots/src/core/plots/circlePacking/type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import type { BaseOptions, Options } from '../../types/common';

export type CirclePackingOptions = Options & BaseOptions;
dongxifan marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions site/.dumi/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ if (window) {
(window as any).lodashEs = require('lodash-es');
/** 不要使用 link, react-dom 冲突 */
(window as any).plots = require('@ant-design/plots');
(window as any).d3Interpolate = require('d3-interpolate');
}
27 changes: 27 additions & 0 deletions site/examples/statistics/treemap/demo/circlePacking.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@


import { CirclePacking } from '@ant-design/plots';
import { interpolateHcl } from 'd3-interpolate';
import React from 'react';
import ReactDOM from 'react-dom';
const DemoCirclePacking = () => {

const config = {
data: {
type: "fetch",
value: "https://assets.antv.antgroup.com/g2/flare.json",
},
valueField: "value",
colorField: "depth",
scale: {
color: {
domain: [0, 5],
range: ["hsl(152,80%,80%)", "hsl(228,30%,40%)"],
interpolate: interpolateHcl
},
},
};
return <CirclePacking {...config} />;
};

ReactDOM.render(<DemoCirclePacking />, document.getElementById('container'));
8 changes: 8 additions & 0 deletions site/examples/statistics/treemap/demo/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
"en": "Treemap Chart"
},
"screenshot": "https://gw.alipayobjects.com/mdn/rms_f5c722/afts/img/A*Ob1jSbCUl8cAAAAAAAAAAABkARQnAQ"
},
{
"filename": "circlePacking.js",
"title": {
"zh": "Circle packing",
"en": "CirclePacking Chart"
},
"screenshot": "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*epG0TaxEVTsAAAAAAAAAAAAADmJ7AQ/original"
}
]
}
1 change: 1 addition & 0 deletions site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@types/react": "^16.14.8",
"@types/react-dom": "^16.9.13",
"cross-env": "^7.0.3",
"d3-interpolate": "^3.0.1",
"dumi": "^2.1.11",
"fecha": "^4.2.3",
"gh-pages": "^2.1.1",
Expand Down