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: color legend issue with repeated view #334

Merged
merged 1 commit into from
Feb 28, 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
9 changes: 5 additions & 4 deletions packages/graphic-walker/src/lib/vega.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export function toVegaSpec({
stack,
geomType,
displayOffset,
dataSource
dataSource,
});
const singleView = channelScales ? resolveScales(channelScales, v, dataSource, mediaTheme) : v;

Expand Down Expand Up @@ -156,7 +156,6 @@ export function toVegaSpec({
} else if (rowFacetField === NULL_FIELD && colFacetField === NULL_FIELD) {
spec.width = Math.floor(width / colRepeatFields.length) - 5;
spec.height = Math.floor(height / rowRepeatFields.length) - 5;
spec.autosize = 'fit';
} 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;
Expand All @@ -168,7 +167,8 @@ export function toVegaSpec({
let result = new Array(rowRepeatFields.length * colRepeatFields.length);
for (let i = 0; i < rowRepeatFields.length; i++) {
for (let j = 0; j < colRepeatFields.length; j++, index++) {
const hasLegend = i === 0 && j === colRepeatFields.length - 1;
const hasLegend = j === colRepeatFields.length - 1;
const showLegend = i == 0;
const v = getSingleView({
x: colRepeatFields[j] || NULL_FIELD,
y: rowRepeatFields[i] || NULL_FIELD,
Expand All @@ -187,7 +187,8 @@ export function toVegaSpec({
defaultAggregated,
stack,
geomType,
hideLegend: !hasLegend,
hasLegend,
hideLegend: !showLegend,
displayOffset,
dataSource,
});
Expand Down
13 changes: 12 additions & 1 deletion packages/graphic-walker/src/vis/spec/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { unexceptedUTCParsedPatternFormats } from '../../lib/op/offset';
export interface SingleViewProps extends IEncodeProps {
defaultAggregated: boolean;
stack: IStackMode;
hasLegend?: boolean;
hideLegend?: boolean;
dataSource: readonly IRow[];
}
Expand Down Expand Up @@ -39,17 +40,27 @@ export function getSingleView(props: SingleViewProps) {
defaultAggregated,
stack,
geomType,
hasLegend = true,
hideLegend = false,
displayOffset,
dataSource,
} = 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) {
if (!hasLegend) {
config.legend = {
disable: true,
};
} else if (hideLegend) {
config.legend = {
gradientOpacity: 0,
labelColor: 'transparent',
symbolOpacity: 0,
symbolStrokeColor: 'transparent',
titleColor: 'transparent',
titleOpacity: 0,
};
}
if (geomType === 'auto') {
const types: ISemanticType[] = [];
Expand Down
Loading