Skip to content

Commit b5781a8

Browse files
authored
Add lineShape option for Line and Area charts (#7582)
Linear Spline Horizontal-Vertical Vertical-Horizontal
1 parent b6f4159 commit b5781a8

File tree

9 files changed

+62
-6
lines changed

9 files changed

+62
-6
lines changed

viz-lib/src/visualizations/chart/Editor/GeneralSettings.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,38 @@ export default function GeneralSettings({ options, data, onOptionsChange }: any)
336336
</Section>
337337
)}
338338

339+
{includes(["line", "area"], options.globalSeriesType) && (
340+
// @ts-expect-error ts-migrate(2745) FIXME: This JSX tag's 'children' prop expects type 'never... Remove this comment to see the full error message
341+
<Section>
342+
<Select
343+
label="Line Shape"
344+
data-test="Chart.LineShape"
345+
defaultValue={options.lineShape}
346+
onChange={(val: any) => onOptionsChange({ lineShape: val })}>
347+
{/* @ts-expect-error ts-migrate(2339) FIXME: Property 'Option' does not exist on type '({ class... Remove this comment to see the full error message */}
348+
<Select.Option value="linear" data-test="Chart.LineShape.Linear">
349+
Linear
350+
{/* @ts-expect-error ts-migrate(2339) FIXME: Property 'Option' does not exist on type '({ class... Remove this comment to see the full error message */}
351+
</Select.Option>
352+
{/* @ts-expect-error ts-migrate(2339) FIXME: Property 'Option' does not exist on type '({ class... Remove this comment to see the full error message */}
353+
<Select.Option value="spline" data-test="Chart.LineShape.Spline">
354+
Spline
355+
{/* @ts-expect-error ts-migrate(2339) FIXME: Property 'Option' does not exist on type '({ class... Remove this comment to see the full error message */}
356+
</Select.Option>
357+
{/* @ts-expect-error ts-migrate(2339) FIXME: Property 'Option' does not exist on type '({ class... Remove this comment to see the full error message */}
358+
<Select.Option value="hv" data-test="Chart.LineShape.HorizontalVertical">
359+
Horizontal-Vertical
360+
{/* @ts-expect-error ts-migrate(2339) FIXME: Property 'Option' does not exist on type '({ class... Remove this comment to see the full error message */}
361+
</Select.Option>
362+
{/* @ts-expect-error ts-migrate(2339) FIXME: Property 'Option' does not exist on type '({ class... Remove this comment to see the full error message */}
363+
<Select.Option value="vh" data-test="Chart.LineShape.VerticalHorizontal">
364+
Vertical-Horizontal
365+
{/* @ts-expect-error ts-migrate(2339) FIXME: Property 'Option' does not exist on type '({ class... Remove this comment to see the full error message */}
366+
</Select.Option>
367+
</Select>
368+
</Section>
369+
)}
370+
339371
{!includes(["custom", "heatmap", "bubble"], options.globalSeriesType) && (
340372
// @ts-expect-error ts-migrate(2745) FIXME: This JSX tag's 'children' prop expects type 'never... Remove this comment to see the full error message
341373
<Section>

viz-lib/src/visualizations/chart/getOptions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const DEFAULT_OPTIONS = {
1818
coefficient: 1,
1919
piesort: true,
2020
color_scheme: "Redash",
21+
lineShape: "linear",
2122

2223
// showDataLabels: false, // depends on chart type
2324
numberFormat: "0,0[.]00000",

viz-lib/src/visualizations/chart/plotly/fixtures/prepareData/line-area/default.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"x": "x",
2121
"y1": "y"
2222
},
23-
"missingValuesAsZero": true
23+
"missingValuesAsZero": true,
24+
"lineShape": "linear"
2425
},
2526
"data": [
2627
{
@@ -46,6 +47,7 @@
4647
"hoverinfo": "text+x+name",
4748
"hover": [],
4849
"text": ["10 ± 0", "20 ± 0", "30 ± 0", "40 ± 0"],
50+
"line": { "shape": "linear" },
4951
"marker": { "color": "red" },
5052
"insidetextfont": { "color": "#ffffff" },
5153
"yaxis": "y"

viz-lib/src/visualizations/chart/plotly/fixtures/prepareData/line-area/keep-missing-values.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"x": "x",
2222
"y1": "y"
2323
},
24-
"missingValuesAsZero": false
24+
"missingValuesAsZero": false,
25+
"lineShape": "linear"
2526
},
2627
"data": [
2728
{
@@ -54,6 +55,7 @@
5455
"hoverinfo": "text+x+name",
5556
"hover": [],
5657
"text": ["10 ± 0", "20 ± 0", "30 ± 0", "40 ± 0"],
58+
"line": { "shape": "linear" },
5759
"marker": { "color": "red" },
5860
"insidetextfont": { "color": "#ffffff" },
5961
"yaxis": "y"
@@ -68,6 +70,7 @@
6870
"hoverinfo": "text+x+name",
6971
"hover": [],
7072
"text": ["", "2 ± 0", "", "4 ± 0"],
73+
"line": { "shape": "linear" },
7174
"marker": { "color": "blue" },
7275
"insidetextfont": { "color": "#ffffff" },
7376
"yaxis": "y"

viz-lib/src/visualizations/chart/plotly/fixtures/prepareData/line-area/missing-values-0.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"x": "x",
2222
"y1": "y"
2323
},
24-
"missingValuesAsZero": true
24+
"missingValuesAsZero": true,
25+
"lineShape": "linear"
2526
},
2627
"data": [
2728
{
@@ -54,6 +55,7 @@
5455
"hoverinfo": "text+x+name",
5556
"hover": [],
5657
"text": ["10 ± 0", "20 ± 0", "30 ± 0", "40 ± 0"],
58+
"line": { "shape": "linear" },
5759
"marker": { "color": "red" },
5860
"insidetextfont": { "color": "#ffffff" },
5961
"yaxis": "y"
@@ -68,6 +70,7 @@
6870
"hoverinfo": "text+x+name",
6971
"hover": [],
7072
"text": ["0", "2 ± 0", "0", "4 ± 0"],
73+
"line": { "shape": "linear" },
7174
"marker": { "color": "blue" },
7275
"insidetextfont": { "color": "#ffffff" },
7376
"yaxis": "y"

viz-lib/src/visualizations/chart/plotly/fixtures/prepareData/line-area/normalized-stacked.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"x": "x",
2222
"y1": "y"
2323
},
24-
"missingValuesAsZero": true
24+
"missingValuesAsZero": true,
25+
"lineShape": "linear"
2526
},
2627
"data": [
2728
{
@@ -56,6 +57,7 @@
5657
"hoverinfo": "text+x+name",
5758
"hover": [],
5859
"text": ["20% (10 ± 0)", "40% (20 ± 0)", "60% (30 ± 0)", "80% (40 ± 0)"],
60+
"line": { "shape": "linear" },
5961
"marker": { "color": "red" },
6062
"insidetextfont": { "color": "#ffffff" },
6163
"yaxis": "y"
@@ -70,6 +72,7 @@
7072
"hoverinfo": "text+x+name",
7173
"hover": [],
7274
"text": ["80% (40 ± 0)", "60% (30 ± 0)", "40% (20 ± 0)", "20% (10 ± 0)"],
75+
"line": { "shape": "linear" },
7376
"marker": { "color": "blue" },
7477
"insidetextfont": { "color": "#ffffff" },
7578
"yaxis": "y"

viz-lib/src/visualizations/chart/plotly/fixtures/prepareData/line-area/normalized.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"x": "x",
2222
"y1": "y"
2323
},
24-
"missingValuesAsZero": true
24+
"missingValuesAsZero": true,
25+
"lineShape": "linear"
2526
},
2627
"data": [
2728
{
@@ -56,6 +57,7 @@
5657
"hoverinfo": "text+x+name",
5758
"hover": [],
5859
"text": ["20% (10 ± 0)", "40% (20 ± 0)", "60% (30 ± 0)", "80% (40 ± 0)"],
60+
"line": { "shape": "linear" },
5961
"marker": { "color": "red" },
6062
"insidetextfont": { "color": "#ffffff" },
6163
"yaxis": "y"
@@ -70,6 +72,7 @@
7072
"hoverinfo": "text+x+name",
7173
"hover": [],
7274
"text": ["80% (40 ± 0)", "60% (30 ± 0)", "40% (20 ± 0)", "20% (10 ± 0)"],
75+
"line": { "shape": "linear" },
7376
"marker": { "color": "blue" },
7477
"insidetextfont": { "color": "#ffffff" },
7578
"yaxis": "y"

viz-lib/src/visualizations/chart/plotly/fixtures/prepareData/line-area/stacked.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"x": "x",
2222
"y1": "y"
2323
},
24-
"missingValuesAsZero": true
24+
"missingValuesAsZero": true,
25+
"lineShape": "linear"
2526
},
2627
"data": [
2728
{
@@ -56,6 +57,7 @@
5657
"hoverinfo": "text+x+name",
5758
"hover": [],
5859
"text": ["10 ± 0", "20 ± 0", "30 ± 0", "40 ± 0"],
60+
"line": { "shape": "linear" },
5961
"marker": { "color": "red" },
6062
"insidetextfont": { "color": "#ffffff" },
6163
"yaxis": "y"
@@ -70,6 +72,7 @@
7072
"hoverinfo": "text+x+name",
7173
"hover": [],
7274
"text": ["1 ± 0", "2 ± 0", "3 ± 0", "4 ± 0"],
75+
"line": { "shape": "linear" },
7376
"marker": { "color": "blue" },
7477
"insidetextfont": { "color": "#ffffff" },
7578
"yaxis": "y"

viz-lib/src/visualizations/chart/plotly/prepareDefaultData.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,17 @@ function prepareBarSeries(series: any, options: any, additionalOptions: any) {
3939

4040
function prepareLineSeries(series: any, options: any) {
4141
series.mode = "lines" + (options.showDataLabels ? "+text" : "");
42+
series.line = {
43+
shape: options.lineShape,
44+
}
4245
return series;
4346
}
4447

4548
function prepareAreaSeries(series: any, options: any) {
4649
series.mode = "lines" + (options.showDataLabels ? "+text" : "");
50+
series.line = {
51+
shape: options.lineShape,
52+
}
4753
series.fill = options.series.stacking ? "tonexty" : "tozeroy";
4854
return series;
4955
}

0 commit comments

Comments
 (0)