Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(explore): pie chart label bugs #13052

Merged
merged 1 commit into from
Feb 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
783 changes: 643 additions & 140 deletions superset-frontend/package-lock.json

Large diffs are not rendered by default.

54 changes: 27 additions & 27 deletions superset-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,34 +65,34 @@
"@babel/runtime-corejs3": "^7.12.5",
"@data-ui/sparkline": "^0.0.84",
"@emotion/core": "^10.0.35",
"@superset-ui/chart-controls": "^0.17.5",
"@superset-ui/core": "^0.17.5",
"@superset-ui/legacy-plugin-chart-calendar": "^0.17.5",
"@superset-ui/legacy-plugin-chart-chord": "^0.17.5",
"@superset-ui/legacy-plugin-chart-country-map": "^0.17.5",
"@superset-ui/legacy-plugin-chart-event-flow": "^0.17.5",
"@superset-ui/legacy-plugin-chart-force-directed": "^0.17.5",
"@superset-ui/legacy-plugin-chart-heatmap": "^0.17.5",
"@superset-ui/legacy-plugin-chart-histogram": "^0.17.5",
"@superset-ui/legacy-plugin-chart-horizon": "^0.17.5",
"@superset-ui/legacy-plugin-chart-map-box": "^0.17.5",
"@superset-ui/legacy-plugin-chart-paired-t-test": "^0.17.5",
"@superset-ui/legacy-plugin-chart-parallel-coordinates": "^0.17.5",
"@superset-ui/legacy-plugin-chart-partition": "^0.17.5",
"@superset-ui/legacy-plugin-chart-pivot-table": "^0.17.5",
"@superset-ui/legacy-plugin-chart-rose": "^0.17.5",
"@superset-ui/legacy-plugin-chart-sankey": "^0.17.5",
"@superset-ui/legacy-plugin-chart-sankey-loop": "^0.17.5",
"@superset-ui/legacy-plugin-chart-sunburst": "^0.17.5",
"@superset-ui/legacy-plugin-chart-treemap": "^0.17.5",
"@superset-ui/legacy-plugin-chart-world-map": "^0.17.5",
"@superset-ui/legacy-preset-chart-big-number": "^0.17.5",
"@superset-ui/chart-controls": "^0.17.8",
"@superset-ui/core": "^0.17.8",
"@superset-ui/legacy-plugin-chart-calendar": "^0.17.8",
"@superset-ui/legacy-plugin-chart-chord": "^0.17.8",
"@superset-ui/legacy-plugin-chart-country-map": "^0.17.8",
"@superset-ui/legacy-plugin-chart-event-flow": "^0.17.8",
"@superset-ui/legacy-plugin-chart-force-directed": "^0.17.8",
"@superset-ui/legacy-plugin-chart-heatmap": "^0.17.8",
"@superset-ui/legacy-plugin-chart-histogram": "^0.17.8",
"@superset-ui/legacy-plugin-chart-horizon": "^0.17.8",
"@superset-ui/legacy-plugin-chart-map-box": "^0.17.8",
"@superset-ui/legacy-plugin-chart-paired-t-test": "^0.17.8",
"@superset-ui/legacy-plugin-chart-parallel-coordinates": "^0.17.8",
"@superset-ui/legacy-plugin-chart-partition": "^0.17.8",
"@superset-ui/legacy-plugin-chart-pivot-table": "^0.17.8",
"@superset-ui/legacy-plugin-chart-rose": "^0.17.8",
"@superset-ui/legacy-plugin-chart-sankey": "^0.17.8",
"@superset-ui/legacy-plugin-chart-sankey-loop": "^0.17.8",
"@superset-ui/legacy-plugin-chart-sunburst": "^0.17.8",
"@superset-ui/legacy-plugin-chart-treemap": "^0.17.8",
"@superset-ui/legacy-plugin-chart-world-map": "^0.17.8",
"@superset-ui/legacy-preset-chart-big-number": "^0.17.8",
"@superset-ui/legacy-preset-chart-deckgl": "^0.4.1",
"@superset-ui/legacy-preset-chart-nvd3": "^0.17.5",
"@superset-ui/plugin-chart-echarts": "^0.17.6",
"@superset-ui/plugin-chart-table": "^0.17.6",
"@superset-ui/plugin-chart-word-cloud": "^0.17.5",
"@superset-ui/preset-chart-xy": "^0.17.5",
"@superset-ui/legacy-preset-chart-nvd3": "^0.17.8",
"@superset-ui/plugin-chart-echarts": "^0.17.8",
"@superset-ui/plugin-chart-table": "^0.17.8",
"@superset-ui/plugin-chart-word-cloud": "^0.17.8",
"@superset-ui/preset-chart-xy": "^0.17.8",
"@vx/responsive": "^0.0.195",
"abortcontroller-polyfill": "^1.1.9",
"antd": "^4.9.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import React, { useEffect, useRef, useState } from 'react';
import PropTypes from 'prop-types';
import { Row, Col, FormControl } from 'react-bootstrap';
import { t, getChartMetadataRegistry } from '@superset-ui/core';
import { Behavior, t, getChartMetadataRegistry } from '@superset-ui/core';
import { useDynamicPluginContext } from 'src/components/DynamicPlugins';
import { Tooltip } from 'src/common/components/Tooltip';
import Modal from 'src/common/components/Modal';
Expand Down Expand Up @@ -166,15 +166,21 @@ const VizTypeControl = props => {
const filterString = filter.toLowerCase();

const filteredTypes = DEFAULT_ORDER.filter(type => registry.has(type))
.filter(type => !registry.get(type).isNativeFilter)
.filter(type => {
const behaviors = registry.get(type)?.behaviors || [];
return behaviors.includes(Behavior.CROSS_FILTER) || !behaviors.length;
})
.map(type => ({
key: type,
value: registry.get(type),
}))
.concat(
registry
.entries()
.filter(entry => !entry.value.isNativeFilter)
.filter(entry => {
Copy link
Contributor

@simcha90 simcha90 Feb 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be move it to some utils like

const getVisibleCharts = ({ behaviours } = {}) => behaviors?.includes(Behavior.CROSS_FILTER) || !behaviors?.length;

and use it like:

.filter(type =>getVisibleCharts(registry.get(type)))
and
.filter(entry =>getVisibleCharts(entry.value))

const behaviors = entry.value?.behaviors || [];
return behaviors.includes(Behavior.CROSS_FILTER) || !behaviors.length;
})
.filter(({ key }) => !typesWithDefaultOrder.has(key)),
)
.filter(entry => entry.value.name.toLowerCase().includes(filterString));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ export default function AntdRangeFilter(props: AntdPluginFilterRangeProps) {
const handleChange = (value: [number, number]) => {
const [lower, upper] = value;

setExtraFormData(getRangeExtraFormData(col, lower, upper));
setExtraFormData({
extraFormData: getRangeExtraFormData(col, lower, upper),
currentState: {
value,
},
});
};

return (
Expand Down
4 changes: 2 additions & 2 deletions superset-frontend/src/filters/components/Range/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { t, ChartMetadata, ChartPlugin } from '@superset-ui/core';
import { Behavior, ChartMetadata, ChartPlugin, t } from '@superset-ui/core';
import buildQuery from './buildQuery';
import controlPanel from './controlPanel';
import transformProps from './transformProps';
Expand All @@ -27,7 +27,7 @@ export default class AntdRangeFilterPlugin extends ChartPlugin {
const metadata = new ChartMetadata({
name: t('Range filter plugin'),
description: 'Range filter plugin using AntD',
isNativeFilter: true,
behaviors: [Behavior.CROSS_FILTER, Behavior.NATIVE_FILTER],
thumbnail,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,12 @@ export default function AntdPluginFilterSelect(
const emptyFilter =
enableEmptyFilter && !inverseSelection && resultValue?.length === 0;
setExtraFormData({
// @ts-ignore
extraFormData: getSelectExtraFormData(
col,
resultValue,
emptyFilter,
inverseSelection,
),
// @ts-ignore (add to superset-ui/core)
currentState: {
value: resultValue,
},
Expand Down
4 changes: 2 additions & 2 deletions superset-frontend/src/filters/components/Select/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { t, ChartMetadata, ChartPlugin } from '@superset-ui/core';
import { Behavior, ChartMetadata, ChartPlugin, t } from '@superset-ui/core';
import buildQuery from './buildQuery';
import controlPanel from './controlPanel';
import transformProps from './transformProps';
Expand All @@ -27,7 +27,7 @@ export default class AntdFilterSelectPlugin extends ChartPlugin {
const metadata = new ChartMetadata({
name: t('Select filter plugin'),
description: 'Select filter plugin using AntD',
isNativeFilter: true,
behaviors: [Behavior.CROSS_FILTER, Behavior.NATIVE_FILTER],
thumbnail,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ params:
metric: count
number_format: SMART_NUMBER
outerRadius: 69
pie_label_type: key
label_type: key
queryFields:
groupby: groupby
metric: metrics
Expand Down
2 changes: 1 addition & 1 deletion superset/examples/configs/charts/First_Time_Developer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ params:
metric: count
number_format: SMART_NUMBER
outerRadius: 69
pie_label_type: key
label_type: key
queryFields:
groupby: groupby
metric: metrics
Expand Down
2 changes: 1 addition & 1 deletion superset/examples/configs/charts/Gender.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ params:
metric: count
number_format: SMART_NUMBER
outerRadius: 69
pie_label_type: key
label_type: key
queryFields:
groupby: groupby
metric: metrics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ params:
sqlExpression: null
number_format: SMART_NUMBER
outerRadius: 67
pie_label_type: key
label_type: key
queryFields:
groupby: groupby
metric: metrics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ params:
sqlExpression: null
number_format: SMART_NUMBER
outerRadius: 65
pie_label_type: key
label_type: key
queryFields:
groupby: groupby
metric: metrics
Expand Down
2 changes: 1 addition & 1 deletion superset/examples/configs/charts/Relocation_ability.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ params:
metric: count
number_format: SMART_NUMBER
outerRadius: 69
pie_label_type: key
label_type: key
queryFields:
groupby: groupby
metric: metrics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ params:
metric: count
number_format: SMART_NUMBER
outerRadius: 61
pie_label_type: key
label_type: key
queryFields:
groupby: groupby
metric: metrics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ params:
metric: count
number_format: SMART_NUMBER
outerRadius: 69
pie_label_type: key
label_type: key
queryFields:
groupby: groupby
metric: metrics
Expand Down
102 changes: 102 additions & 0 deletions superset/migrations/versions/41ce8799acc3_rename_pie_label_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# 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.
"""rename pie label type
Revision ID: 41ce8799acc3
Revises: e11ccdd12658
Create Date: 2021-02-10 12:32:27.385579
"""

# revision identifiers, used by Alembic.
revision = "41ce8799acc3"
down_revision = "e11ccdd12658"

import json

from alembic import op
from sqlalchemy import and_, Column, Integer, String, Text
from sqlalchemy.ext.declarative import declarative_base

from superset import db

Base = declarative_base()


class Slice(Base):
"""Declarative class to do query in upgrade"""

__tablename__ = "slices"
id = Column(Integer, primary_key=True)
viz_type = Column(String(250))
params = Column(Text)


def upgrade():
bind = op.get_bind()
session = db.Session(bind=bind)

slices = (
session.query(Slice)
.filter(and_(Slice.viz_type == "pie", Slice.params.like("%pie_label_type%")))
.all()
)
changes = 0
for slc in slices:
try:
params = json.loads(slc.params)
pie_label_type = params.pop("pie_label_type", None)
if pie_label_type:
changes += 1
params["label_type"] = pie_label_type
slc.params = json.dumps(params, sort_keys=True)
except Exception as e:
print(e)
print(f"Parsing params for slice {slc.id} failed.")
pass

session.commit()
session.close()
print(f"Updated {changes} pie chart labels.")


def downgrade():
bind = op.get_bind()
session = db.Session(bind=bind)

slices = (
session.query(Slice)
.filter(and_(Slice.viz_type == "pie", Slice.params.like("%label_type%")))
.all()
)
changes = 0
for slc in slices:
try:
params = json.loads(slc.params)
label_type = params.pop("label_type", None)
if label_type:
changes += 1
params["pie_label_type"] = label_type
slc.params = json.dumps(params, sort_keys=True)
except Exception as e:
print(e)
print(f"Parsing params for slice {slc.id} failed.")
pass

session.commit()
session.close()
print(f"Updated {changes} pie chart labels.")