Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(multi-view): 修复多图层图表折线图联动取数问题 #2428

Merged
merged 1 commit into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions examples/dual-axes/column-line/demo/slider-column-line.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { DualAxes } from '@antv/g2plot';

const data = [
{ time: '2020-08-20', consumeTime: 10868, completeTime: 649.483 },
{ time: '2020-08-21', consumeTime: 8786, completeTime: 1053.7 },
{ time: '2020-08-22', consumeTime: 10824, completeTime: 679.817 },
{ time: '2020-08-23', consumeTime: 7860, completeTime: 638.117 },
{ time: '2020-08-24', consumeTime: 13253, completeTime: 843.3 },
{ time: '2020-08-25', consumeTime: 17015, completeTime: 1092.983 },
{ time: '2020-08-26', consumeTime: 19298, completeTime: 1036.317 },
{ time: '2020-08-27', consumeTime: 13937, completeTime: 1031.9 },
{ time: '2020-08-28', consumeTime: 11541, completeTime: 803.467 },
{ time: '2020-08-29', consumeTime: 15244, completeTime: 830.733 },
{ time: '2020-08-30', consumeTime: 14247, completeTime: 709.867 },
{ time: '2020-08-31', consumeTime: 9402, completeTime: 665.233 },
{ time: '2020-09-01', consumeTime: 10440, completeTime: 696.367 },
{ time: '2020-09-02', consumeTime: 9345, completeTime: 692.867 },
{ time: '2020-09-03', consumeTime: 18459, completeTime: 936.017 },
{ time: '2020-09-04', consumeTime: 9763, completeTime: 782.867 },
{ time: '2020-09-05', consumeTime: 11074, completeTime: 653.8 },
{ time: '2020-09-06', consumeTime: 11770, completeTime: 856.683 },
{ time: '2020-09-07', consumeTime: 12206, completeTime: 777.15 },
{ time: '2020-09-08', consumeTime: 11434, completeTime: 773.283 },
{ time: '2020-09-09', consumeTime: 16218, completeTime: 833.3 },
{ time: '2020-09-10', consumeTime: 11914, completeTime: 793.517 },
{ time: '2020-09-11', consumeTime: 16781, completeTime: 894.45 },
{ time: '2020-09-12', consumeTime: 10555, completeTime: 725.55 },
{ time: '2020-09-13', consumeTime: 10899, completeTime: 709.967 },
{ time: '2020-09-14', consumeTime: 10713, completeTime: 787.6 },
{ time: '2020-09-15', consumeTime: 0, completeTime: 644.183 },
{ time: '2020-09-16', consumeTime: 0, completeTime: 1066.65 },
{ time: '2020-09-17', consumeTime: 20357, completeTime: 932.45 },
{ time: '2020-09-18', consumeTime: 10424, completeTime: 753.583 },
];

const dualAxes = new DualAxes('container', {
data: [data, data],
xField: 'time',
yField: ['consumeTime', 'completeTime'],
limitInPlot: false,
padding: [10, 20, 80, 30], // 需要设置底部 padding 值,同 css
slider: {},
meta: {
time: {
sync: false, // 开启之后 slider 无法重绘
},
},
geometryOptions: [
{
geometry: 'column',
},
{
geometry: 'line',
},
],
});

dualAxes.render();
135 changes: 135 additions & 0 deletions examples/plugin/association/demo/association-line.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import { MultiView } from '@antv/g2plot';
import { groupBy, get } from '@antv/util';

fetch('https://gw.alipayobjects.com/os/antfincdn/HkxWvFrZuC/association-data.json')
.then((data) => data.json())
.then((data) => {
function getDataByArea(area) {
return get(groupBy(data.line, 'area'), area, []).map((d) => ({
time: d.time,
value: Math.random() * d.value,
area,
}));
}

const plot = new MultiView('container', {
// 关闭 chart 上的 tooltip,子 view 开启 tooltip
tooltip: false,
plots: [
{
type: 'line',
region: { start: { x: 0, y: 0 }, end: { x: 1, y: 0.3 } },
options: {
data: data.line,
xField: 'time',
yField: 'value',
seriesField: 'area',
point: { style: { r: 2.5 } },
meta: {
time: { range: [0, 1] },
},
interactions: [{ type: 'association-active' }, { type: 'association-highlight' }],
},
},
{
type: 'line',
region: { start: { x: 0, y: 0.32 }, end: { x: 0.5, y: 0.65 } },
options: {
data: getDataByArea('华东'),
xField: 'time',
yField: 'value',
seriesField: 'area',
interactions: [{ type: 'association-highlight' }],
point: {
style: { r: 2.5 },
state: {
active: {
style: {
lineWidth: 1,
r: 3,
},
},
},
},
meta: {
time: { range: [0, 1] },
},
smooth: true,
tooltip: {
showCrosshairs: true,
shared: true,
},
state: {
active: {
style: {
lineWidth: 3,
},
},
},
},
},
{
type: 'line',
region: { start: { x: 0.5, y: 0.32 }, end: { x: 1, y: 0.65 } },
options: {
data: getDataByArea('华北'),
xField: 'time',
yField: 'value',
seriesField: 'area',
interactions: [{ type: 'association-highlight' }],
point: { style: { r: 2.5 } },
meta: {
time: { range: [0, 1] },
},
smooth: true,
tooltip: {
showCrosshairs: true,
shared: true,
},
},
},
{
type: 'line',
region: { start: { x: 0, y: 0.67 }, end: { x: 0.5, y: 1 } },
options: {
data: getDataByArea('中南'),
xField: 'time',
yField: 'value',
seriesField: 'area',
interactions: [{ type: 'association-highlight' }],
point: { style: { r: 2.5 } },
meta: {
time: { range: [0, 1] },
},
smooth: true,
tooltip: {
showCrosshairs: true,
shared: true,
},
},
},
{
type: 'line',
region: { start: { x: 0.5, y: 0.67 }, end: { x: 1, y: 1 } },
options: {
data: getDataByArea('西南'),
xField: 'time',
yField: 'value',
seriesField: 'area',
interactions: [{ type: 'association-highlight' }],
point: { style: { r: 2.5 } },
meta: {
time: { range: [0, 1] },
},
smooth: true,
tooltip: {
showCrosshairs: true,
shared: true,
},
},
},
],
});

plot.render();
});
8 changes: 8 additions & 0 deletions examples/plugin/association/demo/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
"en": "Association filter"
},
"screenshot": "https://gw.alipayobjects.com/zos/antfincdn/%24kAk5jxs1v/association-filter.gif"
},
{
"filename": "association-line.ts",
"title": {
"zh":"折线图联动",
"en":"Association line"
},
"screenshot": "https://gw.alipayobjects.com/zos/antfincdn/67tdfeaWWN/line-association.gif"
}
]
}
6 changes: 3 additions & 3 deletions src/plots/multi-view/interactions/association.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { each, get, map } from '@antv/util';
import { each, get, map, isArray } from '@antv/util';
import { registerAction, registerInteraction, View, Element, Action } from '@antv/g2';
import { getAllElements, getViews, getSilbingViews } from '../../../utils';
import { clearHighlight, getElementValue } from './utils';
Expand Down Expand Up @@ -50,8 +50,8 @@ class Association extends Action {
const elements = map(getAllElements(v), (ele) => {
let active = false;
let inactive = false;

if (getElementValue(ele, field) === get(data, field)) {
const dataValue = isArray(data) ? get(data[0], field) : get(data, field);
if (getElementValue(ele, field) === dataValue) {
active = true;
} else {
inactive = true;
Expand Down