mirror of
https://github.com/apache/superset.git
synced 2024-09-06 22:07:34 -04:00
feat(viz-plugins): add date formatting to pivot-table (#10637)
* feat: make pivot table dates formattable * Bump npm packages
This commit is contained in:
parent
84d08cb8da
commit
5136c5c16e
33
superset-frontend/package-lock.json
generated
33
superset-frontend/package-lock.json
generated
@ -397,7 +397,8 @@
|
||||
},
|
||||
"mkdirp": {
|
||||
"version": "0.5.1",
|
||||
"resolved": "",
|
||||
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
|
||||
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
@ -572,7 +573,8 @@
|
||||
"dependencies": {
|
||||
"minimist": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "",
|
||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
|
||||
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=",
|
||||
"dev": true,
|
||||
"optional": true
|
||||
}
|
||||
@ -8488,9 +8490,9 @@
|
||||
}
|
||||
},
|
||||
"@superset-ui/legacy-plugin-chart-pivot-table": {
|
||||
"version": "0.14.14",
|
||||
"resolved": "https://registry.npmjs.org/@superset-ui/legacy-plugin-chart-pivot-table/-/legacy-plugin-chart-pivot-table-0.14.14.tgz",
|
||||
"integrity": "sha512-+Dkzwv9yfiix6/u090RN2U2VF0Axa7sB+dB57UU5IS3zW1/jxW7e5ewEV2LsmcXQ0d87bWXvhUn+IGagkwx7Wg==",
|
||||
"version": "0.14.21",
|
||||
"resolved": "https://registry.npmjs.org/@superset-ui/legacy-plugin-chart-pivot-table/-/legacy-plugin-chart-pivot-table-0.14.21.tgz",
|
||||
"integrity": "sha512-gmj3iu+ibkXwshcSna1V9Tmbh+wBCHi3HKTuy6R9KrB+0585U0dsHro3xe0o14Uamhld6PIeWbZBSl3axXK+SQ==",
|
||||
"requires": {
|
||||
"d3": "^3.5.17",
|
||||
"datatables.net-bs": "^1.10.15",
|
||||
@ -8594,9 +8596,9 @@
|
||||
}
|
||||
},
|
||||
"@superset-ui/legacy-preset-chart-nvd3": {
|
||||
"version": "0.14.17",
|
||||
"resolved": "https://registry.npmjs.org/@superset-ui/legacy-preset-chart-nvd3/-/legacy-preset-chart-nvd3-0.14.17.tgz",
|
||||
"integrity": "sha512-n5mkaO9bqNcN2uSpXASIq3z6WmgajVxE6NV6qtDGOCGDlTnSylwfPVNVURdBhg2mfJT+mFeuYfx54xyn7s20sg==",
|
||||
"version": "0.14.21",
|
||||
"resolved": "https://registry.npmjs.org/@superset-ui/legacy-preset-chart-nvd3/-/legacy-preset-chart-nvd3-0.14.21.tgz",
|
||||
"integrity": "sha512-BbsVZnkkAL2a44XFYQtc24VNINGM5JwXAA9HbygdspumYTUu6cpH2nFVPwc06NREUeeN+EV/zF/AVW2O1IJ1tg==",
|
||||
"requires": {
|
||||
"@data-ui/xy-chart": "^0.0.84",
|
||||
"d3": "^3.5.17",
|
||||
@ -12724,7 +12726,8 @@
|
||||
},
|
||||
"kind-of": {
|
||||
"version": "6.0.2",
|
||||
"resolved": "",
|
||||
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz",
|
||||
"integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
@ -18005,7 +18008,8 @@
|
||||
},
|
||||
"kind-of": {
|
||||
"version": "6.0.2",
|
||||
"resolved": "",
|
||||
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz",
|
||||
"integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
@ -33048,7 +33052,8 @@
|
||||
},
|
||||
"kind-of": {
|
||||
"version": "6.0.2",
|
||||
"resolved": "",
|
||||
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz",
|
||||
"integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
@ -38178,7 +38183,8 @@
|
||||
},
|
||||
"mkdirp": {
|
||||
"version": "0.5.1",
|
||||
"resolved": "",
|
||||
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
|
||||
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
@ -38353,7 +38359,8 @@
|
||||
"dependencies": {
|
||||
"minimist": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "",
|
||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
|
||||
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=",
|
||||
"dev": true,
|
||||
"optional": true
|
||||
}
|
||||
|
@ -84,7 +84,7 @@
|
||||
"@superset-ui/legacy-plugin-chart-paired-t-test": "^0.14.9",
|
||||
"@superset-ui/legacy-plugin-chart-parallel-coordinates": "^0.14.9",
|
||||
"@superset-ui/legacy-plugin-chart-partition": "^0.14.9",
|
||||
"@superset-ui/legacy-plugin-chart-pivot-table": "^0.14.14",
|
||||
"@superset-ui/legacy-plugin-chart-pivot-table": "^0.14.21",
|
||||
"@superset-ui/legacy-plugin-chart-rose": "^0.14.14",
|
||||
"@superset-ui/legacy-plugin-chart-sankey": "^0.14.9",
|
||||
"@superset-ui/legacy-plugin-chart-sankey-loop": "^0.14.9",
|
||||
@ -93,7 +93,7 @@
|
||||
"@superset-ui/legacy-plugin-chart-world-map": "^0.14.16",
|
||||
"@superset-ui/legacy-preset-chart-big-number": "^0.14.9",
|
||||
"@superset-ui/legacy-preset-chart-deckgl": "^0.2.4",
|
||||
"@superset-ui/legacy-preset-chart-nvd3": "^0.14.17",
|
||||
"@superset-ui/legacy-preset-chart-nvd3": "^0.14.21",
|
||||
"@superset-ui/number-format": "^0.14.9",
|
||||
"@superset-ui/plugin-chart-table": "^0.14.20",
|
||||
"@superset-ui/plugin-chart-word-cloud": "^0.14.9",
|
||||
|
@ -72,6 +72,7 @@ from superset.utils.core import (
|
||||
QueryMode,
|
||||
to_adhoc,
|
||||
)
|
||||
from superset.utils.dates import datetime_to_epoch
|
||||
from superset.utils.hashing import md5_sha_from_str
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@ -840,8 +841,20 @@ class PivotTableViz(BaseViz):
|
||||
for metric in metrics:
|
||||
aggfuncs[metric] = self.get_aggfunc(metric, df, self.form_data)
|
||||
|
||||
groupby = self.form_data.get("groupby")
|
||||
columns = self.form_data.get("columns")
|
||||
groupby = self.form_data.get("groupby") or []
|
||||
columns = self.form_data.get("columns") or []
|
||||
|
||||
def _format_datetime(value: Any) -> Optional[str]:
|
||||
if isinstance(value, str):
|
||||
return f"__timestamp:{datetime_to_epoch(pd.Timestamp(value))}"
|
||||
return None
|
||||
|
||||
for column_name in groupby + columns:
|
||||
column = self.datasource.get_column(column_name)
|
||||
if column and column.type in ("DATE", "DATETIME", "TIMESTAMP"):
|
||||
ts = df[column_name].apply(_format_datetime)
|
||||
df[column_name] = ts
|
||||
|
||||
if self.form_data.get("transpose_pivot"):
|
||||
groupby, columns = columns, groupby
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user