Skip to content

An open source alternative to Tableau. Embeddable visual analytic

fix: color legend issue with multi view (#334)

islxyqwe8fd50ca75073
diff --git a/packages/graphic-walker/src/lib/vega.ts b/packages/graphic-walker/src/lib/vega.ts
index 9c779b5b..8114f6b3 100644
--- a/packages/graphic-walker/src/lib/vega.ts
+++ b/packages/graphic-walker/src/lib/vega.ts
@@ -126,7 +126,7 @@ export function toVegaSpec({
stack,
geomType,
displayOffset,
- dataSource
+ dataSource,
});
const singleView = channelScales ? resolveScales(channelScales, v, dataSource, mediaTheme) : v;
@@ -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;
@@ -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,
@@ -187,7 +187,8 @@ export function toVegaSpec({
defaultAggregated,
stack,
geomType,
- hideLegend: !hasLegend,
+ hasLegend,
+ hideLegend: !showLegend,
displayOffset,
dataSource,
});
diff --git a/packages/graphic-walker/src/vis/spec/view.ts b/packages/graphic-walker/src/vis/spec/view.ts
index 3b5e3ab2..98c3d9cb 100644
--- a/packages/graphic-walker/src/vis/spec/view.ts
+++ b/packages/graphic-walker/src/vis/spec/view.ts
@@ -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[];
}
@@ -39,6 +40,7 @@ export function getSingleView(props: SingleViewProps) {
defaultAggregated,
stack,
geomType,
+ hasLegend = true,
hideLegend = false,
displayOffset,
dataSource,
@@ -46,10 +48,19 @@ export function getSingleView(props: SingleViewProps) {
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[] = [];