Skip to content

add color modifcation for node #394

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ envset/
*.tar.gz
*.whl
.tmp/

.vscode/
# built files
dist/
coverage/
Expand Down
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"dependencies": {
"baconjs": "^0.7.71",
"d3-brush": "https://github.com/zakandrewking/d3-brush.git",
"d3-color": "^3.1.0",
"d3-drag": "^1.0.2",
"d3-dsv": "^1.0.3",
"d3-request": "^1.0.3",
Expand All @@ -73,13 +74,13 @@
"vkbeautify": "^0.99.1"
},
"scripts": {
"build": "./node_modules/.bin/webpack --config webpack.prod.js",
"watch": "./node_modules/.bin/webpack --config webpack.prod.js --watch",
"start": "./node_modules/.bin/webpack-dev-server --config webpack.dev.js",
"clean": "rm -r dist/*; rm -r py/escher/static/*",
"test": "./node_modules/.bin/mochapack --webpack-config webpack.test.js \"src/tests/*.js\"",
"copy": "cp dist/escher.min.js dist/index.js && cp package.json py/escher/static/ && cp jupyter/notebook-extension.js py/escher/static/extension.js && cp dist/escher.min.* py/escher/static/ && mkdir -p py/escher/static/jsonschema; cp jsonschema/* py/escher/static/jsonschema/",
"coverage": "./node_modules/.bin/cross-env NODE_ENV=coverage ./node_modules/.bin/nyc --reporter=text-lcov npm run test | ./node_modules/.bin/coveralls"
"build": "webpack --config webpack.prod.js",
"watch": "webpack --config webpack.prod.js --watch",
"start": "webpack-dev-server --config webpack.dev.js",
"clean": "rimraf dist/* py/escher/static/*",
"test": "mochapack --webpack-config webpack.test.js \"src/tests/*.js\"",
"copy": "node scripts/copy.js",
"coverage": "cross-env NODE_ENV=coverage nyc --reporter=text-lcov npm run test | coveralls"
},
"nyc": {
"include": [
Expand Down
99 changes: 89 additions & 10 deletions src/Behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import utils from './utils'
import * as build from './build'
import { drag as d3Drag } from 'd3-drag'
import * as d3Selection from 'd3-selection'
import { color as d3Color } from 'd3-color'

const d3Select = d3Selection.select
const d3Mouse = d3Selection.mouse
Expand Down Expand Up @@ -201,22 +202,12 @@ export default class Behavior {
if (onOff) {
const map = this.map
this.selectableMousedown = d => {
// stop propogation for the buildinput to work right
d3Selection.event.stopPropagation()
// this.parentNode.__data__.wasSelected = d3Select(this.parentNode).classed('selected')
// d3Select(this.parentNode).classed('selected', true)
}
this.selectableClick = function (d) {
// stop propogation for the buildinput to work right
d3Selection.event.stopPropagation()
// click suppressed. This DOES have en effect.
if (d3Selection.event.defaultPrevented) return
// turn off the temporary selection so select_selectable
// works. This is a bit of a hack.
// if (!this.parentNode.__data__.wasSelected)
// d3Select(this.parentNode).classed('selected', false)
map.select_selectable(this, d, d3Selection.event.shiftKey)
// this.parentNode.__data__.wasSelected = false
}
this.nodeMouseover = function (d) {
d3Select(this).style('stroke-width', null)
Expand All @@ -228,6 +219,94 @@ export default class Behavior {
this.nodeMouseout = function (d) {
d3Select(this).style('stroke-width', null)
}
this.map.sel.select('#nodes')
.selectAll('.node-circle')
.on('dblclick', function(d) {
console.log('Node double-clicked:', d);
const defaultFillColor = 'rgb(224, 134, 91)'; // Default fill color from Builder-embed.css
const defaultStrokeColor = 'rgb(162, 69, 16)'; // Default stroke color (black)
const currentFillColor = d3Select(this).style('fill');
console.log(`Current fill color: ${currentFillColor}`);

if (!d.isToggled) {
// Create color selection prompt
const colorPrompt = d3Select('body').append('div')
.style('position', 'fixed')
.style('left', '50%')
.style('top', '50%')
.style('transform', 'translate(-50%, -50%)')
.style('background-color', 'white')
.style('border', '1px solid black')
.style('padding', '20px')
.style('z-index', '1000');

colorPrompt.append('p')
.text('Select color:')
.style('margin-bottom', '10px');

const colorOptions = {
'lime': '#ccff66',
'purple': '#9999FF',
'cyan': '#8da0cb',
'red': '#ff0000',
'blue': '#66ccff',
'white': '#ffffff'
};

Object.entries(colorOptions).forEach(([colorName, colorValue]) => {
colorPrompt.append('button')
.text(colorName)
.style('margin', '5px')
.style('padding', '5px 10px')
.style('background-color', colorValue)
.style('color', colorValue === '#ffffff' ? 'black' : 'white')
.style('border', 'none')
.style('cursor', 'pointer')
.on('click', () => {
const darkerColor = colorValue === '#ffffff' ? '#000000' : d3Color(colorValue).darker(0.8);
d3Select(this)
.transition()
.duration(300)
.style('fill', colorValue)
.style('stroke', darkerColor);

d.fillColor = colorValue;
d.strokeColor = darkerColor;
d.isToggled = true;

colorPrompt.remove();
console.log(`Node colors changed. Fill: ${d.fillColor}, Stroke: ${d.strokeColor}, isToggled: ${d.isToggled}`);
});
});

// Add cancel button
colorPrompt.append('button')
.text('Cancel')
.style('margin', '5px')
.style('padding', '5px 10px')
.style('cursor', 'pointer')
.on('click', () => {
colorPrompt.remove();
});

} else {
// Second double-click: Change back to default
d3Select(this)
.transition()
.duration(300)
.style('fill', defaultFillColor)
.style('stroke', defaultStrokeColor);

// Remove the saved colors
delete d.fillColor;
delete d.strokeColor;
d.isToggled = false;
}

console.log(`Node colors changed. isToggled: ${d.isToggled}`);
d3Selection.event.stopPropagation();
});

} else {
this.selectableMousedown = null
this.selectableClick = null
Expand Down
8 changes: 8 additions & 0 deletions src/Builder-embed.css
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,20 @@ svg.escher-svg g.selected .node-circle{
svg.escher-svg g.selected .label {
fill: rgb(20, 113, 199);
}
/* svg.escher-svg .metabolite-circle {
stroke: rgb(162, 69, 16);
fill: rgb(224, 134, 91);
} */
svg.escher-svg .metabolite-circle {
stroke: rgb(162, 69, 16);
fill: rgb(224, 134, 91);
}



svg.escher-svg g.selected .metabolite-circle {
stroke: rgb(5, 2, 0);
fill: rgb(162, 26, 16)
}
svg.escher-svg .segment {
stroke: #334E75;
Expand Down
Loading