1.5.0 • Published 6 years ago

sd-plotly v1.5.0

Weekly downloads
37
License
MIT
Repository
github
Last release
6 years ago

sd-plotly

React implementations of Plotly with Immutable for rendering logic

Installation and use

sd-plotly requires pandas-js DataFrame or Series objects for plotting in order to make rendering logic faster for API-based visualization.

npm install sd-plotly pandas-js

Importing BarPlot

import ReactDOM from 'react-dom'; 
import { BarPlot } from 'sd-plotly';
import { DataFrame } from 'pandas-js';

const component = <BarPlot 
    id="my-id-to-render-into"
    data={df}
    xName="x"
    yNames={["y"]}
    yType="$,.0f"
    yTicksFormat="$,.0f"
    xLabel="X"
    yLabel="Y"
    xTicks={[1, 2, 3]}
    title="Title"
    marginTop={50}
  />;

ReactDOM.render(component, myDocumentElement);

will create this bar chart:

bar chart example

Components

ScatterPlot

BarPlot

SDPlot

The base React Plotly component for plots

Props

PropTypeDescription
bargapnumberGap between the bars in barplot
barmodeunionType of bar chart to plot
chartTypeunionType of chart
classNamestringclass to give to SDPlot div
configurationsignaturePlot.ly configuration object
dataunionData to render in the plot
displayModeBarbooleanDisplay the modebar?
fontColorstringColor to use for the font
fontFamilystringName of the font family to use for text
fontScalenumberScaling factor for the font, relative to 1
gridColorstringColor to make horizontal/vertical lines on the chart
heightnumberHeight of plot, in pixels
horizontalLinesbooleanDisplay horizontal lines on the chart?
hoverinfostringHover info format https://plot.ly/javascript/reference/#scatter-hoverinfo
idstringDiv id with which to render the SDPlot
legendBackgroundColorstringBackground color for the chart legend, if displayed
legendBorderColorstringBorder color for the chart legend, if displayed
legendLocationunionLocation of the chart legend, if displayed
marginBottomnumberBottom margin for the plot
marginLeftnumberLeft margin for the plot
marginRightnumberRight margin for the plot
marginTopnumberTop margin for the plot
opacitynumberOpacity of data points
orientationunionOrientation of chart
paddingnumberPadding in pixels
paletteArrayArray of colors to use for the traces
paperBackgroundColorstringColor of paper background
plotBackgroundColorstringColor of plot background
redrawDebouncenumberms gap during which only the latest redraw requested should occur
resizeDebouncenumberms gap during which only the latest window resize event should cause a redraw
secondaryAxisbooleanInclude a secondary axis?
showLegendbooleanDisplay the legend for the chart?
titlestringTitle of the chart
traceNamesArrayNames for each of the traces
traceTypesArrayTypes of each of the traces in the plot
verticalLinesbooleanDisplay vertical lines on the chart?
widthnumberWidth of plot, in pixels
xIsDatebooleanx data is a datetime?
xLabelstringLabel for the x data series to display
xNamestringName of the x data series
xRangemodeunionType of range to use for the x axis
xShowTickLabelsbooleanShow x-axis tick labels?
xTickLabelsArrayArray of tick labels to use
xTicksFormatstringd3 formatting string to format x ticks
xTicksPrefixstringPrefix to use for x ticks
xTicksReversebooleanReverse the x axis?
xTicksRotationnumberRotation of x tick labels
xTypestringd3 formatting string to format x values
yHoverFormatstringd3 formatting string to format y values on hover
yLabelstringLabel for the y data series to display
yNamesArrayNames of the y data series
yRangemodeunionType of range to use for the y axis
yShowTickLabelsbooleanShow y-axis tick labels?
yTicksFormatstringd3 formatting string to format y ticks
yTicksPrefixstringPrefix to use for y ticks
yTicksReversebooleanReverse the y axis?
yTicksRotationnumberRotation of y tick labels
yTypestringd3 formatting string to format y values

Methods

toString

Returns

string

plotlyResize

Resize the plot on window resize events

_redraw

Redraw the chart when data is updated

layout

Plotly layout object

Returns

signature

{
  title: string,
  paper_bg_color: string,
  height?: number,
  width?: number,
  plot_bg_color: string,
  barmode?: 'relative' | 'group' | 'stack',
  bargap?: number,
  font: {family: string, size: number, color: string},
  xaxis: T_AXIS,
  yaxis: T_AXIS,
  legend: T_LEGEND,
  margin: T_MARGIN,
  showlegend: boolean,
  yaxis2?: T_AXIS_SECONDARY,
  height?: number,
  width?: number,
}
xAxisStyle

Plotly x-axis style object

Returns

signature

{
  title: string,
  autorange: 'reversed' | true,
  titlefont: {size: number},
  tickangle: number,
  tickfont: {size: number},
  gridcolor: string,
  tickprefix: string,
  type: string,
  tickformat: string,
  hoverformat?: string,
  rangemode: 'tozero' | 'nonnegative' | 'normal',
  showticklabels: boolean,
}
yAxisStyle

Plotly y-axis style object

Returns

signature

{
  title: string,
  autorange: 'reversed' | true,
  titlefont: {size: number},
  tickangle: number,
  tickfont: {size: number},
  gridcolor: string,
  tickprefix: string,
  type: string,
  tickformat: string,
  hoverformat?: string,
  rangemode: 'tozero' | 'nonnegative' | 'normal',
  showticklabels: boolean,
}
legend

Plotly legend style object

Returns

signature

{
  x: number,
  y: number,
  font: {size: number},
  bgcolor: string,
  bordercolor: string,
}
margin

Plotly margin style object

Returns

signature

{
  l: number,
  t: number,
  r: number,
  b: number,
  pad: number
}
secondaryAxis

Plotly secondary axis style object

Returns

intersection

T_AXIS & {
  overlaying: 'y',
  side: 'right',
}
chartData

Convert the Immutable.List passed in to the appropriate array format for Plotly.js

Returns

Array

Array<constants.T_TRACE>
chartDataMultiple

Convert the Immutable.List for multiple plot to the appropriate array format for Plotly.js

Returns

Array

Array<constants.T_TRACE>

Development

Testing and build

$ npm run test
$ npm run build

Testing uses Jest. Building requires the babel compiler.

1.5.0

6 years ago

1.4.0

6 years ago

1.3.0

6 years ago

1.2.0

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago