Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
@d3fc/d3fc-group
Advanced tools
A utility for manipulating CSV / TSV data to allow rendering of grouped series.
A utility for manipulating CSV / TSV data to allow rendering of grouped series.
npm install d3fc-group
The d3-dsv package provides a number of utilities for parsing delimiter-separated values, such as comma-separated (CSV) or tab-separated (TSV). Given a DSV input these parsers produce an array of objects, with properties that correspond to the columns.
For example, using a subset of the data from this D3 example, a simple CSV is parsed as follows:
const data = d3.csvParse(
`State,Under 5 Years,5 to 13 Years
AL,310,552
AK,52,85
AZ,515,828`);
Resulting in the following structure:
[
{'State': 'AL', 'Under 5 Years': '310', '5 to 13 Years': '552' },
{'State': 'AK', 'Under 5 Years': '52', '5 to 13 Years': '85' },
{'State': 'AZ', 'Under 5 Years': '515', '5 to 13 Years': '828' }
];
The group component takes this structure and manipulates it into a form that is more appropriate for rendering each row as an individual series within a grouped chart.
Here is how the group component can be applied to the above output:
const group = fc.group()
.key('State');
const grouped = group(data);
The default group orientation is 'vertical', which creates a 'series' for each of the columns, other than the one which represents the key. With this example, a vertical group is as follows:
[
[["AL", 310], ["AK", 52], ["AZ", 515]],
[["AL", 552], ["AK", 85], ["AZ", 828]]
]
This structure very similar to the output of d3.stack and is suitable for rendering grouped series, in this case grouping by state.
The key for each series is available as series.key and the input data element for each point is available as point.data.
const group = fc.group()
.key('State');
const grouped = group(data);
// [
// [["AL", 310], ["AK", 52], ["AZ", 515]],
// [["AL", 552], ["AK", 85], ["AZ", 828]]
// ]
// each series has a key property
grouped[0].key // 'Under 5 Years'
grouped[1].key // '5 to 13 Years'
// and each data element has a data property:
grouped[0][0].data // {'State': 'AL', 'Under 5 Years': '310', '5 to 13 Years': '552' }
You can also perform a horizontal grouping, as illustrated in the following example:
const group = fc.group()
.orient('horizontal')
.key('State');
const grouped = group(data);
Which creates a series for each row, in this case allowing grouping by age-band:
[
[["Under 5 Years", 310], ["5 to 13 Years", 552]],
[["Under 5 Years", 52 ], ["5 to 13 Years", 85 ]],
[["Under 5 Years", 515], ["5 to 13 Years", 828]]
]
# fc.group()
Constructs a new group generator with the default settings.
# group.key(keyValue)
If keyValue is specified, sets the name of the column within the DSV data that represents the key. If keyValue is not specified, returns the current key.
# group.value(valueFunc)
If valueFunc is specified, sets the accessor function used to obtain the value for a specific row / column. If valueFunc is not specified, returns the current accessor.
The accessor is invoked each time the group component obtains the value for a cell. The valueFunc(row, column)
function is invoked with the current row (as supplied by the DSV parser) and the name of the column. The default implementation of this accessor function coerces all cell values to be Number instances.
# group.orient(orientation)
If orientation is specified, sets the orientation of the group operation. If orientation is not specified, returns the current orientation.
FAQs
A utility for manipulating CSV / TSV data to allow rendering of grouped series.
The npm package @d3fc/d3fc-group receives a total of 1,242 weekly downloads. As such, @d3fc/d3fc-group popularity was classified as popular.
We found that @d3fc/d3fc-group demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.