Skip to content

Commit

Permalink
adjusted new default color config to old defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
Amorano committed Feb 4, 2025
1 parent 235b7bf commit 9db24ba
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 101 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ You can colorize nodes via their `title background`, `node body` or `title text`

## UPDATES

**2024/02/04** @1.6.5:
* adjusted new default color config to old defaults

**2024/02/04** @1.6.0:
* added colorizer option for `title text`
* settings deprecated and removed from ComfyUI settings panel
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "jovimetrix"
description = "Integrates Webcam, MIDI, Spout and GLSL shader support. Animation via tick. Parameter manipulation with wave generator. Math operations with Unary and Binary support. Value conversion for all major types (int, string, list, dict, Image, Mask). Shape mask generation, image stacking and channel ops, batch splitting, merging and randomizing, load images and video from anywhere, dynamic bus routing with a single node, export support for GIPHY, save output anywhere! flatten, crop, transform; check colorblindness, make stereogram or stereoscopic images, or liner interpolate values and more."
version = "1.6.0"
version = "1.6.5"
license = { file = "LICENSE" }
readme = "README.md"
authors = [{ name = "Alexander G. Morano", email = "[email protected]" }]
Expand Down
94 changes: 52 additions & 42 deletions web/core/core_color.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ function colorContrast(hexColor) {
function getColor(node) {
// regex overrides first
const CONFIG_REGEX = app.extensionManager.setting.get(setting_regex);

for (const { regex, ...colors } of CONFIG_REGEX || []) {
if (regex && node.type.match(new RegExp(regex, "i"))) {
return colors;
Expand All @@ -59,17 +58,14 @@ function getColor(node) {
const CONFIG_THEME = app.extensionManager.setting.get(setting_theme);
const newColor = CONFIG_THEME?.[node.type]
?? (function() {
let color = NODE_LIST?.[node.type];
if (color?.category) {
let k = color.category;
while (k) {
if (CONFIG_THEME?.[k]) {
return CONFIG_THEME[k];
}
k = k.substring(0, k.lastIndexOf("/"));
const color = NODE_LIST[node.type];
let k = color?.category;
while (k) {
if (CONFIG_THEME?.[k]) {
return CONFIG_THEME[k];
}
k = k.substring(0, k.lastIndexOf("/"));
}
return null;
})();

return newColor;
Expand Down Expand Up @@ -448,7 +444,10 @@ class JovimetrixPanelColorize {
const table = $el("table.flexible-table");
this.tbody = $el("tbody");

const CONFIG_REGEX = app.extensionManager.setting.get(setting_regex) || [];
let CONFIG_REGEX = app.extensionManager.setting.get(setting_regex) || [];
if (!Array.isArray(CONFIG_REGEX)) {
CONFIG_REGEX = []
}
CONFIG_REGEX.forEach((entry, idx) => {
const data = {
idx: idx,
Expand All @@ -465,18 +464,13 @@ class JovimetrixPanelColorize {
}

createColorPalettes() {
const all_nodes = Object.entries(NODE_LIST || []).sort((a, b) => {
const categoryComparison = a[1].category.toLowerCase().localeCompare(b[1].category.toLowerCase());
return categoryComparison;
});

let background_index = 0;
const categories = [];
const CONFIG_THEME = app.extensionManager.setting.get(setting_theme);

all_nodes.forEach(([nodeName, node]) => {
NODE_LIST.forEach(([nodeName, node]) => {
const category = node.category;
const majorCategory = category.split("/")[0];
const majorCategory = category.split("/")?.[0];

if (!categories.includes(majorCategory)) {
background_index = (background_index + 1) % 2;
Expand Down Expand Up @@ -586,36 +580,52 @@ app.registerExtension({
defaultValue: {}
},
],
async afterConfigureGraph() {
async setup() {

[NODE_LIST] = await Promise.all([
apiGet("/object_info")
]);
const all_nodes = await apiGet("/object_info");
NODE_LIST = Object.entries(all_nodes).sort((a, b) => {
const categoryA = a[1].category.toLowerCase();
const categoryB = b[1].category.toLowerCase();

if (!app.extensionManager.setting.get(setting_regex)) {
let CONFIG_CORE;
try {
[CONFIG_CORE] = await Promise.all([
apiGet("/jovimetrix/config")
]);
// First, sort by category
if (categoryA < categoryB) return -1;
if (categoryA > categoryB) return 1;

const CONFIG_REGEX = CONFIG_CORE.user.default.color.regex || [];
const CONFIG_THEME = CONFIG_CORE.user.default.color.theme;
// If categories are equal, sort by key name
return a[0].toLowerCase().localeCompare(b[0].toLowerCase());
});
NODE_LIST = Object.fromEntries(NODE_LIST);

try {
await app.extensionManager.setting.set(setting_regex, CONFIG_REGEX);
} catch (error) {
console.error(`Error changing setting: ${error}`);
}
const CONFIG_CORE = await apiGet("/jovimetrix/config");

try {
await app.extensionManager.setting.set(setting_theme, CONFIG_THEME);
} catch (error) {
console.error(`Error changing setting: ${error}`);
if (!Array.isArray(app.extensionManager.setting.get(setting_regex))) {
const CONFIG_REGEX = CONFIG_CORE?.user?.default?.color?.regex || [];
await app.extensionManager.setting.set(setting_regex, CONFIG_REGEX);
}

if (!Array.isArray(app.extensionManager.setting.get(setting_theme))) {
const CONFIG_THEME = CONFIG_CORE?.user?.default?.color?.theme || {
"JOVIMETRIX \ud83d\udd3a\ud83d\udfe9\ud83d\udd35": {
title: "#A23DA2"
},
"JOVIMETRIX \ud83d\udd3a\ud83d\udfe9\ud83d\udd35/CREATE": {
title: "#1b871b"
},
"JOVIMETRIX \ud83d\udd3a\ud83d\udfe9\ud83d\udd35/COMPOSE": {
title: "#5C1F9A"
},
"JOVIMETRIX \ud83d\udd3a\ud83d\udfe9\ud83d\udd35/CALC": {
title: "#993838"
},
"JOVIMETRIX \ud83d\udd3a\ud83d\udfe9\ud83d\udd35/DEVICE": {
title: "#1f9999"
},
"JOVIMETRIX \ud83d\udd3a\ud83d\udfe9\ud83d\udd35/UTILITY": {
title: "#0A0A0A"
}
} catch (error) {
console.error("Error initializing Jovimetrix Colorizer Panel:", error);
}
await app.extensionManager.setting.set(setting_theme, CONFIG_THEME);
}

}
});
});
45 changes: 0 additions & 45 deletions web/default.json

This file was deleted.

12 changes: 0 additions & 12 deletions web/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,6 @@ export function domShowModal(innerHTML, eventCallback, timeout=null) {
/*
* Parse a string "255,255,255,255" or a List[255,255,255,255] into hex
*/
export function colorRGB2Hex(input) {
const rgbArray = typeof input == 'string' ? input.match(/\d+/g) : input;
if (rgbArray.length < 3) {
throw new Error('input not 3 or 4 values');
}
const hexValues = rgbArray.map((value, index) => {
if (index == 3 && !value) return 'ff';
const hex = parseInt(value).toString(16);
return hex.length == 1 ? '0' + hex : hex;
});
return '#' + hexValues.slice(0, 3).join('') + (hexValues[3] || '');
}

export function colorLerpHex(colorStart, colorEnd, lerp) {
// Parse color strings into RGB arrays
Expand Down
24 changes: 23 additions & 1 deletion web/widget/widget_vector.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,32 @@

import { app } from "../../../scripts/app.js"
import { widgetToInput, widgetToWidget } from '../util/util_widget.js'
import { domInnerValueChange, colorHex2RGB, colorRGB2Hex } from '../util/util.js'
import { domInnerValueChange } from '../util/util.js'
import { $el } from "../../../scripts/ui.js"
/** @import { IWidget, LGraphCanvas } from '../../types/litegraph/litegraph.d.ts' */

function colorHex2RGB(hex) {
hex = hex.replace(/^#/, '');
const bigint = parseInt(hex, 16);
const r = (bigint >> 16) & 255;
const g = (bigint >> 8) & 255;
const b = bigint & 255;
return [r, g, b];
}

function colorRGB2Hex(input) {
const rgbArray = typeof input == 'string' ? input.match(/\d+/g) : input;
if (rgbArray.length < 3) {
throw new Error('input not 3 or 4 values');
}
const hexValues = rgbArray.map((value, index) => {
if (index == 3 && !value) return 'ff';
const hex = parseInt(value).toString(16);
return hex.length == 1 ? '0' + hex : hex;
});
return '#' + hexValues.slice(0, 3).join('') + (hexValues[3] || '');
}

const VectorWidget = (app, inputName, options, initial, desc='') => {
const values = options[1]?.default || initial;
/** @type {IWidget} */
Expand Down

0 comments on commit 9db24ba

Please sign in to comment.