fix: add advanced analytics to all of timeseries viz (#1308)

* feat: add advanced analytics to all of timeseries viz

* fix namespace
This commit is contained in:
Yongjie Zhao
2021-08-13 18:01:19 +01:00
parent 15fbe4a72a
commit 4de4fc37fc
9 changed files with 192 additions and 490 deletions

View File

@@ -21,7 +21,7 @@ import { t, RollingType, ComparisionType } from '@superset-ui/core';
import { ControlPanelSectionConfig } from '../types';
import { formatSelectOptions } from '../utils';
export const advancedAnalytics: ControlPanelSectionConfig = {
export const advancedAnalyticsControls: ControlPanelSectionConfig = {
label: t('Advanced analytics'),
tabOverride: 'data',
description: t(

View File

@@ -0,0 +1,40 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { t } from '@superset-ui/core';
import { ControlPanelSectionConfig } from '../types';
export const annotationLayers = [];
export const annotationsAndLayersControls: ControlPanelSectionConfig = {
label: t('Annotations and Layers'),
expanded: false,
controlSetRows: [
[
{
name: 'annotation_layers',
config: {
type: 'AnnotationLayerControl',
label: '',
default: annotationLayers,
description: t('Annotation Layers'),
},
},
],
],
};

View File

@@ -0,0 +1,125 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { legacyValidateInteger, legacyValidateNumber, t } from '@superset-ui/core';
import { ControlPanelSectionConfig } from '../types';
export const FORECAST_DEFAULT_DATA = {
forecastEnabled: false,
forecastInterval: 0.8,
forecastPeriods: 10,
forecastSeasonalityDaily: null,
forecastSeasonalityWeekly: null,
forecastSeasonalityYearly: null,
};
export const forecastIntervalControls: ControlPanelSectionConfig = {
label: t('Predictive Analytics'),
expanded: false,
controlSetRows: [
[
{
name: 'forecastEnabled',
config: {
type: 'CheckboxControl',
label: t('Enable forecast'),
renderTrigger: false,
default: FORECAST_DEFAULT_DATA.forecastEnabled,
description: t('Enable forecasting'),
},
},
],
[
{
name: 'forecastPeriods',
config: {
type: 'TextControl',
label: t('Forecast periods'),
validators: [legacyValidateInteger],
default: FORECAST_DEFAULT_DATA.forecastPeriods,
description: t('How many periods into the future do we want to predict'),
},
},
],
[
{
name: 'forecastInterval',
config: {
type: 'TextControl',
label: t('Confidence interval'),
validators: [legacyValidateNumber],
default: FORECAST_DEFAULT_DATA.forecastInterval,
description: t('Width of the confidence interval. Should be between 0 and 1'),
},
},
{
name: 'forecastSeasonalityYearly',
config: {
type: 'SelectControl',
freeForm: true,
label: 'Yearly seasonality',
choices: [
[null, 'default'],
[true, 'Yes'],
[false, 'No'],
],
default: FORECAST_DEFAULT_DATA.forecastSeasonalityYearly,
description: t(
'Should yearly seasonality be applied. An integer value will specify Fourier order of seasonality.',
),
},
},
],
[
{
name: 'forecastSeasonalityWeekly',
config: {
type: 'SelectControl',
freeForm: true,
label: 'Weekly seasonality',
choices: [
[null, 'default'],
[true, 'Yes'],
[false, 'No'],
],
default: FORECAST_DEFAULT_DATA.forecastSeasonalityWeekly,
description: t(
'Should weekly seasonality be applied. An integer value will specify Fourier order of seasonality.',
),
},
},
{
name: 'forecastSeasonalityDaily',
config: {
type: 'SelectControl',
freeForm: true,
label: 'Daily seasonality',
choices: [
[null, 'default'],
[true, 'Yes'],
[false, 'No'],
],
default: FORECAST_DEFAULT_DATA.forecastSeasonalityDaily,
description: t(
'Should daily seasonality be applied. An integer value will specify Fourier order of seasonality.',
),
},
},
],
],
};

View File

@@ -19,3 +19,5 @@
export * from './sections';
export * from './advancedAnalytics';
export * from './annotationsAndLayers';
export * from './forecastInterval';

View File

@@ -17,7 +17,7 @@
* under the License.
*/
import React from 'react';
import { legacyValidateInteger, legacyValidateNumber, t } from '@superset-ui/core';
import { t } from '@superset-ui/core';
import {
ControlPanelConfig,
ControlPanelsContainerProps,
@@ -35,14 +35,7 @@ import {
import { legendSection, showValueControl } from '../../controls';
const {
annotationLayers,
contributionMode,
forecastEnabled,
forecastInterval,
forecastPeriods,
forecastSeasonalityDaily,
forecastSeasonalityWeekly,
forecastSeasonalityYearly,
logAxis,
markerEnabled,
markerSize,
@@ -100,118 +93,9 @@ const config: ControlPanelConfig = {
['row_limit'],
],
},
{
label: t('Annotations and Layers'),
expanded: false,
controlSetRows: [
[
{
name: 'annotation_layers',
config: {
type: 'AnnotationLayerControl',
label: '',
default: annotationLayers,
description: t('Annotation Layers'),
},
},
],
],
},
{
label: t('Predictive Analytics'),
expanded: false,
controlSetRows: [
[
{
name: 'forecastEnabled',
config: {
type: 'CheckboxControl',
label: t('Enable forecast'),
renderTrigger: false,
default: forecastEnabled,
description: t('Enable forecasting'),
},
},
],
[
{
name: 'forecastPeriods',
config: {
type: 'TextControl',
label: t('Forecast periods'),
validators: [legacyValidateInteger],
default: forecastPeriods,
description: t('How many periods into the future do we want to predict'),
},
},
],
[
{
name: 'forecastInterval',
config: {
type: 'TextControl',
label: t('Confidence interval'),
validators: [legacyValidateNumber],
default: forecastInterval,
description: t('Width of the confidence interval. Should be between 0 and 1'),
},
},
{
name: 'forecastSeasonalityYearly',
config: {
type: 'SelectControl',
freeForm: true,
label: 'Yearly seasonality',
choices: [
[null, 'default'],
[true, 'Yes'],
[false, 'No'],
],
default: forecastSeasonalityYearly,
description: t(
'Should yearly seasonality be applied. An integer value will specify Fourier order of seasonality.',
),
},
},
],
[
{
name: 'forecastSeasonalityWeekly',
config: {
type: 'SelectControl',
freeForm: true,
label: 'Weekly seasonality',
choices: [
[null, 'default'],
[true, 'Yes'],
[false, 'No'],
],
default: forecastSeasonalityWeekly,
description: t(
'Should weekly seasonality be applied. An integer value will specify Fourier order of seasonality.',
),
},
},
{
name: 'forecastSeasonalityDaily',
config: {
type: 'SelectControl',
freeForm: true,
label: 'Daily seasonality',
choices: [
[null, 'default'],
[true, 'Yes'],
[false, 'No'],
],
default: forecastSeasonalityDaily,
description: t(
'Should daily seasonality be applied. An integer value will specify Fourier order of seasonality.',
),
},
},
],
],
},
sections.advancedAnalyticsControls,
sections.annotationsAndLayersControls,
sections.forecastIntervalControls,
{
label: t('Chart Options'),
expanded: true,

View File

@@ -17,7 +17,7 @@
* under the License.
*/
import React from 'react';
import { legacyValidateInteger, legacyValidateNumber, t } from '@superset-ui/core';
import { t } from '@superset-ui/core';
import {
ControlPanelConfig,
ControlPanelsContainerProps,
@@ -31,14 +31,7 @@ import { DEFAULT_FORM_DATA, EchartsTimeseriesContributionType } from '../types';
import { legendSection, showValueControl } from '../../controls';
const {
annotationLayers,
contributionMode,
forecastEnabled,
forecastInterval,
forecastPeriods,
forecastSeasonalityDaily,
forecastSeasonalityWeekly,
forecastSeasonalityYearly,
logAxis,
markerEnabled,
markerSize,
@@ -94,118 +87,9 @@ const config: ControlPanelConfig = {
['row_limit'],
],
},
{
label: t('Annotations and Layers'),
expanded: false,
controlSetRows: [
[
{
name: 'annotation_layers',
config: {
type: 'AnnotationLayerControl',
label: '',
default: annotationLayers,
description: t('Annotation Layers'),
},
},
],
],
},
{
label: t('Predictive Analytics'),
expanded: false,
controlSetRows: [
[
{
name: 'forecastEnabled',
config: {
type: 'CheckboxControl',
label: t('Enable forecast'),
renderTrigger: false,
default: forecastEnabled,
description: t('Enable forecasting'),
},
},
],
[
{
name: 'forecastPeriods',
config: {
type: 'TextControl',
label: t('Forecast periods'),
validators: [legacyValidateInteger],
default: forecastPeriods,
description: t('How many periods into the future do we want to predict'),
},
},
],
[
{
name: 'forecastInterval',
config: {
type: 'TextControl',
label: t('Confidence interval'),
validators: [legacyValidateNumber],
default: forecastInterval,
description: t('Width of the confidence interval. Should be between 0 and 1'),
},
},
{
name: 'forecastSeasonalityYearly',
config: {
type: 'SelectControl',
freeForm: true,
label: 'Yearly seasonality',
choices: [
[null, 'default'],
[true, 'Yes'],
[false, 'No'],
],
default: forecastSeasonalityYearly,
description: t(
'Should yearly seasonality be applied. An integer value will specify Fourier order of seasonality.',
),
},
},
],
[
{
name: 'forecastSeasonalityWeekly',
config: {
type: 'SelectControl',
freeForm: true,
label: 'Weekly seasonality',
choices: [
[null, 'default'],
[true, 'Yes'],
[false, 'No'],
],
default: forecastSeasonalityWeekly,
description: t(
'Should weekly seasonality be applied. An integer value will specify Fourier order of seasonality.',
),
},
},
{
name: 'forecastSeasonalityDaily',
config: {
type: 'SelectControl',
freeForm: true,
label: 'Daily seasonality',
choices: [
[null, 'default'],
[true, 'Yes'],
[false, 'No'],
],
default: forecastSeasonalityDaily,
description: t(
'Should daily seasonality be applied. An integer value will specify Fourier order of seasonality.',
),
},
},
],
],
},
sections.advancedAnalyticsControls,
sections.annotationsAndLayersControls,
sections.forecastIntervalControls,
{
label: t('Chart Options'),
expanded: true,

View File

@@ -17,7 +17,7 @@
* under the License.
*/
import React from 'react';
import { legacyValidateInteger, legacyValidateNumber, t } from '@superset-ui/core';
import { t } from '@superset-ui/core';
import {
ControlPanelConfig,
ControlPanelsContainerProps,
@@ -36,14 +36,7 @@ import { legendSection, showValueControl } from '../../controls';
const {
area,
annotationLayers,
contributionMode,
forecastEnabled,
forecastInterval,
forecastPeriods,
forecastSeasonalityDaily,
forecastSeasonalityWeekly,
forecastSeasonalityYearly,
logAxis,
markerEnabled,
markerSize,
@@ -100,119 +93,9 @@ const config: ControlPanelConfig = {
['row_limit'],
],
},
sections.advancedAnalytics,
{
label: t('Annotations and Layers'),
expanded: false,
controlSetRows: [
[
{
name: 'annotation_layers',
config: {
type: 'AnnotationLayerControl',
label: '',
default: annotationLayers,
description: t('Annotation Layers'),
},
},
],
],
},
{
label: t('Predictive Analytics'),
expanded: false,
controlSetRows: [
[
{
name: 'forecastEnabled',
config: {
type: 'CheckboxControl',
label: t('Enable forecast'),
renderTrigger: false,
default: forecastEnabled,
description: t('Enable forecasting'),
},
},
],
[
{
name: 'forecastPeriods',
config: {
type: 'TextControl',
label: t('Forecast periods'),
validators: [legacyValidateInteger],
default: forecastPeriods,
description: t('How many periods into the future do we want to predict'),
},
},
],
[
{
name: 'forecastInterval',
config: {
type: 'TextControl',
label: t('Confidence interval'),
validators: [legacyValidateNumber],
default: forecastInterval,
description: t('Width of the confidence interval. Should be between 0 and 1'),
},
},
{
name: 'forecastSeasonalityYearly',
config: {
type: 'SelectControl',
freeForm: true,
label: 'Yearly seasonality',
choices: [
[null, 'default'],
[true, 'Yes'],
[false, 'No'],
],
default: forecastSeasonalityYearly,
description: t(
'Should yearly seasonality be applied. An integer value will specify Fourier order of seasonality.',
),
},
},
],
[
{
name: 'forecastSeasonalityWeekly',
config: {
type: 'SelectControl',
freeForm: true,
label: 'Weekly seasonality',
choices: [
[null, 'default'],
[true, 'Yes'],
[false, 'No'],
],
default: forecastSeasonalityWeekly,
description: t(
'Should weekly seasonality be applied. An integer value will specify Fourier order of seasonality.',
),
},
},
{
name: 'forecastSeasonalityDaily',
config: {
type: 'SelectControl',
freeForm: true,
label: 'Daily seasonality',
choices: [
[null, 'default'],
[true, 'Yes'],
[false, 'No'],
],
default: forecastSeasonalityDaily,
description: t(
'Should daily seasonality be applied. An integer value will specify Fourier order of seasonality.',
),
},
},
],
],
},
sections.advancedAnalyticsControls,
sections.annotationsAndLayersControls,
sections.forecastIntervalControls,
{
label: t('Chart Options'),
expanded: true,

View File

@@ -17,7 +17,7 @@
* under the License.
*/
import React from 'react';
import { legacyValidateInteger, legacyValidateNumber, t } from '@superset-ui/core';
import { t } from '@superset-ui/core';
import {
ControlPanelConfig,
ControlPanelsContainerProps,
@@ -36,14 +36,7 @@ import { legendSection, showValueControl } from '../controls';
const {
area,
annotationLayers,
contributionMode,
forecastEnabled,
forecastInterval,
forecastPeriods,
forecastSeasonalityDaily,
forecastSeasonalityWeekly,
forecastSeasonalityYearly,
logAxis,
markerEnabled,
markerSize,
@@ -101,119 +94,9 @@ const config: ControlPanelConfig = {
['row_limit'],
],
},
sections.advancedAnalytics,
{
label: t('Annotations and Layers'),
expanded: false,
controlSetRows: [
[
{
name: 'annotation_layers',
config: {
type: 'AnnotationLayerControl',
label: '',
default: annotationLayers,
description: t('Annotation Layers'),
},
},
],
],
},
{
label: t('Predictive Analytics'),
expanded: false,
controlSetRows: [
[
{
name: 'forecastEnabled',
config: {
type: 'CheckboxControl',
label: t('Enable forecast'),
renderTrigger: false,
default: forecastEnabled,
description: t('Enable forecasting'),
},
},
],
[
{
name: 'forecastPeriods',
config: {
type: 'TextControl',
label: t('Forecast periods'),
validators: [legacyValidateInteger],
default: forecastPeriods,
description: t('How many periods into the future do we want to predict'),
},
},
],
[
{
name: 'forecastInterval',
config: {
type: 'TextControl',
label: t('Confidence interval'),
validators: [legacyValidateNumber],
default: forecastInterval,
description: t('Width of the confidence interval. Should be between 0 and 1'),
},
},
{
name: 'forecastSeasonalityYearly',
config: {
type: 'SelectControl',
freeForm: true,
label: 'Yearly seasonality',
choices: [
[null, 'default'],
[true, 'Yes'],
[false, 'No'],
],
default: forecastSeasonalityYearly,
description: t(
'Should yearly seasonality be applied. An integer value will specify Fourier order of seasonality.',
),
},
},
],
[
{
name: 'forecastSeasonalityWeekly',
config: {
type: 'SelectControl',
freeForm: true,
label: 'Weekly seasonality',
choices: [
[null, 'default'],
[true, 'Yes'],
[false, 'No'],
],
default: forecastSeasonalityWeekly,
description: t(
'Should weekly seasonality be applied. An integer value will specify Fourier order of seasonality.',
),
},
},
{
name: 'forecastSeasonalityDaily',
config: {
type: 'SelectControl',
freeForm: true,
label: 'Daily seasonality',
choices: [
[null, 'default'],
[true, 'Yes'],
[false, 'No'],
],
default: forecastSeasonalityDaily,
description: t(
'Should daily seasonality be applied. An integer value will specify Fourier order of seasonality.',
),
},
},
],
],
},
sections.advancedAnalyticsControls,
sections.annotationsAndLayersControls,
sections.forecastIntervalControls,
{
label: t('Chart Options'),
expanded: true,

View File

@@ -23,6 +23,7 @@ import {
QueryFormData,
TimeGranularity,
} from '@superset-ui/core';
import { sections } from '@superset-ui/chart-controls';
import { DEFAULT_LEGEND_FORM_DATA, EchartsLegendFormData, EChartTransformedProps } from '../types';
export enum EchartsTimeseriesContributionType {
@@ -80,14 +81,14 @@ export type EchartsTimeseriesFormData = QueryFormData & {
// @ts-ignore
export const DEFAULT_FORM_DATA: EchartsTimeseriesFormData = {
...DEFAULT_LEGEND_FORM_DATA,
annotationLayers: [],
annotationLayers: sections.annotationLayers,
area: false,
forecastEnabled: false,
forecastInterval: 0.8,
forecastPeriods: 10,
forecastSeasonalityDaily: null,
forecastSeasonalityWeekly: null,
forecastSeasonalityYearly: null,
forecastEnabled: sections.FORECAST_DEFAULT_DATA.forecastEnabled,
forecastInterval: sections.FORECAST_DEFAULT_DATA.forecastInterval,
forecastPeriods: sections.FORECAST_DEFAULT_DATA.forecastPeriods,
forecastSeasonalityDaily: sections.FORECAST_DEFAULT_DATA.forecastSeasonalityDaily,
forecastSeasonalityWeekly: sections.FORECAST_DEFAULT_DATA.forecastSeasonalityWeekly,
forecastSeasonalityYearly: sections.FORECAST_DEFAULT_DATA.forecastSeasonalityYearly,
logAxis: false,
markerEnabled: false,
markerSize: 6,