Skip to content

Commit

Permalink
feat: Add support for Category plots with error bars (#1412)
Browse files Browse the repository at this point in the history
- Wasn't adding the error bars in this case
- Needed for deephaven/deephaven-core#2156 to
work
- Needs deephaven/deephaven-core#4202
- Tested with the snippet in the ticket to create the plot:
```
from deephaven.plot.figure import Figure
from deephaven.plot import PlotStyle
from deephaven import new_table
from deephaven.column import int_col, string_col

source = new_table([
    string_col("Categories", ["A", "B", "C"]),
    int_col("Categories2", [1, 2, 3]),
    int_col("Values", [9, 10, 11]),
    int_col("LowerError", [8, 9, 10]),
    int_col("UpperError", [10, 11, 12])
])

v2_plot = Figure().plot_cat(series_name="Categories Plot v2", t=source, category="Categories2", y="Values", y_low="LowerError", y_high="UpperError").show()
```
- Also tested OHLC and existing Bar plots from the core/docs examples to
ensure they looked the same
  • Loading branch information
mofojed authored Jul 20, 2023
1 parent 792faa1 commit 7480280
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/chart/src/ChartUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ class ChartUtils {
static getPlotlyErrorBars(
x: number[],
xLow: number[],
xHigh: number[]
xHigh: number[],
theme = ChartTheme
): ErrorBar {
const array = xHigh.map((value, i) => value - x[i]);
const arrayminus = xLow.map((value, i) => x[i] - value);
Expand All @@ -205,6 +206,7 @@ class ChartUtils {
symmetric: false,
array,
arrayminus,
color: theme.error_band_line_color,
};
}

Expand Down
6 changes: 5 additions & 1 deletion packages/chart/src/FigureChartModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,11 @@ class FigureChartModel extends ChartModel {
}
seriesData.width = width;
}
} else if (plotStyle === dh.plot.SeriesPlotStyle.LINE) {
} else if (
plotStyle === dh.plot.SeriesPlotStyle.LINE ||
plotStyle === dh.plot.SeriesPlotStyle.ERROR_BAR ||
plotStyle === dh.plot.SeriesPlotStyle.BAR
) {
const { x, xLow, xHigh, y, yLow, yHigh } = seriesData;
if (xLow && xHigh && xLow !== x) {
seriesData.error_x = ChartUtils.getPlotlyErrorBars(
Expand Down

0 comments on commit 7480280

Please sign in to comment.