d3 bar chart selectAll before appending - charts

I've been learning more about the d3 visualization library, and I've seen a few examples of bar charts that have a snippet that looks like
chart.selectAll("rect")
.data(data)
.enter().append("rect")
.attr("y", y)
.attr("width", x)
.attr("height", y.rangeBand());
My confusion is with the first selectAll line. What is the purpose of selecting all rects before they exist since we'll be appending new rects on data enter? Does what goes in the selectAll matter if none of those elements exist?

It is part of the declarative nature of the D3 language. The Thinking with Joins article explains it in detail. An excerpt:
But what’s with the selectAll("circle")? Why do you have to select
elements that don’t exist in order to create new ones? WAT.
Here’s the deal: instead of telling D3 how to do something, tell D3
what you want. In this case, you want the circle elements to
correspond to data: you want one circle per datum. Instead of
instructing D3 to create circles, then, tell D3 that the selection
"circle" should correspond to data—and describe how to get there. This
concept is called the data-join:
This Venn diagram illustrates the data-join. Data bound to existing
elements produce the update (inner) selection. Unbound data produce
the enter selection (left), and unbound elements produce the exit
selection (right). Data Enter Update Elements Exit Thinking with joins
reveals the mystery behind the sequence:
The selectAll("circle") returns the empty selection, since the SVG
container element (svg) is empty. No magic here.
The empty selection is joined to data: data(data). The data method
binds data to elements, producing three virtual selections: enter,
update and exit. The enter selection contains placeholders for any
missing elements. The update selection contains existing elements,
bound to data. Any remaining elements end up in the exit selection for
removal.
Since the selection was empty, all data ends up as placeholder nodes
in enter().
This is the same append as in the first example, but applied to
multiple placeholders; selection methods implicitly iterate over
selected elements. The missing elements are added to the SVG container
by append("circle").
So that’s it. You wanted the selection "circle" to correspond to data,
and you described how to create the missing elements.

In your example selectAll("rect") is called first. But it returns an empty selection.
data(data) will bind the empty selection with the data. It creates new empty selections.
.enter() identifies any DOM elements that needs to be added when the joined array is longer than the selection.
append("rect") appends a rectangle to each empty selection, which is no longer empty
It is well explained and detailed on this section: D3.js data binding, How it works?

Related

Remove leafs from phytree if all the branches have same value

I'm using MATLAB to generate 'phytrees' and I need to simplify them.
The way I thought is by removing subtrees where all the node has the same value and keep only this value + a number that represent how many nodes were deleted.
For example, here is one of the trees:
and I want to replace the subtrees that have the same values like here:
Is there a way to do so?
I did not find a programmatic way to do it, but from the picture you attached I see that you use plot to view your figure. If instead, you'll use the phytreeviewer (just type view(your_phylotree)) you'll get a different figure window, with other related tools.
Specifically, you'll see the Collapse branch button , and the Rename branch button , which will together get you exactly what you want. The first "removing subtrees" (actually hiding them), and the second lets you change the branch name to "value + a number".
You can do all this also by simply right-clicking in the relevant brunch:
Here is an example with data from the docs:
% bulding some tree:
seqs = fastaread('pf00002.fa');
distances = seqpdist(seqs,'method','jukes-cantor','indels','pair');
phylotree = seqneighjoin(distances,'equivar',seqs);
view(phylotree)
After some collapsing and renaming on this tree, and printing it to a figure (with right click on the most top branch, or the root, that you want to include in the figure), I got:
Also, note that every time you hover with the mouse on a branch (even if collapsed) you get a list of the Leafs in that branch and their count:

MSAccess: Call a summation from a subform (in datasheet view) to be displayed in a textbox on the master form?

Sorry if this question is simple but I have googled and haven't found a satisfactory answer.
I'm creating an engineering cost estimator. I have a form that takes inputs as ISO/Drawing, and for each drawing number are many subforms where you can input ComponentDesc and should spit back out a TotalHours to complete number. I've included a picture (sorry for bad quality)
From the image, the table on the bottom is a subform in datasheet mode (which is usually hidden and located in the footer) which will calculate appropriate Total MH (manhours) for the ComponentDesc inputted into the subform on the right. I would like the small (and incomplete) textboxes to the left (below the title "MH Totals for ISO/Drawings") to display the aggregate total from the subform on the bottom.
I've been trying to use DSUM() to define Control Source for the textbox but it keeps coming back with #ERROR as seen in the textbox to the left. Right now what I have typed out is:
=DSum("[Total MH]","frm-PipingHandleMH")
in the expression builder. [Total MH] being my field and frm-PipingHandleMH being the subform on the bottom. I've tried to put brackets around everything but it didn't work (even though I'm not exactly sure what brackets usually do). Any advice?
DSum (and all domain aggregate functions) acts on a table or query. If you want to use that approach you need to refer to the source of that form and use a filter parameter to limit to appropriate records the I.E. if the form's datasource is qry-PipingHandles and if the form you are trying to sum on currently is showing handles for widget 4 then it would be something like:
=dsum("[Total MH]","qry-PipingHandles","[widgetID] = 4")
Note that if that 4 was the currrent state of form then you need to pass it in, so something like:
=dsum("[Total MH]","qry-PipingHandles","[widgetID] = " & [frm-PipingHandlesMH]![WidgetID].Value)
Where you reference the field in the form and append it onto the string that is applied as a filter to the source for Dsum.
Another approach is to put a subtotal in the footer of the form (iirc you don't actually need to show the footer) and then reference that footer control from the parent form.
Brackets are needed to demarcate names that include spaces or other odd characters, they also can be used (e.g. in query design view) to force Access to treat something as a name rather than a string literal.

Modify an ag-grid row after rendering

I need to slightly modify a ag-grid row after it has been rendered. In ag-grid, the actual HTML elements are not necessarily persistent, so manually-set styles may fall off.
For one thing, I have to modify the selection checkbox to set its tabindex to -1. This can technically be done in the cellRenderer callback, although it looks quite hacky. (The checkbox can be found at params.eGridCell.children[0].children[0].wrappedElement.)
But I also have to add a CSS class to some rows to highlight them based on external criteria. I haven't found a way to do this at all.
The best solution would seem to be using some sort of after-rendering callback, but to my knowledge no such thing exists.
I found a couple of related questions, but they were both resolved via cellStyle, which would not suffice here:
Row formatting in ag-Grid
How to provide a background color for an entire row in ag grid based on a certain value in a column?
You have not 1 but 3 options:
getRowClass(params):
Callback version of property 'rowClass'. Function should return a string or an array of strings.
getRowStyle(params):
Callback version of property 'rowStyle'. Function should return an object of CSS values.
processRowPostCreate(params):
Allows you to process rows after they are created. So do final adding of custom attributes etc.
In this last one you have the row in params.eRow.
All taken from https://www.ag-grid.com/javascript-grid-callbacks/index.php

Is it possible to capture checkbox selection(crossmark like X) on flatten pdf

I had an editable pdf with checkbox, after selection i flatten that pdf. from that flatten pdf i need to read the checkbox selection which is looks like crossmark(X), is there any possibility to read that checkbox selection.
When you flatten a PDF, you take away all interactivity. If you have a check box field in an interactive form, and you flatten that form, the check box field is gone. That is the concept of flattening.
What happens in practice?
A check box field has two appearances. One appearance is Off. This appearance can be a path such as a simple square defined as a rectangle. Another appearance can have any name On, Yes, 1 or whatever is defined in the original form. The corresponding appearance can be the same square as the Off appearance with two extra lines that look like a cross, or the square with a character that looks like a check mark, or whatever was defined in the original form.
When you flatten the form, you throw away the name of the check box field, you throw away the widget annotation that corresponds with the field, and you throw away one appearance state (depending on the value of the check box field). The only thing that is left, is one of the two appearances.
If you no longer have the original form, you have no clue as to what this appearance could look like, hence you have no idea what to look for, nor where to look for a specific appearance.
You say that the appearance looks like a cross mark in your case, but whoever reads this question has no idea if this cross mark is a path that was constructed in graphics state, or a glyph that was added in text state.
Long story short: if you flatten first and then expect to be able to read a field value, your design is seriously flawed.
You have to ask yourself: why do I need to flatten the form? Maybe it's sufficient to make the fields read-only. If that's not sufficient, why don't you add an attachment to the PDF that contains the original field values? There are many different ways to work around your problem.

How to highlight first node of GtkTreeView

I would like to highlight the first node of a GtkTreeView and give that node the focus. gtk_tree_view_row_activated () seems appropriate for what I am trying to do, but I couldn't figure out the arguments it takes.
Thanks in advance.
gtk_tree_view_row_activated() actually acts on just one cell. I wonder if you really want to Highlight the row or just select it. I.e. if you want to leave the highlight even if the cursor is on another line.
If that's the case, note that you can define extra fields in the underlying model, for example, if you have 3 fields for your data, you can add field 4 with a color. Then you can tell the renderer to use the color in field 4 (instead of giving the renderer the color immediately).
This example not only changes the background, but also the text color:
http://faq.pygtk.org/index.py?req=show&file=faq13.031.htp
For more sophisticated work, you can even modify the atributes on a cell-per-cell basis:
http://www.pygtk.org/docs/pygtk/class-gtktreeviewcolumn.html#method-gtktreeviewcolumn--set-cell-data-func
Use set_cursor method:
TextView.set_cursor(0,None,False)
0 = Index of the first row