-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
yelinlei.yll
committed
Nov 17, 2023
1 parent
38e9136
commit 60cbc49
Showing
15 changed files
with
442 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from 'react'; | ||
import { VennOptions } from '../../core'; | ||
import { CommonConfig } from '../../interface'; | ||
import { BaseChart } from '../base'; | ||
|
||
export type VennConfig = CommonConfig<VennOptions>; | ||
|
||
const VennChart = (props: VennConfig) => <BaseChart {...props} chartType="Venn" />; | ||
|
||
export default VennChart; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { flow, isArray, omit, remove, set, transformOptions } from '../../utils'; | ||
import { mark } from '../../components'; | ||
import type { Adaptor } from '../../types'; | ||
import { DefaultTransformKey, type VennOptions } from './type'; | ||
|
||
type Params = Adaptor<VennOptions>; | ||
|
||
/** | ||
* @param chart | ||
* @param options | ||
*/ | ||
export function adaptor(params: Params) { | ||
/** | ||
* 图表差异化处理 | ||
*/ | ||
const init = (params: Params) => { | ||
const { options } = params; | ||
const { data, setsField, sizeField } = options; | ||
if (isArray(data)) { | ||
set(options, 'data', { | ||
type: 'inline', | ||
value: data, | ||
transform: [ | ||
{ | ||
type: 'venn', | ||
sets: setsField, | ||
size: sizeField, | ||
as: [DefaultTransformKey.color, DefaultTransformKey.d], | ||
}, | ||
], | ||
}); | ||
set(options, 'colorField', setsField); | ||
set(options?.children[0]?.encode, 'd', sizeField); | ||
} | ||
set(params, 'options', omit(options, ['sizeField', 'setsField'])); | ||
return params; | ||
}; | ||
|
||
// const dField = (params: Params) => { | ||
// const { options } = params; | ||
// const { setsField } = options; | ||
// // set(options?.children[0]?.encode, 'd', 'sets'); | ||
// // set(options?.children[0], 'encode', omit(options?.children[0]?.encode, ['size'])); | ||
|
||
// return params; | ||
// }; | ||
|
||
// const color = (params: Params) => { | ||
// const { options } = params; | ||
// set(options, 'colorField', 'key'); | ||
// return params; | ||
// }; | ||
|
||
const style = (params: Params) => { | ||
const { options } = params; | ||
const { pointStyle, style } = options; | ||
set(options, 'style', { ...style, ...pointStyle }); | ||
set(params, 'options', omit(options, ['pointStyle'])); | ||
return params; | ||
}; | ||
|
||
// const tooltip = (params) => { | ||
// const { options } = params; | ||
// const { tooltip } = options; | ||
// if (!tooltip) { | ||
// set(options, 'tooltip', { | ||
// title: false, | ||
// items: [ | ||
// (d) => { | ||
// return { name: d.key, value: d.size }; | ||
// }, | ||
// ], | ||
// }); | ||
// } | ||
// return params; | ||
// }; | ||
|
||
const transformColorRange = (params: Params) => { | ||
const { options } = params; | ||
const { color } = options; | ||
if (color) { | ||
set(options, 'scale', { | ||
color: { range: color }, | ||
}); | ||
} | ||
return params; | ||
}; | ||
|
||
return flow(init, style, transformColorRange, transformOptions)(params); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { Plot } from '../../base'; | ||
import type { Adaptor } from '../../types'; | ||
import { adaptor } from './adaptor'; | ||
import { DefaultTransformKey, VennOptions } from './type'; | ||
|
||
export type { VennOptions }; | ||
|
||
export class Venn extends Plot<VennOptions> { | ||
/** 图表类型 */ | ||
public type = 'venn'; | ||
|
||
/** | ||
* 获取 折线图 默认配置项 | ||
* 供外部使用 | ||
*/ | ||
static getDefaultOptions(): Partial<VennOptions> { | ||
return { | ||
type: 'view', | ||
children: [{ type: 'path' }], | ||
label: { | ||
position: 'inside', | ||
text: (d) => d.label || '', | ||
}, | ||
legend: { | ||
color: { itemMarker: 'circle' }, | ||
}, | ||
// colorField: 'key', | ||
tooltip: { | ||
title: false, | ||
items: [ | ||
(d) => { | ||
return { name: d.key, value: d.size }; | ||
}, | ||
], | ||
}, | ||
encode: { color: DefaultTransformKey.color, d: DefaultTransformKey.d }, | ||
// colorField: 'sets', | ||
// scale: { | ||
// y: { nice: true }, | ||
// }, | ||
// interaction: { | ||
// tooltip: { | ||
// shared: true, | ||
// }, | ||
// }, | ||
// axis: { | ||
// y: { title: false }, | ||
// x: { title: false }, | ||
// }, | ||
// animate: { | ||
// enter: { type: 'growInX' }, | ||
// }, | ||
}; | ||
} | ||
|
||
/** | ||
* 获取 折线图 默认配置 | ||
*/ | ||
protected getDefaultOptions() { | ||
return Venn.getDefaultOptions(); | ||
} | ||
|
||
/** | ||
* 折线图适配器 | ||
*/ | ||
protected getSchemaAdaptor(): (params: Adaptor<VennOptions>) => void { | ||
return adaptor; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import type { BaseOptions, Options } from '../../types/common'; | ||
|
||
export type VennOptions = Options & BaseOptions; | ||
|
||
export enum DefaultTransformKey { | ||
color = 'key', | ||
d = 'path', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Venn } from '@ant-design/plots'; | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
|
||
const DemoVenn = () => { | ||
const config = { | ||
data: [ | ||
{ sets: ['A'], size: 12, label: 'A' }, | ||
{ sets: ['B'], size: 12, label: 'B' }, | ||
{ sets: ['C'], size: 12, label: 'C' }, | ||
{ sets: ['A', 'B'], size: 2, label: 'A&B' }, | ||
{ sets: ['A', 'C'], size: 2, label: 'A&C' }, | ||
{ sets: ['B', 'C'], size: 2, label: 'B&C' }, | ||
{ sets: ['A', 'B', 'C'], size: 1 }, | ||
], | ||
setsField: 'sets', | ||
sizeField: 'size', | ||
pointStyle: { fillOpacity: 0.85 }, | ||
}; | ||
return <Venn {...config} />; | ||
}; | ||
|
||
ReactDOM.render(<DemoVenn />, document.getElementById('container')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Venn } from '@ant-design/plots'; | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
|
||
const DemoVenn = () => { | ||
const config = { | ||
data: [ | ||
{ sets: ['A'], size: 12, label: 'A' }, | ||
{ sets: ['B'], size: 12, label: 'B' }, | ||
{ sets: ['C'], size: 12, label: 'C' }, | ||
{ sets: ['A', 'B'], size: 2, label: 'A&B' }, | ||
{ sets: ['A', 'C'], size: 2, label: 'A&C' }, | ||
{ sets: ['B', 'C'], size: 2, label: 'B&C' }, | ||
{ sets: ['A', 'B', 'C'], size: 1 }, | ||
], | ||
setsField: 'sets', | ||
sizeField: 'size', | ||
pointStyle: { fillOpacity: 0.85 }, | ||
style: { | ||
fill: (datum, index, data) => { | ||
console.log(data) | ||
const { size } = datum; | ||
if (size <= 2) return '#f4bb51'; | ||
}, | ||
}, | ||
}; | ||
return <Venn {...config} />; | ||
}; | ||
|
||
ReactDOM.render(<DemoVenn />, document.getElementById('container')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Venn } from '@ant-design/plots'; | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
|
||
const DemoVenn = () => { | ||
const config = { | ||
data: { | ||
type: 'fetch', | ||
value: 'https://gw.alipayobjects.com/os/bmw-prod/c4c17fe9-0a93-4255-bc1e-1ff84966d24a.json', | ||
transform: [ | ||
{ | ||
type: 'venn', | ||
sets: 'sets', | ||
size: 'size', | ||
as: ['key', 'path'], | ||
}, | ||
], | ||
}, | ||
setsField: 'sets', | ||
sizeField: 'size', | ||
pointStyle: { fillOpacity: 0.85 }, | ||
color: ['#9DF5CA', '#61DDAA', '#42C090'], | ||
label: { | ||
style: { | ||
lineHeight: 20, | ||
}, | ||
text: (datum) => { | ||
return `${datum.size}`; | ||
}, | ||
}, | ||
interaction: { | ||
tooltip: { | ||
// render 回调方法返回一个innerHTML 或者 DOM | ||
render: (event, { title, items }) => { | ||
console.log(event, { title, items }); | ||
return `<div> | ||
<h3 style="padding:0;margin:0">title:${title}</h3> | ||
<ul>${items.map((d) => `<li><span style="color: ${d.color}">${d.name}</span> ${d.value}</li>`)}</ul> | ||
</div>`; | ||
}, | ||
}, | ||
}, | ||
}; | ||
return <Venn {...config} />; | ||
}; | ||
|
||
ReactDOM.render(<DemoVenn />, document.getElementById('container')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Venn } from '@ant-design/plots'; | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
|
||
const DemoVenn = () => { | ||
const config = { | ||
data: [ | ||
{ sets: ['A'], size: 12, label: 'A' }, | ||
{ sets: ['B'], size: 12, label: 'B' }, | ||
{ sets: ['C'], size: 12, label: 'C' }, | ||
{ sets: ['A', 'B'], size: 2, label: 'A&B' }, | ||
{ sets: ['A', 'C'], size: 2, label: 'A&C' }, | ||
{ sets: ['B', 'C'], size: 2, label: 'B&C' }, | ||
{ sets: ['A', 'B', 'C'], size: 1 }, | ||
], | ||
setsField: 'sets', | ||
sizeField: 'size', | ||
pointStyle: { fillOpacity: 0.85 }, | ||
state: { | ||
active: { | ||
fillOpacity: 0.8, | ||
stroke: 'red', | ||
lineWidth: 1, | ||
}, | ||
inactive: { | ||
fillOpacity: 0.2, | ||
lineWidth: 0, | ||
}, | ||
}, | ||
interaction: { | ||
elementHighlight: true, | ||
}, | ||
}; | ||
return <Venn {...config} />; | ||
}; | ||
|
||
ReactDOM.render(<DemoVenn />, document.getElementById('container')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Venn } from '@ant-design/plots'; | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
|
||
const DemoVenn = () => { | ||
const config = { | ||
data: [ | ||
{ sets: ['A'], size: 12, label: 'A' }, | ||
{ sets: ['B'], size: 12, label: 'B' }, | ||
{ sets: ['C'], size: 12, label: 'C' }, | ||
{ sets: ['A', 'B'], size: 2, label: 'A&B' }, | ||
{ sets: ['A', 'C'], size: 2, label: 'A&C' }, | ||
{ sets: ['B', 'C'], size: 2, label: 'B&C' }, | ||
{ sets: ['A', 'B', 'C'], size: 1 }, | ||
], | ||
setsField: 'sets', | ||
sizeField: 'size', | ||
pointStyle: { fillOpacity: 0.85 }, | ||
label: { | ||
position: 'inside', | ||
text: (d) => d.label || '', | ||
transform: [{ type: 'contrastReverse' }], | ||
} | ||
}; | ||
return <Venn {...config} />; | ||
}; | ||
|
||
ReactDOM.render(<DemoVenn />, document.getElementById('container')); |
Oops, something went wrong.