Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions components/chart/area/area-chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
TooltipComponent
} from 'echarts/components';
import * as echarts from 'echarts/core';
import { parse, stringify } from 'zrender/lib/tool/color';
import React, { useEffect, useMemo, useRef } from 'react';
import { View } from 'react-native';
import { getAxis, valueAxisBoundsFromProps, categoryAxisBoundsFromProps } from '../axis';
Expand All @@ -39,6 +40,12 @@ echarts.use([
LineChart,
]);

const applyOpacity = (colorStr: string, opacity: number) => {
const rgba = parse(colorStr);
if (!rgba) return colorStr;
return stringify([rgba[0], rgba[1], rgba[2], opacity], 'rgba');
};

const ChartComponent = ({
data,
width = 220,
Expand Down Expand Up @@ -67,6 +74,8 @@ const ChartComponent = ({
yAxisTickLabelFormatter,
xAxisLabel,
yAxisLabel,
xAxisNameGap,
yAxisNameGap,
minX,
maxX,
intervalX,
Expand Down Expand Up @@ -205,7 +214,7 @@ const ChartComponent = ({
...(xAxisLabel != null && xAxisLabel !== '' && {
name: xAxisLabel,
nameLocation: 'middle',
nameGap: 25,
nameGap: xAxisNameGap ?? 25,
nameTextStyle: { color: theme.axis.x.tickLabelColor },
}),
axisLabel: {
Expand Down Expand Up @@ -253,7 +262,7 @@ const ChartComponent = ({
...(yAxisLabel != null && yAxisLabel !== '' && {
name: yAxisLabel,
nameLocation: 'middle',
nameGap: 40,
nameGap: yAxisNameGap ?? 40,
nameTextStyle: { color: theme.axis.y.tickLabelColor },
}),
axisLabel: {
Expand Down Expand Up @@ -309,11 +318,9 @@ const ChartComponent = ({
const seriesColor = theme.series[index % theme.series.length].color;
const seriesLineWidth = theme.series[index]?.lineWidth ?? theme.series[0].lineWidth ?? 2;

// Convert opacity (0-1) to hex (00-FF)
const opacityHex = Math.round(areaOpacity * 255).toString(16).padStart(2, '0');
const colorWithOpacity = seriesColor + opacityHex;
const transparentColor = seriesColor + '00';
const solidColor = seriesColor + 'ff';
const colorWithOpacity = applyOpacity(seriesColor, areaOpacity);
const transparentColor = applyOpacity(seriesColor, 0);
const solidColor = applyOpacity(seriesColor, 1);

const areaStyleConfig =
areaFill === 'gradient'
Expand Down Expand Up @@ -451,6 +458,8 @@ const ChartComponent = ({
yAxisTickLabelFormatter,
xAxisLabel,
yAxisLabel,
xAxisNameGap,
yAxisNameGap,
valueAxisBounds,
categoryAxisBounds,
]);
Expand Down
8 changes: 6 additions & 2 deletions components/chart/bubble/bubble-chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ const ChartComponent = ({
yAxisTickLabelFormatter,
xAxisLabel,
yAxisLabel,
xAxisNameGap,
yAxisNameGap,
minX,
maxX,
intervalX,
Expand Down Expand Up @@ -172,7 +174,7 @@ const ChartComponent = ({
...(xAxisLabel != null && xAxisLabel !== '' && {
name: xAxisLabel,
nameLocation: 'middle',
nameGap: 25,
nameGap: xAxisNameGap ?? 25,
nameTextStyle: { color: theme.axis.x.tickLabelColor },
}),
axisLabel: {
Expand Down Expand Up @@ -211,7 +213,7 @@ const ChartComponent = ({
...(yAxisLabel != null && yAxisLabel !== '' && {
name: yAxisLabel,
nameLocation: 'middle',
nameGap: 40,
nameGap: yAxisNameGap ?? 40,
nameTextStyle: { color: theme.axis.y.tickLabelColor },
}),
axisLabel: {
Expand Down Expand Up @@ -336,6 +338,8 @@ const ChartComponent = ({
yAxisTickLabelFormatter,
xAxisLabel,
yAxisLabel,
xAxisNameGap,
yAxisNameGap,
valueAxisBounds,
xAxisBounds,
]);
Expand Down
8 changes: 6 additions & 2 deletions components/chart/candlestick/candlestick-chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ const ChartComponent = ({
yAxisTickLabelFormatter,
xAxisLabel,
yAxisLabel,
xAxisNameGap,
yAxisNameGap,
minX,
maxX,
intervalX,
Expand Down Expand Up @@ -125,7 +127,7 @@ const ChartComponent = ({
...(xAxisLabel != null && xAxisLabel !== '' && {
name: xAxisLabel,
nameLocation: 'middle',
nameGap: 25,
nameGap: xAxisNameGap ?? 25,
nameTextStyle: { color: theme.axis.x.tickLabelColor },
}),
axisLabel: {
Expand Down Expand Up @@ -161,7 +163,7 @@ const ChartComponent = ({
...(yAxisLabel != null && yAxisLabel !== '' && {
name: yAxisLabel,
nameLocation: 'middle',
nameGap: 40,
nameGap: yAxisNameGap ?? 40,
nameTextStyle: { color: theme.axis.y.tickLabelColor },
}),
axisLabel: {
Expand Down Expand Up @@ -316,6 +318,8 @@ const ChartComponent = ({
yAxisTickLabelFormatter,
xAxisLabel,
yAxisLabel,
xAxisNameGap,
yAxisNameGap,
minX,
maxX,
intervalX,
Expand Down
10 changes: 8 additions & 2 deletions components/chart/column/column-chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ const ChartComponent = ({
yAxisTickLabelFormatter,
xAxisLabel,
yAxisLabel,
xAxisNameGap,
yAxisNameGap,
minX,
maxX,
intervalX,
Expand Down Expand Up @@ -233,13 +235,15 @@ const ChartComponent = ({
const categoryTickFormatter = horizontal ? yAxisTickLabelFormatter : xAxisTickLabelFormatter;
const categoryAxisTheme = horizontal ? theme.axis.y : theme.axis.x;
const categoryAxisTitle = horizontal ? yAxisLabel : xAxisLabel;
const categoryAxisNameGap = horizontal ? yAxisNameGap : xAxisNameGap;

const valueShow = horizontal ? showXAxis : showYAxis;
const valueShowTicks = horizontal ? showXAxisTicks : showYAxisTicks;
const valueShowSplitLines = horizontal ? showXAxisSplitLines : showYAxisSplitLines;
const valueTickFormatter = horizontal ? xAxisTickLabelFormatter : yAxisTickLabelFormatter;
const valueAxisTheme = horizontal ? theme.axis.x : theme.axis.y;
const valueAxisTitle = horizontal ? xAxisLabel : yAxisLabel;
const valueAxisNameGap = horizontal ? xAxisNameGap : yAxisNameGap;

const categoryAxisConfig: any = {
type: 'category',
Expand All @@ -250,7 +254,7 @@ const ChartComponent = ({
...(categoryAxisTitle != null && categoryAxisTitle !== '' && {
name: categoryAxisTitle,
nameLocation: 'middle',
nameGap: 25,
nameGap: categoryAxisNameGap ?? 25,
nameTextStyle: { color: categoryAxisTheme.tickLabelColor },
}),
axisLabel: {
Expand Down Expand Up @@ -299,7 +303,7 @@ const ChartComponent = ({
...(valueAxisTitle != null && valueAxisTitle !== '' && {
name: valueAxisTitle,
nameLocation: 'middle',
nameGap: 40,
nameGap: valueAxisNameGap ?? 40,
nameTextStyle: { color: valueAxisTheme.tickLabelColor },
}),
axisLabel: {
Expand Down Expand Up @@ -619,6 +623,8 @@ const ChartComponent = ({
yAxisTickLabelFormatter,
xAxisLabel,
yAxisLabel,
xAxisNameGap,
yAxisNameGap,
categoryAxisData,
valueAxisBounds,
categoryAxisBounds,
Expand Down
10 changes: 10 additions & 0 deletions components/chart/props/cartesian.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@ export interface CartesianChartProps extends CommonChartProps {
* @default undefined
*/
yAxisLabel?: string;
/**
* Distance (px) between the X-axis caption ({@link xAxisLabel}) and the axis line/labels.
* @default 25 (category axis); 40 (value axis)
*/
xAxisNameGap?: number;
/**
* Distance (px) between the Y-axis caption ({@link yAxisLabel}) and the axis line/labels.
* @default 25 (category axis); 40 (value axis)
*/
yAxisNameGap?: number;
/**
* Grid positioning configuration.
*/
Expand Down
8 changes: 6 additions & 2 deletions components/chart/scatter/scatter-chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ const ChartComponent = ({
yAxisTickLabelFormatter,
xAxisLabel,
yAxisLabel,
xAxisNameGap,
yAxisNameGap,
minX,
maxX,
intervalX,
Expand Down Expand Up @@ -171,7 +173,7 @@ const ChartComponent = ({
...(xAxisLabel != null && xAxisLabel !== '' && {
name: xAxisLabel,
nameLocation: 'middle',
nameGap: 25,
nameGap: xAxisNameGap ?? 25,
nameTextStyle: { color: theme.axis.x.tickLabelColor },
}),
axisLabel: {
Expand Down Expand Up @@ -213,7 +215,7 @@ const ChartComponent = ({
...(yAxisLabel != null && yAxisLabel !== '' && {
name: yAxisLabel,
nameLocation: 'middle',
nameGap: 40,
nameGap: yAxisNameGap ?? 40,
nameTextStyle: { color: theme.axis.y.tickLabelColor },
}),
axisLabel: {
Expand Down Expand Up @@ -355,6 +357,8 @@ const ChartComponent = ({
yAxisTickLabelFormatter,
xAxisLabel,
yAxisLabel,
xAxisNameGap,
yAxisNameGap,
valueAxisBounds,
categoryAxisBounds,
]);
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"data-visualization",
"data-analysis"
],
"version": "1.0.3",
"version": "1.0.5",
"scripts": {
"start": "expo start",
"reset-project": "node ./scripts/reset-project.js",
Expand All @@ -33,6 +33,7 @@
"web": "expo start --web",
"lint": "expo lint",
"storybook": "storybook dev -p 6006",
"storybook:clean": "rm -rf node_modules/.cache/storybook node_modules/.vite && storybook dev -p 6006",
"build-storybook": "storybook build",
"generate:wmx": "node ./scripts/generate-wmx.js",
"build:lib": "node ./scripts/build-lib.js",
Expand Down
9 changes: 9 additions & 0 deletions stories/area/x-axis/area.x-axis.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ export const XAxisLabel: Story = {
},
};

/** xAxisNameGap — extra distance (px) between the X-axis label and the axis line. */
export const XAxisNameGap: Story = {
args: {
data,
xAxisLabel: 'Month',
xAxisNameGap: 45,
},
};

/** minX and maxX — fixed X-axis extent (category index; six points → narrow window). */
export const FixedMinMax: Story = {
args: {
Expand Down
9 changes: 9 additions & 0 deletions stories/area/y-axis/area.y-axis.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ export const YAxisLabel: Story = {
},
};

/** yAxisNameGap — extra distance (px) between the Y-axis label and the axis line. */
export const YAxisNameGap: Story = {
args: {
data,
yAxisLabel: 'Revenue ($)',
yAxisNameGap: 55,
},
};

/** minY and maxY — fixed value-axis bounds (non-zero min, headroom above the series). */
export const FixedMinMax: Story = {
args: {
Expand Down
9 changes: 9 additions & 0 deletions stories/bar/x-axis/bar.x-axis.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ export const XAxisLabel: Story = {
},
};

/** xAxisNameGap — extra distance (px) between the X-axis label and the axis line. */
export const XAxisNameGap: Story = {
args: {
data,
xAxisLabel: 'Count',
xAxisNameGap: 45,
},
};

/** minX and maxX — fixed value scale along X (bar length) with non-zero min. */
export const FixedMinMax: Story = {
args: {
Expand Down
9 changes: 9 additions & 0 deletions stories/bar/y-axis/bar.y-axis.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ export const YAxisLabel: Story = {
},
};

/** yAxisNameGap — extra distance (px) between the Y-axis label and the axis line. */
export const YAxisNameGap: Story = {
args: {
data,
yAxisLabel: 'Category',
yAxisNameGap: 55,
},
};

/** minY and maxY — fixed category extent (horizontal bar: category index along Y). */
export const FixedMinMax: Story = {
args: {
Expand Down
9 changes: 9 additions & 0 deletions stories/bubble/x-axis/bubble.x-axis.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ export const XAxisLabel: Story = {
},
};

/** xAxisNameGap — extra distance (px) between the X-axis label and the axis line. */
export const XAxisNameGap: Story = {
args: {
data,
xAxisLabel: 'X',
xAxisNameGap: 45,
},
};

/** minX and maxX — fixed numeric X scale (non-zero min; bubble X ≈ 10–30). */
export const FixedMinMax: Story = {
args: {
Expand Down
9 changes: 9 additions & 0 deletions stories/bubble/y-axis/bubble.y-axis.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ export const YAxisLabel: Story = {
},
};

/** yAxisNameGap — extra distance (px) between the Y-axis label and the axis line. */
export const YAxisNameGap: Story = {
args: {
data,
yAxisLabel: 'Y',
yAxisNameGap: 55,
},
};

/** minY and maxY — fixed Y range with non-zero floor (bubble Y is about 15–30). */
export const FixedMinMax: Story = {
args: {
Expand Down
10 changes: 10 additions & 0 deletions stories/candlestick/x-axis/candlestick.x-axis.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ export const XAxisLabel: Story = {
},
};

/** xAxisNameGap — extra distance (px) between the X-axis label and the axis line. */
export const XAxisNameGap: Story = {
args: {
data,
xAxisData,
xAxisLabel: 'Day',
xAxisNameGap: 45,
},
};

/** minX and maxX — fixed category window (five sessions → indices 1–3). */
export const FixedMinMax: Story = {
args: {
Expand Down
Loading