Skip to content
This repository has been archived by the owner on Mar 5, 2023. It is now read-only.

Ui: Add colors to tag labels #798

Closed
wants to merge 1 commit into from

Conversation

yamgent
Copy link
Member

@yamgent yamgent commented Jan 19, 2018

Part of #784. Rebased, and changed the design of determining the colours of the tag.

Propsed commit message:

All tags in the address book are displayed with the same color.

It is hard to visually look for contacts sharing the same tags.

Let's add different colors for different tags to make the
differentiation of tags clearer.

Note: For demo purpose, don't merge this to master!

@Zhiyuan-Amos
Copy link
Contributor

is this done alrd? :P

@yamgent
Copy link
Member Author

yamgent commented Jan 19, 2018

is this done alrd? :P

Yeah I will submit a review now :P

@CanIHasReview-bot
Copy link

v1

@yamgent submitted v1 for review.

(📚 Archive)

Checkout this PR version locally
git fetch https://github.com/se-edu/addressbook-level4.git refs/pr/798/1/head:BRANCHNAME

where BRANCHNAME is the name of the local branch you wish to fetch this PR to.

@eugenepeh
Copy link
Member

eugenepeh commented Jan 20, 2018

btw for these don't merge this to master! PRs, should we just create and assign the corresponding Label to them? would be easier to see :P

@Zhiyuan-Amos Zhiyuan-Amos added the pr.Answer Pull request is answer for a tutorial in developer guide. Do not actually merge. label Jan 20, 2018
@Zhiyuan-Amos
Copy link
Contributor

should we just create and assign the corresponding Label to them? would be easier to see :P

Yup, thanks for the reminder Eugene ^^

}

/**
* Creates the tag labels for {@code person} and attach them to this {@code PersonCard}.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure whether it's necessary to have and attach them to this {@code PersonCard} since you have already mentioned the word tag labels, so it sounds reasonable that it's gonna be on this PersonCard

@@ -36,6 +38,9 @@ public static void assertCardDisplaysPerson(Person expectedPerson, PersonCardHan
assertEquals(expectedPerson.getAddress().value, actualCard.getAddress());
assertEquals(expectedPerson.getTags().stream().map(tag -> tag.tagName).collect(Collectors.toList()),
actualCard.getTags());
expectedPerson.getTags().stream().map(tag -> tag.tagName).forEach(tag ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this mapping is unnecessary if we store the result of .collect(Collectors.toList()) on line 39.

@@ -36,6 +38,9 @@ public static void assertCardDisplaysPerson(Person expectedPerson, PersonCardHan
assertEquals(expectedPerson.getAddress().value, actualCard.getAddress());
assertEquals(expectedPerson.getTags().stream().map(tag -> tag.tagName).collect(Collectors.toList()),
actualCard.getTags());
expectedPerson.getTags().stream().map(tag -> tag.tagName).forEach(tag ->
assertEquals(Arrays.asList("label", PersonCard.getTagColorStyleFor(tag)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should extract "label" as a constant (it's just a default style class for all Label objects right?), otherwise it's unintuitive :P

.filter(label -> label.getText().equals(tag))
.map(Label::getStyleClass)
.findFirst()
.orElse(null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should throw exception instead to make the test fail faster :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should I throw here? We don't have a NoSuchTagException class or something.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IllegalArgumentException should do. See here.

@yamgent yamgent force-pushed the getting-started-ui-tag branch from efdbfe4 to db24d16 Compare January 22, 2018 04:08
@CanIHasReview-bot
Copy link

v2

@yamgent submitted v2 for review.

(📚 Archive) (📈 Interdiff between v1 and v2)

Checkout this PR version locally
git fetch https://github.com/se-edu/addressbook-level4.git refs/pr/798/2/head:BRANCHNAME

where BRANCHNAME is the name of the local branch you wish to fetch this PR to.

Copy link
Contributor

@Zhiyuan-Amos Zhiyuan-Amos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

actualCard.getTags());

List<String> expectedTags = expectedPerson.getTags().stream().map(tag -> tag.tagName)
.collect(Collectors.toList());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps we can put a newline before .map(...)

@Zhiyuan-Amos Zhiyuan-Amos requested a review from damithc January 22, 2018 07:27
Copy link
Contributor

@damithc damithc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cosmetic suggestions

src/main/java/seedu/address/ui/PersonCard.java Outdated Show resolved Hide resolved
* Returns the color style for {@code tagName}'s label.
*/
public static String getTagColorStyleFor(String tagName) {
return TAG_COLOR_STYLES[Math.abs(tagName.hashCode()) % TAG_COLOR_STYLES.length];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Give explanatory comments about this calculation?

assertEquals(expectedTags, actualCard.getTags());
expectedTags.forEach(tag ->
assertEquals(Arrays.asList(LABEL_DEFAULT_STYLE, PersonCard.getTagColorStyleFor(tag)),
actualCard.getTagStyleClasses(tag)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit of head scratching needed to figure out what is being verified here. use explanatory variables or comments to make it clearer?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, or perhaps we can extract lines 44-47 into a method assertTagsEqual.

Also, we need to update assertCardEquals(PersonCardHandle, PersonCardHandle) right?
Also, I realised that for the expected result Arrays.asList(LABEL_DEFAULT_STYLE, PersonCard.getTagColorStyleFor(tag)), perhaps we shouldn't call PersonCard#getTagColorStyleFor(Tag) cos the actual tags are initialised using that method too. So it's like in some sense, "ownself test ownself".

/**
* Returns the color style for {@code tagName}'s label.
*/
public static String getTagColorStyleFor(String tagName) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems like this method is public static because it's required by the tests? ><

assertEquals(expectedTags, actualCard.getTags());
expectedTags.forEach(tag ->
assertEquals(Arrays.asList(LABEL_DEFAULT_STYLE, PersonCard.getTagColorStyleFor(tag)),
actualCard.getTagStyleClasses(tag)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, or perhaps we can extract lines 44-47 into a method assertTagsEqual.

Also, we need to update assertCardEquals(PersonCardHandle, PersonCardHandle) right?
Also, I realised that for the expected result Arrays.asList(LABEL_DEFAULT_STYLE, PersonCard.getTagColorStyleFor(tag)), perhaps we shouldn't call PersonCard#getTagColorStyleFor(Tag) cos the actual tags are initialised using that method too. So it's like in some sense, "ownself test ownself".

@CanIHasReview-bot
Copy link

v3

@yamgent submitted v3 for review.

(📚 Archive) (📈 Interdiff between v2 and v3)

Checkout this PR version locally
git fetch https://github.com/se-edu/addressbook-level4.git refs/pr/798/3/head:BRANCHNAME

where BRANCHNAME is the name of the local branch you wish to fetch this PR to.

/**
* Returns the color style for {@code tagName}'s label.
*/
private static String getTagColorStyleFor(String tagName) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there isn't a need for static here I think

/**
* Returns the color style for {@code tagName}'s label.
*/
private static String getTagColorStyleFor(String tagName) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm I'm not too sure about this way of testing though. If we only have a few set values for tagName, then maybe we should hardcode:

if (tagName.equals("foo")) {
    return "teal";
} else...

Not too sure about it too, I thought it looks kinda weird cos we are calling the exact same code as the main code base, maybe @damithc can comment on this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yamgent what do you think of hardcoding the expected values here? As mentioned, it is a bit odd to use the same code to test the a piece of code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I can hardcore the expected values. They can seem pretty arbitrary though, but I can add a comment to explain how the values were derived.

Copy link
Contributor

@damithc damithc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment added.

/**
* Returns the color style for {@code tagName}'s label.
*/
private static String getTagColorStyleFor(String tagName) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yamgent what do you think of hardcoding the expected values here? As mentioned, it is a bit odd to use the same code to test the a piece of code.

@yamgent yamgent force-pushed the getting-started-ui-tag branch from 3df17df to a0f850b Compare January 28, 2018 08:54
@yamgent yamgent requested review from damithc and removed request for damithc January 31, 2018 09:15
@CanIHasReview-bot
Copy link

v6

@yamgent submitted v6 for review.

(📚 Archive) (📈 Interdiff between v5 and v6) (📈 Range-Diff between v5 and v6)

Checkout this PR version locally
git fetch https://github.com/se-edu/addressbook-level4.git refs/pr/798/6/head:BRANCHNAME

where BRANCHNAME is the name of the local branch you wish to fetch this PR to.

@yamgent yamgent requested a review from a team August 9, 2018 05:20
@yamgent
Copy link
Member Author

yamgent commented Aug 9, 2018

Changelog:

  • Purely just rebasing, technically should not have any change in logic.

return "grey";

default:
fail(tagName + " does not have a color assigned.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait, after #894, we don't use fail anymore.

The tags are all displayed with the same color.

It is hard to differentiate between tags visually across contacts.
For example, it is hard to visually group all contacts tagged with
"colleague". It is also hard to differentiate between those contacts
that are tagged with "colleague", and those that are not tagged with
"colleague".

Let's add different colors to different tag labels. Tags of the same
name will always receive the same color, while different tag names
should receive different colors if possible.

The hashcode of the tag string is used to determine the tag color.
This will assign a reasonably random color to each tag, and will
also ensure that the tag color remains the same when the user
launches the application again in the future (assuming the
application version remains the same). The idea of using hashcode is
influenced by a developer's suggestion[1].

[1] nus-cs2103-AY1718S1/forum#199
@yamgent yamgent force-pushed the getting-started-ui-tag branch from 259e21f to 1ac2e7c Compare August 18, 2018 12:24
@CanIHasReview-bot
Copy link

v7

@yamgent submitted v7 for review.

(📚 Archive) (📈 Interdiff between v6 and v7) (📈 Range-Diff between v6 and v7)

Checkout this PR version locally
git fetch https://github.com/se-edu/addressbook-level4.git refs/pr/798/7/head:BRANCHNAME

where BRANCHNAME is the name of the local branch you wish to fetch this PR to.

@yamgent yamgent requested a review from damithc August 19, 2018 02:12
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pr.Answer Pull request is answer for a tutorial in developer guide. Do not actually merge.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants