@optilogic/charts 1.3.9 → 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.js
CHANGED
|
@@ -1782,6 +1782,9 @@ FunnelChart.displayName = "FunnelChart";
|
|
|
1782
1782
|
var ROW_HEIGHT_DEFAULT = 36;
|
|
1783
1783
|
var LABEL_WIDTH_DEFAULT = 160;
|
|
1784
1784
|
var HEADER_HEIGHT = 32;
|
|
1785
|
+
var MIN_LABEL_SPACING = 64;
|
|
1786
|
+
var FALLBACK_CHART_WIDTH = 640;
|
|
1787
|
+
var MIN_CHART_WIDTH = 320;
|
|
1785
1788
|
function getTimeBounds(tasks, milestones) {
|
|
1786
1789
|
let min = Infinity;
|
|
1787
1790
|
let max = -Infinity;
|
|
@@ -1843,6 +1846,7 @@ var GanttChart = React17.forwardRef(
|
|
|
1843
1846
|
onTaskClick
|
|
1844
1847
|
}, ref) {
|
|
1845
1848
|
const containerRef = React17.useRef(null);
|
|
1849
|
+
const [containerWidth, setContainerWidth] = React17.useState(0);
|
|
1846
1850
|
const [hoveredId, setHoveredId] = React17.useState(null);
|
|
1847
1851
|
const [tooltipInfo, setTooltipInfo] = React17.useState(null);
|
|
1848
1852
|
const groups = React17.useMemo(() => {
|
|
@@ -1874,10 +1878,27 @@ var GanttChart = React17.forwardRef(
|
|
|
1874
1878
|
() => generateTicks(bounds.min, bounds.max, timeScale),
|
|
1875
1879
|
[bounds, timeScale]
|
|
1876
1880
|
);
|
|
1881
|
+
React17.useEffect(() => {
|
|
1882
|
+
const el = containerRef.current;
|
|
1883
|
+
if (!el || typeof ResizeObserver === "undefined") return;
|
|
1884
|
+
const update = () => setContainerWidth(el.clientWidth);
|
|
1885
|
+
update();
|
|
1886
|
+
const observer = new ResizeObserver(update);
|
|
1887
|
+
observer.observe(el);
|
|
1888
|
+
return () => observer.disconnect();
|
|
1889
|
+
}, []);
|
|
1890
|
+
const chartWidth = Math.max(
|
|
1891
|
+
(containerWidth || labelWidth + FALLBACK_CHART_WIDTH) - labelWidth,
|
|
1892
|
+
MIN_CHART_WIDTH
|
|
1893
|
+
);
|
|
1894
|
+
const labelStep = Math.max(
|
|
1895
|
+
1,
|
|
1896
|
+
Math.ceil(ticks.length / Math.max(1, Math.floor(chartWidth / MIN_LABEL_SPACING)))
|
|
1897
|
+
);
|
|
1877
1898
|
const chartHeight = typeof height === "number" ? height : void 0;
|
|
1878
1899
|
const svgHeight = HEADER_HEIGHT + orderedTasks.length * rowHeight + 8;
|
|
1879
|
-
function xOf(time,
|
|
1880
|
-
return (time - bounds.min) / bounds.span *
|
|
1900
|
+
function xOf(time, width) {
|
|
1901
|
+
return (time - bounds.min) / bounds.span * width;
|
|
1881
1902
|
}
|
|
1882
1903
|
return /* @__PURE__ */ jsxs(
|
|
1883
1904
|
"div",
|
|
@@ -1893,9 +1914,9 @@ var GanttChart = React17.forwardRef(
|
|
|
1893
1914
|
/* @__PURE__ */ jsxs(
|
|
1894
1915
|
"svg",
|
|
1895
1916
|
{
|
|
1896
|
-
width:
|
|
1917
|
+
width: labelWidth + chartWidth,
|
|
1897
1918
|
height: Math.max(svgHeight, chartHeight ?? svgHeight),
|
|
1898
|
-
style: { minWidth: labelWidth +
|
|
1919
|
+
style: { minWidth: labelWidth + MIN_CHART_WIDTH },
|
|
1899
1920
|
children: [
|
|
1900
1921
|
/* @__PURE__ */ jsx(
|
|
1901
1922
|
"rect",
|
|
@@ -1918,7 +1939,8 @@ var GanttChart = React17.forwardRef(
|
|
|
1918
1939
|
}
|
|
1919
1940
|
),
|
|
1920
1941
|
/* @__PURE__ */ jsx("g", { children: ticks.map((tick, i) => {
|
|
1921
|
-
const x = labelWidth + xOf(tick.pos,
|
|
1942
|
+
const x = labelWidth + xOf(tick.pos, chartWidth);
|
|
1943
|
+
const showLabel = i % labelStep === 0;
|
|
1922
1944
|
return /* @__PURE__ */ jsxs("g", { children: [
|
|
1923
1945
|
/* @__PURE__ */ jsx(
|
|
1924
1946
|
"line",
|
|
@@ -1931,7 +1953,7 @@ var GanttChart = React17.forwardRef(
|
|
|
1931
1953
|
strokeDasharray: "2 4"
|
|
1932
1954
|
}
|
|
1933
1955
|
),
|
|
1934
|
-
/* @__PURE__ */ jsx(
|
|
1956
|
+
showLabel && /* @__PURE__ */ jsx(
|
|
1935
1957
|
"text",
|
|
1936
1958
|
{
|
|
1937
1959
|
x: x + 4,
|
|
@@ -1945,8 +1967,8 @@ var GanttChart = React17.forwardRef(
|
|
|
1945
1967
|
}) }),
|
|
1946
1968
|
orderedTasks.map((task, i) => {
|
|
1947
1969
|
const y = HEADER_HEIGHT + i * rowHeight;
|
|
1948
|
-
const barX = labelWidth + xOf(task.start.getTime(),
|
|
1949
|
-
const barW = xOf(task.end.getTime(),
|
|
1970
|
+
const barX = labelWidth + xOf(task.start.getTime(), chartWidth);
|
|
1971
|
+
const barW = xOf(task.end.getTime(), chartWidth) - xOf(task.start.getTime(), chartWidth);
|
|
1950
1972
|
const barH = rowHeight * 0.55;
|
|
1951
1973
|
const barY = y + (rowHeight - barH) / 2;
|
|
1952
1974
|
const color = task.color ?? getChartColor(i);
|
|
@@ -2031,9 +2053,9 @@ var GanttChart = React17.forwardRef(
|
|
|
2031
2053
|
if (fromIdx === void 0) return null;
|
|
2032
2054
|
const toIdx = taskIndex.get(task.id);
|
|
2033
2055
|
const fromTask = orderedTasks[fromIdx];
|
|
2034
|
-
const fromEndX = labelWidth + xOf(fromTask.end.getTime(),
|
|
2056
|
+
const fromEndX = labelWidth + xOf(fromTask.end.getTime(), chartWidth);
|
|
2035
2057
|
const fromY = HEADER_HEIGHT + fromIdx * rowHeight + rowHeight / 2;
|
|
2036
|
-
const toStartX = labelWidth + xOf(task.start.getTime(),
|
|
2058
|
+
const toStartX = labelWidth + xOf(task.start.getTime(), chartWidth);
|
|
2037
2059
|
const toY = HEADER_HEIGHT + toIdx * rowHeight + rowHeight / 2;
|
|
2038
2060
|
const midX = (fromEndX + toStartX) / 2;
|
|
2039
2061
|
return /* @__PURE__ */ jsx("g", { children: /* @__PURE__ */ jsx(
|
|
@@ -2049,8 +2071,8 @@ var GanttChart = React17.forwardRef(
|
|
|
2049
2071
|
) }, `${depId}-${task.id}`);
|
|
2050
2072
|
})
|
|
2051
2073
|
),
|
|
2052
|
-
milestones.map((m
|
|
2053
|
-
const x = labelWidth + xOf(m.date.getTime(),
|
|
2074
|
+
milestones.map((m) => {
|
|
2075
|
+
const x = labelWidth + xOf(m.date.getTime(), chartWidth);
|
|
2054
2076
|
return /* @__PURE__ */ jsxs("g", { children: [
|
|
2055
2077
|
/* @__PURE__ */ jsx(
|
|
2056
2078
|
"line",
|