Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fluid.plotter: correctly construct unique labels #412

Merged
merged 3 commits into from
Nov 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions jsui/fluid.plotter.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ setoutletassist(0, 'Position of mouse in x/y space');

// https://github.com/d3/d3-scale-chromatic
// https://sashamaps.net/docs/resources/20-colors/
const colors = {
var colors = {
default: 'e6194b3cb44bffe1194363d8f58231911eb446f0f0f032e6bcf60cfabebe008080e6beff9a6324fffac8800000aaffc3808000ffd8b1000075808080',
cat : '1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf',
accent : '7fc97fbeaed4fdc086ffff99386cb0f0027fbf5b17666666',
Expand All @@ -28,8 +28,8 @@ const colors = {
};

// Constant Values
const defaultPointColor = [0, 0, 0, 0.8];
const pointSizeScaler = 0.075;
var defaultPointColor = [0, 0, 0, 0.8];
var pointSizeScaler = 0.075;

// Internal State for Mousing
var w = [0,0,0];
Expand Down Expand Up @@ -241,26 +241,28 @@ function setcategories(name) {

function constructColorScheme() {
if (labelDict) {
const data = labelDict.get('data');
const keys = data.getkeys();
var uniques = new Array();
var labelDictAsJson = JSON.parse(labelDict.stringify());
var data = labelDictAsJson.data;
var keys = Object.keys(data)
var uniques = []

// How many unique labels are there?
keys.forEach(function(key) {
var label = data.get(key);
if (uniques.indexOf(label) == -1) {
uniques.push(label)
var label = data[key]
if (uniques.indexOf(label[0]) == -1) {
uniques.push(label[0])
}
})

colorMap = {};
var scheme = strChunk(_colorscheme, 6);

uniques.sort();
uniques.forEach(function(u, i) {
i = i % scheme.length;
var color = hexToRGB(scheme[i], 1.0);
colorMap[u] = color;
});

var scheme = strChunk(_colorscheme, 6);
colorMap = {}
colorMap = uniques.reduce(function(map, u, i) {
const color = hexToRGB(scheme[i % scheme.length], 1.0);
map[u] = color;
return map;
}, {});

// Strip any of the points from the pointColors if they have been assigned here
keys.forEach(function(pt) {
Expand Down Expand Up @@ -435,4 +437,4 @@ forcesize.local = 1; //private
function onresize(w, h) {
forcesize(w, h);
}
onresize.local = 1; //private
onresize.local = 1; //private