Skip to content

Commit

Permalink
fix: new aggergation
Browse files Browse the repository at this point in the history
  • Loading branch information
islxyqwe committed May 7, 2024
1 parent d5f643b commit 0b4414c
Showing 1 changed file with 39 additions and 16 deletions.
55 changes: 39 additions & 16 deletions packages/graphic-walker/src/components/painter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,32 @@ const AggPainterContent = (props: {
const { t } = useTranslation();
const mediaTheme = useContext(themeContext);
const computation = useCompututaion();
const fields = useMemo(
() => [props.x, props.y, props.color, props.size, props.opacity, props.shape].filter((x) => x).map((x) => x!.field),
[props.x, props.y, props.color, props.size, props.opacity, props.shape]
);
const [viewDimensions, viewMeasures] = useMemo(() => {
const fields = [props.x, props.y, props.color, props.size, props.opacity, props.shape].filter((x) => x).map((x) => x!.field);
return [fields.filter((x) => x.analyticType === 'dimension'), fields.filter((x) => x.analyticType === 'measure')];
}, [props.x, props.y, props.color, props.size, props.opacity, props.shape]);
const totalFields = deduper(
fields.concat(
props.facets.flatMap((x) =>
x.dimensions.map((d) => ({
fid: d.fid,
name: d.fid,
semanticType: d.domain.type,
analyticType: d.domain.type === 'nominal' ? 'dimension' : 'measure',
}))
)
),
(x) => x.fid
);
return [totalFields.filter((x) => x.analyticType === 'dimension'), totalFields.filter((x) => x.analyticType === 'measure')];
}, [fields, props.facets]);
const paintDimensions = useMemo(() => {
return deduper(
[props.x, props.y, props.color, props.size, props.opacity, props.shape].filter((x) => x).filter((x) => x!.domain),
(x) => x!.field.fid
).map((x) => x!.domain!);
}, [props.x, props.y, props.color, props.size, props.opacity, props.shape]);
}, []);
const brushSizeRef = useRef(GLOBAL_CONFIG.PAINT_DEFAULT_BRUSH_SIZE);
const [brushSize, setBrushSize] = useState(GLOBAL_CONFIG.PAINT_DEFAULT_BRUSH_SIZE);
brushSizeRef.current = brushSize;
Expand All @@ -200,6 +216,7 @@ const AggPainterContent = (props: {
viewMeasures,
timezoneDisplayOffset: props.displayOffset,
});
console.log(viewMeasures, viewDimensions);
const indexes = useMemo(() => viewData.map(calcIndexesByDimensions(paintDimensions)), [viewData, paintDimensions]);
const [data, loadingResult] = useAsyncMemo(async () => {
const facetResult = await calcPaintMapV2(viewData, { dict: props.dict, facets: props.facets, usedColor: [] });
Expand All @@ -212,7 +229,6 @@ const AggPainterContent = (props: {
};
});
}, [indexes, viewData, props.dict, props.facets]);
console.log(data);

const [pixelOffset, setPixelOffset] = useState([0, 0]);

Expand Down Expand Up @@ -308,7 +324,6 @@ const AggPainterContent = (props: {
c.field = getMeaAggKey(targetField.fid, targetField.aggName);
}
});
console.log('===', spec);

embed(containerRef.current, spec, {
renderer: 'svg' as any,
Expand Down Expand Up @@ -543,16 +558,24 @@ const PainterContent = (props: {
const mediaTheme = useContext(themeContext);
const computation = useCompututaion();
const fields = useMemo(
() => [
{
...props.x,
analyticType: 'measure' as const,
},
{
...props.y,
analyticType: 'measure' as const,
},
],
() =>
deduper(
[
{
...props.x,
analyticType: 'measure' as const,
},
{
...props.y,
analyticType: 'measure' as const,
},
].concat(
props.facets.flatMap((x) =>
x.dimensions.map((d) => ({ fid: d.fid, name: d.fid, semanticType: d.domain.type, analyticType: 'measure' as const }))
)
),
(x) => x.fid
),
[props.x, props.y]
);
const brushSizeRef = useRef(GLOBAL_CONFIG.PAINT_DEFAULT_BRUSH_SIZE);
Expand Down

0 comments on commit 0b4414c

Please sign in to comment.