So I have a width and height of container and viewBox, can't change these things
Only thing I can do is send this component a path
For now the SVG is now adjusting in it's container due to the size being too big
Can I change the aspect ratio / size of SVG via the path ?
Sample Code
<svg viewBox="-2 -3 24 24" width="30px" height="30px" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="display: inline-block; vertical-align: middle;"><path fill="#3E3E3E" d="M18.438 19.102a11 11 0 0 1-18.4-7.184c-.042-.504.372-.915.878-.915.507 0 .912.411.963.915a9.16 9.16 0 0 0 5.793 7.623A9.168 9.168 0 0 0 17.749 17.2h-2.663a.917.917 0 1 1 0-1.832h4.269a.917.917 0 0 1 .916.916v4.264a.916.916 0 0 1-1.833 0V19.1v.002ZM4.248 4.807H6.91a.917.917 0 1 1 0 1.832H2.64a.917.917 0 0 1-.917-.916V1.455a.916.916 0 0 1 1.833 0v1.448a11 11 0 0 1 18.407 7.184c.041.505-.373.915-.88.915-.505 0-.911-.411-.962-.915a9.161 9.161 0 0 0-5.794-7.623A9.168 9.168 0 0 0 4.249 4.807h-.002Z"></path></svg>
Again goal to achieve: make SVG to fit this viewBox and width height.
No you can't. You'd have to change the SVG path to fit the box, but you can't "resize" per-se.
I manually resized your path to fit the box.
<path fill="#3E3E3E" d="M1.2 3.3H4a1 1 0 1 1 0 1.8H.6a1 1 0 0 1-.9-.9V0a1 1 0 0 1 1.9 0v1.4A11 11 0 0 1 20 8.6c0 .5-.4.9-1 .9a1 1 0 0 1-.9-1A9.2 9.2 0 0 0 12.3 1a9.2 9.2 0 0 0-10 2.3ZM17.4 16.1A11 11 0 0 1-1 8.9c0-.5.4-.9 1-.9.4 0 .8.4.9 1a9.2 9.2 0 0 0 5.8 7.5 9.2 9.2 0 0 0 10-2.3h-2.6a1 1 0 1 1 0-1.8h4.3a1 1 0 0 1 .9.9v4.2a1 1 0 0 1-1.9 0v-1.4Z"></path>
How I did it:
I used svgomg with precision: 1, to simplify the path to a point where it was small enough for me to actually manually edit.
Then I split it into two separate paths (top and bottom arrows) (using
the Z as the path separator), wrapped them in <g transform="translate(x, y)"></g> until it looked right, copied the
remainder back into svgomg where it is smart enough to convert the
transforms into a single path.
You can set the transform attribute of the <path> (using scale and translate):
document.querySelector('path').setAttribute('transform', 'scale(0.9)')
See the snippet for example:
document.querySelector('path').setAttribute('transform', 'scale(0.9)')
<svg viewBox="-2 -3 24 24" width="30px" height="30px" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="display: inline-block; vertical-align: middle;"><path fill="#3E3E3E" d="M18.438 19.102a11 11 0 0 1-18.4-7.184c-.042-.504.372-.915.878-.915.507 0 .912.411.963.915a9.16 9.16 0 0 0 5.793 7.623A9.168 9.168 0 0 0 17.749 17.2h-2.663a.917.917 0 1 1 0-1.832h4.269a.917.917 0 0 1 .916.916v4.264a.916.916 0 0 1-1.833 0V19.1v.002ZM4.248 4.807H6.91a.917.917 0 1 1 0 1.832H2.64a.917.917 0 0 1-.917-.916V1.455a.916.916 0 0 1 1.833 0v1.448a11 11 0 0 1 18.407 7.184c.041.505-.373.915-.88.915-.505 0-.911-.411-.962-.915a9.161 9.161 0 0 0-5.794-7.623A9.168 9.168 0 0 0 4.249 4.807h-.002Z"></path></svg>
Related
I would like to use a handful of Eva Icons in my project because the package is quite large. From my understanding we can't install icons individually.
Instead, I've downloaded the svgs and registered the svg pack in the app.component which works:
export class AppComponent implements OnInit {
constructor(private iconsLibrary: NbIconLibraries) {
this.iconsLibrary.registerSvgPack('eva-icons', {
'arrow-back': '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><g data-name="Layer 2"><g data-name="arrow-back"><rect width="24" height="24" transform="rotate(90 12 12)" opacity="0"/><path d="M19 11H7.14l3.63-4.36a1 1 0 1 0-1.54-1.28l-5 6a1.19 1.19 0 0 0-.09.15c0 .05 0 .08-.07.13A1 1 0 0 0 4 12a1 1 0 0 0 .07.36c0 .05 0 .08.07.13a1.19 1.19 0 0 0 .09.15l5 6A1 1 0 0 0 10 19a1 1 0 0 0 .64-.23 1 1 0 0 0 .13-1.41L7.14 13H19a1 1 0 0 0 0-2z"/></g></g></svg>',
'book-open-outline': '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><g data-name="Layer 2"><g data-name="book-open"><rect width="24" height="24" transform="rotate(180 12 12)" opacity="0"/><path d="M20.62 4.22a1 1 0 0 0-.84-.2L12 5.77 4.22 4A1 1 0 0 0 3 5v12.2a1 1 0 0 0 .78 1l8 1.8h.44l8-1.8a1 1 0 0 0 .78-1V5a1 1 0 0 0-.38-.78zM5 6.25l6 1.35v10.15L5 16.4zM19 16.4l-6 1.35V7.6l6-1.35z"/></g></g></svg>',
'camera': '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><g data-name="Layer 2"><g data-name="camera"><rect width="24" height="24" opacity="0"/><path d="M19 7h-3V5.5A2.5 2.5 0 0 0 13.5 3h-3A2.5 2.5 0 0 0 8 5.5V7H5a3 3 0 0 0-3 3v8a3 3 0 0 0 3 3h14a3 3 0 0 0 3-3v-8a3 3 0 0 0-3-3zm-9-1.5a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 .5.5V7h-4zM20 18a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1v-8a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1z"/><path d="M12 10.5a3.5 3.5 0 1 0 3.5 3.5 3.5 3.5 0 0 0-3.5-3.5zm0 5a1.5 1.5 0 1 1 1.5-1.5 1.5 1.5 0 0 1-1.5 1.5z"/></g></g></svg>',
'menu-outline': '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><g data-name="Layer 2"><g data-name="menu"><rect width="24" height="24" transform="rotate(180 12 12)" opacity="0"/><rect x="3" y="11" width="18" height="2" rx=".95" ry=".95"/><rect x="3" y="16" width="18" height="2" rx=".95" ry=".95"/><rect x="3" y="6" width="18" height="2" rx=".95" ry=".95"/></g></g></svg>',
'edit-outline': '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><g data-name="Layer 2"><g data-name="edit"><rect width="24" height="24" opacity="0"/><path d="M19.4 7.34L16.66 4.6A2 2 0 0 0 14 4.53l-9 9a2 2 0 0 0-.57 1.21L4 18.91a1 1 0 0 0 .29.8A1 1 0 0 0 5 20h.09l4.17-.38a2 2 0 0 0 1.21-.57l9-9a1.92 1.92 0 0 0-.07-2.71zM9.08 17.62l-3 .28.27-3L12 9.32l2.7 2.7zM16 10.68L13.32 8l1.95-2L18 8.73z"/></g></g></svg>',
'teams': '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><g data-name="Layer 2"><g data-name="people"><rect width="24" height="24" opacity="0"/><path d="M9 11a4 4 0 1 0-4-4 4 4 0 0 0 4 4zm0-6a2 2 0 1 1-2 2 2 2 0 0 1 2-2z"/><path d="M17 13a3 3 0 1 0-3-3 3 3 0 0 0 3 3zm0-4a1 1 0 1 1-1 1 1 1 0 0 1 1-1z"/><path d="M17 14a5 5 0 0 0-3.06 1.05A7 7 0 0 0 2 20a1 1 0 0 0 2 0 5 5 0 0 1 10 0 1 1 0 0 0 2 0 6.9 6.9 0 0 0-.86-3.35A3 3 0 0 1 20 19a1 1 0 0 0 2 0 5 5 0 0 0-5-5z"/></g></g></svg>',
});
this.iconsLibrary.setDefaultPack('eva-icons');
}
However the nb status is no longer automatically changing the icon colours like before. Please can you advise on how to do this efficiently?
Alternative is to extract the SVG of only the icons you want (from any icon set);
wrap that in a modern W3C Custom Element/WebComponent that recreates the SVG dynamically,
allowing you to alter presentation any way you want, with attributes, properties or CSS properties.
https://iconmeister.github.io/ now has 5000+ icons you can pick from
You then have No dependencies, No external SVG files
As a test I did all your 6 EVA icons: https://jsfiddle.net/WebComponents/5ct36swL/
(and cleaned up the bloated SVG from EVA icons)
Usage:
<style>
svg-icon {
display: block;
background: grey;
--svg-icon-stroke:darkslategray;
}
</style>
<div id=toolBar class=icons>
<svg-icon is="arrow-back" stroke=green></svg-icon>
<svg-icon is="book-open-outline" fill=red></svg-icon>
<svg-icon is="camera" opacity=.2 stroke=red></svg-icon>
<svg-icon is="menu-outline" fill=gold></svg-icon>
<svg-icon is="edit-outline" rotate=45 fill=blue stroke=white></svg-icon>
<svg-icon is="teams" scale=.5></svg-icon>
</div>
Output:
Should work fine in Angular, Vue or Svelte. For React you have to jump through some hoops...
as React only for 71% supports this modern W3C standard (https://custom-elements-everywhere.com/)
(my) Related StackOverflow answers: Custom Elements and SVG
Hi I am having trouble trying to get ifelse statements to work in a plotweb fuction (from bipartite) to color interaction based on the total quantity of interaction of each cell in the matrix. I had the same problem with the high bar colors, but since there were only a few values and one vector, it was easy to manually code.
Here is the code I am using, I want to color interactions greater than 15 as dark turquoise and keep the rest as default grey (grey80).
I have tried many different statements but I cant seem how to figure out what to put in the [,] to signify for the function to go through every individual cell and apply the statement instead of summing them, elem,elem also doesn't seem to work. Attached is a picture of the function's output currently
plotweb(LadyNet,
abuns.type='additional',
arrow="up.center",
text.rot=90,
col.low=c("olivedrab3"),
col.interaction =(ifelse(LadyNet[,] < 15,'grey80','darkturquoise')),
col.high = c("grey10","#FF0000","grey10","#FF0000","grey10","#FF0000","grey10","grey10","grey10"),
high.lab.dis = 0,
ybig=1.2,
y.width.high = .06,
high.spacing = 0.011,
y.lim = c(-1,2))
COCCAL COCSEP CYCPOL CYCSAN EXOFAS HIPCON PSYVIG SCY1 SCYMAR
Acmispon glaber 0 1 0 1 0 0 0 0 0
Ambrosia psilostachya 1 36 0 24 0 6 0 0 0
Artemisia douglasiana 0 0 0 1 0 1 0 0 0
Asclepias fascicularis 0 5 0 4 0 2 0 0 0
Avena fatua 6 10 0 0 0 4 0 0 0
Baccharis pilularis 9 76 0 38 0 27 0 1 0
Baccharis salicifolia 0 2 0 0 0 0 0 0 0
Bromus diandrus 1 8 0 0 0 4 0 0 0
Capsicum annuum 0 0 0 0 0 0 0 0 1
Chenopodium murale 0 1 0 0 0 0 0 0 0
Croton californicus 3 20 0 13 0 54 4 0 0
DEAD WOOD 0 1 0 0 0 0 0 0 0
Distichilis spicata 0 1 0 0 0 0 0 0 0
Echium candicans 0 1 0 3 0 0 0 0 0
Eleocharis acicularis 0 1 0 0 0 0 0 0 0
Encelia californica 1 1 0 3 0 2 0 0 0
Epilobium canum 0 0 0 1 0 0 0 0 0
Erigeron bonariensis 0 4 0 0 0 0 0 0 0
Erigeron canadensis 0 17 0 10 0 2 0 0 0
Erigeron sumatrensis 0 13 0 0 0 1 0 0 0
Eriophyllum confertiflorum 1 10 0 0 0 1 0 0 0
Fence 0 0 0 1 0 0 0 0 0
Festuca perennis 0 1 0 0 0 2 0 0 0
Gambelium speciosa 0 0 0 0 0 1 0 0 0
Geranium dissectum 0 0 0 3 0 0 0 0 0
GROUND 0 1 0 1 0 0 0 0 0
Helminthotheca echioides 0 1 2 17 0 1 0 0 0
Heterotheca grandiflora 2 92 0 12 0 7 1 0 0
Hirschfieldia incana 0 3 0 0 0 1 0 0 0
Juncus patens 0 1 0 0 0 0 0 0 0
Laennecia coulteri 1 65 0 2 0 3 0 0 0
Lobularia maritima 1 1 0 0 0 0 0 0 0
Morus sp. 0 0 0 1 0 0 0 0 0
NoPicture 4 3 0 3 3 2 3 0 0
Oxalis pes-caprae 4 6 0 0 0 2 0 0 0
Pennisetum clandestinum 1 5 0 0 0 0 0 0 0
Polygonum arenastrum 0 1 0 0 0 0 0 0 0
Raphanus sativus 0 1 0 0 0 0 0 0 0
ROCK 0 0 0 1 0 0 0 0 0
Rumex crispus 0 1 0 0 0 0 0 0 0
Rumex salicifolius 0 0 0 3 0 0 0 0 0
Salsola tragus 1 6 0 1 0 1 0 0 0
Salvia leucophylla 0 1 0 0 0 1 0 0 0
Schenoplectus americanus 0 1 0 0 0 0 0 0 0
Solanum nigrum 0 0 0 0 0 1 0 0 0
Sonchus arvensis 0 1 0 0 0 0 0 0 0
Spinacia oleracea 0 0 0 0 0 0 1 0 0
Stipa pulchra 0 1 0 0 0 0 0 0 0
Symphiotrichum subulatum 0 88 0 7 0 3 0 0 0
THATCH 1 3 0 0 0 4 0 0 0
Verbena lasiostachys 1 9 0 0 0 2 0 0 0
For Reference, I have gotten the ifelse statement to function properly in the plotweb function when there was only one species in the lower level attached is an example along with the code:
plotweb(rnet,
abuns.type='additional',
arrow="down.center",
text.rot=90,
col.low=c("olivedrab3"),
col.interaction =(ifelse(rnet[1,] < 12,'grey80','darkturquoise')),
col.high = (ifelse(rnet[1,] < 12,'grey10','darkturquoise')),
high.lab.dis = 0,
ybig=1.2,
y.width.high = .06,
high.spacing = 0.011)
One thing to note is that the col.interaction color matrix should be transposed.
Here is an example that I trust you will find useful:
library(bipartite)
library(grDevices)
plotweb(df,
abuns.type='additional',
arrow="up.center",
text.rot=90,
col.low=c("olivedrab3"),
col.interaction = t(ifelse(df[,] < 15,
adjustcolor('grey80', alpha.f = 0.5), #add alpha to colors
adjustcolor('darkturquoise', alpha.f = 0.5))),
col.high = c("grey10",
"#FF0000",
"grey10",
"#FF0000",
"grey10",
"#FF0000",
"grey10",
"grey10",
"grey10"),
bor.col.interaction = NA, #remove the black border color
high.lab.dis = 0,
ybig=1.2,
y.width.high = .06,
high.spacing = 0.011,
y.lim = c(-1,2))
I have a data frame in R with the following dimensions [15750,93]. I want to construct an image using this data such that there are 3 row coordinates and 31 column coordinates in the image. Each column in the data frame corresponds to data from one coordinate position in the image. The columns in the data frame have been arranged based on their respective coordinates in the following manner [1,1], [2,1], [3,1], [1,2], [2,2], [3,2] ......... [1,31],[2,31],[3,31]
To generate the image, for each column I would like to have an average of all values, a sum of all values and the highest value in each column. This way there will be exactly one value corresponding to a coordinate. And, with the 3 variations, I should get three types of images - average, sum and highest value.
Can someone help me in generating an overall image using this data or can guide me using data with smaller dimensions?
Some demo data below:
Dimensions of the data frame are [11, 15]
0 0 0 0 0 46 0 0 0 0 0 0 0 78 0
0 734 0 0 0 0 932 0 0 56 0 0 0 0 0
0 0 0 115 0 0 0 0 0 0 64 0 0 0 0
0 67 0 0 0 45 0 0 0 0 0 546 0 12 0
0 0 0 0 65 5 56 0 54 0 0 0 0 0 0
667 0 430 0 0 0 0 456 0 0 787 0 0 467 0
0 0 0 0 54 0 0 0 0 0 0 456 90 0 0
778 45 0 0 0 0 24 913 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 26 0 0 0
234 0 0 620 0 0 0 0 0 106 0 0 901 0 0
0 0 0 0 0 0 45 0 34 0 0 0 0 0 0
I would like to have an image of with the dimensions [3,5] and the columns in the above data frame have been arranged based on their respective coordinates in the following manner [1,1], [2,1], [3,1], [1,2], [2,2], [3,2]..... and so on
The image coordinate arrangement
[1,1] [1,2] [1,3] [1,4] [1,5]
[2,1] [2,2] [2,3] [2,4] [2,5]
[3,1] [3,2] [3,3] [3,4] [3,5]
This function reads in your dataset and finds the mean (or max or sum) of each column (yielding a series of numbers, one per column). It then reshapes that series into your desired output dimensions and displays as an image.
df <- read.table(header=FALSE,text="
0 0 0 0 0 46 0 0 0 0 0 0 0 78 0
0 734 0 0 0 0 932 0 0 56 0 0 0 0 0
0 0 0 115 0 0 0 0 0 0 64 0 0 0 0
0 67 0 0 0 45 0 0 0 0 0 546 0 12 0
0 0 0 0 65 5 56 0 54 0 0 0 0 0 0
667 0 430 0 0 0 0 456 0 0 787 0 0 467 0
0 0 0 0 54 0 0 0 0 0 0 456 90 0 0
778 45 0 0 0 0 24 913 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 26 0 0 0
234 0 0 620 0 0 0 0 0 106 0 0 901 0 0
0 0 0 0 0 0 45 0 34 0 0 0 0 0 0
")
img <- function(data, op, tall, wide) image(t(matrix(sapply(data, op), nrow = wide, ncol = tall)),
col = gray((0:32) / 32))
img(df, mean, 3, 5)
img(df, max, 3, 5)
img(df, sum, 3, 5)
I am trying to produce rarefied species accumulation curves for two different habitat types using the rarefaction method in specaccum function of the vegan package using the code:
spa <- specaccum(Example, method = "rarefaction")
The function works for one data set but not the other where it produces this error:
Error in rarefy(t(freq), ind[i], se = TRUE) :
function accepts only integers (counts)
However, the data is laid out exactly the same as the other data set and when I investigate the data frame it says that all the data for the species is in integer form.
Here is a much smaller section of the data frame:
Site AA AB AC AD AE AF AG AH AI AJ AK AL
1.1 0 0 0 0 1 0 0 2 0 0 0 0
1.2 1 0 0 0 0 0 0 0 0 0 0 0
1.3 0 0 1 0 0 0 0 0 0 0 0 0
2.1 1 0 0 0 1 0 0 0 0 0 0 0
2.2 0 1 0 0 0 0 0 0 0 0 0 0
2.3 0 0 0 0 0 0 0 1 0 0 1 1
3.2 0 2 1 0 1 0 0 0 0 0 0 0
3.3 0 0 0 0 2 0 0 3 0 0 0 0
4.1 0 0 0 0 0 0 1 1 0 0 0 0
4.2 0 0 0 0 0 0 0 0 0 0 0 0
4.3 0 0 0 0 1 0 0 1 0 0 0 0
5.1 0 1 0 0 0 1 0 3 0 0 0 0
5.2 0 0 1 0 2 0 0 1 0 0 0 0
5.3 0 0 0 1 3 2 0 4 0 0 0 0
6.1 0 0 0 0 0 0 0 0 0 0 0 0
6.2 0 2 2 0 0 2 0 0 0 0 0 0
6.3 0 0 0 0 0 0 0 0 0 0 0 0
Sites being sampling points within the habitat site, letters denoting species. I am unsure as to why it is working for one set of data but not the other when they are both laid out like this. Can someone help me understand?
Thanks
I want to create a network object, representing a directed network on basis of an edgelist. The first column contains some unique ID of project leaders, the second project partners, let's say:
library("network")
x <- cbind(rbind(1,1,2,2,3), rbind(3,7,10,9,6))
y.nw <- network(x, matrix="edgelist", directed=TRUE, loops=FALSE)
Now my problem is: I need all vertexes to have the right ID, since after creating the network object I have to transfer it back to a adjacency matrix with the right corresponding firm IDs. However, I am not sure in which order I should assign them, since I sorted the dataframe by column 1 (project leaders), which, however, not always show up as project partners as well.
If your ids are sequential integers as in your example, you can produce the adjacency matrix corresponding to the edgelist in your example with:
>as.sociomatrix(y.nw))
1 2 3 4 5 6 7 8 9 10
1 0 0 1 0 0 0 1 0 0 0
2 0 0 0 0 0 0 0 0 1 1
3 0 0 0 0 0 1 0 0 0 0
4 0 0 0 0 0 0 0 0 0 0
5 0 0 0 0 0 0 0 0 0 0
6 0 0 0 0 0 0 0 0 0 0
7 0 0 0 0 0 0 0 0 0 0
8 0 0 0 0 0 0 0 0 0 0
9 0 0 0 0 0 0 0 0 0 0
10 0 0 0 0 0 0 0 0 0 0
But maybe you have a different type of id system in your real input?