8.0.1 • Published 8 days ago

@visa/dumbbell-plot v8.0.1

Weekly downloads
-
License
SEE LICENCE IN LI...
Repository
github
Last release
8 days ago

@visa/dumbbell-plot

An image depicting an example of the default dumbbell-plot component

<dumbbell-plot
  accessibility = {...}
  data = {[{"date":"2016-01-01T00:00:00.000Z","category":"Card A","value":7670994739,"offset":-8},{data}]}
  valueAccessor = {"value"}
  ordinalAccessor = {"date"}
  seriesAccessor = {"category"}
/>

# Installation Steps


  • Using npm

    $ npm i @visa/dumbbell-plot
  • Using yarn

    $ yarn add @visa/dumbbell-plot

# Props Documentation


# Base Props <>

NameTypeDefault Value(s)Description
heightnumber300Height in px of the chart container
widthnumber650Width in px of the chart container
mainTitlestring'Dumbbell Plot Title'The dynamic tag of title for the chart (or you can create your own separately). See highestHeadingLevel prop for how tags get assigned.
subTitlestring/ISubTitleType'This is a subtitle'The dynamic tag for a sub title for the chart (or you can create your own separately). See highestHeadingLevel prop for how tags get assigned.
highestHeadingLevelstring/number'h2'Sets the heading level (which also sets sublevels) for the chart. "p", "span", and "div" are also valid.
layoutstring'vertical'Displays dumbbells in chart vertically or horizontally. (vertical and horizontal are the only valid inputs). If ordinalAccessor is a date, dumbbells will only display vertically.

ISubTitleType Definition

NameTypeDefault Value(s)Description
textstring‘’Text of the subtitle.
keywordsHighlightIKeywordsHighlightType[]''Configuration used to create highlighted words in the subtitle, an array of objects which includes text, mode, color and index keys. See IKeywordsHighlightType definition below for additional details.

IKeywordsHighlightType Definition

Name (keywordsHighlight.)TypeDefault Value(s)Description
textstring''A string of one or multiple words in the subtitle text to be given the highlight treatment
colorstring''HEX code color string to apply to the highlight treatment.
mode'text' or 'background''background''text' will highlight the text itself with the provided color, using ensureTextContrast utility to ensure text contrast. 'background' will highlight the background-color of the created span with the provided color.
indexnumberIf provided, highlight treatment is provided to the specific instance of the text within the sub-title. Otherwise, all instances of the provided string will be given highlight treatment.

# Data Props <>

NameTypeDefault Value(s)Description
ordinalAccessorstring'date'Key used to determine dumbbell's categorical property.
valueAccessorstring'value'Key used to determine dumbbell's numeric property.
seriesAccessorstring'category'Key used to determine dumbbell's series.
uniqueIDstringundefinedID used to identify chart (must be unique per chart), helpful for validation messages. Defaults to UUID v4 standard.
dataobject[]undefinedData used to create chart, an array of objects which includes keys that map to above accessors.
sortOrderstring''Sets bar sort order. Accepts 'asc', 'desc', 'diffAsc' , 'diffDesc' , 'focusAsc', 'focusDesc', 'absoluteDiffAsc', 'absoluteDiffDesc' .

# Accessibility Props <>

NameTypeDefault Value(s)Description
accessibilityobject (custom type)IAccessibilityTypeManages messages and settings for chart accessibility, see object definition below.

IAccessibilityType Definition

Name (accessibility.)TypeDefault Value(s)Description
longDescriptionstring''Use this to add a helpful description of the chart.
executiveSummarystring''Use this to describe the biggest takeaway of the chart.
purposestring''Use this to describe the purpose of this particular chart.
contextExplanationstring''Use this to explain any controls or content on your page that affect or are affected by this chart.
titlestring''Gives the chart an alternate title to be used by screen readers.
elementDescriptionAccessorstring''Optional key used to add an additional description to any element, from your data.
statisticalNotesstring''Use this to provide any statistical explanations, such as trends, clusters, patterns, or outliers.
structureNotesstring''Use this to describe special visual features of the chart, such as sorting, color grouping, etc.
includeDataKeyNamesbooleanfalseIf true, includes data key names in voice over description of each element. EG "Year over year growth: 5.6%" instead of just "5.6%"
hideDataTableButtonbooleanfalseIf true, hides the data table button (but it is still available to screen reader users).
disableValidationbooleanfalseIf true, disables validations of accessibility props for this chart. Validation is intended to be used during development; upon completion, validation should be disabled.
elementsAreInterfaceany/booleannullDefaults to null. Set to true if interacting with the elements in this chart affects your application. Otherwise, must be set to false.
onChangeFuncfunctionundefinedCustom event listener (changeFunc) that enables dev to control accessibility page experience when chart data updates.
showSmallLabelsbooleanfalseDefaults to false. Set to true if you would like to display labels on small elements that are likely to overlap. Note, this could impact accessibility of your graphic.
hideStrokesbooleanfalseDefaults to false. Set to true if you would like to remove automated stroke outlines from the chart, note, this could impact accessibility of your graphic.
hideTexturesbooleanfalseDefaults to false. Set to true if you would like to remove textures from the chart, note, this could impact accessibility of your graphic.
keyboardNavConfigIKeyConfig{ disabled: false }Defaults disabled to false. May be set to true if accessibility.elementsAreInterface = false and suppressEvents = true. This will disable keyboard navigation and simplify chart instructions for screen reader users.
showExperimentalTexturesbooleanfalseDefaults to false. Set to true if you would like leverage our textures which are still undergoing research and development.
// accessibility = { ...accessibility, onChangeFunc: d => changeHandler(d)}
// example of setting updates on page based on changeFunc custom events
const changeHandler = d => {
  if (d.updated && (d.removed || d.added)) {
    let updates = 'The dumbbell chart has ';
    if (d.removed) {
      updates += 'removed ' + d.removed + ' bar' + (d.removed > 1 ? 's ' : ' ');
    }
    if (d.added) {
      updates += (d.removed ? 'and ' : '') + 'added ' + d.added + (d.removed ? '' : d.added > 1 ? ' bars' : ' bar');
    }
    setChartUpdates(updates);
  } else if (d.updated) {
    const newUpdate = "The chart's data has changed, but no bars were removed or added.";
    setChartUpdates(
      newUpdate !== chartUpdates ? newUpdate : "The chart's data has changed again, but no bars were removed or added."
    );
  }
};

# Localization Props <>

NameTypeDefault Value(s)Description
localizationobject (custom type)ILocalizationTypeManages messages and settings for chart localization, see object definition below.

ILocalizationType Definition

Name (localization.)TypeDefault Value(s)Description
languagestring/objectenUse this to add a language to a chart. This can be string value like en or valid translation object.
numeralLocalestring/objectUSUse this to add a numerical locale to a chart. This can be string value like US or valid numeralLocale object.
overwritebooleanfalseUse this to describe the purpose of this particular chart.
skipValidationbooleanfalseIf true, disables validations of localization props for this chart. Validation is intended to be used during development; upon completion, validation should be disabled.

# Annotation Props <>

NameTypeDefault Value(s)Description
annotationsarray{annotations}[]Adds annotations to the chart, see d3-svg-annotation by Susie Lu.

annotations object definition

annotations is an array of objects which needs to have the following properties within them. See the detailed api specifications from d3-svg-annotation, along with additional properties layered on top of that work, documented below.

NameTypeDefault Value(s)Description
accessibilityDescriptionstringundefinedSets the accessibility description for the annotation for screen reader users.

# Axis Props <>

NameTypeDefault Value(s)Description
xAxisobject (custom type)IAxisTypeManages settings for the chart's x axis, see object definition below.
yAxisobject (custom type)IAxisTypeManages settings for the chart's y axis, see object definition below.
minValueOverridenumberundefinedOverrides the calculated default min value.
maxValueOverridenumberundefinedOverrides the calculated default max value.
showBaselineXbooleanfalseWhen selected and layout = vertical, shows the x baseline
showBaselineYbooleanfalseWhen selected and layout = horizontal, shows the y baseline
wrapLabelbooleantrueWhen selected, wraps the ordinal axis labels.

IAxisType Definition

Name (xAxis./yAxis.)TypeDefault Value(s)Description
visiblebooleantrueToggles the visibility of the axis.
displayOnlystring/array'all'Sets display of the available data labels. Options: all, first, last, min max. Combinations can be done with array.
gridVisiblebooleantrueToggles the visibility of the axis grid.
labelstring'X Axis'Sets the label for the axis.
unitstring'' or 'month'Sets the unit of padding for the axis when accessor is a date.
formatstring'' or '%b %y' or '0.0a'Sets the formatting for axis elements, EG %b, refer to d3-time-format and numeral.js.
tickIntervalnumber1Can be used to reduce the frequency of axis ticks. This number sets the interval of axis ticks that are shown.

# Bar & Marker Props <>

NameTypeDefault Value(s)Description
barStyleobject (custom type)IBarStyleTypeSet styling for the dumbbell's bar, see object definition below.
markerobject (custom type)IMarkerStyleTypeSets the visibility, type, and size of the bar marker, see object definition below.
focusMarkerobject (custom type)IFocusStyleTypeOptional. Specifies the key value and size to focus one marker (based on seriesAccessor), see object definition below.

IBarStyleType Definition

Name (barStyle.)TypeDefault Value(s)Description
colorRulestring'default'Sets the color rule for the dumbbell bar (options are 'greaterValue', 'focus' or 'default').
opacitynumber1Sets the opacity of the dumbbell bar.
widthnumber1Sets the width of the dumbbell bar.

IMarkerStyleType Definition

Name (marker.)TypeDefault Value(s)Description
typestring'dot'Sets the shape type of dumbbell markers.
sizeFromBarnumber8Sets the size of the marker.
visiblebooleantrueSets the visibility of dumbbell markers.

IFocusStyleType Definition

Name (focusMarker.)TypeDefault Value(s)Description
keystring''Key used to determine which marker to focus.
sizeFromBarnumber12Sets the size of the focus marker.

# Event Props <>

Events in stencil.js dispatch Custom DOM events for other components to handle, we use Stencil's @Event() decorator to emit events (click, hover, mouseOut) from end user activity on our charts.

NameTypeDefault Value(s)Description
suppressEventsbooleanfalseSuppresses and disables click, hover and mouseOut event emitters. Setting to true can increase performance for non-interactive charts.
cursorstring'default'Changes pointer type during mouse over on data elements. Valid values are 'default' or 'pointer'.
onClickEventfunctionundefinedWhen clickEvent event occurs (e.g., mouse/keyboard click on chart geometry), this event handler will be called with the custom event object (e.g., e), containing data and target node at e.detail {data: d, target: n}. You will need to construct your own functionality of what actions to take within the callback.
clickHighlightobject[][]Data used to track chart selections, an array of objects which includes keys that map to above accessors.
clickStyleobject (custom type)IClickStyleTypeSets the styling of a data element when they are selected, see object definition below.
onHoverEventfunctionundefinedWhen hoverEvent event occurs (e.g., mouse hover/keyboard focus on chart geometry), this event handler will be called with the custom event object (e.g., e), containing data and target node at e.detail {data: d, target: n}. You will need to construct your own functionality of what actions to take within the callback.
onMouseOutEventfunctionundefinedWhen mouseOutEvent event occurs (e.g., mouse/keyboard blur on chart geometry), this event handler will be called, and has no data object. You will need to construct your own functionality of what actions to take within the callback.
hoverHighlightobject{}Datum object used to track active chart element, the object should include keys that map to above accessors.
hoverStyleobject (custom type)IHoverStyleTypeSets the styling of a data element when they are hovered/focused, see object definition below.
interactionKeysstring[][]Sets the column names of data to interact with.
hoverOpacitynumber1Sets opacity of inactive elements when hovering/focused on a chart geometry.
onInitialLoadEventfunctionundefinedWhen initalLoad event occurs (e.g., chart is mounted to window), this event handler will be called with the custom event object (e.g., e), containing the corresponding chartID at e.detail. You will need to construct your own functionality of what actions to take within the callback.
onInitialLoadEndEventfunctionundefinedWhen initalLoadEnd event occurs (e.g., chart has been mounted to window), this event handler will be called with the custom event object (e.g., e), containing the corresponding chartID at e.detail. You will need to construct your own functionality of what actions to take within the callback.
onDrawStartEventfunctionundefinedWhen drawStart event occurs (e.g., chart render function is called), this event handler will be called with the custom event object (e.g., e), containing the corresponding chartID at e.detail. You will need to construct your own functionality of what actions to take within the callback.
onDrawEndEventfunctionundefinedWhen drawEnd event occurs (e.g., chart's stencil lifecycle completes), this event handler will be called with the custom event object (e.g., e), containing the corresponding chartID at e.detail. You will need to construct your own functionality of what actions to take within the callback.
onTransitionEndEventfunctionundefinedWhen transitionEnd event occurs (e.g., chart geometry's transition lifecycle completes), this event handler will be called with the custom event object (e.g., e), containing the corresponding chartID at e.detail. You will need to construct your own functionality of what actions to take within the callback.

IClickStyleType Definition

NameTypeDefault Value(s)Description
colorstring''Sets the color of the clicked element (requires clickHighlight to be valid and sent).
strokeWidthnumber2Sets the stroke width of the clicked element (requires clickHighlight to be valid and sent).

IHoverStyleType Definition

NameTypeDefault Value(s)Description
colorstring''Sets the color of the hovered element (requires hoverHighlight to be valid and sent).
strokeWidthnumber2Sets the stroke width of the hovered element (requires hoverHighlight to be valid and sent).
// example of interactivity code
// note this only tracks a single click, you need your own logic to build the array of currnet selections made by user and then pass that result back to chart
//...
const clickHandler = evt => {
  const d = evt.detail.data; // data is located here
  const t = evt.detail.target; // chart mark/label clicked is located here

  this.currentClickedElement = [d]; // this is passed to clickHighlight prop
};

const hoverHandler = evt => {
  const d = evt.detail.data; // data is located here
  const t = evt.detail.target; // chart mark/label clicked is located here

  this.currentHoveredElement = d; // this is passed to hoverHighlight prop
};

const mouseOutHandler = evt => {
  this.currentHoveredElement = ''; // this is passed to hoverHighlight prop
};

// an example of calling these from within a stencil.js component
<dumbbell-plot
  data={[{ data }]}
  valueAccessor={'value'}
  ordinalAccessor={'date'}
  seriesAccessor={'category'}
  interactionKeys={['date']}
  onClickEvent={this.onClickEvent}
  clickHighlight={this.currentClickedElement}
  clickStyle={this.clickStyle}
  onHoverEvent={this.onHoverEvent}
  onMouseOutEvent={this.onMouseOut}
  hoverHighlight={this.currentHoveredElement}
  hoverStyle={this.hoverStyle}
/>;
//...

# Label Props <>

NameTypeDefault Value(s)Description
dataLabelobject (custom type)IDataLabelTypeControls visibility, styling and placement of data labels, see object definition below.
dataKeyNamesobjectundefinedObject that contains mapping of data keys (e.g., accessors) and user friendly names of the data fields. This prop can be used to enable translation of data keys between languages, or just provide a meaningful name for data elements within a chart. The key:value pairs in this object will effect tooltips, data table, aria labels, axes, etc. Anywhere in chart where data key may be exposed to consumers.
differenceLabelobject (custom type)IDifferenceLabelType Controls visibility, styling and placement of difference labels, see object definition below.
seriesLabelobject (custom type)ISeriesLabelTypeControls visibility, styling and placement of series labels, see object definition below.
legendobject (custom type)ILegendTypeControls visibility and label of the chart legend, see object definition below.
showTooltipbooleantrueToggles whether to display the tooltip on hover/focus on chart geometries.
tooltipLabelobject (custom type)ITooltipLabelTypeControls visibility, content and format of the chart tooltip, see object definition below.

IDataLabelType Definition

NameTypeDefault Value(s)Description
labelAccessorstring''Key used to determine label's property.
visiblebooleantrueToggles the visibility (opacity) of the data labels.
placementstring'ends'Sets the placement of the data label. Accepts 'top', 'bottom', 'left', 'right', and 'ends'. Placement option 'auto' leverages the resolveLabelCollision algorithm and places labels without overlaps in available space on the chart.
formatstring'0.0a'Sets the formatting for the data labels, EG %b, refer to d3-time-format and numeral.js. If used with text or string values, the value declared in labelAccessor will be used without any additional formatting.
collisionHideOnlybooleanfalseToggles whether to run resolveLabelCollision algorithm and hide labels if collision is detected (vs hide and then place). This is overridden by placement being set to auto.

IDifferenceLabelType Definition

NameTypeDefault Value(s)Description
calculationstring'difference'Sets the calculation used in the difference label. Accepts 'difference' or 'middle'.
visiblebooleantrueToggles the visibility (opacity) of the difference labels.
placementstring'left'Sets the placement of the data label. Accepts 'top', 'bottom', 'left', and 'right'.
formatstring'0.0a'Sets the formatting for the data labels, EG %b, refer to d3-time-format and numeral.js. Placement option 'auto' leverages the resolveLabelCollision algorithm and places labels without overlaps in available space on the chart.
collisionHideOnlybooleanfalseToggles whether to run resolveLabelCollision algorithm and hide difference labels if collision is detected (vs hide and then place). This is overridden by placement being set to auto.

ISeriesLabel Definition

NameTypeDefault Value(s)Description
labelstring[][]An array which determines the labels for each series, in order.
visiblebooleantrueToggles the visibility (opacity) of the series labels.
placementstring'right'Sets the placement of the series label, accepts 'left', 'right', 'top', and 'bottom' Placement option 'auto' leverages the resolveLabelCollision algorithm and places labels without overlaps in available space on the chart.
collisionHideOnlybooleanfalseToggles whether to run resolveLabelCollision algorithm and hide series labels if collision is detected (vs hide and then place). This is overridden by placement being set to auto.

ILegendType Definition

NameTypeDefault Value(s)Description
visiblebooleantrueToggles the visibility (opacity/display) of the legend.
interactivebooleanfalseToggles the interactivity of the legend.
labelsstring[]''An array that sets each label in the legend, in order. Passing empty string will populate legend labels directly from data values.

ITooltipLabelType Definition

NameTypeDefault Value(s)Description
labelAccessorstring[][]An array that determines which property of the data is displayed in the tooltip.
labelTitlestring[][]An array that sets the title for each data property in the tooltip.
formatstring''Sets the formatting for the data properties in the tooltip, EG %b, refer to d3-time-format and numeral.js.

# Margin & Padding Props <>

NameTypeDefault Value(s)Description
marginobject (custom type)IBoxModelTypeMargin between the subtitle and the chart area, or between the title and chart area if no subtitle is specified, see object definition below.
paddingobject (custom type)IBoxModelTypePadding between plot area and axes lines, see object definition below.

IBoxModelType Definition

NameTypeDefault Value(s)Description
topnumberheight * 0.01Sets the top margin/padding for the chart container.
bottomnumberheight * 0.01Sets the bottom margin/padding for the chart container.
leftnumberwidth * 0.01Sets the top margin/padding for the chart container.
rightnumberwidth * 0.01Sets the top margin/padding for the chart container.

# Style Props <>

NameTypeDefault Value(s)Description
colorPalettestring'categorical'Included color palettes can be found in our color utility. Overridden by colors.
colorsstring[]undefinedAccepts array of color strings or color values to customize colors beyond our palettes. Colors assigned in order.

# Reference Line Props <>

NameTypeDefault Value(s)Description
referenceLinesobject[][]Data that sets the location and labeling of the reference line(s) see object definition below. ### IReferenceLineType
referenceStyleobject (custom type)IReferenceStyleTypeSets the styling of reference line(s) placed on the chart, see object definition below. #### IReferenceStyleType Definition

IReferenceStyleType Definition

NameTypeDefault Value(s)Description
colorstring'pri_grey'Sets the color of the reference line.
strokeWidthnumber1Sets the stroke width of the reference line.
opacitynumber1Sets the opacity of the reference line.
dashedstring''Sets the dash array property of the path element of the reference line.

referenceLines object definition

referenceLines is an array of objects which needs to have the following properties within them.

NameTypeDefault Value(s)Description
labelstringundefinedSets the label to show for the reference line.
labelPlacementHorizontalstringChart horizontal layout mode: left or middle or right. Chart vertical layout mode: top or bottom.Sets the horizontal label placement for the reference line.
labelPlacementVerticalstringChart horizontal layout mode: left or right. Chart vertical layout mode: top or middle or bottom.Sets the vertical label placement for the reference line.
valuenumberundefinedSets the value where to place the reference line, per the axis.
accessibilityDescriptionstringundefinedDescriptive text for the reference line which will be provided to screen reader users via VCCs accessibility description's setAccessAnnotation utility.
accessibilityDecorationOnlybooleanundefinedWhen the reference line is decorative (e.g., does not provide any additional information), set accessibilityDecorationOnly to true to avoid unnecessary reference line content in VCCs accessibility descriptions.

# Unit Testing Props <>

These props are used in development mode only to facilitate robust testing of charts, the should not be leveraged in a production deployments.

NameTypeDefault Value(s)Description
unitTestbooleanfalseIf true, attaches relevant testing attributes to the chart's DOM elements, this only needs to be true when running our unit tests.
8.0.1

8 days ago

8.0.0

28 days ago

7.2.2

9 months ago

7.2.1

10 months ago

7.2.0

1 year ago

7.1.0

1 year ago

7.0.0

2 years ago

6.2.0

2 years ago

6.1.2

2 years ago

6.1.1

2 years ago

6.1.0

3 years ago

6.0.1

3 years ago

6.0.0

3 years ago

5.3.1

3 years ago

5.3.0

3 years ago

5.2.3

4 years ago

5.2.2

4 years ago

5.2.1

4 years ago

5.2.0

4 years ago

5.1.1

4 years ago

5.1.0

4 years ago