diff --git a/assets/js/dashboard/stats/graph/visitor-graph.js b/assets/js/dashboard/stats/graph/visitor-graph.js
index 0feda96cf..16841d035 100644
--- a/assets/js/dashboard/stats/graph/visitor-graph.js
+++ b/assets/js/dashboard/stats/graph/visitor-graph.js
@@ -32,12 +32,8 @@ const calculateMaximumY = function(dataset) {
class LineGraph extends React.Component {
constructor(props) {
super(props);
- this.boundary = React.createRef()
this.regenerateChart = this.regenerateChart.bind(this);
this.updateWindowDimensions = this.updateWindowDimensions.bind(this);
- this.state = {
- exported: false
- };
}
regenerateChart() {
@@ -232,6 +228,7 @@ class LineGraph extends React.Component {
}
}
+<<<<<<< HEAD
pollExportReady() {
if (document.cookie.includes('exporting')) {
setTimeout(this.pollExportReady.bind(this), 1000);
@@ -330,29 +327,15 @@ class LineGraph extends React.Component {
}
render() {
- const { mainGraphRefreshing, updateMetric, updateInterval, metric, topStatData, query, site, graphData, lastLoadTimestamp } = this.props
+ const { graphData } = this.props
const canvasClass = classNames('mt-4 select-none', { 'cursor-pointer': !['minute', 'hour'].includes(graphData?.interval) })
return (
-
-
-
+
+
+
-
- {mainGraphRefreshing && renderLoader()}
-
- {this.downloadLink()}
- {this.samplingNotice()}
- {this.importedNotice()}
-
-
-
-
-
-
-
-
-
+
)
}
}
@@ -365,13 +348,15 @@ export default class VisitorGraph extends React.Component {
this.state = {
topStatsLoadingState: LoadingState.loading,
mainGraphLoadingState: LoadingState.loading,
- metric: storage.getItem(`metric__${this.props.site.domain}`) || 'visitors'
+ metric: storage.getItem(`metric__${this.props.site.domain}`) || 'visitors',
+ exported: false
}
this.onVisible = this.onVisible.bind(this)
this.updateMetric = this.updateMetric.bind(this)
this.fetchTopStatData = this.fetchTopStatData.bind(this)
this.fetchGraphData = this.fetchGraphData.bind(this)
this.updateInterval = this.updateInterval.bind(this)
+ this.boundary = React.createRef()
}
isIntervalValid(interval) {
@@ -489,12 +474,114 @@ export default class VisitorGraph extends React.Component {
return res
})
}
+
+ pollExportReady() {
+ if (document.cookie.includes('exporting')) {
+ setTimeout(this.pollExportReady.bind(this), 1000);
+ } else {
+ this.setState({ exported: false })
+ }
+ }
+
+ downloadSpinner() {
+ this.setState({ exported: true });
+ document.cookie = "exporting=";
+ setTimeout(this.pollExportReady.bind(this), 1000);
+ }
+
+ downloadLink() {
+ if (this.props.query.period !== 'realtime') {
+
+ if (this.state.exported) {
+ return (
+
+ )
+ } else {
+ const interval = this.state.graphData?.interval
+ const queryParams = api.serializeQuery(this.props.query, [{ interval }])
+ const endpoint = `/${encodeURIComponent(this.props.site.domain)}/export${queryParams}`
+
+ return (
+
+
+
+ )
+ }
+ }
+ }
+
+ samplingNotice() {
+ const samplePercent = this.state.topStatData?.sample_percent
+
+ if (samplePercent && samplePercent < 100) {
+ return (
+
+ )
+ }
+ }
+
+ importedNotice() {
+ const { topStatData } = this.state
+
+ if (!topStatData?.imported_source) return
+
+ const isBeforeNativeStats = (date) => {
+ if (!date) return false
+
+ const nativeStatsBegin = parseNaiveDate(this.props.site.nativeStatsBegin)
+ const parsedDate = parseNaiveDate(date)
+
+ return isBefore(parsedDate, nativeStatsBegin, "day")
+ }
+
+ const isQueryingImportedPeriod = isBeforeNativeStats(topStatData.from)
+ const isComparingImportedPeriod = isBeforeNativeStats(topStatData.comparing_from)
+
+ if (isQueryingImportedPeriod || isComparingImportedPeriod) {
+ const source = topStatData.imported_source
+ const withImported = topStatData.with_imported;
+ const strike = withImported ? "" : " line-through"
+ const target = url.setQuery('with_imported', !withImported)
+ const tip = withImported ? "" : "do not ";
+
+ return (
+
+
+
+ {source[0].toUpperCase()}
+
+
+
+ )
+ }
+ }
+
+ // This function is used for maintaining the main-graph/top-stats container height in the
+ // loading process. The container height depends on how many top stat metrics are returned
+ // from the API, but in the loading state, we don't know that yet. We can use localStorage
+ // to keep track of the Top Stats container height.
+ getTopStatsHeight() {
+ if (this.state.topStatData) {
+ return 'auto'
+ } else {
+ return `${storage.getItem(`topStatsHeight__${this.props.site.domain}`) || 89}px`
+ }
+ }
renderInner() {
const { query, site } = this.props;
const { graphData, metric, topStatData, topStatsLoadingState, mainGraphLoadingState } = this.state;
- const theme = document.querySelector('html').classList.contains('dark') || false
+ const isDarkTheme = document.querySelector('html').classList.contains('dark') || false
const mainGraphRefreshing = (mainGraphLoadingState === LoadingState.refreshing)
const topStatAndGraphLoaded = !!(topStatData && graphData)
@@ -506,7 +593,19 @@ export default class VisitorGraph extends React.Component {
return (
-
+
+
+
+
+ {mainGraphRefreshing && renderLoader()}
+
+ {this.downloadLink()}
+ {this.samplingNotice()}
+ {this.importedNotice()}
+
+
+
+
)
}