@publishfx/publish-chart 2.1.23 → 2.1.25
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/adapters/DataAdapter.js +10 -1
- package/dist/components/g2/base/G2CombineChart.js +1 -1
- package/dist/components/g2/base/g2Helpers.d.ts +3 -1
- package/dist/components/g2/base/g2Helpers.js +10 -5
- package/dist/components/g2/base/g2bar.js +3 -2
- package/dist/components/g2/base/g2combine.js +8 -5
- package/dist/components/g2/base/g2line.js +4 -2
- package/package.json +1 -1
|
@@ -159,7 +159,16 @@ class DataAdapter {
|
|
|
159
159
|
}
|
|
160
160
|
});
|
|
161
161
|
const xKey = config.x ?? 'x';
|
|
162
|
-
|
|
162
|
+
if (config.isDescend) {
|
|
163
|
+
const sortData = tdv.rows.map((item)=>item[xKey]);
|
|
164
|
+
combinedv.rows.sort((a, b)=>{
|
|
165
|
+
const aIndex = sortData.indexOf(a[xKey]);
|
|
166
|
+
const bIndex = sortData.indexOf(b[xKey]);
|
|
167
|
+
if (-1 === aIndex) return 1;
|
|
168
|
+
if (-1 === bIndex) return -1;
|
|
169
|
+
return aIndex - bIndex;
|
|
170
|
+
});
|
|
171
|
+
} else combinedv.rows.sort((a, b)=>{
|
|
163
172
|
const aIndex = allKeys.has(a[xKey]) ? Array.from(allKeys).indexOf(a[xKey]) : -1;
|
|
164
173
|
const bIndex = allKeys.has(b[xKey]) ? Array.from(allKeys).indexOf(b[xKey]) : -1;
|
|
165
174
|
if (-1 === aIndex) return 1;
|
|
@@ -183,7 +183,7 @@ const G2CombineChart = ({ height = 300, data, x = "", y = "", z = "", indicatorM
|
|
|
183
183
|
percent: ""
|
|
184
184
|
});
|
|
185
185
|
});
|
|
186
|
-
groupData.sort((a, b)=>xKey.indexOf(a.groupName) - xKey.indexOf(b.groupName));
|
|
186
|
+
if (!isDescend) groupData.sort((a, b)=>xKey.indexOf(a.groupName) - xKey.indexOf(b.groupName));
|
|
187
187
|
groupResult = groupResult.concat(groupData);
|
|
188
188
|
});
|
|
189
189
|
groupResult.forEach((item)=>{
|
|
@@ -275,9 +275,11 @@ export declare function applyLegendColor(view: any, options?: ApplyLegendColorOp
|
|
|
275
275
|
export interface AuxiliaryLineItem {
|
|
276
276
|
name: string;
|
|
277
277
|
value: number;
|
|
278
|
-
axis?: 'left' | 'right';
|
|
278
|
+
axis?: 'left' | 'right' | '';
|
|
279
279
|
}
|
|
280
280
|
export interface ApplyAuxiliaryLineYOptions {
|
|
281
|
+
maxLeft?: number;
|
|
282
|
+
maxRight?: number;
|
|
281
283
|
stroke?: string;
|
|
282
284
|
strokeOpacity?: number;
|
|
283
285
|
labelMaxLength?: number;
|
|
@@ -146,22 +146,27 @@ function applyLegendColor(view, options = {}) {
|
|
|
146
146
|
}
|
|
147
147
|
function applyAuxiliaryLineY(view, lines, options = {}) {
|
|
148
148
|
if (!lines?.length) return;
|
|
149
|
-
const {
|
|
149
|
+
const { labelMaxLength = 5, stroke = 'rgb(234, 54, 106)', maxLeft, maxRight } = options;
|
|
150
150
|
lines.forEach((auxLine)=>{
|
|
151
151
|
view.lineY().data([
|
|
152
152
|
{
|
|
153
153
|
y: auxLine.value
|
|
154
154
|
}
|
|
155
|
-
]).encode('y', auxLine.value).style('stroke', stroke).style('strokeOpacity',
|
|
155
|
+
]).encode('y', auxLine.value).style('stroke', stroke).style('strokeOpacity', 1).style('opacity', 1).style('lineWidth', 2).style('shadowColor', 'transparent').animate(false).scale('y', {
|
|
156
156
|
key: auxLine?.axis === 'right' ? 'line' : 'main'
|
|
157
157
|
}).axis('x', false).label({
|
|
158
158
|
opacity: 1,
|
|
159
|
-
dx:
|
|
159
|
+
dx: -20,
|
|
160
160
|
dy: 0,
|
|
161
161
|
text: splitTextToMultiline(auxLine.name, labelMaxLength, '<br />'),
|
|
162
162
|
position: auxLine?.axis === 'right' ? 'bottom-right' : 'bottom-left',
|
|
163
|
-
render: (text)
|
|
164
|
-
|
|
163
|
+
render: (text)=>{
|
|
164
|
+
let top = auxLine?.name?.length > 5 ? -38 : -24;
|
|
165
|
+
if ((auxLine?.axis === 'left' || auxLine?.axis === '') && maxLeft && auxLine.value > 0.92 * maxLeft || auxLine?.axis === 'right' && maxRight && auxLine.value > 0.92 * maxRight) top = 0;
|
|
166
|
+
top += 'px';
|
|
167
|
+
return `<div style="background-color: rgba(255, 0, 102, 0.15); padding: 5px; border-radius: 5px;font-size: 12px;position: absolute;left: ${auxLine?.axis === 'right' ? '-75px' : '0px'}; top: ${top} ; display:inline-block; min-width: 65px; line-height: 14px; color: #FF0066;
|
|
168
|
+
font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;">${text}</div>`;
|
|
169
|
+
}
|
|
165
170
|
});
|
|
166
171
|
});
|
|
167
172
|
}
|
|
@@ -19,7 +19,7 @@ function renderG2BarChart(container, options) {
|
|
|
19
19
|
insetBottom: 0
|
|
20
20
|
});
|
|
21
21
|
const view = getMainView(chart);
|
|
22
|
-
view.attr('marginLeft', 0).attr('marginRight', isHorizontal ? 30 :
|
|
22
|
+
view.attr('marginLeft', 0).attr('marginRight', isHorizontal ? 30 : 30).attr('marginTop', 10).attr('marginBottom', isLegend ? 0 : 16);
|
|
23
23
|
if (isHorizontal) view.coordinate({
|
|
24
24
|
transform: [
|
|
25
25
|
{
|
|
@@ -131,7 +131,8 @@ function renderG2BarChart(container, options) {
|
|
|
131
131
|
}
|
|
132
132
|
});
|
|
133
133
|
applyAuxiliaryLineY(view, auxiliaryLineData, {
|
|
134
|
-
labelMaxLength: 5
|
|
134
|
+
labelMaxLength: 5,
|
|
135
|
+
maxLeft: maxY
|
|
135
136
|
});
|
|
136
137
|
const nodeResult = applyNodeData(view, nodeData, x, y);
|
|
137
138
|
if (isDataTag && formatLabel) interval.label({
|
|
@@ -17,7 +17,7 @@ function renderG2CombineChart(container, options) {
|
|
|
17
17
|
animate: null
|
|
18
18
|
});
|
|
19
19
|
const view = getMainView(chart);
|
|
20
|
-
view.attr('
|
|
20
|
+
view.attr('marginLeft', 0).attr('marginRight', 30).attr('marginTop', 26).attr('marginBottom', 0).animate(false);
|
|
21
21
|
view.data(data);
|
|
22
22
|
const xValueCount = new Set(data.map((d)=>d[x])).size;
|
|
23
23
|
applyAxisX(view, {
|
|
@@ -104,7 +104,7 @@ function renderG2CombineChart(container, options) {
|
|
|
104
104
|
const groupType = String(datum.groupType ?? '');
|
|
105
105
|
const index = legendItems.findIndex((item)=>item.id === `${groupType}_${datum.isCombine}`);
|
|
106
106
|
return {
|
|
107
|
-
value: datum[BAR_Y_FIELD],
|
|
107
|
+
value: null === datum[BAR_Y_FIELD] ? '-' : datum[BAR_Y_FIELD],
|
|
108
108
|
name: datum['groupType'],
|
|
109
109
|
indicatorId,
|
|
110
110
|
channel: Y_AXIS_FIELD,
|
|
@@ -116,7 +116,7 @@ function renderG2CombineChart(container, options) {
|
|
|
116
116
|
}
|
|
117
117
|
].filter(Boolean) : [
|
|
118
118
|
(datum)=>datum.groupType.includes('_compare') ? false : {
|
|
119
|
-
value: datum[BAR_Y_FIELD],
|
|
119
|
+
value: null === datum[BAR_Y_FIELD] ? '-' : datum[BAR_Y_FIELD],
|
|
120
120
|
name: datum['groupType'],
|
|
121
121
|
indicatorId: datum['groupType'],
|
|
122
122
|
channel: Y_AXIS_FIELD,
|
|
@@ -167,7 +167,7 @@ function renderG2CombineChart(container, options) {
|
|
|
167
167
|
(datum)=>{
|
|
168
168
|
const item = legendItems.find((item)=>item.id === `${datum?.groupType}_${datum?.isCombine}`);
|
|
169
169
|
return {
|
|
170
|
-
value: datum[LINE_Y_FIELD],
|
|
170
|
+
value: null === datum[LINE_Y_FIELD] ? '-' : datum[LINE_Y_FIELD],
|
|
171
171
|
name: getIndicatorCompareName(_indicatorMap, datum['groupType']),
|
|
172
172
|
indicatorId: datum['groupType'],
|
|
173
173
|
channel: Y_AXIS_FIELD,
|
|
@@ -298,7 +298,10 @@ function renderG2CombineChart(container, options) {
|
|
|
298
298
|
tipFontSize: '12px',
|
|
299
299
|
tipBoxShadow: '0 3px 6px -4px rgba(0, 0, 0, 1)'
|
|
300
300
|
});
|
|
301
|
-
applyAuxiliaryLineY(view, auxiliaryLineData
|
|
301
|
+
applyAuxiliaryLineY(view, auxiliaryLineData, {
|
|
302
|
+
maxLeft,
|
|
303
|
+
maxRight
|
|
304
|
+
});
|
|
302
305
|
const nodeResult = applyNodeData(view, nodeData, x, 'groupValue');
|
|
303
306
|
if (formatLabel) {
|
|
304
307
|
if (isDataTag) {
|
|
@@ -17,7 +17,7 @@ function renderG2LineChart(container, options) {
|
|
|
17
17
|
insetBottom: 0
|
|
18
18
|
});
|
|
19
19
|
const view = getMainView(chart);
|
|
20
|
-
view.attr('marginLeft', 0).attr('marginRight',
|
|
20
|
+
view.attr('marginLeft', 0).attr('marginRight', 30).attr('marginTop', 10).attr('marginBottom', isLegend ? 0 : 16).animate(false);
|
|
21
21
|
view.data(data);
|
|
22
22
|
const domainMin = minY ?? 0;
|
|
23
23
|
applyScaleYLinear(view, {
|
|
@@ -117,7 +117,9 @@ function renderG2LineChart(container, options) {
|
|
|
117
117
|
tipFontSize: '12px',
|
|
118
118
|
tipBoxShadow: '0 3px 6px -4px rgba(0, 0, 0, 1)'
|
|
119
119
|
});
|
|
120
|
-
applyAuxiliaryLineY(view, auxiliaryLineData
|
|
120
|
+
applyAuxiliaryLineY(view, auxiliaryLineData, {
|
|
121
|
+
maxLeft: maxY
|
|
122
|
+
});
|
|
121
123
|
const nodeResult = applyNodeData(view, nodeData, x, y);
|
|
122
124
|
if (isDataTag && formatLabel) {
|
|
123
125
|
line.label({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@publishfx/publish-chart",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.25",
|
|
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": [
|