Skip to content

Commit

Permalink
fix: Use same typing for indexAxis as other charts series (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
wmai authored Sep 25, 2023
1 parent 3e832f7 commit 78a9cd4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -705,8 +705,8 @@ const ScatterPlotChartArgs: Props<DataFrame, ChartOptions> = {
data: {
loading: false,
value: [
{label: 'id-0', x: -10, y: 20},
{label: 'id-1', x: 20, y: -10},
{label: 'id-0', x: -10, y: 20},
{label: 'id-1', x: 20, y: -10},
{label: 'id-2', x: 5, y: 2},
{label: 'id-3', x: 7, y: 3}
],
Expand Down Expand Up @@ -760,7 +760,7 @@ function generateNormalDistribution(n: number, xMean = 0, xStdDev = 1, yMean = 0
const points = [];
for (let i = 0; i < n; i++) {
points.push({
label: `id-${i}`,
label: `id-${i}`,
x: randomNormal(xMean, xStdDev),
y: randomNormal(yMean, yStdDev),
});
Expand All @@ -779,8 +779,8 @@ const ScatterplotNormalDistribChartArgs: Props<DataFrame, ChartOptions> = {
{
label: "Serie 1",
type: ChartSeriesType.Scatter,
valueColumn:"x",
indexAxis:"y",
valueColumn:"y",
indexAxis:"x",
backgroundColor: COLORS.blue,
},
],
Expand All @@ -790,7 +790,7 @@ const ScatterplotNormalDistribChartArgs: Props<DataFrame, ChartOptions> = {
title: {
display: true,
text: "Horizontal axis"
},
},
beginAtZero: true
},
y: {
Expand All @@ -808,6 +808,6 @@ const ScatterplotNormalDistribChartArgs: Props<DataFrame, ChartOptions> = {
},
};
export const ScatterplotNormalDistribChart = {
args: ScatterplotNormalDistribChartArgs,
args: ScatterplotNormalDistribChartArgs,
parameters: {chromatic: { disableSnapshot: true }}
};
5 changes: 4 additions & 1 deletion packages/visualizations/src/components/Chart/datasets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ export default function toDataset(df: DataFrame, s: ChartSeries): ChartDataset {
return {
type: 'scatter',
label: defaultValue(s.label, ''),
data: df.map((entry) => ({ x: entry[s.indexAxis], y: entry[s.valueColumn] })),
data: df.map((entry) => ({
x: entry[defaultValue(s.indexAxis, 'x')],
y: entry[defaultValue(s.valueColumn, 'y')],
})),
datalabels: chartJsDataLabels(s.dataLabels),
backgroundColor: singleChartJsColor(s.backgroundColor),
pointRadius: defaultValue(s.pointRadius, 5),
Expand Down
2 changes: 1 addition & 1 deletion packages/visualizations/src/components/Chart/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export interface Scatter {
type: ChartSeriesType.Scatter;
valueColumn: string;
label?: string;
indexAxis: string;
indexAxis?: 'x' | 'y';
/** Point color */
backgroundColor?: Color | Color[];
pointRadius?: number;
Expand Down

0 comments on commit 78a9cd4

Please sign in to comment.