td-plots 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +41 -0
- package/dist/components/Histogram.d.ts +11 -0
- package/dist/components/TestPlot.d.ts +6 -0
- package/dist/index.css +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.esm.css +1 -0
- package/dist/index.esm.js +102 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +105 -0
- package/dist/index.js.map +1 -0
- package/package.json +80 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Ann Sizemore Blevins
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# td-plots
|
|
2
|
+
|
|
3
|
+
A React + TypeScript component library for interactive Plotly.js charts, with Storybook documentation and Vite-powered builds.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## Getting Started
|
|
7
|
+
|
|
8
|
+
### Install dependencies
|
|
9
|
+
```sh
|
|
10
|
+
pnpm install
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Run Storybook
|
|
14
|
+
```sh
|
|
15
|
+
pnpm storybook
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
### Build the library
|
|
19
|
+
```sh
|
|
20
|
+
pnpm run build
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage Example
|
|
24
|
+
|
|
25
|
+
Import and use the `TestPlot` component in your React app:
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
import { TestPlot } from './src/components/TestPlot';
|
|
29
|
+
|
|
30
|
+
export default function App() {
|
|
31
|
+
return <TestPlot xaxisTitle="X Label" yaxisTitle="Y Label" />;
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Project Structure
|
|
36
|
+
- `src/components/` – Plot components (e.g., `TestPlot.tsx`)
|
|
37
|
+
- `stories/` – Storybook stories for components
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
## License
|
|
41
|
+
MIT
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import './plotStyles.scss';
|
|
2
|
+
export type HistogramPlotProps = {
|
|
3
|
+
data: number[];
|
|
4
|
+
title?: string;
|
|
5
|
+
xAxisTitle?: string;
|
|
6
|
+
barColor?: string;
|
|
7
|
+
unselectedBarColor?: string;
|
|
8
|
+
selectorsColor?: string;
|
|
9
|
+
};
|
|
10
|
+
export declare const HistogramPlot: (props: HistogramPlotProps) => import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export default HistogramPlot;
|
package/dist/index.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.plot-container{height:100%;overflow:hidden!important;width:100%}.plot-container .point{border-radius:5px!important;overflow:hidden!important}.plot-container .cursor-ns-resize{height:0;width:0}.plot-container .cursor-ew-resize{fill:var(--selection-color,blue)!important;stroke:var(--selection-color,blue)!important}.plot-container .selectionlayer>path{stroke:var(--selection-color,blue)!important;stroke-dasharray:0!important;stroke-width:1px!important;opacity:.5!important}.plot-container .zoomlayer>path{stroke-dasharray:0!important;stroke:var(--selection-color,blue)!important;fill:var(--selection-color,blue)!important}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.plot-container{height:100%;overflow:hidden!important;width:100%}.plot-container .point{border-radius:5px!important;overflow:hidden!important}.plot-container .cursor-ns-resize{height:0;width:0}.plot-container .cursor-ew-resize{fill:var(--selection-color,blue)!important;stroke:var(--selection-color,blue)!important}.plot-container .selectionlayer>path{stroke:var(--selection-color,blue)!important;stroke-dasharray:0!important;stroke-width:1px!important;opacity:.5!important}.plot-container .zoomlayer>path{stroke-dasharray:0!important;stroke:var(--selection-color,blue)!important;fill:var(--selection-color,blue)!important}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { lazy } from 'react';
|
|
3
|
+
|
|
4
|
+
var Plot$1 = lazy(function () { return import('react-plotly.js'); });
|
|
5
|
+
var HistogramPlot = function (props) {
|
|
6
|
+
var data = props.data, title = props.title, xAxisTitle = props.xAxisTitle, _a = props.barColor, barColor = _a === void 0 ? 'rgb(72, 72, 74)' : _a, _b = props.unselectedBarColor, unselectedBarColor = _b === void 0 ? 'rgba(203, 195, 195, 0.88)' : _b, _c = props.selectorsColor, selectorsColor = _c === void 0 ? 'black' : _c;
|
|
7
|
+
var plotlyData = [
|
|
8
|
+
{
|
|
9
|
+
x: data,
|
|
10
|
+
type: 'histogram',
|
|
11
|
+
marker: {
|
|
12
|
+
color: barColor !== null && barColor !== void 0 ? barColor : 'blue',
|
|
13
|
+
line: {
|
|
14
|
+
color: "white",
|
|
15
|
+
width: 0.5,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
// The following property is listed in the api. Not sure why typescript doesn't know about it.
|
|
19
|
+
// Styles the unselected bars in the histogram
|
|
20
|
+
//@ts-ignore
|
|
21
|
+
unselected: {
|
|
22
|
+
marker: {
|
|
23
|
+
color: unselectedBarColor,
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
hovertemplate: '[%{x})<br>Count: %{y}<extra></extra>', // Custom hover text
|
|
27
|
+
}
|
|
28
|
+
];
|
|
29
|
+
var layout = {
|
|
30
|
+
title: { text: title },
|
|
31
|
+
xaxis: {
|
|
32
|
+
title: {
|
|
33
|
+
text: xAxisTitle
|
|
34
|
+
},
|
|
35
|
+
// range: [Math.min(...data, 0), Math.max(...data)], // Range needs to get padding on both sides based on bin size. Consider calculating bins here.
|
|
36
|
+
showgrid: true,
|
|
37
|
+
zeroline: true,
|
|
38
|
+
showline: true,
|
|
39
|
+
mirror: 'ticks',
|
|
40
|
+
gridcolor: '#efefef',
|
|
41
|
+
gridwidth: 0.2,
|
|
42
|
+
zerolinecolor: '#969696',
|
|
43
|
+
zerolinewidth: 1,
|
|
44
|
+
linecolor: '#bababa',
|
|
45
|
+
linewidth: 1,
|
|
46
|
+
fixedrange: true, // Disable zooming
|
|
47
|
+
ticklabelposition: 'outside',
|
|
48
|
+
},
|
|
49
|
+
yaxis: {
|
|
50
|
+
title: {
|
|
51
|
+
text: 'Count'
|
|
52
|
+
},
|
|
53
|
+
showgrid: true,
|
|
54
|
+
zeroline: true,
|
|
55
|
+
showline: true,
|
|
56
|
+
mirror: 'ticks',
|
|
57
|
+
gridcolor: '#efefef',
|
|
58
|
+
gridwidth: 0.2,
|
|
59
|
+
zerolinecolor: '#969696',
|
|
60
|
+
zerolinewidth: 1,
|
|
61
|
+
linecolor: '#bababa',
|
|
62
|
+
linewidth: 1,
|
|
63
|
+
fixedrange: true, // Disable zooming
|
|
64
|
+
ticksuffix: ' ', // Add space between y axis and ticks
|
|
65
|
+
},
|
|
66
|
+
bargap: 0.03, // Gap between bars
|
|
67
|
+
dragmode: 'select',
|
|
68
|
+
selectdirection: 'h', // Allow selection in horizontal direction
|
|
69
|
+
};
|
|
70
|
+
var config = {
|
|
71
|
+
responsive: true, // Make the plot responsive
|
|
72
|
+
displayModeBar: false, // Hide the mode bar
|
|
73
|
+
displaylogo: false, // Hide the Plotly logo
|
|
74
|
+
scrollZoom: false, // Disable zooming with scroll
|
|
75
|
+
staticPlot: false, // Enable interactivity
|
|
76
|
+
};
|
|
77
|
+
return (jsx("div", { className: "plot-container", style: {
|
|
78
|
+
'--selection-color': selectorsColor,
|
|
79
|
+
}, children: jsx(Plot$1, { data: plotlyData, layout: layout, config: config }) }));
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
var Plot = lazy(function () { return import('react-plotly.js'); });
|
|
83
|
+
var TestPlot = function (props) {
|
|
84
|
+
var _a, _b;
|
|
85
|
+
var data = [
|
|
86
|
+
{
|
|
87
|
+
x: [1, 2, 3, 4],
|
|
88
|
+
y: [10, 15, 13, 17],
|
|
89
|
+
type: 'bar',
|
|
90
|
+
marker: { color: 'blue' },
|
|
91
|
+
},
|
|
92
|
+
];
|
|
93
|
+
var layout = {
|
|
94
|
+
title: { text: 'Test Bar Plot' },
|
|
95
|
+
xaxis: { title: { text: (_a = props.xaxisTitle) !== null && _a !== void 0 ? _a : 'X Axis' } },
|
|
96
|
+
yaxis: { title: { text: (_b = props.yaxisTitle) !== null && _b !== void 0 ? _b : 'Y Axis' } },
|
|
97
|
+
};
|
|
98
|
+
return jsx(Plot, { data: data, layout: layout });
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export { HistogramPlot, TestPlot };
|
|
102
|
+
//# sourceMappingURL=index.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../src/components/Histogram.tsx","../src/components/TestPlot.tsx"],"sourcesContent":["import React, { lazy } from 'react';\nimport { PlotParams } from 'react-plotly.js';\nimport './plotStyles.scss'; // Importing styles for the plot\n\nconst Plot = lazy(() => import('react-plotly.js'));\n\nexport type HistogramPlotProps = {\n data: number[];\n title?: string;\n xAxisTitle?: string;\n barColor?: string; // Optional prop to set the color of the bars\n unselectedBarColor?: string; // Optional prop to set the color of unselected bars\n selectorsColor?: string; // Optional prop to set the color of elements in the selection box\n}\nexport const HistogramPlot = (props: HistogramPlotProps) => {\n\n const {\n data,\n title,\n xAxisTitle,\n barColor = 'rgb(72, 72, 74)',\n unselectedBarColor = 'rgba(203, 195, 195, 0.88)',\n selectorsColor = 'black',\n } = props;\n\n const plotlyData: PlotParams['data'] = [\n {\n x: data,\n type: 'histogram',\n marker: { \n color: barColor ?? 'blue',\n line: {\n color: \"white\",\n width: 0.5,\n },\n },\n // The following property is listed in the api. Not sure why typescript doesn't know about it.\n // Styles the unselected bars in the histogram\n //@ts-ignore\n unselected: {\n marker: { \n color: unselectedBarColor,\n }\n },\n hovertemplate: '[%{x})<br>Count: %{y}<extra></extra>', // Custom hover text\n }\n ];\n\n const layout: PlotParams['layout'] = {\n title: {text: title},\n xaxis: {\n title: {\n text: xAxisTitle\n },\n // range: [Math.min(...data, 0), Math.max(...data)], // Range needs to get padding on both sides based on bin size. Consider calculating bins here.\n showgrid: true,\n zeroline: true,\n showline: true,\n mirror: 'ticks',\n gridcolor: '#efefef',\n gridwidth: 0.2,\n zerolinecolor: '#969696',\n zerolinewidth: 1,\n linecolor: '#bababa',\n linewidth: 1,\n fixedrange: true, // Disable zooming\n ticklabelposition: 'outside',\n },\n yaxis: {\n title: {\n text: 'Count'\n },\n showgrid: true,\n zeroline: true,\n showline: true,\n mirror: 'ticks',\n gridcolor: '#efefef',\n gridwidth: 0.2,\n zerolinecolor: '#969696',\n zerolinewidth: 1,\n linecolor: '#bababa',\n linewidth: 1,\n fixedrange: true, // Disable zooming\n ticksuffix: ' ', // Add space between y axis and ticks\n },\n bargap: 0.03, // Gap between bars\n dragmode: 'select',\n selectdirection: 'h', // Allow selection in horizontal direction\n };\n\n const config: PlotParams['config'] = {\n responsive: true, // Make the plot responsive\n displayModeBar: false, // Hide the mode bar\n displaylogo: false, // Hide the Plotly logo\n scrollZoom: false, // Disable zooming with scroll\n staticPlot: false, // Enable interactivity\n };\n\n return (\n <div \n className=\"plot-container\"\n style={{\n '--selection-color': selectorsColor,\n } as React.CSSProperties}\n >\n <Plot data={plotlyData} layout={layout} config={config} />\n </div>\n );\n}\n\nexport default HistogramPlot;\n","// A test bar plotly plot\nimport React, { lazy } from 'react';\nimport { PlotParams } from 'react-plotly.js';\n\nconst Plot = lazy(() => import('react-plotly.js'));\n\nexport type TestPlotProps = {\n yaxisTitle?: string;\n xaxisTitle?: string;\n}\nexport const TestPlot = (props: TestPlotProps) => {\n const data: PlotParams['data'] = [\n {\n x: [1, 2, 3, 4],\n y: [10, 15, 13, 17],\n type: 'bar' as const,\n marker: { color: 'blue' },\n },\n ];\n\n const layout = {\n title: {text: 'Test Bar Plot'},\n xaxis: { title: {text: props.xaxisTitle ?? 'X Axis'} },\n yaxis: { title: {text: props.yaxisTitle ?? 'Y Axis'} },\n };\n\n return <Plot data={data} layout={layout} />;\n};\n\nexport default TestPlot;\n"],"names":["Plot","_jsx"],"mappings":";;;AAIA,IAAMA,MAAI,GAAG,IAAI,CAAC,YAAA,EAAM,OAAA,OAAO,iBAAiB,CAAC,CAAA,EAAA,CAAC;AAU3C,IAAM,aAAa,GAAG,UAAC,KAAyB,EAAA;AAGnD,IAAA,IAAA,IAAI,GAMF,KAAK,KANH,EACJ,KAAK,GAKH,KAAK,CAAA,KALF,EACL,UAAU,GAIR,KAAK,CAAA,UAJG,EACV,EAAA,GAGE,KAAK,SAHqB,EAA5B,QAAQ,GAAA,EAAA,KAAA,MAAA,GAAG,iBAAiB,KAAA,EAC5B,EAAA,GAEE,KAAK,CAAA,kBAFyC,EAAhD,kBAAkB,GAAA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AE,KAAK,EAAE,MAAM,EAAE;AAC1B,SAAA;KACF;AAED,IAAA,IAAM,MAAM,GAAG;AACb,QAAA,KAAK,EAAE,EAAC,IAAI,EAAE,eAAe,EAAC;AAC9B,QAAA,KAAK,EAAE,EAAE,KAAK,EAAE,EAAC,IAAI,EAAE,CAAA,EAAA,GAAA,KAAK,CAAC,UAAU,MAAA,IAAA,IAAA,EAAA,KAAA,MAAA,GAAA,EAAA,GAAI,QAAQ,EAAC,EAAE;AACtD,QAAA,KAAK,EAAE,EAAE,KAAK,EAAE,EAAC,IAAI,EAAE,CAAA,EAAA,GAAA,KAAK,CAAC,UAAU,MAAA,IAAA,IAAA,EAAA,KAAA,MAAA,GAAA,EAAA,GAAI,QAAQ,EAAC,EAAE;KACvD;IAED,OAAOC,GAAA,CAAC,IAAI,EAAA,EAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAA,CAAI;AAC7C;;;;"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
|
|
6
|
+
var Plot$1 = react.lazy(function () { return import('react-plotly.js'); });
|
|
7
|
+
var HistogramPlot = function (props) {
|
|
8
|
+
var data = props.data, title = props.title, xAxisTitle = props.xAxisTitle, _a = props.barColor, barColor = _a === void 0 ? 'rgb(72, 72, 74)' : _a, _b = props.unselectedBarColor, unselectedBarColor = _b === void 0 ? 'rgba(203, 195, 195, 0.88)' : _b, _c = props.selectorsColor, selectorsColor = _c === void 0 ? 'black' : _c;
|
|
9
|
+
var plotlyData = [
|
|
10
|
+
{
|
|
11
|
+
x: data,
|
|
12
|
+
type: 'histogram',
|
|
13
|
+
marker: {
|
|
14
|
+
color: barColor !== null && barColor !== void 0 ? barColor : 'blue',
|
|
15
|
+
line: {
|
|
16
|
+
color: "white",
|
|
17
|
+
width: 0.5,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
// The following property is listed in the api. Not sure why typescript doesn't know about it.
|
|
21
|
+
// Styles the unselected bars in the histogram
|
|
22
|
+
//@ts-ignore
|
|
23
|
+
unselected: {
|
|
24
|
+
marker: {
|
|
25
|
+
color: unselectedBarColor,
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
hovertemplate: '[%{x})<br>Count: %{y}<extra></extra>', // Custom hover text
|
|
29
|
+
}
|
|
30
|
+
];
|
|
31
|
+
var layout = {
|
|
32
|
+
title: { text: title },
|
|
33
|
+
xaxis: {
|
|
34
|
+
title: {
|
|
35
|
+
text: xAxisTitle
|
|
36
|
+
},
|
|
37
|
+
// range: [Math.min(...data, 0), Math.max(...data)], // Range needs to get padding on both sides based on bin size. Consider calculating bins here.
|
|
38
|
+
showgrid: true,
|
|
39
|
+
zeroline: true,
|
|
40
|
+
showline: true,
|
|
41
|
+
mirror: 'ticks',
|
|
42
|
+
gridcolor: '#efefef',
|
|
43
|
+
gridwidth: 0.2,
|
|
44
|
+
zerolinecolor: '#969696',
|
|
45
|
+
zerolinewidth: 1,
|
|
46
|
+
linecolor: '#bababa',
|
|
47
|
+
linewidth: 1,
|
|
48
|
+
fixedrange: true, // Disable zooming
|
|
49
|
+
ticklabelposition: 'outside',
|
|
50
|
+
},
|
|
51
|
+
yaxis: {
|
|
52
|
+
title: {
|
|
53
|
+
text: 'Count'
|
|
54
|
+
},
|
|
55
|
+
showgrid: true,
|
|
56
|
+
zeroline: true,
|
|
57
|
+
showline: true,
|
|
58
|
+
mirror: 'ticks',
|
|
59
|
+
gridcolor: '#efefef',
|
|
60
|
+
gridwidth: 0.2,
|
|
61
|
+
zerolinecolor: '#969696',
|
|
62
|
+
zerolinewidth: 1,
|
|
63
|
+
linecolor: '#bababa',
|
|
64
|
+
linewidth: 1,
|
|
65
|
+
fixedrange: true, // Disable zooming
|
|
66
|
+
ticksuffix: ' ', // Add space between y axis and ticks
|
|
67
|
+
},
|
|
68
|
+
bargap: 0.03, // Gap between bars
|
|
69
|
+
dragmode: 'select',
|
|
70
|
+
selectdirection: 'h', // Allow selection in horizontal direction
|
|
71
|
+
};
|
|
72
|
+
var config = {
|
|
73
|
+
responsive: true, // Make the plot responsive
|
|
74
|
+
displayModeBar: false, // Hide the mode bar
|
|
75
|
+
displaylogo: false, // Hide the Plotly logo
|
|
76
|
+
scrollZoom: false, // Disable zooming with scroll
|
|
77
|
+
staticPlot: false, // Enable interactivity
|
|
78
|
+
};
|
|
79
|
+
return (jsxRuntime.jsx("div", { className: "plot-container", style: {
|
|
80
|
+
'--selection-color': selectorsColor,
|
|
81
|
+
}, children: jsxRuntime.jsx(Plot$1, { data: plotlyData, layout: layout, config: config }) }));
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
var Plot = react.lazy(function () { return import('react-plotly.js'); });
|
|
85
|
+
var TestPlot = function (props) {
|
|
86
|
+
var _a, _b;
|
|
87
|
+
var data = [
|
|
88
|
+
{
|
|
89
|
+
x: [1, 2, 3, 4],
|
|
90
|
+
y: [10, 15, 13, 17],
|
|
91
|
+
type: 'bar',
|
|
92
|
+
marker: { color: 'blue' },
|
|
93
|
+
},
|
|
94
|
+
];
|
|
95
|
+
var layout = {
|
|
96
|
+
title: { text: 'Test Bar Plot' },
|
|
97
|
+
xaxis: { title: { text: (_a = props.xaxisTitle) !== null && _a !== void 0 ? _a : 'X Axis' } },
|
|
98
|
+
yaxis: { title: { text: (_b = props.yaxisTitle) !== null && _b !== void 0 ? _b : 'Y Axis' } },
|
|
99
|
+
};
|
|
100
|
+
return jsxRuntime.jsx(Plot, { data: data, layout: layout });
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
exports.HistogramPlot = HistogramPlot;
|
|
104
|
+
exports.TestPlot = TestPlot;
|
|
105
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/components/Histogram.tsx","../src/components/TestPlot.tsx"],"sourcesContent":["import React, { lazy } from 'react';\nimport { PlotParams } from 'react-plotly.js';\nimport './plotStyles.scss'; // Importing styles for the plot\n\nconst Plot = lazy(() => import('react-plotly.js'));\n\nexport type HistogramPlotProps = {\n data: number[];\n title?: string;\n xAxisTitle?: string;\n barColor?: string; // Optional prop to set the color of the bars\n unselectedBarColor?: string; // Optional prop to set the color of unselected bars\n selectorsColor?: string; // Optional prop to set the color of elements in the selection box\n}\nexport const HistogramPlot = (props: HistogramPlotProps) => {\n\n const {\n data,\n title,\n xAxisTitle,\n barColor = 'rgb(72, 72, 74)',\n unselectedBarColor = 'rgba(203, 195, 195, 0.88)',\n selectorsColor = 'black',\n } = props;\n\n const plotlyData: PlotParams['data'] = [\n {\n x: data,\n type: 'histogram',\n marker: { \n color: barColor ?? 'blue',\n line: {\n color: \"white\",\n width: 0.5,\n },\n },\n // The following property is listed in the api. Not sure why typescript doesn't know about it.\n // Styles the unselected bars in the histogram\n //@ts-ignore\n unselected: {\n marker: { \n color: unselectedBarColor,\n }\n },\n hovertemplate: '[%{x})<br>Count: %{y}<extra></extra>', // Custom hover text\n }\n ];\n\n const layout: PlotParams['layout'] = {\n title: {text: title},\n xaxis: {\n title: {\n text: xAxisTitle\n },\n // range: [Math.min(...data, 0), Math.max(...data)], // Range needs to get padding on both sides based on bin size. Consider calculating bins here.\n showgrid: true,\n zeroline: true,\n showline: true,\n mirror: 'ticks',\n gridcolor: '#efefef',\n gridwidth: 0.2,\n zerolinecolor: '#969696',\n zerolinewidth: 1,\n linecolor: '#bababa',\n linewidth: 1,\n fixedrange: true, // Disable zooming\n ticklabelposition: 'outside',\n },\n yaxis: {\n title: {\n text: 'Count'\n },\n showgrid: true,\n zeroline: true,\n showline: true,\n mirror: 'ticks',\n gridcolor: '#efefef',\n gridwidth: 0.2,\n zerolinecolor: '#969696',\n zerolinewidth: 1,\n linecolor: '#bababa',\n linewidth: 1,\n fixedrange: true, // Disable zooming\n ticksuffix: ' ', // Add space between y axis and ticks\n },\n bargap: 0.03, // Gap between bars\n dragmode: 'select',\n selectdirection: 'h', // Allow selection in horizontal direction\n };\n\n const config: PlotParams['config'] = {\n responsive: true, // Make the plot responsive\n displayModeBar: false, // Hide the mode bar\n displaylogo: false, // Hide the Plotly logo\n scrollZoom: false, // Disable zooming with scroll\n staticPlot: false, // Enable interactivity\n };\n\n return (\n <div \n className=\"plot-container\"\n style={{\n '--selection-color': selectorsColor,\n } as React.CSSProperties}\n >\n <Plot data={plotlyData} layout={layout} config={config} />\n </div>\n );\n}\n\nexport default HistogramPlot;\n","// A test bar plotly plot\nimport React, { lazy } from 'react';\nimport { PlotParams } from 'react-plotly.js';\n\nconst Plot = lazy(() => import('react-plotly.js'));\n\nexport type TestPlotProps = {\n yaxisTitle?: string;\n xaxisTitle?: string;\n}\nexport const TestPlot = (props: TestPlotProps) => {\n const data: PlotParams['data'] = [\n {\n x: [1, 2, 3, 4],\n y: [10, 15, 13, 17],\n type: 'bar' as const,\n marker: { color: 'blue' },\n },\n ];\n\n const layout = {\n title: {text: 'Test Bar Plot'},\n xaxis: { title: {text: props.xaxisTitle ?? 'X Axis'} },\n yaxis: { title: {text: props.yaxisTitle ?? 'Y Axis'} },\n };\n\n return <Plot data={data} layout={layout} />;\n};\n\nexport default TestPlot;\n"],"names":["Plot","lazy","_jsx"],"mappings":";;;;;AAIA,IAAMA,MAAI,GAAGC,UAAI,CAAC,YAAA,EAAM,OAAA,OAAO,iBAAiB,CAAC,CAAA,EAAA,CAAC;AAU3C,IAAM,aAAa,GAAG,UAAC,KAAyB,EAAA;AAGnD,IAAA,IAAA,IAAI,GAMF,KAAK,KANH,EACJ,KAAK,GAKH,KAAK,CAAA,KALF,EACL,UAAU,GAIR,KAAK,CAAA,UAJG,EACV,EAAA,GAGE,KAAK,SAHqB,EAA5B,QAAQ,GAAA,EAAA,KAAA,MAAA,GAAG,iBAAiB,KAAA,EAC5B,EAAA,GAEE,KAAK,CAAA,kBAFyC,EAAhD,kBAAkB,GAAA,EAAA,KAAA,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AE,MAAM,EAAE;AAC1B,SAAA;KACF;AAED,IAAA,IAAM,MAAM,GAAG;AACb,QAAA,KAAK,EAAE,EAAC,IAAI,EAAE,eAAe,EAAC;AAC9B,QAAA,KAAK,EAAE,EAAE,KAAK,EAAE,EAAC,IAAI,EAAE,CAAA,EAAA,GAAA,KAAK,CAAC,UAAU,MAAA,IAAA,IAAA,EAAA,KAAA,MAAA,GAAA,EAAA,GAAI,QAAQ,EAAC,EAAE;AACtD,QAAA,KAAK,EAAE,EAAE,KAAK,EAAE,EAAC,IAAI,EAAE,CAAA,EAAA,GAAA,KAAK,CAAC,UAAU,MAAA,IAAA,IAAA,EAAA,KAAA,MAAA,GAAA,EAAA,GAAI,QAAQ,EAAC,EAAE;KACvD;IAED,OAAOC,cAAA,CAAC,IAAI,EAAA,EAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAA,CAAI;AAC7C;;;;;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "td-plots",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Custom React plotting components built with Plotly.js",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/asizemore/td-plots"
|
|
8
|
+
},
|
|
9
|
+
"main": "dist/index.js",
|
|
10
|
+
"module": "dist/index.esm.js",
|
|
11
|
+
"types": "dist/index.d.ts",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"keywords": [
|
|
16
|
+
"react",
|
|
17
|
+
"plotly",
|
|
18
|
+
"charts",
|
|
19
|
+
"histogram",
|
|
20
|
+
"visualization"
|
|
21
|
+
],
|
|
22
|
+
"author": "Ann Blevins",
|
|
23
|
+
"license": "ISC",
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"react": ">=18.0.0",
|
|
26
|
+
"react-dom": ">=18.0.0"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"plotly.js": "^3.0.1",
|
|
30
|
+
"react-plotly.js": "^2.6.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@chromatic-com/storybook": "^4.0.1",
|
|
34
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
|
35
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
36
|
+
"@rollup/plugin-typescript": "^12.0.0",
|
|
37
|
+
"@storybook/addon-a11y": "^9.0.13",
|
|
38
|
+
"@storybook/addon-docs": "^9.0.13",
|
|
39
|
+
"@storybook/addon-onboarding": "^9.0.13",
|
|
40
|
+
"@storybook/addon-vitest": "^9.0.13",
|
|
41
|
+
"@storybook/react": "9.0.9",
|
|
42
|
+
"@storybook/react-vite": "^9.0.13",
|
|
43
|
+
"@testing-library/jest-dom": "^6.6.3",
|
|
44
|
+
"@testing-library/react": "^16.3.0",
|
|
45
|
+
"@types/node": "^24.0.4",
|
|
46
|
+
"@types/plotly.js": "^3.0.2",
|
|
47
|
+
"@types/react": "^19.1.8",
|
|
48
|
+
"@types/react-dom": "^19.1.6",
|
|
49
|
+
"@types/react-plotly.js": "^2.6.3",
|
|
50
|
+
"@vitejs/plugin-react": "^4.6.0",
|
|
51
|
+
"@vitest/browser": "^3.2.4",
|
|
52
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
53
|
+
"@vitest/ui": "^3.2.4",
|
|
54
|
+
"dotenv": "^16.5.0",
|
|
55
|
+
"jsdom": "^26.1.0",
|
|
56
|
+
"playwright": "^1.53.1",
|
|
57
|
+
"react": "^19.1.0",
|
|
58
|
+
"react-dom": "^19.1.0",
|
|
59
|
+
"rollup": "^4.9.0",
|
|
60
|
+
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
61
|
+
"rollup-plugin-postcss": "^4.0.2",
|
|
62
|
+
"sass": "^1.69.0",
|
|
63
|
+
"storybook": "^9.0.13",
|
|
64
|
+
"ts-node": "^10.9.2",
|
|
65
|
+
"typescript": "^5.8.3",
|
|
66
|
+
"vite": "^5.4.19",
|
|
67
|
+
"vitest": "^3.2.4",
|
|
68
|
+
"vitest-browser-react": "^1.0.0",
|
|
69
|
+
"vitest-plugin": "link:@storybook/addon-vitest/vitest-plugin"
|
|
70
|
+
},
|
|
71
|
+
"scripts": {
|
|
72
|
+
"build": "npm run clean && npm run build:rollup && npm run build:types",
|
|
73
|
+
"build:rollup": "rollup -c",
|
|
74
|
+
"build:types": "tsc --project tsconfig.build.json --emitDeclarationOnly",
|
|
75
|
+
"clean": "rm -rf dist",
|
|
76
|
+
"test": "vitest run",
|
|
77
|
+
"storybook": "storybook dev -p 6006",
|
|
78
|
+
"build-storybook": "storybook build"
|
|
79
|
+
}
|
|
80
|
+
}
|