diff options
author | Kristóf Marussy <kristof@marussy.com> | 2024-01-03 02:13:15 +0100 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2024-01-03 13:33:55 +0100 |
commit | 2fe65e414ff3194cdddde01bea6818bbab5290e9 (patch) | |
tree | a597343718059a2ee8727a296e817f997876f248 /subprojects/frontend | |
parent | refactor: matching node names in CLI and web (diff) | |
download | refinery-2fe65e414ff3194cdddde01bea6818bbab5290e9.tar.gz refinery-2fe65e414ff3194cdddde01bea6818bbab5290e9.tar.zst refinery-2fe65e414ff3194cdddde01bea6818bbab5290e9.zip |
feat(web): color identifiers and nodes
We use a palette-based coloring strategy, where each class and enum gets a color
from
Diffstat (limited to 'subprojects/frontend')
-rw-r--r-- | subprojects/frontend/src/editor/EditorTheme.ts | 24 | ||||
-rw-r--r-- | subprojects/frontend/src/graph/GraphTheme.tsx | 23 | ||||
-rw-r--r-- | subprojects/frontend/src/graph/dotSource.ts | 5 | ||||
-rw-r--r-- | subprojects/frontend/src/theme/ThemeProvider.tsx | 40 | ||||
-rw-r--r-- | subprojects/frontend/src/xtext/xtextServiceResults.ts | 9 |
5 files changed, 89 insertions, 12 deletions
diff --git a/subprojects/frontend/src/editor/EditorTheme.ts b/subprojects/frontend/src/editor/EditorTheme.ts index 9f560dfb..383e1b75 100644 --- a/subprojects/frontend/src/editor/EditorTheme.ts +++ b/subprojects/frontend/src/editor/EditorTheme.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | 2 | * SPDX-FileCopyrightText: 2021-2024 The Refinery Authors <https://refinery.tools/> |
3 | * | 3 | * |
4 | * SPDX-License-Identifier: EPL-2.0 | 4 | * SPDX-License-Identifier: EPL-2.0 |
5 | */ | 5 | */ |
@@ -8,10 +8,29 @@ import cancelSVG from '@material-icons/svg/svg/cancel/baseline.svg?raw'; | |||
8 | import expandMoreSVG from '@material-icons/svg/svg/expand_more/baseline.svg?raw'; | 8 | import expandMoreSVG from '@material-icons/svg/svg/expand_more/baseline.svg?raw'; |
9 | import infoSVG from '@material-icons/svg/svg/info/baseline.svg?raw'; | 9 | import infoSVG from '@material-icons/svg/svg/info/baseline.svg?raw'; |
10 | import warningSVG from '@material-icons/svg/svg/warning/baseline.svg?raw'; | 10 | import warningSVG from '@material-icons/svg/svg/warning/baseline.svg?raw'; |
11 | import { alpha, styled, type CSSObject } from '@mui/material/styles'; | 11 | import { |
12 | alpha, | ||
13 | styled, | ||
14 | type CSSObject, | ||
15 | type Theme, | ||
16 | } from '@mui/material/styles'; | ||
17 | import { range } from 'lodash-es'; | ||
12 | 18 | ||
13 | import svgURL from '../utils/svgURL'; | 19 | import svgURL from '../utils/svgURL'; |
14 | 20 | ||
21 | function createTypeHashStyles(theme: Theme): CSSObject { | ||
22 | const result: CSSObject = {}; | ||
23 | range(theme.palette.highlight.typeHash.length).forEach((i) => { | ||
24 | result[`.tok-problem-typeHash-${i}`] = { | ||
25 | '&, .tok-typeName': { | ||
26 | color: theme.palette.highlight.typeHash[i]?.text, | ||
27 | fontWeight: theme.typography.fontWeightEditorTypeHash, | ||
28 | }, | ||
29 | }; | ||
30 | }); | ||
31 | return result; | ||
32 | } | ||
33 | |||
15 | export default styled('div', { | 34 | export default styled('div', { |
16 | name: 'EditorTheme', | 35 | name: 'EditorTheme', |
17 | shouldForwardProp: (propName) => | 36 | shouldForwardProp: (propName) => |
@@ -124,6 +143,7 @@ export default styled('div', { | |||
124 | fontStyle: 'normal', | 143 | fontStyle: 'normal', |
125 | }, | 144 | }, |
126 | }, | 145 | }, |
146 | ...createTypeHashStyles(theme), | ||
127 | }; | 147 | }; |
128 | 148 | ||
129 | const matchingStyle: CSSObject = { | 149 | const matchingStyle: CSSObject = { |
diff --git a/subprojects/frontend/src/graph/GraphTheme.tsx b/subprojects/frontend/src/graph/GraphTheme.tsx index 14d58b96..60fd7925 100644 --- a/subprojects/frontend/src/graph/GraphTheme.tsx +++ b/subprojects/frontend/src/graph/GraphTheme.tsx | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> | 2 | * SPDX-FileCopyrightText: 2023-2024 The Refinery Authors <https://refinery.tools/> |
3 | * | 3 | * |
4 | * SPDX-License-Identifier: EPL-2.0 | 4 | * SPDX-License-Identifier: EPL-2.0 |
5 | */ | 5 | */ |
@@ -7,7 +7,13 @@ | |||
7 | import cancelSVG from '@material-icons/svg/svg/cancel/baseline.svg?raw'; | 7 | import cancelSVG from '@material-icons/svg/svg/cancel/baseline.svg?raw'; |
8 | import labelSVG from '@material-icons/svg/svg/label/baseline.svg?raw'; | 8 | import labelSVG from '@material-icons/svg/svg/label/baseline.svg?raw'; |
9 | import labelOutlinedSVG from '@material-icons/svg/svg/label/outline.svg?raw'; | 9 | import labelOutlinedSVG from '@material-icons/svg/svg/label/outline.svg?raw'; |
10 | import { alpha, styled, type CSSObject } from '@mui/material/styles'; | 10 | import { |
11 | alpha, | ||
12 | styled, | ||
13 | type CSSObject, | ||
14 | type Theme, | ||
15 | } from '@mui/material/styles'; | ||
16 | import { range } from 'lodash-es'; | ||
11 | 17 | ||
12 | import svgURL from '../utils/svgURL'; | 18 | import svgURL from '../utils/svgURL'; |
13 | 19 | ||
@@ -31,6 +37,18 @@ function createEdgeColor( | |||
31 | }; | 37 | }; |
32 | } | 38 | } |
33 | 39 | ||
40 | function createTypeHashStyles(theme: Theme): CSSObject { | ||
41 | const result: CSSObject = {}; | ||
42 | range(theme.palette.highlight.typeHash.length).forEach((i) => { | ||
43 | result[`.node-typeHash-${i}`] = { | ||
44 | '& [fill="green"]': { | ||
45 | fill: theme.palette.highlight.typeHash[i]?.box, | ||
46 | }, | ||
47 | }; | ||
48 | }); | ||
49 | return result; | ||
50 | } | ||
51 | |||
34 | export default styled('div', { | 52 | export default styled('div', { |
35 | name: 'GraphTheme', | 53 | name: 'GraphTheme', |
36 | })(({ theme }) => ({ | 54 | })(({ theme }) => ({ |
@@ -68,6 +86,7 @@ export default styled('div', { | |||
68 | '.node-exists-UNKNOWN [stroke="black"]': { | 86 | '.node-exists-UNKNOWN [stroke="black"]': { |
69 | strokeDasharray: '5 2', | 87 | strokeDasharray: '5 2', |
70 | }, | 88 | }, |
89 | ...createTypeHashStyles(theme), | ||
71 | '.edge': { | 90 | '.edge': { |
72 | '& text': { | 91 | '& text': { |
73 | fontFamily: theme.typography.fontFamily, | 92 | fontFamily: theme.typography.fontFamily, |
diff --git a/subprojects/frontend/src/graph/dotSource.ts b/subprojects/frontend/src/graph/dotSource.ts index bd358dfa..3ac5eb1c 100644 --- a/subprojects/frontend/src/graph/dotSource.ts +++ b/subprojects/frontend/src/graph/dotSource.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> | 2 | * SPDX-FileCopyrightText: 2023-2024 The Refinery Authors <https://refinery.tools/> |
3 | * | 3 | * |
4 | * SPDX-License-Identifier: EPL-2.0 | 4 | * SPDX-License-Identifier: EPL-2.0 |
5 | */ | 5 | */ |
@@ -142,6 +142,9 @@ function createNodes( | |||
142 | if (data.unaryPredicates.size === 0) { | 142 | if (data.unaryPredicates.size === 0) { |
143 | classList.push('node-empty'); | 143 | classList.push('node-empty'); |
144 | } | 144 | } |
145 | if (node.typeHash !== undefined) { | ||
146 | classList.push(`node-typeHash-${node.typeHash}`); | ||
147 | } | ||
145 | const classes = classList.join(' '); | 148 | const classes = classList.join(' '); |
146 | const name = nodeName(graph, node); | 149 | const name = nodeName(graph, node); |
147 | const border = node.kind === 'INDIVIDUAL' ? 2 : 1; | 150 | const border = node.kind === 'INDIVIDUAL' ? 2 : 1; |
diff --git a/subprojects/frontend/src/theme/ThemeProvider.tsx b/subprojects/frontend/src/theme/ThemeProvider.tsx index 18310147..a996cde8 100644 --- a/subprojects/frontend/src/theme/ThemeProvider.tsx +++ b/subprojects/frontend/src/theme/ThemeProvider.tsx | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | 2 | * SPDX-FileCopyrightText: 2021-2024 The Refinery Authors <https://refinery.tools/> |
3 | * | 3 | * |
4 | * SPDX-License-Identifier: EPL-2.0 | 4 | * SPDX-License-Identifier: EPL-2.0 |
5 | */ | 5 | */ |
@@ -24,6 +24,11 @@ interface OuterPalette { | |||
24 | border: string; | 24 | border: string; |
25 | } | 25 | } |
26 | 26 | ||
27 | interface TypeHashPalette { | ||
28 | text: string; | ||
29 | box: string; | ||
30 | } | ||
31 | |||
27 | interface HighlightPalette { | 32 | interface HighlightPalette { |
28 | number: string; | 33 | number: string; |
29 | parameter: string; | 34 | parameter: string; |
@@ -41,17 +46,20 @@ interface HighlightPalette { | |||
41 | selected: string; | 46 | selected: string; |
42 | contrastText: string; | 47 | contrastText: string; |
43 | }; | 48 | }; |
49 | typeHash: TypeHashPalette[]; | ||
44 | } | 50 | } |
45 | 51 | ||
46 | declare module '@mui/material/styles' { | 52 | declare module '@mui/material/styles' { |
47 | interface TypographyVariants { | 53 | interface TypographyVariants { |
48 | fontWeightEditorNormal: number; | 54 | fontWeightEditorNormal: number; |
55 | fontWeightEditorTypeHash: number; | ||
49 | fontWeightEditorBold: number; | 56 | fontWeightEditorBold: number; |
50 | editor: TypographyStyle; | 57 | editor: TypographyStyle; |
51 | } | 58 | } |
52 | 59 | ||
53 | interface TypographyVariantsOptions { | 60 | interface TypographyVariantsOptions { |
54 | fontWeightEditorNormal?: number; | 61 | fontWeightEditorNormal?: number; |
62 | fontWeightEditorTypeHash?: number; | ||
55 | fontWeightEditorBold?: number; | 63 | fontWeightEditorBold?: number; |
56 | editor?: TypographyStyle; | 64 | editor?: TypographyStyle; |
57 | } | 65 | } |
@@ -78,6 +86,7 @@ function createResponsiveTheme( | |||
78 | '"Open Sans Variable", "Open Sans", "Roboto", "Helvetica", "Arial", sans-serif', | 86 | '"Open Sans Variable", "Open Sans", "Roboto", "Helvetica", "Arial", sans-serif', |
79 | fontWeightMedium: 500, | 87 | fontWeightMedium: 500, |
80 | fontWeightEditorNormal: 400, | 88 | fontWeightEditorNormal: 400, |
89 | fontWeightEditorTypeHash: 500, | ||
81 | fontWeightEditorBold: 700, | 90 | fontWeightEditorBold: 700, |
82 | button: { | 91 | button: { |
83 | fontWeight: 600, | 92 | fontWeight: 600, |
@@ -220,7 +229,7 @@ const lightTheme = (() => { | |||
220 | palette: { | 229 | palette: { |
221 | mode: 'light', | 230 | mode: 'light', |
222 | primary: { main: '#038a99' }, | 231 | primary: { main: '#038a99' }, |
223 | secondary: { main: '#e45649' }, | 232 | secondary: { main: '#61afef' }, |
224 | error: { main: '#ca1243' }, | 233 | error: { main: '#ca1243' }, |
225 | warning: { main: '#c18401' }, | 234 | warning: { main: '#c18401' }, |
226 | success: { main: '#50a14f' }, | 235 | success: { main: '#50a14f' }, |
@@ -256,6 +265,18 @@ const lightTheme = (() => { | |||
256 | selected: '#d500f9', | 265 | selected: '#d500f9', |
257 | contrastText: '#fff', | 266 | contrastText: '#fff', |
258 | }, | 267 | }, |
268 | typeHash: [ | ||
269 | { text: '#986801', box: '#e5c07b' }, | ||
270 | { text: '#d6493e', box: '#e06c75' }, | ||
271 | { text: '#50a14f', box: '#98c379' }, | ||
272 | { text: '#a626a4', box: '#c678dd' }, | ||
273 | { text: '#4078f2', box: '#80a7f4' }, | ||
274 | { text: '#827662', box: '#e3d1b2' }, | ||
275 | { text: '#904f53', box: '#e78b8f' }, | ||
276 | { text: '#637855', box: '#abcc94' }, | ||
277 | { text: '#805f89', box: '#dbb2e8' }, | ||
278 | { text: '#5987ae', box: '#92c0e9' }, | ||
279 | ], | ||
259 | }, | 280 | }, |
260 | }, | 281 | }, |
261 | }); | 282 | }); |
@@ -270,6 +291,7 @@ const darkTheme = (() => { | |||
270 | { | 291 | { |
271 | typography: { | 292 | typography: { |
272 | fontWeightEditorNormal: 350, | 293 | fontWeightEditorNormal: 350, |
294 | fontWeightEditorTypeHash: 350, | ||
273 | fontWeightEditorBold: 650, | 295 | fontWeightEditorBold: 650, |
274 | }, | 296 | }, |
275 | palette: { | 297 | palette: { |
@@ -277,7 +299,7 @@ const darkTheme = (() => { | |||
277 | primary: { main: '#56b6c2' }, | 299 | primary: { main: '#56b6c2' }, |
278 | secondary: { main: '#be5046' }, | 300 | secondary: { main: '#be5046' }, |
279 | error: { main: '#e06c75' }, | 301 | error: { main: '#e06c75' }, |
280 | warning: { main: '#e5c07b' }, | 302 | warning: { main: '#d19a66' }, |
281 | success: { main: '#98c379' }, | 303 | success: { main: '#98c379' }, |
282 | info: { main: '#61afef' }, | 304 | info: { main: '#61afef' }, |
283 | background: { | 305 | background: { |
@@ -311,6 +333,18 @@ const darkTheme = (() => { | |||
311 | selected: '#dd33fa', | 333 | selected: '#dd33fa', |
312 | contrastText: darkBackground, | 334 | contrastText: darkBackground, |
313 | }, | 335 | }, |
336 | typeHash: [ | ||
337 | { text: '#e5c07b', box: '#ae8003' }, | ||
338 | { text: '#e06c75', box: '#a23b47' }, | ||
339 | { text: '#98c379', box: '#428141' }, | ||
340 | { text: '#c678dd', box: '#854797' }, | ||
341 | { text: '#61afef', box: '#3982bb' }, | ||
342 | { text: '#e3d1b2', box: '#827662' }, | ||
343 | { text: '#e78b8f', box: '#904f53' }, | ||
344 | { text: '#abcc94', box: '#647e63' }, | ||
345 | { text: '#dbb2e8', box: '#805f89' }, | ||
346 | { text: '#92c0e9', box: '#4f7799' }, | ||
347 | ], | ||
314 | }, | 348 | }, |
315 | }, | 349 | }, |
316 | }, | 350 | }, |
diff --git a/subprojects/frontend/src/xtext/xtextServiceResults.ts b/subprojects/frontend/src/xtext/xtextServiceResults.ts index e473bd48..792c7de3 100644 --- a/subprojects/frontend/src/xtext/xtextServiceResults.ts +++ b/subprojects/frontend/src/xtext/xtextServiceResults.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | 2 | * SPDX-FileCopyrightText: 2021-2024 The Refinery Authors <https://refinery.tools/> |
3 | * | 3 | * |
4 | * SPDX-License-Identifier: EPL-2.0 | 4 | * SPDX-License-Identifier: EPL-2.0 |
5 | */ | 5 | */ |
@@ -137,6 +137,7 @@ export type ModelGenerationStartedResult = z.infer< | |||
137 | export const NodeMetadata = z.object({ | 137 | export const NodeMetadata = z.object({ |
138 | name: z.string(), | 138 | name: z.string(), |
139 | simpleName: z.string(), | 139 | simpleName: z.string(), |
140 | typeHash: z.string().optional(), | ||
140 | kind: z.enum(['IMPLICIT', 'INDIVIDUAL', 'NEW']), | 141 | kind: z.enum(['IMPLICIT', 'INDIVIDUAL', 'NEW']), |
141 | }); | 142 | }); |
142 | 143 | ||
@@ -182,15 +183,15 @@ export type SemanticsResult = z.infer<typeof SemanticsResult>; | |||
182 | 183 | ||
183 | export const ModelGenerationResult = z.union([ | 184 | export const ModelGenerationResult = z.union([ |
184 | z.object({ | 185 | z.object({ |
185 | uuid: z.string().nonempty(), | 186 | uuid: z.string().min(1), |
186 | status: z.string(), | 187 | status: z.string(), |
187 | }), | 188 | }), |
188 | z.object({ | 189 | z.object({ |
189 | uuid: z.string().nonempty(), | 190 | uuid: z.string().min(1), |
190 | error: z.string(), | 191 | error: z.string(), |
191 | }), | 192 | }), |
192 | SemanticsSuccessResult.extend({ | 193 | SemanticsSuccessResult.extend({ |
193 | uuid: z.string().nonempty(), | 194 | uuid: z.string().min(1), |
194 | }), | 195 | }), |
195 | ]); | 196 | ]); |
196 | 197 | ||