@antv/gpt-vis 1.0.1 → 1.0.2
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/README.md +87 -33
- package/README.zh-CN.md +87 -33
- package/dist/cjs/util/crosshair-axis-labels.d.ts +7 -1
- package/dist/cjs/util/crosshair-axis-labels.js +127 -30
- package/dist/cjs/util/html.d.ts +1 -0
- package/dist/cjs/util/html.js +29 -0
- package/dist/cjs/util/theme.js +3 -3
- package/dist/cjs/util/tokens.js +4 -4
- package/dist/cjs/vis/dual-axes/index.js +18 -0
- package/dist/cjs/vis/funnel/index.d.ts +0 -1
- package/dist/cjs/vis/funnel/index.js +21 -23
- package/dist/cjs/vis/table/index.js +13 -5
- package/dist/esm/util/crosshair-axis-labels.d.ts +7 -1
- package/dist/esm/util/crosshair-axis-labels.js +138 -35
- package/dist/esm/util/html.d.ts +1 -0
- package/dist/esm/util/html.js +3 -0
- package/dist/esm/util/theme.js +3 -3
- package/dist/esm/util/tokens.js +4 -4
- package/dist/esm/vis/dual-axes/index.js +31 -1
- package/dist/esm/vis/funnel/index.d.ts +0 -1
- package/dist/esm/vis/funnel/index.js +15 -14
- package/dist/esm/vis/table/index.js +9 -9
- package/dist/umd/index.min.js +1 -1
- package/package.json +1 -1
|
@@ -94,12 +94,10 @@ export var Funnel = function Funnel(options) {
|
|
|
94
94
|
_config$theme = config.theme,
|
|
95
95
|
theme = _config$theme === void 0 ? chartTheme : _config$theme,
|
|
96
96
|
title = config.title,
|
|
97
|
-
_config$locale = config.locale,
|
|
98
|
-
renderLocale = _config$locale === void 0 ? locale : _config$locale,
|
|
99
97
|
conversionRateLabel = config.conversionRateLabel,
|
|
100
98
|
_config$style = config.style,
|
|
101
99
|
style = _config$style === void 0 ? {} : _config$style;
|
|
102
|
-
var chartLocale = resolveChartLocale(
|
|
100
|
+
var chartLocale = resolveChartLocale(locale);
|
|
103
101
|
var labels = FUNNEL_LABELS[chartLocale];
|
|
104
102
|
var numberFormatter = new Intl.NumberFormat(chartLocale);
|
|
105
103
|
var stageConversionRateLabel = conversionRateLabel !== null && conversionRateLabel !== void 0 ? conversionRateLabel : labels.conversionRate;
|
|
@@ -117,6 +115,7 @@ export var Funnel = function Funnel(options) {
|
|
|
117
115
|
var formatValue = function formatValue(value) {
|
|
118
116
|
return Number.isFinite(value) ? numberFormatter.format(value) : '—';
|
|
119
117
|
};
|
|
118
|
+
var isInverted = data.length > 1 && data[0].value < data[data.length - 1].value;
|
|
120
119
|
var metricsByCategory = new Map(data.map(function (item, index) {
|
|
121
120
|
var previous = data[index - 1];
|
|
122
121
|
return [item.category, {
|
|
@@ -208,14 +207,14 @@ export var Funnel = function Funnel(options) {
|
|
|
208
207
|
lineHeight: 17
|
|
209
208
|
}
|
|
210
209
|
}, {
|
|
211
|
-
text: function text(_d, index) {
|
|
212
|
-
return index
|
|
210
|
+
text: function text(_d, index, items) {
|
|
211
|
+
return (isInverted ? index < items.length - 1 : index > 0) ? '———' : '';
|
|
213
212
|
},
|
|
214
|
-
position: 'top-right',
|
|
213
|
+
position: isInverted ? 'bottom-right' : 'top-right',
|
|
215
214
|
fill: tokens.textSecondary,
|
|
216
215
|
fillOpacity: 0.72,
|
|
217
|
-
dx:
|
|
218
|
-
dy: -6,
|
|
216
|
+
dx: 8,
|
|
217
|
+
dy: isInverted ? 6 : -6,
|
|
219
218
|
style: {
|
|
220
219
|
fontFamily: CHART_FONT_FAMILY,
|
|
221
220
|
fontSize: 8,
|
|
@@ -224,13 +223,15 @@ export var Funnel = function Funnel(options) {
|
|
|
224
223
|
}
|
|
225
224
|
}, {
|
|
226
225
|
text: function text(_d, index, items) {
|
|
227
|
-
|
|
226
|
+
var from = isInverted ? items[index] : items[index - 1];
|
|
227
|
+
var to = isInverted ? items[index + 1] : items[index];
|
|
228
|
+
return from && to ? formatMetricLabel(stageConversionRateLabel, formatConversionRate(from.value, to.value), chartLocale) : '';
|
|
228
229
|
},
|
|
229
|
-
position: 'top-right',
|
|
230
|
+
position: isInverted ? 'bottom-right' : 'top-right',
|
|
230
231
|
textAlign: 'left',
|
|
231
232
|
textBaseline: 'middle',
|
|
232
233
|
fill: tokens.textPrimary,
|
|
233
|
-
dx:
|
|
234
|
+
dx: 26,
|
|
234
235
|
style: {
|
|
235
236
|
fontFamily: CHART_FONT_FAMILY,
|
|
236
237
|
fontSize: 11,
|
|
@@ -257,10 +258,10 @@ export var Funnel = function Funnel(options) {
|
|
|
257
258
|
}].concat(_toConsumableArray(data.length > 1 ? [{
|
|
258
259
|
type: 'connector',
|
|
259
260
|
data: [{
|
|
260
|
-
startX: data[0].category,
|
|
261
|
-
startY: data[data.length - 1].category,
|
|
261
|
+
startX: isInverted ? data[data.length - 1].category : data[0].category,
|
|
262
|
+
startY: isInverted ? data[0].category : data[data.length - 1].category,
|
|
262
263
|
endX: 0,
|
|
263
|
-
endY: (data[0].value - data[data.length - 1].value) / 2
|
|
264
|
+
endY: Math.abs(data[0].value - data[data.length - 1].value) / 2
|
|
264
265
|
}],
|
|
265
266
|
encode: {
|
|
266
267
|
x: 'startX',
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { measureText } from 'measury';
|
|
2
|
+
import { escapeHtml } from "../../util/html";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* TableConfig defines the configuration for rendering the table.
|
|
@@ -14,7 +15,7 @@ var CELL_PADDING = 16; // 8px * 2
|
|
|
14
15
|
var MIN_WIDTH_MULTIPLIER = 1.1;
|
|
15
16
|
|
|
16
17
|
// CSS styles for the table component
|
|
17
|
-
var TABLE_STYLES = "\n .".concat(SCOPE_ID, " {\n font-family: ").concat(FONT_FAMILY, ";\n overflow: auto;\n height: 100%;\n padding: 16px;\n }\n\n .").concat(SCOPE_ID, " .table-title {\n font-size: 16px;\n font-weight: 500;\n margin-bottom: 12px;\n color: #1d2129;\n }\n\n .").concat(SCOPE_ID, " table {\n border-collapse: separate;\n border-spacing: 0;\n background: #fff;\n border-radius: 8px;\n overflow: hidden;\n }\n\n .").concat(SCOPE_ID, " th,\n .").concat(SCOPE_ID, " td {\n border-bottom: 1px solid #f0f0f0;\n padding: 8px;\n text-align: left;\n font-size: 14px;\n color: #333;\n white-space: nowrap;\n }\n\n .").concat(SCOPE_ID, " th {\n background: #f5f5f5;\n font-weight: 600;\n color: #000000e0;\n position: relative;\n }\n\n .").concat(SCOPE_ID, " th:not(:last-child)::after {\n content: '';\n position: absolute;\n top: 25%;\n right: 0;\n width: 1px;\n height: 50%;\n background: #e0e0e0;\n }\n\n .").concat(SCOPE_ID, " tr {\n transition: background 0.2s;\n }\n\n .").concat(SCOPE_ID, " tbody tr:hover {\n background: #f5f5f5;\n cursor: pointer;\n }\n\n .").concat(SCOPE_ID, "[data-theme=\"dark\"] {\n background: #000;\n }\n\n .").concat(SCOPE_ID, "[data-theme=\"dark\"] .table-title {\n color: #ffffffd9;\n }\n\n .").concat(SCOPE_ID, "[data-theme=\"dark\"] table {\n background: #141414;\n }\n\n .").concat(SCOPE_ID, "[data-theme=\"dark\"] th,\n .").concat(SCOPE_ID, "[data-theme=\"dark\"] td {\n border-bottom: 1px solid #303030;\n color: #ffffffd9;\n }\n\n .").concat(SCOPE_ID, "[data-theme=\"dark\"] th {\n background: #1f1f1f;\n color: #ffffffa6;\n }\n\n .").concat(SCOPE_ID, "[data-theme=\"dark\"] th:not(:last-child)::after {\n background: #303030;\n }\n\n .").concat(SCOPE_ID, "[data-theme=\"dark\"] tbody tr:hover {\n background: #1f1f1f;\n }\n");
|
|
18
|
+
var TABLE_STYLES = "\n .".concat(SCOPE_ID, " {\n font-family: ").concat(FONT_FAMILY, ";\n overflow: auto;\n height: 100%;\n padding: 16px;\n }\n\n .").concat(SCOPE_ID, " .table-title {\n font-size: 16px;\n font-weight: 500;\n margin-bottom: 12px;\n color: #1d2129;\n }\n\n .").concat(SCOPE_ID, " .table-empty {\n padding: 20px;\n text-align: center;\n color: #999;\n }\n\n .").concat(SCOPE_ID, " table {\n border-collapse: separate;\n border-spacing: 0;\n background: #fff;\n border-radius: 8px;\n overflow: hidden;\n }\n\n .").concat(SCOPE_ID, " th,\n .").concat(SCOPE_ID, " td {\n border-bottom: 1px solid #f0f0f0;\n padding: 8px;\n text-align: left;\n font-size: 14px;\n color: #333;\n white-space: nowrap;\n }\n\n .").concat(SCOPE_ID, " th {\n background: #f5f5f5;\n font-weight: 600;\n color: #000000e0;\n position: relative;\n }\n\n .").concat(SCOPE_ID, " th:not(:last-child)::after {\n content: '';\n position: absolute;\n top: 25%;\n right: 0;\n width: 1px;\n height: 50%;\n background: #e0e0e0;\n }\n\n .").concat(SCOPE_ID, " tr {\n transition: background 0.2s;\n }\n\n .").concat(SCOPE_ID, " tbody tr:hover {\n background: #f5f5f5;\n cursor: pointer;\n }\n\n .").concat(SCOPE_ID, "[data-theme=\"dark\"] {\n background: #000;\n }\n\n .").concat(SCOPE_ID, "[data-theme=\"dark\"] .table-title {\n color: #ffffffd9;\n }\n\n .").concat(SCOPE_ID, "[data-theme=\"dark\"] table {\n background: #141414;\n }\n\n .").concat(SCOPE_ID, "[data-theme=\"dark\"] th,\n .").concat(SCOPE_ID, "[data-theme=\"dark\"] td {\n border-bottom: 1px solid #303030;\n color: #ffffffd9;\n }\n\n .").concat(SCOPE_ID, "[data-theme=\"dark\"] th {\n background: #1f1f1f;\n color: #ffffffa6;\n }\n\n .").concat(SCOPE_ID, "[data-theme=\"dark\"] th:not(:last-child)::after {\n background: #303030;\n }\n\n .").concat(SCOPE_ID, "[data-theme=\"dark\"] tbody tr:hover {\n background: #1f1f1f;\n }\n");
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* Calculate the minimum width needed for a table based on its data.
|
|
@@ -122,10 +123,11 @@ export var Table = function Table(options) {
|
|
|
122
123
|
if (theme === 'dark') {
|
|
123
124
|
tableWrapper.setAttribute('data-theme', 'dark');
|
|
124
125
|
}
|
|
126
|
+
var titleHTML = title ? "<div class=\"table-title\">".concat(escapeHtml(title), "</div>") : '';
|
|
125
127
|
|
|
126
128
|
// Handle empty data case
|
|
127
129
|
if (data.length === 0) {
|
|
128
|
-
tableWrapper.innerHTML = "\n ".concat(
|
|
130
|
+
tableWrapper.innerHTML = "\n ".concat(titleHTML, "\n <div class=\"table-empty\">No data available</div>\n ");
|
|
129
131
|
container.appendChild(tableWrapper);
|
|
130
132
|
return;
|
|
131
133
|
}
|
|
@@ -137,17 +139,15 @@ export var Table = function Table(options) {
|
|
|
137
139
|
var minWidth = calculateTableMinWidth(data, columns);
|
|
138
140
|
// Ensure a minimum width for columns
|
|
139
141
|
minWidth = Math.max(minWidth, columns.length * 100);
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
var headerHTML = columns.map(function (col) {
|
|
143
|
-
return "<th>".concat(col, "</th>");
|
|
142
|
+
var headerHTML = columns.map(function (column) {
|
|
143
|
+
return "<th>".concat(escapeHtml(column), "</th>");
|
|
144
144
|
}).join('');
|
|
145
145
|
var bodyHTML = data.map(function (row) {
|
|
146
|
-
return "<tr>".concat(columns.map(function (
|
|
147
|
-
return "<td>".concat(row[
|
|
146
|
+
return "<tr>".concat(columns.map(function (column) {
|
|
147
|
+
return "<td>".concat(escapeHtml(row[column]), "</td>");
|
|
148
148
|
}).join(''), "</tr>");
|
|
149
149
|
}).join('');
|
|
150
|
-
tableWrapper.innerHTML = "\n ".concat(
|
|
150
|
+
tableWrapper.innerHTML = "\n ".concat(titleHTML, "\n <table style=\"min-width: ").concat(minWidth, "px;\">\n <thead><tr>").concat(headerHTML, "</tr></thead>\n <tbody>").concat(bodyHTML, "</tbody>\n </table>\n ");
|
|
151
151
|
container.appendChild(tableWrapper);
|
|
152
152
|
};
|
|
153
153
|
|