
Research
/Security News
9 Malicious NuGet Packages Deliver Time-Delayed Destructive Payloads
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.
@datawheel/vizbuilder
Advanced tools
A React component that generates multiple kinds of charts from a tesseract-olap dataset.
A React component to visualize multiple kinds of charts according to the data returned by a olap-client query.
We suggest the use of the pnpm package manager, but npm and yarn can be used without a problem.
npm i @datawheel/vizbuilder
This component only exports a React component that makes the charts based on one or multiple queries. The internal code does all the possible remixes that make sense based on the query results it is passed, and the additional parameters it is given. These parameters mainly restrict the types of charts generated and add parameters to the d3plus config for each chart, and are usually dependent to the datasource it is being used for this visualization.
To use it, import the named component from the package:
import {Vizbuilder} from "@datawheel/vizbuilder";
This package doesn't include a stylesheet. It's up to your implementation to setup the UI of the component. The DOM nodes have classnames under the vb- namespace. It's suggested to take advantage of CSS grid or CSS flexbox to structure the layout and order of the elements.
queriesQueryResult | QueryResult[]A single query result, or an array of these, to generate the charts. Each QueryResult object should contain the needed info about the cube where the information is coming from, query used to get the data, and the data aggregation itself. Check the QueryResult interface to know details of the object structure.
allowedChartTypesChartType[]["barchart", "barchartyear", "donut", "geomap", "histogram", "lineplot", "pie", "stacked", "treemap"]An array of the names of the kinds of charts the instance can generate.
classNamestringundefinedA classname for CSS styling.
datacapnumber20000The maximum number of data points the instance can use to generate a chart, reduce it if the chart rendering frozes the browser.
defaultLocalestring"en"If you implement another (or many) locale, this property sets the one shown initially.
measureConfigRecord<string, D3plusConfig> | ((measure: OlapClient.Measure) => D3plusConfig){}Useful to set a specific d3plus config to use depending on the measure used in the query. The config parameters resulting from using this property have priority over all other config params determined by internal heuristic.
This property accepts a function or an object. If a function is passed, it will be called with the relevant olap-client Measure instance object, and must return an object with the properties wanted to be merged to the chart config. If an object is passed, the value whose key matches the measure.name will be merged to the chart config.
showConfidenceIntbooleanfalseToggles showing confidence intervals / margins of error when available in the query.
toolbarReact.ReactNodeundefinedAllows the user to add a toolbar inside the area of the component. In the DOM tree, it is placed before the charts, but the layout can be modified with CSS.
topojsonConfigRecord<string, D3plusConfig> | ((level: OlapClient.Level) => D3plusConfig){}Useful to set a specific d3plus config to use depending on the level used in the query.
Can be passed a function or an object. If a function is passed, it will be called with the relevant olap-client Level instance object, which will be a geographic-type of level; it must return an object with the properties wanted to be assigned to the chart config. If instead an object is passed, the object value whose key matches with either level.uniqueName, level.fullName, or level.name, in that order, will be assigned to the chart config.
translationsRecord<string, Translation>{}An object with localization labels to use within the component. The keys are locale codes and the values are objects that comply with the Translation interface. This is an example of the structure:
const translations = {
"en": {
action_apply: "Apply",
action_back: "Back",
action_close: "Close",
...
},
"es": {
action_apply: "Aplicar",
action_back: "Volver",
action_close: "Cerrar",
...
}
}
An example of the message keys is available in this file. These are also the default labels used if this parameter is not set, or if the defaultLocale parameter points to a locale not available.
userConfigD3plusConfigundefinedA general use d3plus config object, which will be applied to all charts.
The package has some typings set in TypeScript to help development. All these are also exported by the package. It is encouraged to use them to verify the structures are complying with the required properties.
type ChartTypeA string from the following list:
type ChartType =
| "barchart"
| "barchartyear"
| "donut"
| "geomap"
| "histogram"
| "lineplot"
| "pie"
| "stacked"
| "treemap";
interface QueryResultAn object with information about the cube where the info belongs to, the parameters used to execute the query, and the resulting dataset. This component is designed to work around the data structures defined on the olap-client package, so these properties can be easily obtained after executing a query with it. All properties are required.
The PlainCube interface comes from olap-client, and can be obtained from a Cube instance calling the cube.toJSON() method. The dataset is the tidy data array returned by a jsonrecords query. The QueryParams interface is described next, and can be constructed from a olap-client Query instance.
interface QueryResult {
cube: OlapClient.PlainCube;
dataset: any[];
params: QueryParams;
}
interface QueryParamsThe QueryParams interface describes the parameters used in the query, using raw objects, with the name of the property as identifier:
interface QueryParams {
locale: string;
booleans: {
[name: string]: boolean;
};
cuts: Array<{
dimension?: string;
hierarchy?: string;
level: string;
members: string[];
}>;
drilldowns: Array<{
dimension?: string;
hierarchy?: string;
level: string;
properties?: string[];
caption?: string;
}>;
filters: Array<{
comparison: string;
formatter?: (value: number) => string;
measure: string;
value: string;
}>;
measures: Array<{
collection?: string;
formatter?: (value: number) => string;
lci?: string;
measure: string;
moe?: string;
source?: string;
uci?: string;
}>;
}
Some remarks:
booleans, cuts, drilldowns, filters, and measures) must be present, but can be empty arrays.?) at the end of the property name are optional, but encouraged to avoid collisions.level name used in the descriptor object can be the uniqueName, the fullName, or the name of the level; these three are matched in that order.members property in the cuts descriptor items is an array of member key, for the members defined in the cut on that level.properties property in the drilldowns descriptor items is an array of property name, belonging to the level defined along it. Likewise, the caption property is just a property name.formatter property, if defined, should be a function that receives a number value, and outputs a string. This formatting function will be used wherever the values for the measure defined along it is shown.measures descriptor items, if a moe is defined, lci and uci won't be considered.Notice the QueryParams object can also contain Formatter functions, so it can't be serialized and rehydrated from a JSON string. This is important if you plan to store the object in a Redux store, for example, as it can result in unexpected behavior when using some features.
For ease of development, this package also exports a helper function buildQueryParams as a named export, to quickly convert an olap-client Query object into a QueryParams object. Check the definition below for details on how to use it.
interface TranslationAn object whose keys are message keys, and its values the localized string to show in the interface. Here is an example of a Translation object and how it should be used.
const translation: Translation = {
/* These are actions shown in buttons in the UI */
action_close: "Close",
action_download: "Download {{format}}",
action_enlarge: "Enlarge",
action_fileissue: "File an issue",
action_retry: "Retry",
aggregators: {
avg: "Average",
max: "Max",
min: "Min"
},
/* These labels are shown in the charts tooltip */
chart_labels: {
ci: "Confidence Interval",
moe: "Margin of Error",
source: "Source",
collection: "Collection"
},
/* These labels are shown in the suggested error message when filing a new issue */
error: {
detail: "",
message: "Error details: \"{{message}}\".",
title: "Title: "
},
/* Message for the default NonIdealState when no charts are valid for queries */
nonidealstate_msg: "No results",
/* For listing words */
sentence_connectors: {
and: "and"
},
/* Sentence fragments for dynamically constructing chart titles (see example for use)*/
title: {
of_selected_cut_members: "of Selected {{members}} Members",
top_drilldowns: "for Top {{drilldowns}}",
by_drilldowns: "by {{drilldowns}}",
over_time: "Over Time",
measure_and_modifier: "{{modifier}} {{measure}}"
}
}
namespace StructThe types defined in the Struct namespace are for private use and might change between versions. Changes in these are not considered for semver version bumps, only the previously described.
function buildQueryParams()Creates a QueryParams object from a olap-client Query object. The function has the following shape:
function buildQueryParams(
query: OlapClient.Query,
formatters?:
| Record<string, (value: number) => string>
| (measure: OlapClient.Measure | "growth" | "rca") => (value: number) => string
): QueryParams;
The formatters parameter behaves similarly to the measureConfig property from the Vizbuilder component: it can receive either
Formatter functions as values, orolap-client Calculation (which means, it can be either a Measure object, or one of the strings "growth" and "rca"), which must return a Formatter function for these values.An example implementation would be:
import {buildQueryParams} from "@datawheel/vizbuilder";
[...]
const agg = await client.execQuery(query);
return {
cube: cube.toJSON(),
dataset: agg.data,
params: buildQueryParams(agg.query, {
"Total value": dollarFormatter,
"Average value": dollarFormatter
})
}
[...]
As a way to circumvent the limitations in the OLAP server, the labels of the entities used to formulate the Query can be localized through the use of the caption annotation. Vizbuilder uses the locale of the query to pick the localized caption from the olap-client entity Annotations, and uses that caption in Axis, Titles and Labels.
If a Schema Entity contains the following properties:
"name": "Calendar Year",
"annotations": {
"caption": "Year",
"caption_es": "Año",
},
"es" locale would use the "Año" caption, from the caption_es annotation, in the UI."en", or any other, since there's no caption_en annotation, it would fallback to use "caption", and would show "Year" in the UI.caption in the Annotations, the UI would use the name "Calendar Year" as final fallback."zh_CHS"/"zh_CHT". In these cases, an additional fallback step would look for a caption_zh if caption_zh_CHS wasn't present.© 2019 Datawheel, LLC
This project is made available under the MIT License.
FAQs
A React component that generates multiple kinds of charts from a tesseract-olap dataset.
The npm package @datawheel/vizbuilder receives a total of 26 weekly downloads. As such, @datawheel/vizbuilder popularity was classified as not popular.
We found that @datawheel/vizbuilder demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 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.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.