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

chore: ability to change facet chart fixed size #372

Merged
merged 1 commit into from
Apr 12, 2024
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
10 changes: 5 additions & 5 deletions packages/graphic-walker/src/lib/vega.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ export function toVegaSpec({
} else {
const rowNums = rowFacetField !== NULL_FIELD ? new Set(dataSource.map((x) => x[rowFacetField.fid])).size : 1;
const colNums = colFacetField !== NULL_FIELD ? new Set(dataSource.map((x) => x[colFacetField.fid])).size : 1;
spec.width = Math.floor((width - (rowFacetField === NULL_FIELD ? 40 : 94)) / colNums - 23);
spec.height = Math.floor((height - (colFacetField === NULL_FIELD ? 24 : 94)) / rowNums - 23);
spec.width = Math.floor(width / colNums);
spec.height = Math.floor(height / rowNums);
}

const v = getSingleView({
Expand All @@ -127,7 +127,7 @@ export function toVegaSpec({
geomType,
displayOffset,
dataSource,
vegaConfig
vegaConfig,
});
const singleView = scales ? resolveScales(scales, v, dataSource, mediaTheme) : v;

Expand Down Expand Up @@ -160,8 +160,8 @@ export function toVegaSpec({
} else {
const rowNums = rowFacetField !== NULL_FIELD ? new Set(dataSource.map((x) => x[rowFacetField.fid])).size : 1;
const colNums = colFacetField !== NULL_FIELD ? new Set(dataSource.map((x) => x[colFacetField.fid])).size : 1;
spec.width = Math.floor((width / colRepeatFields.length - (rowFacetField === NULL_FIELD ? 40 : 94)) / colNums - 23);
spec.height = Math.floor((height / rowRepeatFields.length - (colFacetField === NULL_FIELD ? 24 : 94)) / rowNums - 23);
spec.width = Math.floor(width / colRepeatFields.length / colNums);
spec.height = Math.floor(height / rowRepeatFields.length / rowNums);
}

let index = 0;
Expand Down
7 changes: 1 addition & 6 deletions packages/graphic-walker/src/renderer/specRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,9 @@ const SpecRenderer = forwardRef<IReactVegaHandler, SpecRendererProps>(function (
const text = draggableFieldState.text;
const format = _format;

const rowLeftFacetFields = useMemo(() => rows.slice(0, -1).filter((f) => f.analyticType === 'dimension'), [rows]);
const colLeftFacetFields = useMemo(() => columns.slice(0, -1).filter((f) => f.analyticType === 'dimension'), [columns]);

const isPivotTable = geoms[0] === 'table';

const hasFacet = rowLeftFacetFields.length > 0 || colLeftFacetFields.length > 0;

const enableResize = size.mode === 'fixed' && !hasFacet && Boolean(onChartResize);
const enableResize = size.mode === 'fixed' && Boolean(onChartResize);
const mediaTheme = useContext(themeContext);
const uiTheme = useContext(uiThemeContext);
const themeConfig = getTheme({
Expand Down
5 changes: 2 additions & 3 deletions packages/graphic-walker/src/vis/react-vega.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,6 @@ const ReactVega = forwardRef<IReactVegaHandler, ReactVegaProps>(function ReactVe
};
if (res.view.width() === 0) {
if (res.view.signal('child_width') !== undefined) {
// is faceted view
res.view.signal(
'child_width',
specs[0].width - modifier.width / Math.round((areaWidth || width) / colRepeatFields.length / specs[0].width)
Expand Down Expand Up @@ -527,15 +526,15 @@ const ReactVega = forwardRef<IReactVegaHandler, ReactVegaProps>(function ReactVe
<div ref={areaRef} className="inset-0 absolute" />
<CanvaContainer
style={{
...(layoutMode === 'full' ? { width: '100%', height: '100%' } : {}),
...(layoutMode === 'auto' ? {} : { width: '100%', height: '100%' }),
}}
rowSize={Math.max(rowRepeatFields.length, 1)}
colSize={Math.max(colRepeatFields.length, 1)}
ref={containerRef}
>
{/* <div ref={container}></div> */}
{viewPlaceholders.map((view, i) => (
<div key={i} ref={view}></div>
<div key={i} ref={view} className={layoutMode === 'auto' ? '' : 'overflow-hidden'}></div>
))}
</CanvaContainer>
</div>
Expand Down
Loading