@optilogic/charts 1.3.8 → 1.3.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +34 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +34 -12
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/specialized/gantt-chart.tsx +56 -19
package/dist/index.cjs
CHANGED
|
@@ -1803,6 +1803,9 @@ FunnelChart.displayName = "FunnelChart";
|
|
|
1803
1803
|
var ROW_HEIGHT_DEFAULT = 36;
|
|
1804
1804
|
var LABEL_WIDTH_DEFAULT = 160;
|
|
1805
1805
|
var HEADER_HEIGHT = 32;
|
|
1806
|
+
var MIN_LABEL_SPACING = 64;
|
|
1807
|
+
var FALLBACK_CHART_WIDTH = 640;
|
|
1808
|
+
var MIN_CHART_WIDTH = 320;
|
|
1806
1809
|
function getTimeBounds(tasks, milestones) {
|
|
1807
1810
|
let min = Infinity;
|
|
1808
1811
|
let max = -Infinity;
|
|
@@ -1864,6 +1867,7 @@ var GanttChart = React17__namespace.forwardRef(
|
|
|
1864
1867
|
onTaskClick
|
|
1865
1868
|
}, ref) {
|
|
1866
1869
|
const containerRef = React17__namespace.useRef(null);
|
|
1870
|
+
const [containerWidth, setContainerWidth] = React17__namespace.useState(0);
|
|
1867
1871
|
const [hoveredId, setHoveredId] = React17__namespace.useState(null);
|
|
1868
1872
|
const [tooltipInfo, setTooltipInfo] = React17__namespace.useState(null);
|
|
1869
1873
|
const groups = React17__namespace.useMemo(() => {
|
|
@@ -1895,10 +1899,27 @@ var GanttChart = React17__namespace.forwardRef(
|
|
|
1895
1899
|
() => generateTicks(bounds.min, bounds.max, timeScale),
|
|
1896
1900
|
[bounds, timeScale]
|
|
1897
1901
|
);
|
|
1902
|
+
React17__namespace.useEffect(() => {
|
|
1903
|
+
const el = containerRef.current;
|
|
1904
|
+
if (!el || typeof ResizeObserver === "undefined") return;
|
|
1905
|
+
const update = () => setContainerWidth(el.clientWidth);
|
|
1906
|
+
update();
|
|
1907
|
+
const observer = new ResizeObserver(update);
|
|
1908
|
+
observer.observe(el);
|
|
1909
|
+
return () => observer.disconnect();
|
|
1910
|
+
}, []);
|
|
1911
|
+
const chartWidth = Math.max(
|
|
1912
|
+
(containerWidth || labelWidth + FALLBACK_CHART_WIDTH) - labelWidth,
|
|
1913
|
+
MIN_CHART_WIDTH
|
|
1914
|
+
);
|
|
1915
|
+
const labelStep = Math.max(
|
|
1916
|
+
1,
|
|
1917
|
+
Math.ceil(ticks.length / Math.max(1, Math.floor(chartWidth / MIN_LABEL_SPACING)))
|
|
1918
|
+
);
|
|
1898
1919
|
const chartHeight = typeof height === "number" ? height : void 0;
|
|
1899
1920
|
const svgHeight = HEADER_HEIGHT + orderedTasks.length * rowHeight + 8;
|
|
1900
|
-
function xOf(time,
|
|
1901
|
-
return (time - bounds.min) / bounds.span *
|
|
1921
|
+
function xOf(time, width) {
|
|
1922
|
+
return (time - bounds.min) / bounds.span * width;
|
|
1902
1923
|
}
|
|
1903
1924
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1904
1925
|
"div",
|
|
@@ -1914,9 +1935,9 @@ var GanttChart = React17__namespace.forwardRef(
|
|
|
1914
1935
|
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1915
1936
|
"svg",
|
|
1916
1937
|
{
|
|
1917
|
-
width:
|
|
1938
|
+
width: labelWidth + chartWidth,
|
|
1918
1939
|
height: Math.max(svgHeight, chartHeight ?? svgHeight),
|
|
1919
|
-
style: { minWidth: labelWidth +
|
|
1940
|
+
style: { minWidth: labelWidth + MIN_CHART_WIDTH },
|
|
1920
1941
|
children: [
|
|
1921
1942
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1922
1943
|
"rect",
|
|
@@ -1939,7 +1960,8 @@ var GanttChart = React17__namespace.forwardRef(
|
|
|
1939
1960
|
}
|
|
1940
1961
|
),
|
|
1941
1962
|
/* @__PURE__ */ jsxRuntime.jsx("g", { children: ticks.map((tick, i) => {
|
|
1942
|
-
const x = labelWidth + xOf(tick.pos,
|
|
1963
|
+
const x = labelWidth + xOf(tick.pos, chartWidth);
|
|
1964
|
+
const showLabel = i % labelStep === 0;
|
|
1943
1965
|
return /* @__PURE__ */ jsxRuntime.jsxs("g", { children: [
|
|
1944
1966
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1945
1967
|
"line",
|
|
@@ -1952,7 +1974,7 @@ var GanttChart = React17__namespace.forwardRef(
|
|
|
1952
1974
|
strokeDasharray: "2 4"
|
|
1953
1975
|
}
|
|
1954
1976
|
),
|
|
1955
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1977
|
+
showLabel && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1956
1978
|
"text",
|
|
1957
1979
|
{
|
|
1958
1980
|
x: x + 4,
|
|
@@ -1966,8 +1988,8 @@ var GanttChart = React17__namespace.forwardRef(
|
|
|
1966
1988
|
}) }),
|
|
1967
1989
|
orderedTasks.map((task, i) => {
|
|
1968
1990
|
const y = HEADER_HEIGHT + i * rowHeight;
|
|
1969
|
-
const barX = labelWidth + xOf(task.start.getTime(),
|
|
1970
|
-
const barW = xOf(task.end.getTime(),
|
|
1991
|
+
const barX = labelWidth + xOf(task.start.getTime(), chartWidth);
|
|
1992
|
+
const barW = xOf(task.end.getTime(), chartWidth) - xOf(task.start.getTime(), chartWidth);
|
|
1971
1993
|
const barH = rowHeight * 0.55;
|
|
1972
1994
|
const barY = y + (rowHeight - barH) / 2;
|
|
1973
1995
|
const color = task.color ?? getChartColor(i);
|
|
@@ -2052,9 +2074,9 @@ var GanttChart = React17__namespace.forwardRef(
|
|
|
2052
2074
|
if (fromIdx === void 0) return null;
|
|
2053
2075
|
const toIdx = taskIndex.get(task.id);
|
|
2054
2076
|
const fromTask = orderedTasks[fromIdx];
|
|
2055
|
-
const fromEndX = labelWidth + xOf(fromTask.end.getTime(),
|
|
2077
|
+
const fromEndX = labelWidth + xOf(fromTask.end.getTime(), chartWidth);
|
|
2056
2078
|
const fromY = HEADER_HEIGHT + fromIdx * rowHeight + rowHeight / 2;
|
|
2057
|
-
const toStartX = labelWidth + xOf(task.start.getTime(),
|
|
2079
|
+
const toStartX = labelWidth + xOf(task.start.getTime(), chartWidth);
|
|
2058
2080
|
const toY = HEADER_HEIGHT + toIdx * rowHeight + rowHeight / 2;
|
|
2059
2081
|
const midX = (fromEndX + toStartX) / 2;
|
|
2060
2082
|
return /* @__PURE__ */ jsxRuntime.jsx("g", { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -2070,8 +2092,8 @@ var GanttChart = React17__namespace.forwardRef(
|
|
|
2070
2092
|
) }, `${depId}-${task.id}`);
|
|
2071
2093
|
})
|
|
2072
2094
|
),
|
|
2073
|
-
milestones.map((m
|
|
2074
|
-
const x = labelWidth + xOf(m.date.getTime(),
|
|
2095
|
+
milestones.map((m) => {
|
|
2096
|
+
const x = labelWidth + xOf(m.date.getTime(), chartWidth);
|
|
2075
2097
|
return /* @__PURE__ */ jsxRuntime.jsxs("g", { children: [
|
|
2076
2098
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2077
2099
|
"line",
|