Is there an equivalent of the CSS z-index for vis.js nodes?
Suppose that I have 2 kinds of nodes (in a graph with physics disabled): Circles and rectangles. I would like the rectangles to always be displayed over the circles when they are overlapping.
Kind of a late reply but the short answer is: no
See this issue: https://github.com/almende/vis/issues/3146
Judging by the mentioned issue, a more precise answer would be: there's no documented way to set z-index (and there's no such concept), but what you can use (with a risk of getting this broken at some update) is nodes are drawn in the same order they are defined. From comment:
I used the following test nodes:
var nodes = [
{id: 'a', label: 'a', shape: 'dot'},
{id: 'b', label: 'b', shape: 'dot'},
{id: 'c', label: 'c', shape: 'dot'},
{id: 'd', label: 'd', shape: 'dot'}
];
When not selected, these will draw in the node order:
Now, let's change the order:
var nodes = [
{id: 'c', label: 'c', shape: 'dot'},
{id: 'b', label: 'b', shape: 'dot'},
{id: 'd', label: 'd', shape: 'dot'},
{id: 'a', label: 'a', shape: 'dot'}
];
Related
I am trying to find all the keys that have the world 'symbol' and print out their respective values in one go. The data set given is wrapped in a list as well.
[{'symbol': 'BTCUSDT', 'initialMargin': '2.68109529', 'maintMargin': '0.13405476', 'unrealizedProfit': '-0.07952355', 'positionInitialMargin': '2.68109529', 'openOrderInitialMargin': '0', 'leverage': '5', 'isolated': False, 'entryPrice': '0.899', 'maxNotional': '250000', 'positionSide': 'BOTH', 'positionAmt': '15.0', 'notional': '13.40547645', 'isolatedWallet': '0', 'updateTime': '1676641281047', 'bidNotional': '0', 'askNotional': '0'}, {'symbol': 'EOSUSDT', 'initialMargin': '3.22845093', 'maintMargin': '0.08071127', 'unrealizedProfit': '-0.06225465', 'positionInitialMargin': '3.22845093', 'openOrderInitialMargin': '0', 'leverage': '5', 'isolated': False, 'entryPrice': '1.072', 'maxNotional': '2000000', 'positionSide': 'BOTH', 'positionAmt': '-15.0', 'notional': '-16.14225465', 'isolatedWallet': '0', 'updateTime': '1676641497608', 'bidNotional': '0', 'askNotional': '0'}]
So I want to pull both the 'BTCUSDT' and 'EOSUSDT' by finding the word 'symbol'
I've tried everything to get this to work.
It seems that there is no on_click option with dropdown widgets, I was wondering if there is some sort of workaround. One method I was thinking was, everytime an option is chosen, to flush the options and start the dropdown from the top again, where the top option would be the empty "".
For instance suppose I have:
from IPython.html import widgets
from IPython.display import display
def dropdown_event_handler(change):
print(change.new)
# flush the options and start from "" again
options = ["", "A", "B"]
dropdown = widgets.Dropdown(options=options, description="Categories")
dropdown.observe(dropdown_event_handler, names="value")
display(dropdown)
So the desired behaviour is that if I press "A" and "A" again, A would be printed out twice.
As you already suggested, you could set the value of the widget to "" after each change:
from IPython.html import widgets
from IPython.display import display
def dropdown_event_handler(change):
print(change.new)
dropdown.value = ""
options = ["", "A", "B"]
dropdown = widgets.Dropdown(options=options, description="Categories")
dropdown.observe(dropdown_event_handler, names='value')
display(dropdown)
And I fear that is your only option. The Dropdown widget has no other type than "change". You can see all available types by printing them with type=All.
from IPython.html import widgets
from IPython.display import display
from traitlets import All
def dropdown_event_handler(change):
print(change)
options = ["", "A", "B"]
dropdown = widgets.Dropdown(options=options, description="Categories")
dropdown.observe(dropdown_event_handler, type=All)
display(dropdown)
Output:
{'name': '_property_lock', 'old': traitlets.Undefined, 'new': {'index': 1}, 'owner': Dropdown(description='Categories', options=('', 'A', 'B'), value=''), 'type': 'change'}
{'name': 'label', 'old': '', 'new': 'A', 'owner': Dropdown(description='Categories', index=1, options=('', 'A', 'B'), value=''), 'type': 'change'}
{'name': 'value', 'old': '', 'new': 'A', 'owner': Dropdown(description='Categories', index=1, options=('', 'A', 'B'), value='A'), 'type': 'change'}
{'name': 'index', 'old': 0, 'new': 1, 'owner': Dropdown(description='Categories', index=1, options=('', 'A', 'B'), value='A'), 'type': 'change'}
{'name': '_property_lock', 'old': {'index': 1}, 'new': {}, 'owner': Dropdown(description='Categories', index=1, options=('', 'A', 'B'), value='A'), 'type': 'change'}
So you can't observe a value in a Dropdown widget if it did not change. For more information see the Traitlets documentation.
I have a list of maps, that I get from querying my database.It has a datetime field that I want to transform into another list of maps where the datetime field is transformed to it's corresponding epoch value.
What i have:
[
%{
m_id: 267,
end: #DateTime<2020-03-07 17:30:00Z>,
start: #DateTime<2020-03-07 14:30:00Z>,
type: "normal",
s_name: "smum",
w_id: 256
},
%{
m_id: 267,
end: #DateTime<2020-03-07 07:30:00Z>,
start: #DateTime<2020-03-07 04:30:00Z>,
type: "normal",
s_name: "smum",
w_id: 256
}
]
What i want to transform it to:
[
%{
m_id: 267,
end: 12356789, #some epoch value for eg
start: 12367576, #some epoch value for eg
type: "normal",
s_name: "smum",
w_id: 256
},
%{
m_id: 267,
end: 12334567, #some epoch value for eg
start: 12354767, #some epoch value for eg
type: "normal",
s_name: "smum",
w_id: 256
}
]
To transform a single map, you can do
%{map | end: DateTime.to_unix(map.end), start: DateTime.to_unix(map.start) }
So just Enum.map over the list to apply this to all list members:
Enum.map(list, fn map -> %{map | end: DateTime.to_unix(map.end), start: DateTime.to_unix(map.start) } end)
(I suspected there may be a problem using the map update syntax here because end is a reserved word, but I tested in https://www.jdoodle.com/execute-elixir-online/ and it works.)
I would go with Kernel.SpecialForms.for/1 comprehension.
for %{start: s, end: e} = map <- list do
%{map | start: DateTime.to_unix(s), end: DateTime.to_unix(e)}
end
It’s slightly different from Enum.map/2 solution, because it would discard those elements not having either start or end keys. To handle those properly, one should use Map.update/4 wisely.
I have the following data
new Chart(ctx2, {
type: 'bar',
data: {
labels: $scope.teamGraphAssociateName,
datasets: [{
data: $scope.teamGraphAgileRewards,
backgroundColor: $scope.backgroundColors,
borderWidth: 1.5
}
]
}
});
This data gets success data of all the associates name on the (X axis) from labels.
For the $scope.teamGraphAgileRewards in console i'm getting data like this:
(3) [Array(1), Array(2), Array(1)]
0: [7]
1: (2) [2, 3]
2: [10]
length: 3
I'm getting the grap like this.(only the last array [10] is getting visible on graph)
Y
|
|
|
| 10
|_______________ X
ASS1 ASS2 ASS3
(labels)
But I want this data to be visible on stacked bar graph like this.
Y
|
| 3
|
| 7 2 10
|_______________ X
ASS1 ASS2 ASS3
(labels)
Well, you will need to rearange your data. Data structure of chart is different than this you are sending to chart. See example:
var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ["ASS1", "ASS2", "ASS3"],
datasets: [{
stack: 'Stack 0',
data: [7, 3, 10],
backgroundColor: 'blue'
},
{
stack: 'Stack 0',
data: [0, 2, 0],
backgroundColor: 'green'
}]
},
options: {
legend: {
display: false
},
responsive: false,
scales: {
xAxes: [{
stacked: true,
}],
yAxes: [{
stacked: true
}]
}
}
});
That's how your chart should look like. Each data what you add to dataset is sent to labels, so when you send arrays in array it can't be recognized, that you want to add multiple values for one label. Group your values in way, that you have 3 values for one dataset (['ASS1value', 'ASS2value', 'ASS3value']), like I've added in sample.
I think it is pretty straightforward. All I am trying to do is update the original dictionary's 'code' with that of another dictionary which has the value. I get a feeling 2 for loops and an IF loop can be further shortened to get the answer. In my actual problem, I have few 1000's of dicts that I have to update. Thanks guys!
Python:
referencedict = {'A': 'abc', 'B': 'xyz'}
mylistofdict = [{'name': 'John', 'code': 'A', 'age': 28}, {'name': 'Mary', 'code': 'B', 'age': 32}, {'name': 'Joe', 'code': 'A', 'age': 43}]
for eachdict in mylistofdict:
for key, value in eachdict.items():
if key == 'code':
eachdict[key] = referencedict[value]
print mylistofdict
Output:
[{'age': 28, 'code': 'abc', 'name': 'John'}, {'age': 32, 'code': 'xyz', 'name': 'Mary'}, {'age': 43, 'code': 'abc', 'name': 'Joe'}]
There is no need to loop over all values of eachdict, just look up code directly:
for eachdict in mylistofdict:
if 'code' not in eachdict:
continue
eachdict['code'] = referencedict[eachdict['code']]
You can probably omit the test for code being present, your example list always contains a code entry, but I thought it better to be safe. Looking up the code in the referencedict structure assumes that all possible codes are available.
I used if 'code' not in eachdict: continue here; the opposite is just as valid (if 'code' in eachdict), but this way you can more easily remove the line if you do not need it, and you save yourself an indent level.
referencedict = {'A': 'abc', 'B': 'xyz'}
mylistofdict = [{'name': 'John', 'code': 'A', 'age': 28}, {'name': 'Mary', 'code': 'B', 'age': 32}, {'name': 'Joe', 'code': 'A', 'age': 43}]
for x in mylistofdict:
try:
x['code']=referencedict.get(x['code'])
except KeyError:
pass
print(mylistofdict)