I'm trying to make a checkbox group in Perl with sub-titles dividing certain checkboxes. All the checkboxes are related, but they are in subcategories that I would like to be displayed when the user is selecting their choices.
my $grocery_list = $q->checkbox_group(
-name=>'grocery_list',
-values=>\#items,
-linebreak=>'true',
-labels=>\%items,
In the above example, I might have 'Milk' and 'Cheese' be under the subcategory of "DAIRY", while 'Ham' and 'Turkey' are under the subcategory of "MEATS". I already have a checkbox group with my values but I'm struggling creating those subcategory titles (DAIRY and MEATS) in between the subgroups of checkboxes. Ideally, the subcategory titles wouldn't be checkboxes, but would just divide checkboxes. Is it possible to put these subdivisions in a single checkbox, or would I have to make multiple checkboxes and merge the checked items into a single array afterward?
Note that CGI is no longer considered to be best practice. You should read CGI::Alternatives for an explanation, as well as suggestions for alternative modules.
You need the fieldset and legend elements to do what you describe. Without any additional CSS, the former draws a box around the group of inputs that it contains, and the latter labels that box.
Unfortunately, the checkbox_group convenience method doesn't allow you to subdivide its elements between two field sets, so you will have to call it twice with the same parameters except for the values and labels. It may be better to write your own helper routine that calls checkbox directly to build appropriate grouping.
Here's the basic idea. There's nothing magical about the CGI methods -- they just generate HTML according to the parameters you pass.
my %labels = (
milk => 'Milk',
cheese => 'Cheese',
ham => 'Ham',
turkey => 'Turkey',
);
my #dairy_items = qw/ milk cheese /;
my #meat_items = qw/ ham turkey /;
my $dairy = $q->checkbox_group(
-name => 'grocery_list',
-values => \#dairy_items,
-linebreak => 'true',
-labels => \%labels,
);
my $meat = $q->checkbox_group(
-name => 'grocery_list',
-values => \#meat_items,
-linebreak => 'true',
-labels => \%labels,
);
print
$q->start_form,
$q->fieldset(
$q->legend('Dairy'),
$dairy,
),
$q->fieldset(
$q->legend('Meat'),
$meat,
),
$q->end_form;
Related
I've been experimenting with the HierarchicalGraphMachine class to help visualise the machine structures as I edit them.
from transitions.extensions import HierarchicalGraphMachine as Machine
count_states = ['1', '2', '3', 'done']
count_trans = [
['increase', '1', '2'],
['increase', '2', '3'],
['decrease', '3', '2'],
['decrease', '2', '1'],
['done', '3', 'done'],
['reset', '*', '1']
]
counter = Machine(states=count_states, transitions=count_trans, initial='1')
states = ['waiting', 'collecting', {'name': 'counting', 'children': counter, 'initial': '1'}]
transitions = [
['collect', '*', 'collecting'],
['wait', '*', 'waiting'],
['count', 'collecting', 'counting']
]
collector = Machine(states=states, transitions=transitions, initial='waiting')
collector.get_graph(show_roi=False).draw('count1.png', prog='dot')
This generates the expected graphic showing both the parent and nested states in full (I'm not yet authorised to upload the graphics).
Is there a way to generate a the full parent state machine graphic without expanding the nested states? For example reducing the nested states to an empty box.
I've tried "show_roi=True", but this only shows the current transition event, and removes all other states.
Depending on whether you use the pygraphviz (default in 0.8.8 and prior) or graphviz backend, get_graph may return a pygraphiv.AGraph object or a custom transitions.Graph. An AGraph is easier to manipulate while the second is basically the pure graph notation in dot. However, you can manipulate both according to your needs. For instance, you could filter edges and nodes from an AGraph and rebuild a 'flat' version of it:
# your code here ...
collector.collect()
graph = collector.get_graph()
# iterate over all edges; We know that parent and child states are connected
# with an underscore. We just collect the root element of each source
# and target element of each edge. Furthermore, we collect the edge color,
# and the label which is stored either in 'label', 'taillabel' or 'headlabel'
new_edges = [(edge[0].split('_')[0],
edge[1].split('_')[0],
edge.attr['color'],
edge.attr['label']
or edge.attr['taillabel']
or edge.attr['headlabel']) for edge in graph.edges()]
# States with children are noted as subgraphs. We collect their name and their
# current color.
new_nodes = [(sgraph.graph_attr['label'], sgraph.graph_attr['color'])
for sgraph in graph.subgraphs()]
# We add all states that have no children and also do not contain an
# underscore in their name. An underscore would suggest that this node/state
# is a child/substate.
new_nodes += [(node.name, node.attr['color'])
for node in graph.nodes() if '_' not in node.name]
# remove everything from the graph obeject
graph.clear()
# and add nodes and edges again
for name, color in new_nodes:
graph.add_node(name, color=color)
for start, target, color, label in new_edges:
if label:
graph.add_edge(start, target, color=color, label=label)
graph.draw('agraph.png', prog='dot')
This results in the following graph:
You see that I also collected the edge and node color to visualize the last transition but graph.clear() removed all the 'default' styling attributes.
They could be copied and restored as well or we could only remove nodes, edges and subgraphs. This depends on how much you are willing to mess with (py)graphviz.
In PhpStrom there are some facilities which are short array Align when multiline and many more
Here is an example
http://prntscr.com/pyfkc8
Another Link
Now I want to align array in vs-code ....
How can I do that?
This is a normal Array
$x=array(
0 => "zero",
123122 => "one two three",
251=> "two five"
);
Now I want Like this
$x=[
0 => "zero",
123 => "one two three",
25 => "two five"
];
Is this possible is vs-code?
I think you are looking for a extension called "ALIGNMENT"
JUST INSTALL IT AND ALIGN THE SECTION OF CODE YOU WANT JUST BY
SELECTION.
HERE is a list of Extension:
https://marketplace.visualstudio.com/search?term=tag%3Aalignment&target=VSCode&category=All%20categories&sortBy=Relevance
And Here is the Extension i'm talking about:
https://marketplace.visualstudio.com/items?itemName=annsk.alignment
I'm using Dash to plot some data. I currently have a clustered bar chart with two data sets (one for each bar in the clusters.) These data sets have their name and the corresponding color of the bars displayed in the top, left-hand corner of the figure. They can be clicked to be toggled on and off, which will remove their corresponding bars from the chart.
Separately, I have a checklist of items that can be displayed in the chart. I am using a callback to update the graph so that it only displays what the user has checked. This updates the graph as expected, however, it also resets the bars/datasets such that both are enabled. Ie. if you select only one of the bars, then select some new checklist items, it will display the new checklist items and both of the bars.
My thinking is that the logical way to do this is to pass some variable as a second input to the callback function, then set up the outputted figure within the function to only display the proper bars. However, I can't seem to find a variable that contains this data.
From what I can tell, the accessible properties of the Plotly graph object are 'id', 'clickData', 'clickAnnotationData', 'hoverData', 'clear_on_unhover', 'selectedData', 'relayoutData', 'figure', 'style', 'className', 'animate', 'animation_options', 'config', and 'loading_state'.
I've investigated all of these, and it seems that none hold the data that I am looking for. Does anyone know of an easy way to access this data?
This is how my callback is working right now:
#app.callback(
dash.dependencies.Output('theGraph', 'figure'),
[dash.dependencies.Input('theChecklist','values'),
dash.dependencies.Input('theGraph', 'clickData')
]
)
def updateGraph(checklistValues, figureInput):
#print to see what the variables hold
print(checklistValues)
print(figureInput)
figure=go.Figure(
data = [
go.Bar(
x = df[df['MyColumnName'].isin(checklistValues)].groupby('MyColumnName').size().index,
y = df[df['MyColumnName'].isin(checklistValues)].groupby('MyColumnName').size().values,
name = 'Bar 1'
),
go.Bar(
x = df[df['MyColumnName'].isin(checklistValues)].groupby('MyColumnName')['# cores'].sum().reset_index()['MyColumnName'],
y = df[df['MyColumnName'].isin(checklistValues)].groupby('MyColumnName')['# cores'].sum().reset_index()['MyOtherColumnName'],
name = 'Bar 2'
)
],
layout=go.Layout(
title='The Title',
showlegend=True,
legend=go.layout.Legend(
x=0,
y=1.0
),
margin=go.layout.Margin(l=40, r=40, t=40, b=110)
)
)
return figure
I have 2 sets of radio buttons. Is it possible in ValidForm Builder to set one instance of radio buttons to a certain value based on a conditional check against the other radio button?
// Radio List #1
$objRB1 = $objForm->addField('rb1', 'Radio Button #1', VFORM_RADIO_LIST,
array(),
array(),
array('default' => $default['rb1'])
);
$objRB1->addField('Red', 'R');
$objRB1->addField('Green', 'G');
$objRB1->addField('Blue', 'B');
// Radio List #2 -- NEED TO FORCE SET THIS TO "Delta" WHENEVER "Blue" IS SELECTED ABOVE
$objRB2 = $objForm->addField('rb2', 'Radio Button #2', VFORM_RADIO_LIST,
array(),
array(),
array('default' => $default['rb2'])
);
$objRB2->addField('Alpha', 'A');
$objRB2->addField('Delta', 'D');
$objRB2->addField('Omega', 'O');
How might that be done, if possible, in VFB?
ValidForm Builder conditions
ValidForm Builder has three conditions:
Visible
Enabled
Required
These three settings you can influence with conditions at the moment. Conditions don't change (default) values.
Workaround
A workaround would be to create two fields: one with value A as default value and one with value B as default value.
Then, you use a condition to trigger the visibility of both fields. When, on a third field, option A is chosen, only field A is visible with default value A. When option B is chosen, field B is shown (with the exact same label and values) but with value B as default value.
However, when implementing such a workaround, make sure you don't name field A and B exactly the same. Field names should always be unique.
Setting a radio button in the current form is simple:
$clone->set_visible([radio => '1']);
With an unknown number of radio buttons (probably 10 to 20) a loop should work:
while(1) {last if (!$clone->set_visible([radio => '1']));};
However, though setvisible always returns 1. My guess is it only returns 0 when nothing is set at all. But if even one field is set, it can get "re-set".
How do i stop after all radios are set? Or do i need to determine how many there are first?
You can find all inputs you need first:
my #radio_inputs = $mech->find_all_inputs(
type => 'radio',
);