-
Notifications
You must be signed in to change notification settings - Fork 3
[ENG-877] Initial Implementation node tags for Obsidian #455
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ef2a057
feature complete
trangdoan982 ea9b9fc
reorganize
trangdoan982 3c6c359
rm box shadow style
trangdoan982 d4c7558
address some PR comments
trangdoan982 c43ff6b
some problem sovled
trangdoan982 b10257e
address all PR comments
trangdoan982 f956cd8
sm fix
trangdoan982 4596a88
address PR comments
trangdoan982 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import { DiscourseNode } from "~/types"; | ||
|
|
||
| // Color palette similar to Roam's implementation | ||
| const COLOR_PALETTE: Record<string, string> = { | ||
| black: "#1d1d1d", | ||
| blue: "#4263eb", | ||
| green: "#099268", | ||
| grey: "#adb5bd", | ||
| lightBlue: "#4dabf7", | ||
| lightGreen: "#40c057", | ||
| lightRed: "#ff8787", | ||
| lightViolet: "#e599f7", | ||
| orange: "#f76707", | ||
| red: "#e03131", | ||
| violet: "#ae3ec9", | ||
| white: "#ffffff", | ||
| yellow: "#ffc078", | ||
| }; | ||
|
|
||
| const COLOR_ARRAY = Object.keys(COLOR_PALETTE); | ||
|
|
||
| // TODO switch to colord - https://linear.app/discourse-graphs/issue/ENG-836/button-like-css-styling-for-node-tag | ||
| export const getContrastColor = (bgColor: string): string => { | ||
| const hex = bgColor.replace("#", ""); | ||
|
|
||
| if (hex.length !== 6) return "#000000"; | ||
|
|
||
| const r = parseInt(hex.substring(0, 2), 16); | ||
| const g = parseInt(hex.substring(2, 4), 16); | ||
| const b = parseInt(hex.substring(4, 6), 16); | ||
|
|
||
| if (isNaN(r) || isNaN(g) || isNaN(b)) return "#000000"; | ||
|
|
||
| const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255; | ||
|
|
||
| return luminance > 0.5 ? "#000000" : "#ffffff"; | ||
| }; | ||
|
|
||
| export const getNodeTagColors = ( | ||
| nodeType: DiscourseNode, | ||
| nodeIndex: number, | ||
| ): { backgroundColor: string; textColor: string } => { | ||
| const customColor = nodeType.color || ""; | ||
|
|
||
| const safeIndex = | ||
| nodeIndex >= 0 && nodeIndex < COLOR_ARRAY.length ? nodeIndex : 0; | ||
| const paletteColorKey = COLOR_ARRAY[safeIndex]; | ||
trangdoan982 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const paletteColor = paletteColorKey | ||
| ? COLOR_PALETTE[paletteColorKey] | ||
| : COLOR_PALETTE.blue; | ||
|
|
||
| const backgroundColor = customColor || paletteColor || "#4263eb"; | ||
| const textColor = getContrastColor(backgroundColor); | ||
|
|
||
| return { backgroundColor, textColor }; | ||
| }; | ||
|
|
||
|
|
||
| export const getAllDiscourseNodeColors = ( | ||
| nodeTypes: DiscourseNode[], | ||
| ): Array<{ | ||
| nodeType: DiscourseNode; | ||
| colors: { backgroundColor: string; textColor: string }; | ||
| }> => { | ||
| return nodeTypes.map((nodeType, index) => ({ | ||
| nodeType, | ||
| colors: getNodeTagColors(nodeType, index), | ||
| })); | ||
| }; | ||
trangdoan982 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.