Skip to content

Commit 6035808

Browse files
authored
chore: DH-19612: cherry-pick indicator fixes (#2460)
Fixes from #2344 and #2353
1 parent 4d90873 commit 6035808

File tree

11 files changed

+77
-7
lines changed

11 files changed

+77
-7
lines changed

packages/chart/src/Chart.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ const log = Log.module('Chart');
4444

4545
type ChartSettings = ColumnFormatSettings &
4646
DateTimeFormatSettings & {
47-
decimalFormatOptions?: DecimalColumnFormatterOptions;
48-
integerFormatOptions?: IntegerColumnFormatterOptions;
47+
defaultDecimalFormatOptions?: DecimalColumnFormatterOptions;
48+
defaultIntegerFormatOptions?: IntegerColumnFormatterOptions;
4949
webgl?: boolean;
5050
};
5151

@@ -653,18 +653,21 @@ class Chart extends Component<ChartProps, ChartState> {
653653
const columnFormats = FormatterUtils.getColumnFormats(settings);
654654
const dateTimeFormatterOptions =
655655
FormatterUtils.getDateTimeFormatterOptions(settings);
656-
const { decimalFormatOptions = {}, integerFormatOptions = {} } = settings;
656+
const {
657+
defaultDecimalFormatOptions = {},
658+
defaultIntegerFormatOptions = {},
659+
} = settings;
657660

658661
if (
659662
!deepEqual(this.columnFormats, columnFormats) ||
660663
!deepEqual(this.dateTimeFormatterOptions, dateTimeFormatterOptions) ||
661-
!deepEqual(this.decimalFormatOptions, decimalFormatOptions) ||
662-
!deepEqual(this.integerFormatOptions, integerFormatOptions)
664+
!deepEqual(this.decimalFormatOptions, defaultDecimalFormatOptions) ||
665+
!deepEqual(this.integerFormatOptions, defaultIntegerFormatOptions)
663666
) {
664667
this.columnFormats = FormatterUtils.getColumnFormats(settings);
665668
this.dateTimeFormatterOptions = dateTimeFormatterOptions;
666-
this.decimalFormatOptions = decimalFormatOptions;
667-
this.integerFormatOptions = integerFormatOptions;
669+
this.decimalFormatOptions = defaultDecimalFormatOptions;
670+
this.integerFormatOptions = defaultIntegerFormatOptions;
668671
this.updateFormatter();
669672
}
670673

packages/chart/src/ChartTheme.module.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,9 @@
2121
ocean-color: var(--dh-color-chart-geo-ocean);
2222
lake-color: var(--dh-color-chart-geo-lake);
2323
river-color: var(--dh-color-chart-geo-river);
24+
25+
/* Indicator */
26+
indicator-increasing: var(--dh-color-chart-indicator-increase);
27+
indicator-decreasing: var(--dh-color-chart-indicator-decrease);
28+
indicator-gauge: var(--dh-color-chart-indicator-gauge);
2429
}

packages/chart/src/ChartTheme.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ export interface ChartTheme {
2828
ocean_color: string;
2929
lake_color: string;
3030
river_color: string;
31+
32+
// Indicator
33+
indicator_increasing: string;
34+
indicator_decreasing: string;
35+
indicator_gauge: string;
3136
}
3237

3338
export function defaultChartTheme(): Readonly<ChartTheme> {
@@ -65,6 +70,10 @@ export function defaultChartTheme(): Readonly<ChartTheme> {
6570
ocean_color: chartTheme['ocean-color'],
6671
lake_color: chartTheme['lake-color'],
6772
river_color: chartTheme['river-color'],
73+
// Indicator
74+
indicator_increasing: chartTheme['indicator-increasing'],
75+
indicator_decreasing: chartTheme['indicator-decreasing'],
76+
indicator_gauge: chartTheme['indicator-gauge'],
6877
});
6978
}
7079

packages/chart/src/ChartUtils.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import type {
1717
AxisType as PlotlyAxisType,
1818
MarkerSymbol,
1919
Template,
20+
Delta,
2021
} from 'plotly.js';
2122
import { assertNotNull, bindAllMethods, Range } from '@deephaven/utils';
2223
import { ChartTheme } from './ChartTheme';
@@ -2058,6 +2059,9 @@ class ChartUtils {
20582059
ohlc_increasing,
20592060
ohlc_decreasing,
20602061
title_color,
2062+
indicator_increasing,
2063+
indicator_decreasing,
2064+
indicator_gauge,
20612065
} = theme;
20622066

20632067
return {
@@ -2095,6 +2099,20 @@ class ChartUtils {
20952099
},
20962100
},
20972101
],
2102+
indicator: [
2103+
{
2104+
title: { font: { color: title_color } },
2105+
delta: {
2106+
decreasing: {
2107+
color: indicator_decreasing,
2108+
} as Delta['increasing'],
2109+
increasing: {
2110+
color: indicator_increasing,
2111+
} as Delta['decreasing'],
2112+
},
2113+
gauge: { bar: { color: indicator_gauge } },
2114+
},
2115+
],
20982116
},
20992117
/* eslint-enable camelcase */
21002118
layout: this.makeDefaultLayout(theme),

packages/chart/src/__snapshots__/ChartTheme.test.ts.snap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ exports[`defaultChartTheme should create the default chart theme 1`] = `
66
"colorway": "chartTheme['colorway']",
77
"error_band_line_color": "chartTheme['error-band-line-color']",
88
"gridcolor": "chartTheme['gridcolor']",
9+
"indicator_decreasing": "chartTheme['indicator-decreasing']",
10+
"indicator_gauge": "chartTheme['indicator-gauge']",
11+
"indicator_increasing": "chartTheme['indicator-increasing']",
912
"lake_color": "chartTheme['lake-color']",
1013
"land_color": "chartTheme['land-color']",
1114
"legend_color": "chartTheme['legend-color']",

packages/chart/src/__snapshots__/ChartUtils.test.ts.snap

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,28 @@ exports[`makeDefaultTemplate should create a default template 1`] = `
1212
},
1313
},
1414
],
15+
"indicator": [
16+
{
17+
"delta": {
18+
"decreasing": {
19+
"color": "ChartTheme['indicator_decreasing']",
20+
},
21+
"increasing": {
22+
"color": "ChartTheme['indicator_increasing']",
23+
},
24+
},
25+
"gauge": {
26+
"bar": {
27+
"color": "ChartTheme['indicator_gauge']",
28+
},
29+
},
30+
"title": {
31+
"font": {
32+
"color": "ChartTheme['title_color']",
33+
},
34+
},
35+
},
36+
],
1537
"ohlc": [
1638
{
1739
"decreasing": {

packages/components/src/theme/theme-dark/theme-dark-semantic-chart.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,9 @@
4747
--dh-color-chart-geo-ocean: var(--dh-color-gray-300);
4848
--dh-color-chart-geo-lake: var(--dh-color-blue-200);
4949
--dh-color-chart-geo-river: var(--dh-color-blue-200);
50+
51+
/* Indicator */
52+
--dh-color-chart-indicator-increase: var(--dh-color-visual-green);
53+
--dh-color-chart-indicator-decrease: var(--dh-color-visual-red);
54+
--dh-color-chart-indicator-gauge: var(--dh-color-green-1000);
5055
}

packages/components/src/theme/theme-light/theme-light-semantic-chart.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,9 @@
4747
--dh-color-chart-geo-ocean: var(--dh-color-gray-300);
4848
--dh-color-chart-geo-lake: var(--dh-color-blue-400);
4949
--dh-color-chart-geo-river: var(--dh-color-blue-400);
50+
51+
/* Indicator */
52+
--dh-color-chart-indicator-increase: var(--dh-color-visual-green);
53+
--dh-color-chart-indicator-decrease: var(--dh-color-visual-red);
54+
--dh-color-chart-indicator-gauge: var(--dh-color-green-1000);
5055
}
2.67 KB
Loading
4.66 KB
Loading

0 commit comments

Comments
 (0)