Selecting 2 random unique values out of an array in azure cosmos - azure-cosmosdb

I have a cosmos SQLdb document that contains an array called "creatorStyleColours" and it looks like this:
"creatorStyleColours":
[
"black",
"beige",
"grey",
"white"
]
I need to be able to choose 2 unique colours from the array e.g. I don't want to pick white and white.
Ive tried a couple of ways of doing this but I cant seem to get the query right as it keeps erroring. for example.
SELECT *
FROM c IN t.creatorStyleColours
ORDER BY RAND ()
Could someone please advise what query I need to achieve my random list of 2 colours without selecting the same one twice?

Related

Variable Pattern on ApexCharts Series

I've currently got a working multi-series that's similar to this Apexcharts example. Within this series, I am using the colors function to specify certain colors depending on certain conditions. For example, as shown in this example, I can do:
colors: [
({ seriesIndex }) => {
// if one condition, return a color
// else if another condition, return a different color
}
]
What I'm trying to do now is something similar to create different patterns within the data series, similar to how it's possible to do so with colors. I have tried to look at the fill object as specified here, but obviously, this will create a standard pattern across all data on the graph. I'd like to specify conditions to return different patterns for specific data (like the colors function).
Is this possible with Apexcharts? I.e., is there a function that allows me to create conditions based on the seriesIndex to create different patterns? Ultimately, I'd like to create some sort of visual difference for certain data (not in terms of color, but moreso patterns/gradients) so that certain data is easily distinguishable from others. What is the best approach for this?
I have tried to use linear-gradient in colors but I'm not sure if that is possible. Alternatively, could I create a custom css within the graph options to fulfil this requirement?
There is a possibility built in with the fill property that allows you to have different patterns for different series:
fill: {
type: 'pattern',
opacity: 1,
pattern: {
style: ['circles', 'slantedLines', 'verticalLines', 'horizontalLines'], // string or array of strings
}
},
Source: https://apexcharts.com/vue-chart-demos/bar-charts/patterned/
Working example:
https://codesandbox.io/s/happy-stallman-ysyec?file=/src/App.js
(In the example I used multiple fill types for different series - something, that is possible, too)

Creating graph with leaf nodes colored differently

I have the following data set (sample):
child,parent
Z,B
T,B
B,A
C,T
X,B
K,A
and i want to create a graph that has the leaf nodes differently colored. However, im unable to achieve it with the following cypher query:
load csv with headers from "file:///test.csv" as test
merge(n:Node{id:test.child})
merge(m:Node{id:test.parent})
merge(m)-[:TO]-(n)
How to achieve it?
If you want the leaf nodes to have a different colour than the other nodes you can assign a different label to them and choose a different colour for that label.
First I would assign the (child)-->(parent) relationship in a specific order by adding a > to your load query.
LOAD CSV WITH HEADERS FROM "file:///test.csv" AS test
MERGE (n:Node {id:test.child} )
MERGE (m:Node {id:test.parent} )
MERGE (m)<-[:TO]-(n)
Then i would traverse the freshly loaded tree to find the leaf nodes and I would assign them a new label. Assuming B is the root ode of the loaded tree.
MATCH (leaf:Node)
WHERE NOT ((leaf)<--())
SET leaf:Leaf
Then in the browser UI I would select the Leaf label and pick a different colour for it. Then something like this should return
MATCH path=(n:Node {id: 'B'})-[:TO*]-(end:Node)
RETURN path

OrientDB – Graph Visualization related questions?

OrientDB Version: 2.2.0-beta2
Hello Everyone,
Use case we are working on, is giving user access to Graph Visualization and hide the complexity of the query via Javascript function. Ex:
SQL: SELECT FROM COUNTRY WHERE NAME=’CANADA’
Function: SELECT findCountry(‘CANADA’)
Now, users are asking questions if there is a way to adjust the look n feel of the graph visualization.
I am looking for your suggestions as an advice or point to some kind of document?
Most of our data is in hierarchy format – Is it possible instead of circles, we display data in org-chart format or pure right to left?
Also, instead of circle can we use another other shape? i.e. rectangle or triangle? Depend on the class.
Possible to word-wrap the label in the circle?
Possible to show multiple properties in the circle? i.e. ID + Name
Possible to change the Stroke colour based on the property in the class ex: If the City is also the capital then can the stroke color to RED and size to 5 but keep the fill color same as other cities?
Any way to undo on the Graph tool? Ex: if we are doing drill down from 1 > 2 > 3 > 4 and undo 4 and back to number 3?
Really appreciate your thoughts.
regards

How to code edge attributes as vertex attributes using igraph in R

I am graphing a network and trying to color the vertices using non-overlapping attributes. I want my network diagram to be colored according to different attributes. In this example, if the first three letters of ID 2 are equal to U 50 or U 51, I want this to show up as red. I have 5 attributes I want this graph coded by and any observations that don't fall into one of the categories should be coded in a default color. In this way I will be able to see the intensity of these attributes and better communicate this to other people. So far, I have been unable to get the code to work using a variety of different coding methods. First I tried to create a new variable that assigned the correct attribute to each observation before converting it into an i graph object.
anon.nd$vertexcolor[substr(anon.nd$ID2,1,3)=="U50" | substr(anon.nd$ID2,1,3)=="U51"]<-"O"
anon.nd$vertexcolor[substr(anon.nd$ID2,1,3)=="U54" | substr(anon.nd$ID2,1,3)=="U55"]<-"P"
anon.nd$vertexcolor[anon.nd$INT.type=="K1"]<-"INT.NB"
anon.nd$vertexcolor[anon.nd$Country=="L12"]<-"UK"
anon.nd$vertexcolor[anon.nd$ID2=="U769"]<-"OBL"`
I then specified the colors I wanted to assign to each each attribute. I used the get vertex attribute code and filled in the appropriate colors.
anon.nd1<-graph.data.frame(anon.nd)
vertex_colors=get.vertex.attribute(anon.nd1,"vertexcolor")
colors=c('azure3', 'firebrick1', 'orange1', 'darkblue', 'darkolivegreen', 'gold')
vertex_colors[vertex_colors==0]=colors[1]
vertex_colors[vertex_colors==1]=colors[2]
vertex_colors[vertex_colors==2]=colors[3]
vertex_colors[vertex_colors==3]=colors[4]
vertex_colors[vertex_colors==4]=colors[5]
vertex_colors[vertex_colors==5]=colors[6]
I tried this same method using just:
vertex_colors<-vertex_colors+1
Then to plot, I changed my edge color to black, specified my layout, and change the size of my edges and vertices.
E(anon.nd1)$color="black"
nd.layout<-layout.fruchterman.reingold(anon.nd1)
plot(anon.nd1, layout=nd.layout, vertex.color=vertex_colors, vertex.size=2, edge.arrow.size=.01, vertex.label=NA)
Using this method, no color shows up on the vertices, not even the default color. Using a different method where I set the vertex attribute, I do a little better. The default color shows up, but the colors I want do not.
anon.nd2<-graph.data.frame(anon.nd)
V(anon.nd2)$colors<-"azure3"
V(anon.nd2)$colors[substr(anon.nd2$ID2,1,3)=="U50" | substr(anon.nd2$ID2,1,3)=="U51"]<-"firebrick1"
V(anon.nd2)$colors[substr(anon.nd2$ID2,1,3)=="U54" | substr(anon.nd2$ID2,1,3)=="U55"]<-"orange1"
V(anon.nd2)$colors[anon.nd2$Country=="L12"]<-"darkblue"
V(anon.nd2)$colors[anon.nd2$INT.type=="K1"]<-"darkolivegreen"
V(anon.nd2)$colors[anon.nd2$ID2=="U769"]<-"gold"
E(anon.nd2)$color<-"black"
nd.layout<-layout.fruchterman.reingold(anon.nd2)
windows(width=20, height=16)
plot(anon.nd2, layout=nd.layout, vertex.size=2, edge.arrow.size=.01, vertex.label=NA, vertex.color="vertex_colors")
I think the problem might be that I am trying to code vertex color using multiple (non-overlapping) edge attributes. But I don't know how to convert and edge attribute into a vertex attribute. I also don't know if there is some other, unidentified problem with my code.
Here is the link to my data is copied below as well as a link to my full code file which has one or two other methods I tried using to solve this problem. Any help would be much appreciated!
Data
And here is an R file with my code, which is also above: R-file
I think you are messing up your vertex_color vector, have a look at it with head().
anon.nd$vertexcolor[anon.nd$INT.type=="K1"]<-"INT.NB"
vertex_colors[vertex_colors==0]=colors[1]
You first assign a string and then compare with numbers, so non of them should be true.
plot(anon.nd2, layout=nd.layout, vertex.size=2, edge.arrow.size=.01, vertex.label=NA, vertex.color="vertex_colors")
This contains a typo and returns an error for me since "vertex_colors" isn't a colour name.
Last but not least, does
plot(anon.nd2, vertex.color=colors)
or
plot(anon.nd2, vertex.color=1:8)
result in a colourful plots? If yes, the vertex_colors vector is your problem, if not something else is.

Flex 3 prevent duplicate stacking in ColumnChart control

Here is my Problem:
I'm currently using a ColumnChart to display 6 label/value pairs.
When two labels are the same, the chart stacks them up, one on top of the other.
I want to display these duplicates side by side, their value might be the same or it might be distinct.
My first thought was to append a unique id to the label, but that's not possible according to the client. So, is there a way to tell the chart to also take a hidden id into consideration?
Someone suggested to do some sort of grouping, but I need to display each chart separate, as if they were distinct charts.
the chart's data provider is an array of these objects:
obj.description = "des";
obj.countV = 3;//some arbitrary number
obj.id = 2; //a unique id...
the chart code:
I found my solution:
append an index # at the end of each column label.
Use a labelFunction to remove the last char:
columnLabel.slice(0, -1);
that fooled the chart into thinking they're all uniques but display all duplicates side by side.

Resources