Skip to content

Commit 5c48d5c

Browse files
authored
add skillmap option for pixellating the background image (#10877) (#10878)
* add skillmap option for pixellating the background image * typo
1 parent 930a5fd commit 5c48d5c

File tree

7 files changed

+27
-9
lines changed

7 files changed

+27
-9
lines changed

skillmap/src/App.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ interface AppProps {
5757
skillMaps: { [key: string]: SkillMap };
5858
activityOpen: boolean;
5959
backgroundImageUrl: string;
60+
pixelatedBackground?: boolean;
6061
theme: SkillGraphTheme;
6162
signedIn: boolean;
6263
activityId: string;
@@ -71,7 +72,7 @@ interface AppProps {
7172
dispatchSetPageTitle: (title: string) => void;
7273
dispatchSetPageDescription: (description: string) => void;
7374
dispatchSetPageInfoUrl: (infoUrl: string) => void;
74-
dispatchSetPageBackgroundImageUrl: (backgroundImageUrl: string) => void;
75+
dispatchSetPageBackgroundImageUrl: (backgroundImageUrl: string, pixelatedBackground?: boolean) => void;
7576
dispatchSetPageBannerImageUrl: (bannerImageUrl: string) => void;
7677
dispatchSetUser: (user: UserState) => void;
7778
dispatchSetPageSourceUrl: (url: string, status: PageSourceStatus) => void;
@@ -228,13 +229,13 @@ class AppImpl extends React.Component<AppProps, AppState> {
228229
}
229230

230231
if (metadata) {
231-
const { title, description, infoUrl, backgroundImageUrl,
232+
const { title, description, infoUrl, backgroundImageUrl, pixelatedBackground,
232233
bannerImageUrl, theme, alternateSources } = metadata;
233234
setPageTitle(title);
234235
this.props.dispatchSetPageTitle(title);
235236
if (description) this.props.dispatchSetPageDescription(description);
236237
if (infoUrl) this.props.dispatchSetPageInfoUrl(infoUrl);
237-
if (backgroundImageUrl) this.props.dispatchSetPageBackgroundImageUrl(backgroundImageUrl);
238+
if (backgroundImageUrl) this.props.dispatchSetPageBackgroundImageUrl(backgroundImageUrl, pixelatedBackground);
238239
if (bannerImageUrl) this.props.dispatchSetPageBannerImageUrl(bannerImageUrl);
239240
if (alternateSources) this.props.dispatchSetPageAlternateUrls(alternateSources);
240241
if (theme) this.props.dispatchSetPageTheme(theme);
@@ -432,7 +433,7 @@ class AppImpl extends React.Component<AppProps, AppState> {
432433
}
433434

434435
render() {
435-
const { skillMaps, activityOpen, backgroundImageUrl, theme } = this.props;
436+
const { skillMaps, activityOpen, backgroundImageUrl, theme, pixelatedBackground } = this.props;
436437
const { error, showingSyncLoader, forcelang } = this.state;
437438
const maps = Object.keys(skillMaps).map((id: string) => skillMaps[id]);
438439
const feedbackEnabled = pxt.U.ocvEnabled();
@@ -446,7 +447,7 @@ class AppImpl extends React.Component<AppProps, AppState> {
446447
<div className={`skill-map-container ${activityOpen ? "hidden" : ""}`} style={{ backgroundColor: theme.backgroundColor }}>
447448
{ error
448449
? <div className="skill-map-error">{error}</div>
449-
: <SkillGraphContainer maps={maps} backgroundImageUrl={backgroundImageUrl} backgroundColor={theme.backgroundColor} strokeColor={theme.strokeColor} />
450+
: <SkillGraphContainer maps={maps} backgroundImageUrl={backgroundImageUrl} backgroundColor={theme.backgroundColor} pixelatedBackground={pixelatedBackground} strokeColor={theme.strokeColor} />
450451
}
451452
{ !error && <InfoPanel onFocusEscape={this.focusCurrentActivity} />}
452453
</div>
@@ -568,6 +569,7 @@ function mapStateToProps(state: SkillMapState, ownProps: any) {
568569
skillMaps: state.maps,
569570
activityOpen: !!state.editorView,
570571
backgroundImageUrl: state.backgroundImageUrl,
572+
pixelatedBackground: state.pixelatedBackground,
571573
theme: state.theme,
572574
signedIn: state.auth.signedIn,
573575
activityId: state.selectedItem?.activityId,

skillmap/src/actions/dispatch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const dispatchResetUser = () => ({ type: actions.RESET_USER });
2121
export const dispatchSetPageTitle = (title: string) => ({ type: actions.SET_PAGE_TITLE, title });
2222
export const dispatchSetPageDescription = (description: string) => ({ type: actions.SET_PAGE_DESCRIPTION, description });
2323
export const dispatchSetPageInfoUrl = (infoUrl: string) => ({ type: actions.SET_PAGE_INFO_URL, infoUrl });
24-
export const dispatchSetPageBackgroundImageUrl = (backgroundImageUrl: string) => ({ type: actions.SET_PAGE_BACKGROUND_IMAGE_URL, backgroundImageUrl });
24+
export const dispatchSetPageBackgroundImageUrl = (backgroundImageUrl: string, pixelatedBackground?: boolean) => ({ type: actions.SET_PAGE_BACKGROUND_IMAGE_URL, backgroundImageUrl, pixelatedBackground });
2525
export const dispatchSetPageBannerImageUrl = (bannerImageUrl: string) => ({ type: actions.SET_PAGE_BANNER_IMAGE_URL, bannerImageUrl });
2626
export const dispatchSetPageTheme = (theme: SkillGraphTheme) => ({ type: actions.SET_PAGE_THEME, theme });
2727
export const dispatchSetPageSourceUrl = (url: string, status: PageSourceStatus) => ({ type: actions.SET_PAGE_SOURCE_URL, url, status });

skillmap/src/components/SkillGraphContainer.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ interface SkillGraphContainerProps {
1515
graphs: SvgGraph[];
1616
backgroundImageUrl: string;
1717
backgroundColor: string;
18+
pixelatedBackground?: boolean;
1819
strokeColor: string;
1920
graphSize: {
2021
width: number;
@@ -50,7 +51,7 @@ export class SkillGraphContainerImpl extends React.Component<SkillGraphContainer
5051
}
5152

5253
render() {
53-
const { maps, graphs, graphSize, backgroundImageUrl, backgroundColor, strokeColor } = this.props;
54+
const { maps, graphs, graphSize, backgroundImageUrl, pixelatedBackground, backgroundColor, strokeColor } = this.props;
5455
const { backgroundSize } = this.state;
5556
let altTextColor: string = 'black';
5657
let backgroundAltText: string = lf("Background image for {0}", maps[0]?.displayName || lf("skillmap"));
@@ -97,7 +98,13 @@ export class SkillGraphContainerImpl extends React.Component<SkillGraphContainer
9798
</svg>
9899
</MenuBar>
99100
{backgroundImageUrl && <div className="skill-graph-background">
100-
<img src={backgroundImageUrl} alt={backgroundAltText} onLoad={this.onImageLoad} style={{ color: altTextColor }} />
101+
<img
102+
src={backgroundImageUrl}
103+
className={pixelatedBackground ? "pixelated" : undefined}
104+
alt={backgroundAltText}
105+
onLoad={this.onImageLoad}
106+
style={{ color: altTextColor }}
107+
/>
101108
</div>}
102109
</div>
103110
</div>

skillmap/src/lib/skillMap.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ interface PageMetadata {
33
description?: string;
44
infoUrl?: string;
55
backgroundImageUrl?: string;
6+
pixelatedBackground?: boolean;
67
bannerImageUrl?: string; // Banner image in the info panel when no activity is selected
78
theme?: SkillGraphTheme
89
alternateSources?: string[]; // List of alternate pageSourceUrls to import user projects from

skillmap/src/lib/skillMapParser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ function inflateMetadata(section: MarkdownSection): PageMetadata {
389389
description: section.attributes["description"],
390390
infoUrl: cleanInfoUrl(section.attributes["infourl"]),
391391
backgroundImageUrl: section.attributes["backgroundurl"],
392+
pixelatedBackground: isTrue(section.attributes["pixelatedbackground"]),
392393
bannerImageUrl: section.attributes["bannerurl"],
393394
alternateSources: parseList(section.attributes["alternatesources"]),
394395
theme: {

skillmap/src/store/reducer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface SkillMapState {
1414
description: string;
1515
infoUrl?: string;
1616
backgroundImageUrl?: string;
17+
pixelatedBackground?: boolean;
1718
bannerImageUrl?: string;
1819
user: UserState;
1920
pageSourceUrl: string;
@@ -124,6 +125,7 @@ const topReducer = (state: SkillMapState = initialState, action: any): SkillMapS
124125
description: initialState.description,
125126
infoUrl: initialState.infoUrl,
126127
backgroundImageUrl: undefined,
128+
pixelatedBackground: undefined,
127129
bannerImageUrl: undefined,
128130
alternateSourceUrls: undefined,
129131
theme: {
@@ -326,7 +328,8 @@ const topReducer = (state: SkillMapState = initialState, action: any): SkillMapS
326328
case actions.SET_PAGE_BACKGROUND_IMAGE_URL:
327329
return {
328330
...state,
329-
backgroundImageUrl: action.backgroundImageUrl
331+
backgroundImageUrl: action.backgroundImageUrl,
332+
pixelatedBackground: action.pixelatedBackground
330333
}
331334
case actions.SET_PAGE_BANNER_IMAGE_URL:
332335
return {

skillmap/src/styles/skillgraph.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
max-height: 100%;
3838
}
3939

40+
.skill-graph-background img.pixelated {
41+
image-rendering: pixelated;
42+
}
43+
4044
/*******************************/
4145
/***** HIGH CONTRAST *****/
4246
/*******************************/

0 commit comments

Comments
 (0)