Methods
addBackground(html)
- Description:
- adds background styles to raw html
- Source:
Parameters:
| Name |
Type |
Description |
html |
string
|
raw html |
addDays(startDate, days) → {String}
- Description:
- Calculates a new date by summing a given amount of days to a given date
- Source:
Parameters:
| Name |
Type |
Description |
startDate |
String
|
Date |
days |
Number
|
Number of days to add |
Returns:
Offsetted date
-
Type
-
String
bindAutoResize(chart)
- Description:
- Watch the chart container and redraw when its width changes.
- Source:
Parameters:
| Name |
Type |
Description |
chart |
function
|
Chart instance |
calculatePercent(value, total, decimals) → {String}
- Description:
- Calculates percentage of value from total
- Source:
Parameters:
| Name |
Type |
Description |
value |
Number
|
Value to check |
total |
Number
|
Sum of values |
decimals |
String
|
Specifies number of decimals https://github.com/d3/d3-format |
Returns:
Percentage
-
Type
-
String
computeDefaultStyleByTagName(tagName) → {Object}
- Description:
- Extracts the styles of elements of the given tag name
- Source:
Parameters:
| Name |
Type |
Description |
tagName |
String
|
Tag name that we will check for styles |
Returns:
Values of the styles applied to the given element
-
Type
-
Object
convertMillisecondsToDays(milliseconds) → {Number}
- Description:
- Takes a number representing milliseconds and convert to days
- Source:
Parameters:
| Name |
Type |
Description |
milliseconds |
Number
|
Any number of days in milliseconds |
Returns:
Number of days that the input represents
-
Type
-
Number
convertSvgToHtml(d3svg) → {String}
- Description:
- Takes the D3 SVG element, adds proper SVG tags, adds inline styles
from stylesheets, adds white background and returns string
- Source:
Parameters:
| Name |
Type |
Description |
d3svg |
SVGElement
|
TYPE d3 svg element |
Returns:
String of passed d3
-
Type
-
String
createCanvas(width, height) → {object}
- Description:
- Source:
Parameters:
| Name |
Type |
Description |
width |
number
|
|
height |
number
|
|
Returns:
TYPE canvas element
-
Type
-
object
createImage(svgHtml) → {object}
- Description:
- Source:
Parameters:
| Name |
Type |
Description |
svgHtml |
string
|
string representation of svg el |
Returns:
TYPE element
![]()
, src points at svg
-
Type
-
object
diffDays(startDate, endDate) → {Number}
- Description:
- Calculates difference between dates in days
- Source:
Parameters:
| Name |
Type |
Description |
startDate |
String
|
Date in string form |
endDate |
String
|
Date in string form |
Returns:
Number of days between dates
-
Type
-
Number
downloadCanvas(canvas, filename, extensionType)
- Description:
- Triggers browser to download image, convert canvas to url,
we need to append the link el to the dom before clicking it for Firefox to register
point at it and trigger click
- Source:
Parameters:
| Name |
Type |
Default |
Description |
canvas |
object
|
|
TYPE: el |
filename |
string
|
|
|
extensionType |
string
|
image/png
|
|
drawImageOnCanvas(image, canvas)
- Description:
- Source:
Parameters:
| Name |
Type |
Description |
image |
object
|
TYPE:el , to be drawn |
canvas |
object
|
TYPE: el |
exportChart(svgs, filename, title)
- Description:
- Main function to be used as a method by chart instances to export charts to png
- Source:
Parameters:
| Name |
Type |
Description |
svgs |
array
|
(or an svg element) pass in both chart & legend as array or just chart as svg or in array |
filename |
string
|
[download to be called .png] |
title |
string
|
Title for the image |
finalizeChart(chart)
- Description:
- Apply accessibility to marks after the chart has drawn them.
- Source:
Parameters:
| Name |
Type |
Description |
chart |
function
|
Chart instance |
- Description:
- Formats a floating point value depending on its value range
- Source:
Parameters:
| Name |
Type |
Description |
value |
Number
|
Decimal point value to format |
Returns:
Formatted value to show
-
Type
-
Number
- Description:
- Some browsers need special formatting, we handle that here
- Source:
Parameters:
| Name |
Type |
Description |
html |
string
|
string of svg html |
Returns:
string of svg html
-
Type
-
string
- Description:
- Formats an integer value depending on its value range
- Source:
Parameters:
| Name |
Type |
Description |
value |
Number
|
Decimal point value to format |
Returns:
Formatted value to show
-
Type
-
Number
getAxisSettingsFromTimeSpan(timeSpan) → {String}
- Description:
- Figures out the proper settings from the current time span
- Source:
Parameters:
| Name |
Type |
Description |
timeSpan |
Number
|
Span of time charted by the graph in milliseconds |
Returns:
Type of settings for the given timeSpan
-
Type
-
String
- Description:
- Takes a locale (string) and the format to return and returns a function to format dates
- Source:
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
locale |
String
|
|
|
Locale tag eg. en-US, fr-FR, ru-RU |
timeUnit |
String
|
<optional>
|
'day'
|
Minute, hour, day, dayMonth, month, year |
Returns:
Function that formats dates in the proper locale
-
Type
-
function
getMaxNumOfHorizontalTicks(width, dataPointNumber) → {Number}
- Description:
- Calculates the maximum number of ticks for the x axis
- Source:
Parameters:
| Name |
Type |
Description |
width |
Number
|
Chart width |
dataPointNumber |
Number
|
Number of entries on the data |
Returns:
Number of ticks to render
-
Type
-
Number
getTextWidth(text, fontSizeopt, fontFaceopt) → {String}
- Description:
- Figures out an approximate of the text width by using a canvas element
This avoids having to actually render the text to measure it from the DOM itself
- Source:
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
text |
String
|
|
|
Text to measure |
fontSize |
Number
|
<optional>
|
12
|
Font size (or default) |
fontFace |
String
|
<optional>
|
'Arial'
|
Font family to use in the calculation (or default) |
Returns:
Approximated width of the text
-
Type
-
String
getTimeSeriesAxis(dataByDate, width, settingsopt, localeopt) → {object}
- Description:
- Returns tick object to be used when building the x axis
- Source:
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
dataByDate |
dataByDate
|
|
|
Chart data ordered by Date |
width |
Number
|
|
|
Chart width |
settings |
String
|
<optional>
|
null
|
Optional forced settings for axis |
locale |
String
|
<optional>
|
null
|
Optional forced locale |
Returns:
tick settings for major and minr axis
-
Type
-
object
getValueSize(value, limits)
- Description:
- Return a relative size for the value given, based in our decimal or integer tables
- Source:
Parameters:
| Name |
Type |
Description |
value |
Number
|
Value to assess its relative size |
limits |
Object
|
Object establishing the limits and formats
to consider the value of a given size |
handleImageLoad(canvas, filename, e)
- Description:
- Handles on load event fired by img.onload, this=img
- Source:
Parameters:
| Name |
Type |
Description |
canvas |
object
|
TYPE: el |
filename |
string
|
|
e |
object
|
|
initializeSerializer() → {function}
- Description:
- returns serializer function, only run it when you know you want to serialize your chart
- Source:
Returns:
serializer to add styles in line to dom string
-
Type
-
function
isInteger(value) → {Boolean}
- Description:
- Checks if a number is an integer or a decimal value
- Source:
Parameters:
| Name |
Type |
Description |
value |
Number
|
Value to check |
Returns:
If it is an integer
-
Type
-
Boolean
isValidLocaleDefinition(locale) → {Boolean}
- Description:
- Checks if a locale definition object contains the required keys
- Source:
Parameters:
| Name |
Type |
Description |
locale |
LocaleObject
|
Locale to check |
Returns:
Is the locale definition has a correct format (https://cdn.jsdelivr.net/npm/d3-format/locale/en-US.json)
-
Type
-
Boolean
noteChartRender(chart, svgSelection, container)
- Description:
- Record the rendered root and container. Called from buildSVG.
- Source:
Parameters:
| Name |
Type |
Description |
chart |
function
|
Chart instance |
svgSelection |
object
|
D3 selection for the chart root |
container |
Element
|
DOM node passed to the chart |
prependTitle(html, title, svgWidth) → {string}
- Description:
- if passed, append title to the raw html to appear on graph
- Source:
Parameters:
| Name |
Type |
Description |
html |
string
|
raw html string |
title |
string
|
title of the graph |
svgWidth |
number
|
width of graph container |
Returns:
raw html with title prepended
-
Type
-
string
setDefaultLocale(locale) → {Object}
- Description:
- Sets the given locale as the new default locale through d3-format's formatDefaultLocale
When an object is used, it simply uses it to set the new locale.
- Source:
Parameters:
| Name |
Type |
Description |
locale |
LocaleObject
|
The desired locale object |
Returns:
Object with a 'format' and 'formatPrefix' functions
-
Type
-
Object
syncAccessibility(chart)
- Description:
- Apply ARIA roles and accessible name/description on the chart root.
- Source:
Parameters:
| Name |
Type |
Description |
chart |
function
|
Chart instance |
uniqueId(prefix) → {String}
- Description:
- Generates a unique id with a prefix
- Source:
Parameters:
| Name |
Type |
Description |
prefix |
String
|
Prefix to add before the id |
Returns:
Unique id
-
Type
-
String
wrapText(xOffset, fontSize, availableWidth, node) → {void}
- Description:
- Wraps a selection of text within the available width
- Source:
Parameters:
| Name |
Type |
Description |
xOffset |
Number
|
X axis offset for the text |
fontSize |
Number
|
Size of the base font |
availableWidth |
Number
|
Width of the container where the text needs to wrap on |
node |
D3Selection
|
SVG text element that contains the text to wrap
REF: http://bl.ocks.org/mbostock/7555321
More discussions on https://github.com/mbostock/d3/issues/1642 |
Returns:
-
Type
-
void
wrapTextWithEllipses(text, width, xposopt, limitopt, lineHeightopt) → {void}
- Description:
- Wraps a selection of text within the available width, also adds class .adjust-upwards
to configure a y offset for entries with multiple rows
- Source:
Parameters:
| Name |
Type |
Attributes |
Default |
Description |
text |
D3Selection
|
|
|
D3 text element |
width |
Number
|
|
|
Width of the container where the text needs to wrap on |
xpos |
Number
|
<optional>
|
0
|
Number passed to determine the x offset |
limit |
Number
|
<optional>
|
2
|
Number of lines before an ellipses is added and the rest of the text is cut off |
lineHeight |
Number
|
<optional>
|
1.2
|
line height to determine how much we need to shift lines around
REF: http://bl.ocks.org/mbostock/7555321
More discussions on https://github.com/mbostock/d3/issues/1642 |
Returns:
-
Type
-
void
Type Definitions
D3Selection
- Source:
Properties:
| Name |
Type |
Description |
length |
Number
|
Size of the selection |
parentNode |
DOMElement
|
Parent of the selection |
Type:
LineChartData
- Source:
Properties:
Type:
Example
{
dataByTopic: [
{
topicName: 'San Francisco',
topic: 123,
dates: [
{
date: '2017-01-16T16:00:00-08:00',
value: 1
},
{
date: '2017-01-16T17:00:00-08:00',
value: 2
}
]
},
{
topicName: 'Other',
topic: 345,
dates: [
{...},
{...}
]
}
]
}
RowChartData
- Source:
Properties:
| Name |
Type |
Description |
value |
Number
|
Value of the group (required) |
name |
String
|
Name of the group (required) |
Type:
Example
[
{
value: 1,
name: 'foorow',
pctChange: 23
},
{
value: 1,
name: 'luminous',
pctChange: 20
}
]
areaChartData
- Source:
Properties:
| Name |
Type |
Description |
date |
String
|
Date of the entry in ISO8601 format (required) |
name |
String
|
Name of the entry (required) |
value |
Number
|
Value of the entry (required) |
Type:
Example
[
{
date: "2011-01-05T00:00:00Z",
name: "Direct",
value: 0
}
]
lineChartDataByTopic
- Source:
Properties:
| Name |
Type |
Description |
topicName |
String
|
Topic name (required) |
topic |
Number
|
Topic identifier (required) |
dates |
Array.<Object>
|
All date entries with values for that topic (required) |
Type:
Example
{
topicName: 'San Francisco',
topic: 123,
dates: [
{
date: '2017-01-16T16:00:00-08:00',
value: 1
},
{
date: '2017-01-16T17:00:00-08:00',
value: 2
}
]
}