cytoscape.js-grid-guide icon indicating copy to clipboard operation
cytoscape.js-grid-guide copied to clipboard

Support change background

Open kubitre opened this issue 3 years ago • 15 comments

Hello! I want to upgrade your wonderful library so that it allows you to change the background. just pass the background setting (color)(change naming, this color is GridLinesColor): https://github.com/iVis-at-Bilkent/cytoscape.js-grid-guide/blob/296adb1ba35295352501e5d7fc94476ebe2d4c57/src/index.js#L35

Change as:

gridColor: '#fff', // Color of grid background
gridLinesColor: '#dedede' // Color of grid lines

, and after need add in svg rendering https://github.com/iVis-at-Bilkent/cytoscape.js-grid-guide/blob/296adb1ba35295352501e5d7fc94476ebe2d4c57/src/draw_grid.js#L55-L56

following code:

<svg width="'+ canvasWidth + '" height="'+ canvasHeight + '" xmlns="http://www.w3.org/2000/svg">\n\
            <defs>\n\
                <pattern id="horizontalLines" width="' + increment + '" height="' + increment + '" patternUnits="userSpaceOnUse">\n\
                    <path d="M ' + increment + ' 0 L 0 0 0 ' + 0 + '" fill="none" stroke="' + options.gridLinesColor + '" stroke-width="' + options.lineWidth + '" />\n\
                </pattern>\n\
                <pattern id="verticalLines" width="' + increment + '" height="' + increment + '" patternUnits="userSpaceOnUse">\n\
                    <path d="M ' + 0 + ' 0 L 0 0 0 ' + increment + '" fill="none" stroke="' + options.gridLinesColor + '" stroke-width="' + options.lineWidth + '" />\n\
                </pattern>\n\
            </defs>\n\
<rect width="100%" height="100%"  fill="' + options.gridColor + '" />\n\
<rect width="100%" height="100%" fill="url(#horizontalLines)" transform="translate('+ 0 + ', ' + initialValueY + ')" />\n\
<rect width="100%" height="100%" fill="url(#verticalLines)" transform="translate('+ initialValueX + ', ' + 0 + ')" />\n\

This result i showed on attached image: image

kubitre avatar Oct 07 '21 19:10 kubitre

@ugurdogrusoz

kubitre avatar Oct 07 '21 19:10 kubitre

@kinimesi @royludo @metincansiper please, asnwer, this is feature

kubitre avatar Oct 07 '21 19:10 kubitre

@kubitre Feel free to do a PR to the unstable branch please

ugurdogrusoz avatar Oct 08 '21 05:10 ugurdogrusoz

@kubitre why don't you just set the background color of cytoscape div?

kinimesi avatar Oct 08 '21 06:10 kinimesi

@kinimesi it seems that this option is a crutch =) The point is not to do it well for me, but to everyone who possibly uses this lib. If you change the background through the configuration, besides, this is not a super global change, backward compatible, I see no reason not to support it

kubitre avatar Oct 08 '21 19:10 kubitre

@ugurdogrusoz check my pr please

kubitre avatar Oct 08 '21 19:10 kubitre

@kubitre I'm sorry, but I think it's redundant to have such an option in this extension while the same feature can be achieved by just setting the CSS background color for Cytoscape div

#cy {
  background: #000;
}

Also the default fill option must be none so that it doesn't overlay the Cytoscape canvas in case someone set its background to a different color.

kinimesi avatar Oct 08 '21 22:10 kinimesi

I think @kinimesi is right.

ugurdogrusoz avatar Oct 09 '21 05:10 ugurdogrusoz

Ok, but this not work image

kubitre avatar Oct 09 '21 05:10 kubitre

all lines are colored as background color of this div

kubitre avatar Oct 09 '21 06:10 kubitre

this work if i change alpha level to 0.9, but If you have to bother like that, then this is some kind of game

kubitre avatar Oct 09 '21 06:10 kubitre

image

kubitre avatar Oct 09 '21 06:10 kubitre

but if i change grid lines color to white for example, i get full fill color as background color of div

kubitre avatar Oct 09 '21 06:10 kubitre

ok, this problem i also solve, but the solution is not obvious, the parameter would solve it much better, let me make it so that if the user does not set anything, then the parameter will be substituted as none, as you wrote, then it will just be more obvious to everyone, and there will be no extra z-index manipulation to do

I Solve this by change Z-index at the div to 0, but after i get small artifacts on grid lines on size lines small then 2 image

kubitre avatar Oct 09 '21 06:10 kubitre

@kubitre how do those rectangular white dots appear?

I agree with @kinimesi. The background color of your canvas is not related to this extension. By using CSS, you can set the background color of your canvas. If you set a background color, z-index should also be set. You can play with gridColor option for different colored grid lines.

canbax avatar Feb 14 '22 07:02 canbax