Skip to content

Commit a06f68e

Browse files
committed
docs: 实现随机选择效果
1 parent 94aeb9b commit a06f68e

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

docs/demos/config/demo/Sankey/basic.tsx

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
import type { IVChart, SankeyProps } from '@sensoro-design/chart';
22
import { Sankey } from '@sensoro-design/chart';
33
import React from 'react';
4+
import { foreach } from 'tree-lodash';
5+
6+
function getRandomElement<T = any>(arr: T[]) {
7+
if (arr.length === 0) {
8+
return null;
9+
}
10+
const randomIndex = Math.floor(Math.random() * arr.length);
11+
return arr[randomIndex];
12+
}
413

514
const values = [
615
{
@@ -187,10 +196,41 @@ function Example() {
187196

188197
if (!chart)
189198
return;
199+
// chart.setHovered([
200+
// {
201+
// name: '高风险',
202+
// },
203+
// ]);
204+
205+
const names: string[] = [];
206+
207+
foreach(
208+
values[0].nodes,
209+
(item) => {
210+
const name = item.name as unknown as string;
211+
if (!names.includes(name) && name !== '今日巡航次数') {
212+
names.push(name);
213+
}
214+
},
215+
{
216+
strategy: 'breadth',
217+
},
218+
);
219+
220+
setInterval(() => {
221+
const name = getRandomElement(names);
222+
223+
if (name) {
224+
chart.setHovered([
225+
{
226+
name,
227+
},
228+
]);
229+
}
230+
}, 2 * 1000);
190231
chart.setTooltipHandler({
191232
showTooltip: (activeType, data, params) => {
192-
// eslint-disable-next-line no-console
193-
console.log(activeType, data, params);
233+
// console.log(activeType, data, params);
194234
setTooltipStyles((prev) => {
195235
return {
196236
...prev,

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"react-dom": "catalog:",
5959
"rspress": "catalog:",
6060
"simple-git-hooks": "catalog:",
61+
"tree-lodash": "^0.4.0",
6162
"typescript": "catalog:",
6263
"vitest": "catalog:"
6364
},

pnpm-lock.yaml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)