Skip to content

Commit 6b12059

Browse files
committed
feat: added setting for using color fallback
1 parent cb93715 commit 6b12059

File tree

7 files changed

+544
-21
lines changed

7 files changed

+544
-21
lines changed

package-lock.json

Lines changed: 500 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@
8686
"@fullcalendar/vue": "^5.1.0",
8787
"@types/chart.js": "^2.9.23",
8888
"@types/chrome": "0.0.89",
89+
"@types/color": "^3.0.1",
90+
"@types/d3": "^6.3.0",
8991
"@types/jest": "^24.9.1",
9092
"@types/lodash": "^4.14.157",
9193
"@types/node": "^12.12.50",

src/util/color.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import _ from 'lodash';
22
import { Category, matchString, loadClasses } from './classes';
3-
const Color = require('color');
4-
const d3 = require('d3');
3+
import Color from 'color';
4+
import * as d3 from 'd3';
55

66
// TODO: Move elsewhere
77
interface Event {
@@ -24,7 +24,9 @@ const COLOR_UNCAT = '#CCC';
2424
const scale = d3.scaleOrdinal(['#90CAF9', '#FFE082', '#EF9A9A', '#A5D6A7']);
2525

2626
// Needed to prewarm the color table
27-
scale.domain([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]);
27+
scale.domain(
28+
'0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20'.split(/, /)
29+
);
2830

2931
const customColors = {
3032
afk: '#EEE',
@@ -52,9 +54,12 @@ const customColors = {
5254
// Social media sites
5355
'messenger.com': Color('#3b5998').lighten(0.5),
5456
'facebook.com': Color('#3b5998').lighten(0.5),
57+
58+
// Categories
59+
uncategorized: COLOR_UNCAT,
5560
};
5661

57-
function hashcode(str: string) {
62+
function hashcode(str: string): number {
5863
let hash = 0;
5964
if (str.length === 0) {
6065
return hash;
@@ -70,7 +75,7 @@ function hashcode(str: string) {
7075
export function getColorFromString(appname: string) {
7176
appname = appname || '';
7277
appname = appname.toLowerCase();
73-
return customColors[appname] || scale(Math.abs(hashcode(appname) % 20));
78+
return customColors[appname] || scale(Math.abs(hashcode(appname) % 20).toString());
7479
}
7580

7681
// TODO: Move into vuex?
@@ -84,7 +89,6 @@ export function getColorFromCategory(c: Category, allCats: Category[]): string {
8489
const parentCat = allCats.find(cc => _.isEqual(cc.name, parent));
8590
return getColorFromCategory(parentCat, allCats);
8691
} else {
87-
// TODO: Fix reasonable fallback
8892
return COLOR_UNCAT;
8993
}
9094
}
@@ -97,7 +101,17 @@ export function getCategoryColorFromString(str: string): string {
97101
if (c !== null) {
98102
return getColorFromCategory(c, allCats);
99103
} else {
100-
// TODO: Fix reasonable fallback
104+
return fallbackColor(str);
105+
}
106+
}
107+
108+
function fallbackColor(str: string): string {
109+
// Get fallback color
110+
// TODO: Fetch setting from somewhere better, where defaults are respected
111+
const useColorFallback = localStorage !== undefined ? localStorage.useColorFallback : true;
112+
if (useColorFallback) {
113+
return getColorFromString(str);
114+
} else {
101115
return COLOR_UNCAT;
102116
}
103117
}

src/views/activity/Activity.vue

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,16 @@ div
6363
h5 Options
6464

6565
div.row
66-
div.col-md-6
67-
b-form-group(label="Show/filter category" label-cols="5" label-cols-lg="4")
68-
b-form-select(v-model="filterCategory", :options="categories")
69-
70-
div.row
71-
div.col-md-12
66+
div.col-lg-6
7267
b-form-checkbox(v-model="filterAFK")
7368
| Filter AFK
74-
div.col-md-12
7569
b-form-checkbox(v-model="includeAudible")
7670
| Count audible browser tab as active
7771

72+
div.col-lg-6
73+
b-form-group(label="Show/filter category" label-cols="5" label-cols-lg="4")
74+
b-form-select(v-model="filterCategory", :options="categories")
75+
7876
aw-devonly
7977
b-btn(id="load-demo", @click="load_demo")
8078
| Load demo data

src/views/settings/ColorSettings.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ export default {
1616
useColorFallback: localStorage.useColorFallback || true,
1717
};
1818
},
19-
methods: {
20-
set: function (useColorFallback) {
21-
localStorage.useColorFallback = useColorFallback;
22-
console.log('Set useColorFallback to ' + useColorFallback);
19+
watch: {
20+
useColorFallback(val) {
21+
localStorage.useColorFallback = val;
22+
console.log('Set useColorFallback to ' + val);
2323
},
2424
},
2525
};

src/views/settings/ReleaseNotificationSettings.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ div
44
div
55
h5.mb-0 New release notification
66
div
7-
b-form-checkbox(v-model="data.isEnabled" @change="saveData", switch)
7+
b-form-checkbox(v-model="data.isEnabled" switch)
88
small
99
| We will send you a notification if there is a new release available for download, this check will happen at most once per day.
1010
</template>
@@ -26,6 +26,14 @@ export default {
2626
},
2727
};
2828
},
29+
watch: {
30+
data: {
31+
handler() {
32+
this.saveData();
33+
},
34+
deep: true,
35+
},
36+
},
2937
created() {
3038
this.retrieveData();
3139
},

src/views/settings/Settings.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ div
2222
ReleaseNotificationSettings
2323
hr
2424

25-
//ColorSettings
26-
//hr
25+
ColorSettings
26+
27+
hr
2728

2829
CategorizationSettings
2930

0 commit comments

Comments
 (0)