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(aggr): field unmatched when fid duplicated #112

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 5 additions & 2 deletions packages/graphic-walker/src/vis/spec/aggregate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import { COUNT_FIELD_ID } from '../../constants';
import { IViewField } from '../../interfaces';
import { getMeaAggKey } from '../../utils';

export function channelAggregate(encoding: { [key: string]: any }, fields: IViewField[]) {
export function channelAggregate(encoding: { [key: string]: any }, channels: WeakMap<object, IViewField>) {
Object.values(encoding).forEach((c) => {
const targetField = fields.find((f) => f.fid === c.field && !('aggregate' in c));
if ('aggregate' in c) {
return;
}
const targetField = channels.get(c);
if (targetField && targetField.fid === COUNT_FIELD_ID) {
c.title = 'Count';
c.field = getMeaAggKey(targetField.fid, targetField.aggName)
Expand Down
6 changes: 4 additions & 2 deletions packages/graphic-walker/src/vis/spec/encode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export function availableChannels(geomType: string): Set<string> {
}
return new Set(['column', 'opacity', 'color', 'row', 'size', 'x', 'y', 'xOffset', 'yOffset', 'shape']);
}
export function channelEncode(props: IEncodeProps) {
export function channelEncode(props: IEncodeProps): [{ [key: string]: any }, WeakMap<object, IViewField>] {
const channels = new WeakMap<object, IViewField>();
const avcs = availableChannels(props.geomType);
const encoding: { [key: string]: any } = {};
Object.keys(props)
Expand All @@ -46,6 +47,7 @@ export function channelEncode(props: IEncodeProps) {
if (props[c].analyticType === 'measure') {
encoding[c].type = 'quantitative';
}
channels.set(encoding[c], props[c]);
}
});
// FIXME: temporal fix, only for x and y relative order
Expand All @@ -70,5 +72,5 @@ export function channelEncode(props: IEncodeProps) {
}
}
}
return encoding;
return [encoding, channels];
}
7 changes: 3 additions & 4 deletions packages/graphic-walker/src/vis/spec/view.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ISemanticType, IStackMode, IViewField } from '../../interfaces';
import { ISemanticType, IStackMode } from '../../interfaces';
import { autoMark } from './mark';
import { NULL_FIELD } from './field';
import { channelAggregate } from './aggregate';
Expand Down Expand Up @@ -32,7 +32,6 @@ export function getSingleView(props: SingleViewProps) {
geomType,
hideLegend = false,
} = props;
const fields: IViewField[] = [x, y, color, opacity, size, shape, row, column, xOffset, yOffset, theta, radius, text];
let markType = geomType;
let config: any = {};
if (hideLegend) {
Expand All @@ -47,7 +46,7 @@ export function getSingleView(props: SingleViewProps) {
markType = autoMark(types);
}

let encoding = channelEncode({
let [encoding, mapping] = channelEncode({
geomType: markType,
x,
y,
Expand All @@ -65,7 +64,7 @@ export function getSingleView(props: SingleViewProps) {
text
});
if (defaultAggregated) {
channelAggregate(encoding, fields);
channelAggregate(encoding, mapping);
}
addTooltipEncode(encoding, details, defaultAggregated);
channelStack(encoding, stack);
Expand Down