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: Color consistency E2E tests #21622

Merged
merged 37 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
f222ec9
feat(color): color consistency enhancements
stephenLYZ Sep 18, 2022
831676d
fix when label color was changed
stephenLYZ Sep 21, 2022
0aa409b
Merge branch 'feat-color-enhancement' of https://github.com/stephenLY…
geido Sep 27, 2022
9bc7d4f
Test color scheme across nested and main tabs
geido Sep 27, 2022
1e9a8d8
Enhance tests
geido Sep 28, 2022
e741ec9
feat(color): color consistency enhancements
stephenLYZ Sep 18, 2022
f536682
fix when label color was changed
stephenLYZ Sep 21, 2022
7422e50
fix: getColor issue
stephenLYZ Oct 3, 2022
24b7e7b
fix: test
stephenLYZ Oct 4, 2022
f506d74
Merge branch 'feat-color-enhancement' of https://github.com/stephenLY…
geido Oct 4, 2022
0b788c1
Merge branch 'master' of https://github.com/apache/superset into chor…
geido Oct 4, 2022
f576d6e
Update tests
geido Oct 4, 2022
22b696c
Lint
geido Oct 4, 2022
6e79fac
fix: ci
stephenLYZ Oct 4, 2022
d54aa7c
fix: add chart color
stephenLYZ Oct 4, 2022
bb738d6
Merge branch 'feat-color-enhancement' of https://github.com/stephenLY…
geido Oct 5, 2022
1594bec
fix: color not reset if remove color scheme
stephenLYZ Oct 8, 2022
f3212e4
fix lint
stephenLYZ Oct 9, 2022
37e8e80
fix: test
stephenLYZ Oct 10, 2022
a9bacb5
fix: test
stephenLYZ Oct 10, 2022
ac94bbe
Merge branch 'feat-color-enhancement' of https://github.com/stephenLY…
geido Oct 10, 2022
6db4c30
fix
stephenLYZ Oct 10, 2022
89bb2b3
Merge branch 'feat-color-enhancement' of https://github.com/stephenLY…
geido Oct 11, 2022
99ba83b
Update tests
geido Oct 11, 2022
6b7b942
Merge branch 'master' into feat-color-enhancement
stephenLYZ Oct 12, 2022
c9c851c
fix: color source
stephenLYZ Oct 13, 2022
5a2081f
Merge branch 'feat-color-enhancement' of https://github.com/stephenLY…
stephenLYZ Oct 13, 2022
8b72999
Merge branch 'feat-color-enhancement' of https://github.com/stephenLY…
geido Oct 13, 2022
190a534
Add Explore test
geido Oct 13, 2022
8cecb56
Test original colors
geido Oct 13, 2022
11ffaeb
Enhance original color tests
geido Oct 13, 2022
d20665a
fix label color will change color order
stephenLYZ Oct 14, 2022
db38929
Merge branch 'feat-color-enhancement' of https://github.com/stephenLY…
geido Oct 14, 2022
ea4c2e8
Fix test
geido Oct 14, 2022
c7c80c3
Merge branch 'master' of https://github.com/apache/superset into chor…
geido Oct 18, 2022
56b31d5
Update test
geido Oct 18, 2022
0db2623
Update num of dashboards
geido Oct 19, 2022
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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -478,3 +478,12 @@ export function addCountryNameFilter() {
testItems.topTenChart.filterColumn,
);
}

export function openTab(tabComponentIndex: number, tabIndex: number) {
return cy
.getBySel('dashboard-component-tabs')
.eq(tabComponentIndex)
.find('[role="tab"]')
.eq(tabIndex)
.click();
}
6 changes: 6 additions & 0 deletions superset-frontend/cypress-base/cypress/support/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ declare namespace Cypress {
* Get
*/
getDashboards(): cy;
getDashboard(dashboardId: string | number): Record<string, any>;
getCharts(): cy;

/**
Expand All @@ -80,6 +81,11 @@ declare namespace Cypress {
deleteDashboardByName(dashboardName: string, failOnStatusCode: boolean): cy;
deleteChartByName(name: string, failOnStatusCode: boolean): cy;
deleteChart(id: number, failOnStatusCode: boolean): cy;

/**
* Update
*/
updateDashboard(dashboardId: number, body: Record<string, any>): cy;
}
}

Expand Down
29 changes: 29 additions & 0 deletions superset-frontend/cypress-base/cypress/support/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,35 @@ Cypress.Commands.add('getDashboards', () =>
.then(resp => resp.body.result),
);

Cypress.Commands.add('getDashboard', (dashboardId: string | number) =>
cy
.request({
method: 'GET',
url: `api/v1/dashboard/${dashboardId}`,
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${TokenName}`,
},
})
.then(resp => resp.body.result),
);

Cypress.Commands.add(
'updateDashboard',
(dashboardId: number, body: Record<string, any>) =>
cy
.request({
method: 'PUT',
url: `api/v1/dashboard/${dashboardId}`,
body,
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${TokenName}`,
},
})
.then(resp => resp.body.result),
);

Cypress.Commands.add('deleteChart', (id: number, failOnStatusCode = false) =>
cy
.request({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class CategoricalColorScale extends ExtensibleFunction {
* @param {*} parentForcedColors optional parameter that comes from parent
* (usually CategoricalColorNamespace) and supersede this.forcedColors
*/
constructor(colors: string[], parentForcedColors?: ColorsLookup) {
constructor(colors: string[], parentForcedColors: ColorsLookup = {}) {
super((value: string, sliceId?: number) => this.getColor(value, sliceId));

this.originColors = colors;
Expand All @@ -67,30 +67,25 @@ class CategoricalColorScale extends ExtensibleFunction {
const cleanedValue = stringifyAndTrim(value);
const sharedLabelColor = getSharedLabelColor();

const parentColor = this.parentForcedColors?.[cleanedValue];
if (parentColor) {
sharedLabelColor.addSlice(cleanedValue, parentColor, sliceId);
return parentColor;
}

const forcedColor = this.forcedColors[cleanedValue];
if (forcedColor) {
sharedLabelColor.addSlice(cleanedValue, forcedColor, sliceId);
return forcedColor;
}

if (isFeatureEnabled(FeatureFlag.USE_ANALAGOUS_COLORS)) {
const multiple = Math.floor(
this.domain().length / this.originColors.length,
);
if (multiple > this.multiple) {
this.multiple = multiple;
const newRange = getAnalogousColors(this.originColors, multiple);
this.range(this.originColors.concat(newRange));
// priority: parentForcedColors > forcedColors > labelColors
let color =
this.parentForcedColors?.[cleanedValue] ||
this.forcedColors?.[cleanedValue] ||
sharedLabelColor.getColorMap().get(cleanedValue);

if (!color) {
if (isFeatureEnabled(FeatureFlag.USE_ANALAGOUS_COLORS)) {
const multiple = Math.floor(
this.domain().length / this.originColors.length,
);
if (multiple > this.multiple) {
this.multiple = multiple;
const newRange = getAnalogousColors(this.originColors, multiple);
this.range(this.originColors.concat(newRange));
}
}
color = this.scale(cleanedValue);
}

const color = this.scale(cleanedValue);
sharedLabelColor.addSlice(cleanedValue, color, sliceId);

return color;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,113 +18,79 @@
*/

import { CategoricalColorNamespace } from '.';
import { FeatureFlag, isFeatureEnabled, makeSingleton } from '../utils';
import { getAnalogousColors } from './utils';
import { makeSingleton } from '../utils';

export enum SharedLabelColorSource {
dashboard,
explore,
}
export class SharedLabelColor {
sliceLabelColorMap: Record<number, Record<string, string | undefined>>;
sliceLabelMap: Map<number, string[]>;

constructor() {
// { sliceId1: { label1: color1 }, sliceId2: { label2: color2 } }
this.sliceLabelColorMap = {};
}
colorMap: Map<string, string>;

getColorMap(
colorNamespace?: string,
colorScheme?: string,
updateColorScheme?: boolean,
) {
if (colorScheme) {
const categoricalNamespace =
CategoricalColorNamespace.getNamespace(colorNamespace);
const sharedLabels = this.getSharedLabels();
let generatedColors: string[] = [];
let sharedLabelMap;
source: SharedLabelColorSource;

if (sharedLabels.length) {
const colorScale = categoricalNamespace.getScale(colorScheme);
const colors = colorScale.range();
if (isFeatureEnabled(FeatureFlag.USE_ANALAGOUS_COLORS)) {
const multiple = Math.ceil(sharedLabels.length / colors.length);
generatedColors = getAnalogousColors(colors, multiple);
sharedLabelMap = sharedLabels.reduce(
(res, label, index) => ({
...res,
[label.toString()]: generatedColors[index],
}),
{},
);
} else {
// reverse colors to reduce color conflicts
colorScale.range(colors.reverse());
sharedLabelMap = sharedLabels.reduce(
(res, label) => ({
...res,
[label.toString()]: colorScale(label),
}),
{},
);
}
}
constructor() {
// { sliceId1: [label1, label2, ...], sliceId2: [label1, label2, ...] }
this.sliceLabelMap = new Map();
this.colorMap = new Map();
this.source = SharedLabelColorSource.dashboard;
}

const labelMap = Object.keys(this.sliceLabelColorMap).reduce(
(res, sliceId) => {
// get new color scale instance
const colorScale = categoricalNamespace.getScale(colorScheme);
return {
...res,
...Object.keys(this.sliceLabelColorMap[sliceId]).reduce(
(res, label) => ({
...res,
[label]: updateColorScheme
? colorScale(label)
: this.sliceLabelColorMap[sliceId][label],
}),
{},
),
};
},
{},
);
updateColorMap(colorNamespace?: string, colorScheme?: string) {
const categoricalNamespace =
CategoricalColorNamespace.getNamespace(colorNamespace);
const newColorMap = new Map();
this.colorMap.clear();
this.sliceLabelMap.forEach(labels => {
const colorScale = categoricalNamespace.getScale(colorScheme);
labels.forEach(label => {
const newColor = colorScale(label);
newColorMap.set(label, newColor);
});
});
this.colorMap = newColorMap;
}

return {
...labelMap,
...sharedLabelMap,
};
}
return undefined;
getColorMap() {
return this.colorMap;
}

addSlice(label: string, color: string, sliceId?: number) {
if (!sliceId) return;
this.sliceLabelColorMap[sliceId] = {
...this.sliceLabelColorMap[sliceId],
[label]: color,
};
if (
this.source !== SharedLabelColorSource.dashboard ||
sliceId === undefined
)
return;
const labels = this.sliceLabelMap.get(sliceId) || [];
labels.push(label);
this.sliceLabelMap.set(sliceId, labels);
this.colorMap.set(label, color);
}

removeSlice(sliceId: number) {
delete this.sliceLabelColorMap[sliceId];
if (this.source !== SharedLabelColorSource.dashboard) return;
this.sliceLabelMap.delete(sliceId);
const newColorMap = new Map();
this.sliceLabelMap.forEach(labels => {
labels.forEach(label => {
newColorMap.set(label, this.colorMap.get(label));
});
});
this.colorMap = newColorMap;
}

clear() {
this.sliceLabelColorMap = {};
reset() {
const copyColorMap = new Map(this.colorMap);
copyColorMap.forEach((_, label) => {
this.colorMap.set(label, '');
});
}

getSharedLabels() {
const tempLabels = new Set<string>();
const result = new Set<string>();
Object.keys(this.sliceLabelColorMap).forEach(sliceId => {
const colorMap = this.sliceLabelColorMap[sliceId];
Object.keys(colorMap).forEach(label => {
if (tempLabels.has(label) && !result.has(label)) {
result.add(label);
} else {
tempLabels.add(label);
}
});
});
return [...result];
clear() {
this.sliceLabelMap.clear();
this.colorMap.clear();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export * from './utils';
export {
default as getSharedLabelColor,
SharedLabelColor,
SharedLabelColorSource,
} from './SharedLabelColorSingleton';

export const BRAND_COLOR = '#00A699';
Loading