@publishfx/publish-chart 2.1.15 → 2.1.18

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.
@@ -15,7 +15,7 @@ import { G2BarLegend } from "./G2BarLegend.js";
15
15
  const G2BarChart = ({ height = 300, data, x = "", y = "", indicatorMap, onChartClick, legend = "", config, nodeSetting = {
16
16
  showType: 0,
17
17
  type: []
18
- }, auxiliaryLineData, highlightDate = [], indicators = [], timeRange })=>{
18
+ }, auxiliaryLineData, highlightDate = [], indicators = [], timeRange, isTooltipContent })=>{
19
19
  const { formatter, dataTransform, config: contextConfig } = useChartContext();
20
20
  const tooltipContainerRef = useG2TooltipContainer();
21
21
  const themeColors = contextConfig?.theme?.colors || [];
@@ -99,7 +99,10 @@ const G2BarChart = ({ height = 300, data, x = "", y = "", indicatorMap, onChartC
99
99
  transformedData,
100
100
  activeIds
101
101
  ]);
102
- const canvasMarginBottom = legendItems.length > 1 ? 2 === nodeSetting.showType ? 32 : 16 : 0;
102
+ const vizBottom = useMemo(()=>isTooltipContent ? 26 : 16, [
103
+ isTooltipContent
104
+ ]);
105
+ const canvasMarginBottom = legendItems.length > 1 ? 2 === nodeSetting.showType ? 32 : vizBottom : 0;
103
106
  useEffect(()=>{
104
107
  if (!containerRef.current || !transformedData.length) return;
105
108
  if (chartRef.current) {
@@ -164,6 +167,16 @@ const G2BarChart = ({ height = 300, data, x = "", y = "", indicatorMap, onChartC
164
167
  title: tooltipTitle
165
168
  });
166
169
  });
170
+ const handleWindowResize = ()=>{
171
+ setTimeout(()=>{
172
+ if (chartRef.current && containerRef.current) {
173
+ const width = containerRef.current.clientWidth;
174
+ const height = containerRef.current.clientHeight;
175
+ chartRef.current.changeSize(width, height);
176
+ }
177
+ }, 100);
178
+ };
179
+ window.addEventListener("resize", handleWindowResize);
167
180
  return ()=>{
168
181
  if (chartRef.current) {
169
182
  chartRef.current.off("plot:click");
@@ -79,8 +79,10 @@ const G2BarLegend = ({ items, activeIds, onChange, pageSize: pageSizeProp, maxLa
79
79
  display: "flex",
80
80
  flexWrap: "nowrap",
81
81
  gap: 8,
82
- maxWidth: "100%",
83
- overflow: "hidden"
82
+ flex: 1,
83
+ minWidth: 0,
84
+ overflow: "hidden",
85
+ justifyContent: "center"
84
86
  },
85
87
  children: visibleItems.map((item)=>{
86
88
  const isActive = activeIds.includes(item.id);
@@ -121,15 +123,23 @@ const G2BarLegend = ({ items, activeIds, onChange, pageSize: pageSizeProp, maxLa
121
123
  borderRadius: 4,
122
124
  cursor: "pointer",
123
125
  userSelect: "none",
126
+ minWidth: 0,
124
127
  opacity: isActive ? 1 : 0.5
125
128
  },
126
129
  children: [
127
130
  marker,
128
131
  /*#__PURE__*/ jsx(Tooltip, {
129
- content: item.label,
130
- disabled: true,
132
+ content: /*#__PURE__*/ jsx("span", {
133
+ style: {
134
+ color: "rgb(80, 89, 104)"
135
+ },
136
+ children: item.label
137
+ }),
138
+ disabled: false,
139
+ color: "white",
131
140
  children: /*#__PURE__*/ jsx("span", {
132
141
  style: {
142
+ maxWidth: 300,
133
143
  overflow: "hidden",
134
144
  textOverflow: "ellipsis",
135
145
  whiteSpace: "nowrap"
@@ -147,7 +157,8 @@ const G2BarLegend = ({ items, activeIds, onChange, pageSize: pageSizeProp, maxLa
147
157
  alignItems: "center",
148
158
  gap: 4,
149
159
  marginLeft: 8,
150
- whiteSpace: "nowrap"
160
+ whiteSpace: "nowrap",
161
+ flexShrink: 0
151
162
  },
152
163
  children: [
153
164
  /*#__PURE__*/ jsx("button", {
@@ -143,7 +143,7 @@ const G2CombineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorM
143
143
  const lineGroupTypeArr = sortedGroupTypes.filter((v)=>"true" === v.split("_")[1]);
144
144
  const items = sortedGroupTypes.map((id, index)=>{
145
145
  const colorIndex = index;
146
- const indicatorId = id.split("_")[0];
146
+ const indicatorId = id.split("_").slice(0, -1).join("_");
147
147
  const isCombine = "true" === id.split("_")[1];
148
148
  const lineGroupTypeIndex = lineGroupTypeArr.indexOf(id);
149
149
  const color = isGroupRef.current ? isCombine ? lineColors[lineGroupTypeIndex] || lineColors[0] : themeColors[colorIndex] || themeColors[0] : 0 === colorIndex ? themeColors[colorIndex] : lineColors[colorIndex - 1];
@@ -192,7 +192,7 @@ const G2CombineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorM
192
192
  groupResult = groupResult.concat(groupData);
193
193
  });
194
194
  groupResult.forEach((item)=>{
195
- item.total = result.filter((d)=>d.groupName === item.groupName).reduce((acc, d)=>acc + ("" === d.groupValue ? 0 : d.groupValue), 0);
195
+ item.total = result.filter((d)=>d.groupName === item.groupName).reduce((acc, d)=>acc + ("" === d.groupValue || "-" === d.groupValue ? 0 : d.groupValue), 0);
196
196
  });
197
197
  return groupResult;
198
198
  }
@@ -226,7 +226,10 @@ const G2CombineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorM
226
226
  filterLeftData,
227
227
  filterRightData
228
228
  ]);
229
- const canvasMarginBottom = legendItems.length > 1 ? 2 === nodeSetting.showType ? 32 : 16 : 0;
229
+ const vizBottom = useMemo(()=>isTooltipContent ? 26 : 16, [
230
+ isTooltipContent
231
+ ]);
232
+ const canvasMarginBottom = legendItems.length > 1 ? 2 === nodeSetting.showType ? 32 : vizBottom : 0;
230
233
  const containerRef = useRef(null);
231
234
  const chartRef = useRef(null);
232
235
  const [viewWidth, setViewWidth] = useState(0);
@@ -311,12 +314,23 @@ const G2CombineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorM
311
314
  title: tooltipTitle
312
315
  });
313
316
  });
317
+ const handleWindowResize = ()=>{
318
+ setTimeout(()=>{
319
+ if (chartRef.current && containerRef.current) {
320
+ const width = containerRef.current.clientWidth;
321
+ const height = containerRef.current.clientHeight;
322
+ chartRef.current.changeSize(width, height);
323
+ }
324
+ }, 100);
325
+ };
326
+ window.addEventListener("resize", handleWindowResize);
314
327
  return ()=>{
315
328
  if (chartRef.current) {
316
329
  chartRef.current.off("plot:click");
317
330
  chartRef.current.destroy();
318
331
  chartRef.current = null;
319
332
  }
333
+ window.removeEventListener("resize", handleWindowResize);
320
334
  };
321
335
  }, [
322
336
  filteredData,
@@ -16,7 +16,7 @@ import { renderG2LineChart } from "./g2line.js";
16
16
  const G2LineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorMap, onChartClick, timeRange, legend = "", config, nodeSetting = {
17
17
  showType: 0,
18
18
  type: []
19
- }, auxiliaryLineData, highlightDate, indicators = [] })=>{
19
+ }, auxiliaryLineData, highlightDate, indicators = [], isTooltipContent })=>{
20
20
  const { formatter, dataTransform, config: contextConfig } = useChartContext();
21
21
  const tooltipContainerRef = useG2TooltipContainer();
22
22
  const themeColors = contextConfig?.theme?.colors || [];
@@ -121,7 +121,10 @@ const G2LineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorMap,
121
121
  transformedData,
122
122
  activeIds
123
123
  ]);
124
- const canvasMarginBottom = legendItems.length > 1 ? 2 === nodeSetting.showType ? 32 : 16 : 0;
124
+ const vizBottom = useMemo(()=>isTooltipContent ? 26 : 16, [
125
+ isTooltipContent
126
+ ]);
127
+ const canvasMarginBottom = legendItems.length > 1 ? 2 === nodeSetting.showType ? 32 : vizBottom : 0;
125
128
  useEffect(()=>{
126
129
  if (!containerRef.current || !filteredData.length) return;
127
130
  if (chartRef.current) {
@@ -191,6 +194,16 @@ const G2LineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorMap,
191
194
  });
192
195
  chart.on("plot:pointerenter:", (event)=>{});
193
196
  }
197
+ const handleWindowResize = ()=>{
198
+ setTimeout(()=>{
199
+ if (chartRef.current && containerRef.current) {
200
+ const width = containerRef.current.clientWidth;
201
+ const height = containerRef.current.clientHeight;
202
+ chartRef.current.changeSize(width, height);
203
+ }
204
+ }, 100);
205
+ };
206
+ window.addEventListener("resize", handleWindowResize);
194
207
  return ()=>{
195
208
  if (chartRef.current) {
196
209
  chartRef.current.off("plot:click");
@@ -298,13 +298,15 @@ export interface GetColorByGroupTypeOptions {
298
298
  export declare function getColorByGroupType(groupType: string, options: GetColorByGroupTypeOptions): string;
299
299
  export declare function applyHighlightDate(view: any, x: string, data: any, highlightDate: string[], isHighlight: boolean): void;
300
300
  export declare function applyNodeData(view: any, nodeData: any[], x: string, y: string): {
301
- pointP: {
302
- x: number;
303
- y: number;
304
- };
305
- pointData: any;
306
- color: string;
307
- }[];
301
+ getNodeList: () => {
302
+ pointP: {
303
+ x: number;
304
+ y: number;
305
+ };
306
+ pointData: any;
307
+ color: string;
308
+ }[];
309
+ };
308
310
  export declare function adjustDomainMax(domainMin: number, domainMax: number): number;
309
311
  export declare const sortByIndicators: (arr: string[], indicators: string[]) => string[];
310
312
  export declare function intervalSort(a: any, b: any): number;
@@ -81,7 +81,7 @@ function applyAxisX(mark, options = {}) {
81
81
  },
82
82
  labelAlign: 'horizontal',
83
83
  labelDx: (_datum, _index, _data)=>0,
84
- labelRender: (datum)=>{
84
+ labelRender: isHorizontal ? void 0 : (datum)=>{
85
85
  let left = '0%';
86
86
  if (datum.value > 0.9) left = '-13%';
87
87
  else if (datum.value < 0.1) left = '10%';
@@ -249,7 +249,9 @@ function applyNodeData(view, nodeData, x, y) {
249
249
  }
250
250
  });
251
251
  });
252
- return nodeList;
252
+ return {
253
+ getNodeList: ()=>nodeList
254
+ };
253
255
  }
254
256
  function adjustDomainMax(domainMin, domainMax) {
255
257
  return domainMax === domainMin ? domainMin > 0 ? 1.1 * domainMax : domainMax + 1000 : domainMax;
@@ -1,7 +1,6 @@
1
1
  import { lines } from "@antv/g-pattern";
2
2
  import { applyAuxiliaryLineY, applyAxisX, applyAxisY, applyHighlightDate, applyNodeData, applyScaleYLinear, createChart, getColorByGroupType, getMainView } from "./g2Helpers.js";
3
3
  const Y_AXIS_FIELD = 'groupValue';
4
- const CLOSE_NODE_DEBUG = false;
5
4
  const CLOSE_HIGHLIGHT_DEBUG = false;
6
5
  function renderG2BarChart(container, options) {
7
6
  const { data, nodeData, x, y, maxY, timeRange: _timeRange, themeColors, indicators = [], indicatorMap: _indicatorMap = {}, formatAxis, highlightDate = [], isDataTag = false, isLegend = true, isHorizontal = false, isHighlight = true, isCompare = false, isClickable = false, legend, formatLabel, height = 300, tooltipRender, auxiliaryLineData = [], onNodeListChange, onChartRender } = options;
@@ -143,10 +142,7 @@ function renderG2BarChart(container, options) {
143
142
  bounding: tooltipBounding
144
143
  });
145
144
  applyAuxiliaryLineY(view, auxiliaryLineData);
146
- if (!CLOSE_NODE_DEBUG) {
147
- const nodeList = applyNodeData(view, nodeData, x, y);
148
- onNodeListChange?.(nodeList);
149
- }
145
+ const nodeResult = applyNodeData(view, nodeData, x, y);
150
146
  if (isDataTag && formatLabel) interval.label({
151
147
  style: {
152
148
  fontWeight: 600
@@ -172,6 +168,7 @@ function renderG2BarChart(container, options) {
172
168
  if (onChartRender && viewCoordinate) onChartRender({
173
169
  layout: viewCoordinate
174
170
  });
171
+ onNodeListChange?.(nodeResult.getNodeList());
175
172
  hasEmittedNodeList = true;
176
173
  });
177
174
  return chart;
@@ -390,8 +390,7 @@ function renderG2CombineChart(container, options) {
390
390
  tipBoxShadow: '0 3px 6px -4px rgba(0, 0, 0, 1)'
391
391
  });
392
392
  applyAuxiliaryLineY(view, auxiliaryLineData);
393
- const nodeList = applyNodeData(view, nodeData, x, 'groupValue');
394
- onNodeListChange?.(nodeList);
393
+ const nodeResult = applyNodeData(view, nodeData, x, 'groupValue');
395
394
  if (formatLabel) {
396
395
  if (isDataTag) {
397
396
  const groupedByX = intervalData.reduce((acc, item)=>{
@@ -442,11 +441,11 @@ function renderG2CombineChart(container, options) {
442
441
  let hasEmittedNodeList = false;
443
442
  chart.on('afterrender', ()=>{
444
443
  if (hasEmittedNodeList) return;
445
- if (onNodeListChange) onNodeListChange(nodeList);
446
444
  const viewLayout = chart.getContext()?.views?.[0]?.layout;
447
445
  if (onChartRender && viewLayout) onChartRender({
448
446
  layout: viewLayout
449
447
  });
448
+ onNodeListChange?.(nodeResult.getNodeList());
450
449
  hasEmittedNodeList = true;
451
450
  });
452
451
  return chart;
@@ -126,8 +126,7 @@ function renderG2LineChart(container, options) {
126
126
  tipBoxShadow: '0 3px 6px -4px rgba(0, 0, 0, 1)'
127
127
  });
128
128
  applyAuxiliaryLineY(view, auxiliaryLineData);
129
- const nodeList = applyNodeData(view, nodeData, x, y);
130
- onNodeListChange?.(nodeList);
129
+ const nodeResult = applyNodeData(view, nodeData, x, y);
131
130
  if (isDataTag && formatLabel) {
132
131
  line.label({
133
132
  dy: -10,
@@ -161,11 +160,11 @@ function renderG2LineChart(container, options) {
161
160
  let hasEmittedNodeList = false;
162
161
  chart.on('afterrender', ()=>{
163
162
  if (hasEmittedNodeList) return;
164
- if (onNodeListChange) onNodeListChange(nodeList);
165
163
  const viewLayout = chart.getContext()?.views?.[0]?.layout;
166
164
  if (onChartRender && viewLayout) onChartRender({
167
165
  layout: viewLayout
168
166
  });
167
+ onNodeListChange?.(nodeResult.getNodeList());
169
168
  hasEmittedNodeList = true;
170
169
  });
171
170
  return chart;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@publishfx/publish-chart",
3
- "version": "2.1.15",
3
+ "version": "2.1.18",
4
4
  "description": "A React chart component library for the Publish platform, including BarChart, LineChart, BarLineChart and other visualization components",
5
5
  "type": "module",
6
6
  "keywords": [