From 65e0ab44873e50523019c3f2b84f4b021af36ce0 Mon Sep 17 00:00:00 2001
From: lxfu1 <954055752@qq.com>
Date: Fri, 6 Sep 2024 16:34:22 +0800
Subject: [PATCH 1/2] chore: custom shape demo
---
.../case/interactions/demo/custom-shape.js | 49 +++++++++++++++++++
.../examples/case/interactions/demo/meta.json | 8 +++
2 files changed, 57 insertions(+)
create mode 100644 site/examples/case/interactions/demo/custom-shape.js
diff --git a/site/examples/case/interactions/demo/custom-shape.js b/site/examples/case/interactions/demo/custom-shape.js
new file mode 100644
index 000000000..9a921eb8f
--- /dev/null
+++ b/site/examples/case/interactions/demo/custom-shape.js
@@ -0,0 +1,49 @@
+import { Column } from '@ant-design/plots';
+import React from 'react';
+import ReactDOM from 'react-dom';
+
+const DemoCustomShape = () => {
+ const config = {
+ data: [
+ { type: '1-3秒', value: 0.36 },
+ { type: '4-10秒', value: 0.25 },
+ { type: '11-30秒', value: 0.24 },
+ { type: '31-60秒', value: 0.19 },
+ { type: '1-3分', value: 0.12 },
+ { type: '3-10分', value: 0.15 },
+ { type: '10-30分', value: 0.16 },
+ { type: '30+分', value: 0.1 },
+ ],
+ xField: 'type',
+ yField: 'value',
+ annotations: [
+ {
+ type: 'shape',
+ xField: 'type',
+ yField: 'value',
+ style: {
+ render: ({ x, y }, context) => {
+ const { document } = context;
+ const g = document.createElement('g', {});
+ const { width } = document.getElementsByClassName('element')[0].getBBox();
+ const rect = document.createElement('rect', {
+ style: {
+ x: x - width / 2,
+ y: y - 20,
+ width,
+ height: 10,
+ fill: '#FF8C16',
+ cursor: 'pointer',
+ },
+ });
+ g.appendChild(rect);
+ return g;
+ },
+ },
+ },
+ ],
+ };
+ return ;
+};
+
+ReactDOM.render(, document.getElementById('container'));
diff --git a/site/examples/case/interactions/demo/meta.json b/site/examples/case/interactions/demo/meta.json
index 555170d2f..4e83f785a 100644
--- a/site/examples/case/interactions/demo/meta.json
+++ b/site/examples/case/interactions/demo/meta.json
@@ -51,6 +51,14 @@
"en": "Data update"
},
"screenshot": "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*0O5VR5z7zlgAAAAAAAAAAAAADmJ7AQ/original"
+ },
+ {
+ "filename": "custom-shape.js",
+ "title": {
+ "zh": "自定义图形标记",
+ "en": "Custom shape"
+ },
+ "screenshot": "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*n4GESr9WhDQAAAAAAAAAAAAADmJ7AQ/original"
}
]
}
\ No newline at end of file
From fa0e2508ee8f8e20f1bb4b266f69171887db402e Mon Sep 17 00:00:00 2001
From: lxfu1 <954055752@qq.com>
Date: Fri, 6 Sep 2024 16:49:07 +0800
Subject: [PATCH 2/2] chore: default selected demo
---
.../interactions/demo/default-selected.js | 40 +++++++++++++++++++
.../examples/case/interactions/demo/meta.json | 8 ++++
2 files changed, 48 insertions(+)
create mode 100644 site/examples/case/interactions/demo/default-selected.js
diff --git a/site/examples/case/interactions/demo/default-selected.js b/site/examples/case/interactions/demo/default-selected.js
new file mode 100644
index 000000000..6b61f5e35
--- /dev/null
+++ b/site/examples/case/interactions/demo/default-selected.js
@@ -0,0 +1,40 @@
+import React from 'react';
+import ReactDOM from 'react-dom';
+import { Bar } from '@ant-design/plots';
+
+const DemoSelected = () => {
+ const config = {
+ data: [
+ { type: '分类一', value: 87 },
+ { type: '分类二', value: 65 },
+ { type: '分类三', value: 48 },
+ { type: '分类四', value: 15 },
+ { type: '分类五', value: 10 },
+ { type: '其他', value: 5 },
+ ],
+ xField: 'type',
+ yField: 'value',
+ colorField: 'type',
+ state: {
+ unselected: { opacity: 0.5 },
+ selected: { lineWidth: 3, stroke: 'red' },
+ },
+ interaction: {
+ elementSelect: true,
+ },
+ onReady: ({ chart, ...rest }) => {
+ chart.on(
+ 'afterrender',
+ () => {
+ const { document } = chart.getContext().canvas;
+ const elements = document.getElementsByClassName('element');
+ elements[0]?.emit('click');
+ },
+ true,
+ );
+ },
+ };
+ return ;
+};
+
+ReactDOM.render(, document.getElementById('container'));
diff --git a/site/examples/case/interactions/demo/meta.json b/site/examples/case/interactions/demo/meta.json
index 4e83f785a..a80003ce7 100644
--- a/site/examples/case/interactions/demo/meta.json
+++ b/site/examples/case/interactions/demo/meta.json
@@ -59,6 +59,14 @@
"en": "Custom shape"
},
"screenshot": "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*n4GESr9WhDQAAAAAAAAAAAAADmJ7AQ/original"
+ },
+ {
+ "filename": "default-selected.js",
+ "title": {
+ "zh": "默认选中",
+ "en": "Default selected"
+ },
+ "screenshot": "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*PKwaRJj4WNsAAAAAAAAAAAAADmJ7AQ/original"
}
]
}
\ No newline at end of file