Skip to content

Commit 05f41c1

Browse files
committed
feat: add color names from hex codes, add track.title to desc
1 parent a68cc83 commit 05f41c1

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"@mui/material": "^5.15.1",
1919
"@mui/x-tree-view": "6.0.0-beta.0",
2020
"gosling.js": "^0.13.2",
21+
"hex-color-to-color-name": "^1.0.2",
2122
"pixi.js": "^6.5.10",
2223
"react": "^18.2.0",
2324
"react-aria-components": "1.0.0-beta.2",

pnpm-lock.yaml

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/alt-gosling-model/alt-text/text-tree.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { AltGoslingSpec, AltTrackSingle } from '@alt-gosling/schema/alt-gosling-schema';
2-
32
import { arrayToString, markToText, channelToText, capDesc } from '../util';
43

4+
import { GetColorName } from 'hex-color-to-color-name';
55

66
export function addTreeDescriptions(altGoslingSpec: AltGoslingSpec) {
77
addTrackPositionDescriptions(altGoslingSpec);
@@ -186,11 +186,15 @@ function addTrackAppearanceDescriptions(altGoslingSpec: AltGoslingSpec) {
186186
desc = desc.concat(capDesc(track.charttype) + '.');
187187
} else {
188188
if (markToText.get(track.appearance.details.mark)) {
189-
desc = desc.concat('Chart with ' + markToText.get(track.appearance.details.mark) + '.');
189+
desc = desc.concat(`Chart with ${markToText.get(track.appearance.details.mark)}.`);
190190
} else {
191-
desc = desc.concat('Unknown chart.')
191+
desc = desc.concat(`Unknown chart.`)
192192
}
193193
}
194+
195+
if (track.title) {
196+
desc = desc.concat(` Chart is titled '${track.title}'.`)
197+
}
194198

195199
const encodingDescriptions = addEncodingDescriptions(track);
196200
// console.log('encdesc', encodingDescriptions);
@@ -328,6 +332,12 @@ function addEncodingDescriptions(track: AltTrackSingle) {
328332
for (let i = 0; i < track.appearance.details.encodings.encodingValue.length; i++) {
329333
const e = track.appearance.details.encodings.encodingValue[i];
330334
if (e.name === 'color') {
335+
// if the color is denoted as a hex code, get the name of the color value
336+
if (typeof e.details.value === 'string') {
337+
if (e.details.value[0] === '#') {
338+
e.details.value = GetColorName(e.details.value.slice(0)).toLowerCase();
339+
}
340+
}
331341
descValue = descValue.concat('The color of the ' + markToText.get(mark) + ' is ' + e.details.value + '.');
332342
descList.push(['color', 'The color of the ' + markToText.get(mark) + ' is ' + e.details.value + '.']);
333343
}

0 commit comments

Comments
 (0)