Skip to content

Commit

Permalink
esLint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
enxebre committed Mar 9, 2016
1 parent ea41491 commit 6303d46
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"indent": [2, 2, {SwitchCase: 1}],
"jsx-quotes": 1,
"quotes": [2, "single"],
"camelcase": 2,
"camelcase": 1,
"no-undefined": 2,
"no-unused-vars": 0,
"curly": 2,
Expand Down
10 changes: 7 additions & 3 deletions src/components/TaskTable/TaskTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ class TaskTable extends React.Component {
orderTasksByParameter(tasks = [], parameterToOrderBy = 'timestamp') {
var parameter = parameterToOrderBy;
tasks.sort(function(a, b) {
if (a[parameter] < b[parameter]) return 1;
if (a[parameter] > b[parameter]) return -1;
if (a[parameter] < b[parameter]) {
return 1;
}
if (a[parameter] > b[parameter]) {
return -1;
}
return 0;
});
return tasks;
Expand All @@ -46,7 +50,7 @@ class TaskTable extends React.Component {
<RadioButton
ref="orderByTime"
value="timestamp"
label="Time of live"
label="Up time"
style={this.getStyles().radioButton}
/>
<RadioButton
Expand Down
26 changes: 19 additions & 7 deletions src/components/TaskVisualizer/TaskVisualizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,33 @@ class TaskVisualizer extends React.Component {
this.setState({parameterToGroupBy: e.target.value});
}

stringToColour(str) {
// str to hash
for (var i = 0, hash = 0; i < str.length; hash = str.charCodeAt(i++) + ((hash << 5) - hash));
// int/hash to hex
for (var i = 0, colour = '#'; i < 3; colour += ('00' + ((hash >> i++ * 8) & 0xFF).toString(16)).slice(-2));
//http://stackoverflow.com/questions/3426404/create-a-hexadecimal-colour-based-on-a-string-with-javascript
hashCode(str) { // java String#hashCode
var hash = 0;
for (var i = 0; i < str.length; i++) {
hash = str.charCodeAt(i) + ((hash << 5) - hash);
}
return hash;
}

intToRGB(i){
var c = (i & 0x00FFFFFF)
.toString(16)
.toUpperCase();

return '#' + '00000'.substring(0, 6 - c.length) + c;
}

return colour;
stringToColor(string) {
return this.intToRGB(this.hashCode(string));
}

// Return a hash appName: HEX_color_value
createAppColorList(tasks) {
let appColorList = {};
for(var index in tasks) {
let appName = tasks[index].name;
appColorList[appName] = this.stringToColour(appName);
appColorList[appName] = this.stringToColor(appName);
}
return appColorList;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('TaskVisualizer', function() {
it('gets Hex colors from app names', function() {
const TaskVisualizer = require('../TaskVisualizer');
let object = new TaskVisualizer();
expect(object.stringToColour('anyAppName')).toMatch("#[a-zA-Z0-9]{6,}$");
expect(object.stringToColor('anyAppName')).toMatch("#[a-zA-Z0-9]{6,}$");
});

it('creates a hash like => appName: hexColor from an array of tasks.', function() {
Expand Down

0 comments on commit 6303d46

Please sign in to comment.