diff --git a/examples/dynamic-plots/brush/demo/meta.json b/examples/dynamic-plots/brush/demo/meta.json index 0be5a7f0bd..d75d021bb9 100644 --- a/examples/dynamic-plots/brush/demo/meta.json +++ b/examples/dynamic-plots/brush/demo/meta.json @@ -5,19 +5,19 @@ }, "demos": [ { - "filename": "scatter-brush.ts", + "filename": "scatter-brush.jsx", "title": { - "zh": "散点图刷选", - "en": "Brush of scatter" + "zh": "散点图刷选高亮", + "en": "Brush highlight of scatter" }, "new": true, "screenshot": "https://gw.alipayobjects.com/zos/antfincdn/BlpX0yZrRH/brush-highlight.gif" }, { - "filename": "scatter-brush-x.ts", + "filename": "scatter-brush-filter.ts", "title": { - "zh": "散点图 x 方向刷选", - "en": "Brush on x position of scatter" + "zh": "散点图刷选", + "en": "Brush of scatter" }, "new": true, "screenshot": "https://gw.alipayobjects.com/zos/antfincdn/x6%24CDJpPny/brush-x.gif" diff --git a/examples/dynamic-plots/brush/demo/scatter-brush-x.ts b/examples/dynamic-plots/brush/demo/scatter-brush-filter.ts similarity index 83% rename from examples/dynamic-plots/brush/demo/scatter-brush-x.ts rename to examples/dynamic-plots/brush/demo/scatter-brush-filter.ts index 3bceb120bb..38b9da6954 100644 --- a/examples/dynamic-plots/brush/demo/scatter-brush-x.ts +++ b/examples/dynamic-plots/brush/demo/scatter-brush-filter.ts @@ -15,8 +15,6 @@ fetch('https://gw.alipayobjects.com/os/antvdemo/assets/data/scatter.json') }, brush: { enabled: true, - // 圈选类型,默认: 'rect', 也可以设置 'y-rect', 'circle', 'path' - type: 'x-rect', mask: { style: { fill: 'rgba(255,0,0,0.15)', diff --git a/examples/dynamic-plots/brush/demo/scatter-brush.jsx b/examples/dynamic-plots/brush/demo/scatter-brush.jsx new file mode 100644 index 0000000000..bb02b6abae --- /dev/null +++ b/examples/dynamic-plots/brush/demo/scatter-brush.jsx @@ -0,0 +1,87 @@ +import React from 'react'; +import ReactDOM from 'react-dom'; +import { Select } from 'antd'; +import { Scatter } from '@antv/g2plot'; +import insertCss from 'insert-css'; + +class Plot extends React.Component { + chartNodeRef = React.createRef(); + chartRef = React.createRef(); + + componentDidMount() { + const chartDom = this.chartNodeRef.current; + const plot = new Scatter(chartDom, { + data: [], + xField: 'weight', + yField: 'height', + colorField: 'gender', + size: 5, + shape: 'circle', + pointStyle: { + fillOpacity: 1, + }, + brush: { + enabled: true, + // 圈选高亮,不指定默认为: filter + action: 'highlight', + mask: { + style: { + fill: 'rgba(0,0,0,0.15)', + stroke: 'rgba(0,0,0,0.45)', + lineWidth: 0.5, + }, + }, + }, + }); + + // Step 3: 渲染图表 + plot.render(); + this.chartRef.current = plot; + + fetch('https://gw.alipayobjects.com/os/antvdemo/assets/data/scatter.json') + .then((res) => res.json()) + .then((data) => { + plot.changeData(data); + }); + } + + handleChange = (v) => { + const plot = this.chartRef.current; + if (plot) { + plot.update({ brush: { type: v } }); + } + }; + + render() { + return ( +
+
+ Brush 类型 + +
+
+
+ ); + } +} + +// 我们用 insert-css 演示引入自定义样式 +// 推荐将样式添加到自己的样式文件中 +// 若拷贝官方代码,别忘了 npm install insert-css +insertCss(` + .select-label { + margin-right: 8px; + } + .select-label:not(:first-of-type) { + margin-left: 8px; + } + .chart-wrapper { + margin-top: 12px; + } +`); + +ReactDOM.render(, document.getElementById('container')); diff --git a/examples/dynamic-plots/brush/demo/scatter-brush.ts b/examples/dynamic-plots/brush/demo/scatter-brush.ts deleted file mode 100644 index e1014475e7..0000000000 --- a/examples/dynamic-plots/brush/demo/scatter-brush.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { Scatter } from '@antv/g2plot'; - -fetch('https://gw.alipayobjects.com/os/antvdemo/assets/data/scatter.json') - .then((res) => res.json()) - .then((data) => { - const plot = new Scatter('container', { - data, - xField: 'weight', - yField: 'height', - colorField: 'gender', - size: 5, - shape: 'circle', - pointStyle: { - fillOpacity: 1, - }, - brush: { - enabled: true, - // 圈选高亮,不指定默认为: filter - action: 'highlight', - mask: { - style: { - fill: 'rgba(0,0,0,0.15)', - stroke: 'rgba(0,0,0,0.45)', - lineWidth: 0.5, - }, - }, - }, - }); - plot.render(); - });