![New axobject-query Maintainer Faces Backlash Over Controversial Decision to Support Legacy Node.js Versions](https://cdn.sanity.io/images/cgdhsj6q/production/86e6ebdea652d20da070ebbda20134b839972db7-1024x1024.webp?w=800&fit=max&auto=format)
Security News
New axobject-query Maintainer Faces Backlash Over Controversial Decision to Support Legacy Node.js Versions
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.
d3plus-legend
Advanced tools
Readme
An easy to use javascript chart legend.
If you use NPM, run npm install d3plus-legend --save
. Otherwise, download the latest release. The released bundle supports AMD, CommonJS, and vanilla environments. You can also load directly from d3plus.org:
<script src="https://d3plus.org/js/d3plus-legend.v0.8.full.min.js"></script>
This is a global class, and extends all of the methods and functionality of BaseClass
.
BaseClass
# new ColorScale()
Creates an SVG scale based on an array of data. If data is specified, immediately draws based on the specified array and returns the current class instance. If data is not specified on instantiation, it can be passed/updated after instantiation using the data method.
# ColorScale.render([callback]) <>
Renders the current ColorScale to the page. If a callback is specified, it will be called once the ColorScale is done drawing.
This is a static method of ColorScale
, and is chainable with other methods of this Class.
# ColorScale.axisConfig([value]) <>
The ColorScale is constructed by combining an Axis for the ticks/labels and a Rect for the actual color box (or multiple boxes, as in a jenks scale). Because of this, there are separate configs for the Axis class used to display the text (axisConfig) and the Rect class used to draw the color breaks (rectConfig). This method acts as a pass-through to the config method of the Axis. An example usage of this method can be seen here.
This is a static method of ColorScale
, and is chainable with other methods of this Class.
# ColorScale.align([value]) <>
If value is specified, sets the horizontal alignment to the specified value and returns the current class instance. If value is not specified, returns the current horizontal alignment.
This is a static method of ColorScale
, and is chainable with other methods of this Class.
# ColorScale.buckets([value]) <>
The number of discrete buckets to create in a bucketed color scale. Will be overridden by any custom Array of colors passed to the color
method.
This is a static method of ColorScale
, and is chainable with other methods of this Class.
# ColorScale.bucketAxis([value]) <>
Determines whether or not to use an Axis to display bucket scales (both "buckets" and "jenks"). When set to false
, bucketed scales will use the Legend
class to display squares for each range of data. When set to true
, bucketed scales will be displayed on an Axis
, similar to "linear" scales.
This is a static method of ColorScale
, and is chainable with other methods of this Class.
# ColorScale.color([value]) <>
Overrides the default internal logic of colorMin
, colorMid
, and colorMax
to only use just this specified color. If a single color is given as a String, then the scale is interpolated by lightening that color. Otherwise, the function expects an Array of color values to be used in order for the scale.
This is a static method of ColorScale
, and is chainable with other methods of this Class.
# ColorScale.colorMax([value]) <>
Defines the color to be used for numbers greater than the value of the midpoint
on the scale (defaults to 0
). Colors in between this value and the value of colorMid
will be interpolated, unless a custom Array of colors has been specified using the color
method.
This is a static method of ColorScale
, and is chainable with other methods of this Class.
# ColorScale.colorMid([value]) <>
Defines the color to be used for the midpoint of a diverging scale, based on the current value of the midpoint
method (defaults to 0
). Colors in between this value and the values of colorMin
and colorMax
will be interpolated, unless a custom Array of colors has been specified using the color
method.
This is a static method of ColorScale
, and is chainable with other methods of this Class.
# ColorScale.colorMin([value]) <>
Defines the color to be used for numbers less than the value of the midpoint
on the scale (defaults to 0
). Colors in between this value and the value of colorMid
will be interpolated, unless a custom Array of colors has been specified using the color
method.
This is a static method of ColorScale
, and is chainable with other methods of this Class.
If data is specified, sets the data array to the specified array and returns the current class instance. If data is not specified, returns the current data array. A shape key will be drawn for each object in the array.
This is a static method of ColorScale
, and is chainable with other methods of this Class.
# ColorScale.duration([value]) <>
If value is specified, sets the transition duration of the ColorScale and returns the current class instance. If value is not specified, returns the current duration.
This is a static method of ColorScale
, and is chainable with other methods of this Class.
# ColorScale.height([value]) <>
If value is specified, sets the overall height of the ColorScale and returns the current class instance. If value is not specified, returns the current height value.
This is a static method of ColorScale
, and is chainable with other methods of this Class.
# ColorScale.legendConfig([value]) <>
The ColorScale is constructed by combining an Axis for the ticks/labels and a Rect for the actual color box (or multiple boxes, as in a jenks scale). Because of this, there are separate configs for the Axis class used to display the text (axisConfig) and the Rect class used to draw the color breaks (rectConfig). This method acts as a pass-through to the config method of the Axis. An example usage of this method can be seen here.
This is a static method of ColorScale
, and is chainable with other methods of this Class.
# ColorScale.midpoint([value]) <>
The number value to be used as the anchor for colorMid
, and defines the center point of the diverging color scale.
This is a static method of ColorScale
, and is chainable with other methods of this Class.
# ColorScale.orient([value]) <>
Sets the flow of the items inside the ColorScale. If no value is passed, the current flow will be returned.
This is a static method of ColorScale
, and is chainable with other methods of this Class.
If called after the elements have been drawn to DOM, will returns the outer bounds of the ColorScale content.
This is a static method of ColorScale
.
{"width": 180, "height": 24, "x": 10, "y": 20}
# ColorScale.padding([value]) <>
If value is specified, sets the padding between each key to the specified number and returns the current class instance. If value is not specified, returns the current padding value.
This is a static method of ColorScale
, and is chainable with other methods of this Class.
# ColorScale.rectConfig([value]) <>
The ColorScale is constructed by combining an Axis for the ticks/labels and a Rect for the actual color box (or multiple boxes, as in a jenks scale). Because of this, there are separate configs for the Axis class used to display the text (axisConfig) and the Rect class used to draw the color breaks (rectConfig). This method acts as a pass-through to the config method of the Rect. An example usage of this method can be seen here.
This is a static method of ColorScale
, and is chainable with other methods of this Class.
# ColorScale.scale([value]) <>
If value is specified, sets the scale of the ColorScale and returns the current class instance. If value is not specified, returns the current scale value.
This is a static method of ColorScale
, and is chainable with other methods of this Class.
# ColorScale.select([selector]) <>
If selector is specified, sets the SVG container element to the specified d3 selector or DOM element and returns the current class instance. If selector is not specified, returns the current SVG container element.
This is a static method of ColorScale
, and is chainable with other methods of this Class.
The height of horizontal color scales, and width when positioned vertical.
This is a static method of ColorScale
, and is chainable with other methods of this Class.
# ColorScale.value([value]) <>
If value is specified, sets the value accessor to the specified function or string and returns the current class instance. If value is not specified, returns the current value accessor.
This is a static method of ColorScale
, and is chainable with other methods of this Class.
function value(d) {
return d.value;
}
# ColorScale.width([value]) <>
If value is specified, sets the overall width of the ColorScale and returns the current class instance. If value is not specified, returns the current width value.
This is a static method of ColorScale
, and is chainable with other methods of this Class.
This is a global class, and extends all of the methods and functionality of BaseClass
.
BaseClass
# new Legend()
Creates an SVG scale based on an array of data. If data is specified, immediately draws based on the specified array and returns the current class instance. If data is not specified on instantiation, it can be passed/updated after instantiation using the data method.
# Legend.render([callback]) <>
Renders the current Legend to the page. If a callback is specified, it will be called once the legend is done drawing.
This is a static method of Legend
, and is chainable with other methods of this Class.
If value is specified, sets the active method for all shapes to the specified function and returns the current class instance. If value is not specified, returns the current active method.
This is a static method of Legend
, and is chainable with other methods of this Class.
If value is specified, sets the horizontal alignment to the specified value and returns the current class instance. If value is not specified, returns the current horizontal alignment.
This is a static method of Legend
, and is chainable with other methods of this Class.
If data is specified, sets the data array to the specified array and returns the current class instance. If data is not specified, returns the current data array. A shape key will be drawn for each object in the array.
This is a static method of Legend
, and is chainable with other methods of this Class.
# Legend.direction([value]) <>
Sets the flow of the items inside the legend. If no value is passed, the current flow will be returned.
This is a static method of Legend
, and is chainable with other methods of this Class.
If value is specified, sets the transition duration of the legend and returns the current class instance. If value is not specified, returns the current duration.
This is a static method of Legend
, and is chainable with other methods of this Class.
If value is specified, sets the overall height of the legend and returns the current class instance. If value is not specified, returns the current height value.
This is a static method of Legend
, and is chainable with other methods of this Class.
If value is specified, sets the hover method for all shapes to the specified function and returns the current class instance. If value is not specified, returns the current hover method.
This is a static method of Legend
, and is chainable with other methods of this Class.
If value is specified, sets the id accessor to the specified function and returns the current class instance. If value is not specified, returns the current id accessor.
This is a static method of Legend
, and is chainable with other methods of this Class.
function value(d) {
return d.id;
}
If value is specified, sets the label accessor to the specified function or string and returns the current class instance. If value is not specified, returns the current label accessor, which is the id accessor by default.
This is a static method of Legend
, and is chainable with other methods of this Class.
If called after the elements have been drawn to DOM, will returns the outer bounds of the legend content.
This is a static method of Legend
.
{"width": 180, "height": 24, "x": 10, "y": 20}
If value is specified, sets the padding between each key to the specified number and returns the current class instance. If value is not specified, returns the current padding value.
This is a static method of Legend
, and is chainable with other methods of this Class.
# Legend.select([selector]) <>
If selector is specified, sets the SVG container element to the specified d3 selector or DOM element and returns the current class instance. If selector is not specified, returns the current SVG container element.
This is a static method of Legend
, and is chainable with other methods of this Class.
If value is specified, sets the shape accessor to the specified function or string and returns the current class instance. If value is not specified, returns the current shape accessor.
This is a static method of Legend
, and is chainable with other methods of this Class.
# Legend.shapeConfig([config]) <>
If config is specified, sets the methods that correspond to the key/value pairs for each shape and returns the current class instance. If config is not specified, returns the current shape configuration.
This is a static method of Legend
, and is chainable with other methods of this Class.
If value is specified, sets the title of the legend and returns the current class instance. If value is not specified, returns the current title.
This is a static method of Legend
, and is chainable with other methods of this Class.
# Legend.titleConfig([value]) <>
If value is specified, sets the title configuration of the legend and returns the current class instance. If value is not specified, returns the current title configuration.
This is a static method of Legend
, and is chainable with other methods of this Class.
# Legend.verticalAlign([value]) <>
If value is specified, sets the vertical alignment to the specified value and returns the current class instance. If value is not specified, returns the current vertical alignment.
This is a static method of Legend
, and is chainable with other methods of this Class.
If value is specified, sets the overall width of the legend and returns the current class instance. If value is not specified, returns the current width value.
This is a static method of Legend
, and is chainable with other methods of this Class.
FAQs
An easy to use javascript chart legend.
The npm package d3plus-legend receives a total of 353 weekly downloads. As such, d3plus-legend popularity was classified as not popular.
We found that d3plus-legend demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.
Security News
Results from the 2023 State of JavaScript Survey highlight key trends, including Vite's dominance, rising TypeScript adoption, and the enduring popularity of React. Discover more insights on developer preferences and technology usage.
Security News
The US Justice Department has penalized two consulting firms $11.3 million for failing to meet cybersecurity requirements on federally funded projects, emphasizing strict enforcement to protect sensitive government data.