Skip to content

Commit

Permalink
docs: add text search demo
Browse files Browse the repository at this point in the history
  • Loading branch information
hustcc committed Nov 11, 2022
1 parent b36c722 commit 8bbea20
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions site/.dumi/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ if (window) {
(window as any).d3Array = require('d3-array');
(window as any).d3GeoProjection = require('d3-geo-projection');
(window as any).topojson = require('topojson');
(window as any).gPluginA11y = require('@antv/g-plugin-a11y');
}
16 changes: 16 additions & 0 deletions site/examples/others/plugins/demo/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"title": {
"zh": "涓枃鍒嗙被",
"en": "Category"
},
"demos": [
{
"filename": "text-search.ts",
"title": {
"zh": "Ctrl+F 鏂囨湰鎼滅储",
"en": "Search text by Ctrl+F"
},
"screenshot": "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*TehBRbDnoIkAAAAAAAAAAAAADmJ7AQ/original"
}
]
}
39 changes: 39 additions & 0 deletions site/examples/others/plugins/demo/text-search.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Chart } from '@antv/g2';
import { Plugin } from '@antv/g-plugin-a11y';

const plugin = new Plugin({ enableExtractingText: true });

const left = (d) => d.end > -1500 && d.start > -3000;

const chart = new Chart({
container: 'container',
width: 900,
height: 1000,
paddingRight: 80,
plugins: [plugin],
});

chart.coordinate({ type: 'transpose' });

chart
.interval()
.data({
type: 'fetch',
value: 'https://assets.antv.antgroup.com/g2/world-history.json',
})
.transform({ type: 'sortX', by: 'y' })
.transform({ type: 'sortColor', by: 'y', reducer: 'min' })
.axis('x', false)
.encode('x', 'civilization')
.encode('y', ['start', 'end'])
.encode('color', 'region')
.scale('color', { palette: 'set2' })
.label({
text: 'civilization',
position: (d) => (left(d) ? 'left' : 'right'),
textAlign: (d) => (left(d) ? 'end' : 'start'),
dx: (d) => (left(d) ? -5 : 5),
fontSize: 10,
});

chart.render();
4 changes: 4 additions & 0 deletions site/examples/others/plugins/index.en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
title: Plugins
order: 5
---
4 changes: 4 additions & 0 deletions site/examples/others/plugins/index.zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
title: 鎻掍欢
order: 5
---
1 change: 1 addition & 0 deletions site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
},
"dependencies": {
"@antv/dumi-theme-antv": "^0.3.0-beta.5",
"@antv/g-plugin-a11y": "^0.4.27",
"d3-array": "^3.2.0",
"d3-geo-projection": "^4.0.0",
"d3-hierarchy": "^3.1.2",
Expand Down

0 comments on commit 8bbea20

Please sign in to comment.