Skip to content

Commit c7c99d1

Browse files
authored
Merge pull request #84 from LuCEresearchlab/usability-fixes
Usability fixes
2 parents 78a448d + 6002ff8 commit c7c99d1

File tree

4 files changed

+30
-15
lines changed

4 files changed

+30
-15
lines changed

frontend/src/components/tagger_component/MisconceptionTagElement.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import stringEquals from "../../util/StringEquals";
2020
import TruthCircle from "./TruthCircle";
2121
import NoMisconception from "../../util/NoMisconception";
2222
import {FormatColorReset} from "@material-ui/icons";
23+
import {highlightStyle} from "../../helpers/Util";
2324

2425
const {TAGGING_SERVICE_URL} = require('../../../config.json')
2526

@@ -216,12 +217,7 @@ function MisconceptionTagElement(
216217
post_answer(r, tags)
217218
}}
218219
text={answer.data}
219-
highlightStyle={(range: HighlightRange) => {
220-
return {
221-
backgroundColor: range.color + "C8",
222-
}
223-
}
224-
}
220+
highlightStyle={highlightStyle}
225221
/></StyledTableCell>
226222
<StyledTableCell>{
227223
enabled ?

frontend/src/components/v2/cluster_handler_component/ClusterHandler.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ function ClusterHandler({taggingSession, taggingClusterSession, dispatchTaggingC
256256

257257
return (
258258
<Container>
259-
<div>
259+
<div style={{marginLeft: '2em'}}>
260260
<TextField id={'search_filter'} type={'text'} value={state.query} onChange={
261261
(e) => {
262262
e.preventDefault()
@@ -266,7 +266,7 @@ function ClusterHandler({taggingSession, taggingClusterSession, dispatchTaggingC
266266
}
267267
)
268268
}
269-
} label={"Filter"}/>
269+
} label={"Search"}/>
270270
<Button style={{height: 48, width: 48}} onClick={(e) => {
271271
e.preventDefault()
272272
setState({

frontend/src/components/v2/tagger_component/ClusterView.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import KeyIndication from "./KeyIndication";
2020
import {clusterSessionPost, setRanges, setTagsAndRanges} from "../../../model/TaggingClusterSessionDispatch";
2121
import TruthCircle from "../../tagger_component/TruthCircle";
2222
import {FormatColorReset} from "@material-ui/icons";
23+
import {highlightStyle} from "../../../helpers/Util";
2324

2425
const {TAGGING_SERVICE_URL} = require('../../../../config.json')
2526

@@ -99,12 +100,6 @@ function ClusterItem({answer, taggingClusterSession, dispatchTaggingClusterSessi
99100
dispatchTaggingClusterSession(clusterSessionPost())
100101
}
101102

102-
const highlightStyle = (range: HighlightRange) => {
103-
return {
104-
backgroundColor: range.color + "C8",
105-
}
106-
}
107-
108103
const clear = () => {
109104
dispatchTaggingClusterSession(setRanges(answer, []))
110105
dispatchTaggingClusterSession(clusterSessionPost())

frontend/src/helpers/Util.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,36 @@ function getColor(misconceptions_available: MisconceptionElement[], misc: (strin
5656
return found ? found.color : ""
5757
}
5858

59+
function pickTextColorBasedOnBgColorAdvanced(backgroundColor: string): string {
60+
const color = backgroundColor.substring(1, 7)
61+
const r = parseInt(color.substring(0, 2), 16); // hexToR
62+
const g = parseInt(color.substring(2, 4), 16); // hexToG
63+
const b = parseInt(color.substring(4, 6), 16); // hexToB
64+
const uicolors = [r / 255, g / 255, b / 255];
65+
const c = uicolors.map((col: number) => {
66+
if (col <= 0.03928) {
67+
return col / 12.92;
68+
}
69+
return Math.pow((col + 0.055) / 1.055, 2.4)
70+
})
71+
const L = (0.2126 * c[0]) + (0.7152 * c[1]) + (0.0722 * c[2])
72+
return (L > 0.179) ? '#000000' : '#FFFFFF'
73+
}
74+
75+
function highlightStyle(range: HighlightRange) {
76+
return {
77+
color: pickTextColorBasedOnBgColorAdvanced(range.color),
78+
backgroundColor: range.color,
79+
}
80+
}
81+
5982
export {
6083
NO_COLOR,
6184
isUsingDefaultColor,
6285
isNoMisconception,
6386
getMillis,
6487
highlightRangesColorUpdating,
6588
filteredMisconceptions,
66-
getColor
89+
getColor,
90+
highlightStyle
6791
}

0 commit comments

Comments
 (0)