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

feat: add Echarts Graph chart #13111

Merged
merged 20 commits into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 2 additions & 2 deletions superset-frontend/src/visualizations/presets/MainPreset.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import CalendarChartPlugin from '@superset-ui/legacy-plugin-chart-calendar';
import ChordChartPlugin from '@superset-ui/legacy-plugin-chart-chord';
import CountryMapChartPlugin from '@superset-ui/legacy-plugin-chart-country-map';
import EventFlowChartPlugin from '@superset-ui/legacy-plugin-chart-event-flow';
import ForceDirectedChartPlugin from '@superset-ui/legacy-plugin-chart-force-directed';
import HeatmapChartPlugin from '@superset-ui/legacy-plugin-chart-heatmap';
import HistogramChartPlugin from '@superset-ui/legacy-plugin-chart-histogram';
import HorizonChartPlugin from '@superset-ui/legacy-plugin-chart-horizon';
Expand Down Expand Up @@ -58,6 +57,7 @@ import {
EchartsPieChartPlugin,
EchartsBoxPlotChartPlugin,
EchartsTimeseriesChartPlugin,
EchartsGraphChartPlugin
} from '@superset-ui/plugin-chart-echarts';
import {
AntdSelectFilterPlugin,
Expand Down Expand Up @@ -88,7 +88,7 @@ export default class MainPreset extends Preset {
new DualLineChartPlugin().configure({ key: 'dual_line' }),
new EventFlowChartPlugin().configure({ key: 'event_flow' }),
new FilterBoxChartPlugin().configure({ key: 'filter_box' }),
new ForceDirectedChartPlugin().configure({ key: 'directed_force' }),
new EchartsGraphChartPlugin().configure({ key: 'graph_chart' }),
new HeatmapChartPlugin().configure({ key: 'heatmap' }),
new HistogramChartPlugin().configure({ key: 'histogram' }),
new HorizonChartPlugin().configure({ key: 'horizon' }),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# 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.
"""legacy force directed to echart

Revision ID: 1412ec1e5a7b
Revises: 070c043f2fdb
Create Date: 2021-02-14 11:46:02.379832

"""
import json

import sqlalchemy as sa
from alembic import op
from sqlalchemy import Column, Integer, or_, String, Text
from sqlalchemy.ext.declarative import declarative_base

from superset import db

# revision identifiers, used by Alembic.
revision = "1412ec1e5a7b"
down_revision = "070c043f2fdb"


Base = declarative_base()


class Slice(Base):
__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)

for slc in session.query(Slice).filter(Slice.viz_type.like("directed_force")):
params = json.loads(slc.params)

groupby = params.get("groupby", [])
if groupby:
params["source"] = groupby[0]
params["target"] = groupby[1]
mayurnewase marked this conversation as resolved.
Show resolved Hide resolved
params["edgeLength"] = 400
params["repulsion"] = 1000
params["layout"] = "force"
del params["groupby"]
del params["charge"]
del params["collapsed_fieldsets"]
mayurnewase marked this conversation as resolved.
Show resolved Hide resolved
del params["link_length"]
slc.params = json.dumps(params)

slc.viz_type = "graph_chart"
session.merge(slc)
session.commit()
session.close()


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

for slc in session.query(Slice).filter(Slice.viz_type.like("graph_chart")):
params = json.loads(slc.params)
source = params.get("source", "")
target = params.get("target", "")
if source and target:
params["groupby"] = [source, target]
del params["source"]
del params["target"]
del params["edgeLength"]
del params["repulsion"]
del params["layout"]
params["charge"] = "-500"