This repository has been archived by the owner on Dec 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 272
feat(plugin-chart-echarts): Emit cross filters for pie and boxplot #1010
Merged
villebro
merged 12 commits into
apache-superset:master
from
maloun96:enable-emitting-filter
Mar 19, 2021
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
de2c642
feat(plugin-chart-echarts): emit filter events when clicking on slice
villebro 1217c7c
feat(plugin-chart-echarts): enable emitting filter
maloun96 3339470
clean up filter state
villebro 1976273
check eventHandlers by emitFilter flag
maloun96 79adce3
feat(plugin-chart-echarts): multiple choices for filter
maloun96 43f5ad5
WIP
villebro 9a23503
feat(plugin-chart-echarts): select multiple values
villebro 3895b0e
add conditional control item for emitting filter
maloun96 36d7a71
add cross filter for box plot chart
maloun96 cf5117a
refactor: combine values and indexes single object
maloun96 3839f9a
fix: eslint
maloun96 f1630df
Add default emitFilter for BoxPlot. Check emit filter before handle c…
maloun96 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -16,10 +16,79 @@ | |||||||||||||||||||||||||||||||||||||
* specific language governing permissions and limitations | ||||||||||||||||||||||||||||||||||||||
* under the License. | ||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||
import React from 'react'; | ||||||||||||||||||||||||||||||||||||||
import { EchartsProps } from '../types'; | ||||||||||||||||||||||||||||||||||||||
import React, { useCallback } from 'react'; | ||||||||||||||||||||||||||||||||||||||
import Echart from '../components/Echart'; | ||||||||||||||||||||||||||||||||||||||
import { EventHandlers } from '../types'; | ||||||||||||||||||||||||||||||||||||||
import { BoxPlotChartTransformedProps } from './types'; | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
export default function EchartsBoxPlot({ height, width, echartOptions }: EchartsProps) { | ||||||||||||||||||||||||||||||||||||||
return <Echart height={height} width={width} echartOptions={echartOptions} />; | ||||||||||||||||||||||||||||||||||||||
export default function EchartsBoxPlot({ | ||||||||||||||||||||||||||||||||||||||
height, | ||||||||||||||||||||||||||||||||||||||
width, | ||||||||||||||||||||||||||||||||||||||
echartOptions, | ||||||||||||||||||||||||||||||||||||||
setDataMask, | ||||||||||||||||||||||||||||||||||||||
labelMap, | ||||||||||||||||||||||||||||||||||||||
groupby, | ||||||||||||||||||||||||||||||||||||||
selectedValues, | ||||||||||||||||||||||||||||||||||||||
}: BoxPlotChartTransformedProps) { | ||||||||||||||||||||||||||||||||||||||
const handleChange = useCallback( | ||||||||||||||||||||||||||||||||||||||
(values: string[]) => { | ||||||||||||||||||||||||||||||||||||||
const groupbyValues = values.map(value => labelMap[value]); | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
setDataMask({ | ||||||||||||||||||||||||||||||||||||||
crossFilters: { | ||||||||||||||||||||||||||||||||||||||
extraFormData: { | ||||||||||||||||||||||||||||||||||||||
append_form_data: { | ||||||||||||||||||||||||||||||||||||||
filters: | ||||||||||||||||||||||||||||||||||||||
values.length === 0 | ||||||||||||||||||||||||||||||||||||||
? [] | ||||||||||||||||||||||||||||||||||||||
: groupby.map((col, idx) => { | ||||||||||||||||||||||||||||||||||||||
const val = groupbyValues.map(v => v[idx]); | ||||||||||||||||||||||||||||||||||||||
if (val === null || val === undefined) | ||||||||||||||||||||||||||||||||||||||
return { | ||||||||||||||||||||||||||||||||||||||
col, | ||||||||||||||||||||||||||||||||||||||
op: 'IS NULL', | ||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||
return { | ||||||||||||||||||||||||||||||||||||||
col, | ||||||||||||||||||||||||||||||||||||||
op: 'IN', | ||||||||||||||||||||||||||||||||||||||
val: val as (string | number | boolean)[], | ||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||
}), | ||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||
currentState: { | ||||||||||||||||||||||||||||||||||||||
value: groupbyValues ?? null, | ||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||
ownFilters: { | ||||||||||||||||||||||||||||||||||||||
currentState: { | ||||||||||||||||||||||||||||||||||||||
selectedValues: values, | ||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||
[groupby, labelMap, setDataMask, selectedValues], | ||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
const eventHandlers: EventHandlers = { | ||||||||||||||||||||||||||||||||||||||
click: props => { | ||||||||||||||||||||||||||||||||||||||
const { name } = props; | ||||||||||||||||||||||||||||||||||||||
const values = Object.values(selectedValues); | ||||||||||||||||||||||||||||||||||||||
if (values.includes(name)) { | ||||||||||||||||||||||||||||||||||||||
handleChange(values.filter(v => v !== name)); | ||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||
handleChange([...values, name]); | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
return ( | ||||||||||||||||||||||||||||||||||||||
<Echart | ||||||||||||||||||||||||||||||||||||||
height={height} | ||||||||||||||||||||||||||||||||||||||
width={width} | ||||||||||||||||||||||||||||||||||||||
echartOptions={echartOptions} | ||||||||||||||||||||||||||||||||||||||
eventHandlers={eventHandlers} | ||||||||||||||||||||||||||||||||||||||
selectedValues={selectedValues} | ||||||||||||||||||||||||||||||||||||||
/> | ||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import { t } from '@superset-ui/core'; | ||
import { FeatureFlag, isFeatureEnabled, t } from '@superset-ui/core'; | ||
import { | ||
D3_FORMAT_DOCS, | ||
D3_FORMAT_OPTIONS, | ||
|
@@ -62,6 +62,20 @@ export default { | |
expanded: true, | ||
controlSetRows: [ | ||
['color_scheme'], | ||
isFeatureEnabled(FeatureFlag.DASHBOARD_CROSS_FILTERS) | ||
? [ | ||
{ | ||
name: 'emit_filter', | ||
config: { | ||
type: 'CheckboxControl', | ||
label: t('Enable emitting filters'), | ||
default: false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we pick the default value from |
||
renderTrigger: true, | ||
description: t('Enable emmiting filters.'), | ||
}, | ||
}, | ||
] | ||
: [], | ||
[ | ||
{ | ||
name: 'x_ticks_layout', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -16,10 +16,79 @@ | |||||||||||||||||||||||||||||||||||||
* specific language governing permissions and limitations | ||||||||||||||||||||||||||||||||||||||
* under the License. | ||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||
import React from 'react'; | ||||||||||||||||||||||||||||||||||||||
import { EchartsProps } from '../types'; | ||||||||||||||||||||||||||||||||||||||
import React, { useCallback } from 'react'; | ||||||||||||||||||||||||||||||||||||||
import { PieChartTransformedProps } from './types'; | ||||||||||||||||||||||||||||||||||||||
import Echart from '../components/Echart'; | ||||||||||||||||||||||||||||||||||||||
import { EventHandlers } from '../types'; | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
export default function EchartsPie({ height, width, echartOptions }: EchartsProps) { | ||||||||||||||||||||||||||||||||||||||
return <Echart height={height} width={width} echartOptions={echartOptions} />; | ||||||||||||||||||||||||||||||||||||||
export default function EchartsPie({ | ||||||||||||||||||||||||||||||||||||||
height, | ||||||||||||||||||||||||||||||||||||||
width, | ||||||||||||||||||||||||||||||||||||||
echartOptions, | ||||||||||||||||||||||||||||||||||||||
setDataMask, | ||||||||||||||||||||||||||||||||||||||
labelMap, | ||||||||||||||||||||||||||||||||||||||
groupby, | ||||||||||||||||||||||||||||||||||||||
selectedValues, | ||||||||||||||||||||||||||||||||||||||
}: PieChartTransformedProps) { | ||||||||||||||||||||||||||||||||||||||
const handleChange = useCallback( | ||||||||||||||||||||||||||||||||||||||
(values: string[]) => { | ||||||||||||||||||||||||||||||||||||||
const groupbyValues = values.map(value => labelMap[value]); | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
setDataMask({ | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here we also need to check if |
||||||||||||||||||||||||||||||||||||||
crossFilters: { | ||||||||||||||||||||||||||||||||||||||
extraFormData: { | ||||||||||||||||||||||||||||||||||||||
append_form_data: { | ||||||||||||||||||||||||||||||||||||||
filters: | ||||||||||||||||||||||||||||||||||||||
values.length === 0 | ||||||||||||||||||||||||||||||||||||||
? [] | ||||||||||||||||||||||||||||||||||||||
: groupby.map((col, idx) => { | ||||||||||||||||||||||||||||||||||||||
const val = groupbyValues.map(v => v[idx]); | ||||||||||||||||||||||||||||||||||||||
if (val === null || val === undefined) | ||||||||||||||||||||||||||||||||||||||
return { | ||||||||||||||||||||||||||||||||||||||
col, | ||||||||||||||||||||||||||||||||||||||
op: 'IS NULL', | ||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||
return { | ||||||||||||||||||||||||||||||||||||||
col, | ||||||||||||||||||||||||||||||||||||||
op: 'IN', | ||||||||||||||||||||||||||||||||||||||
val: val as (string | number | boolean)[], | ||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||
}), | ||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||
currentState: { | ||||||||||||||||||||||||||||||||||||||
value: groupbyValues ?? null, | ||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||
ownFilters: { | ||||||||||||||||||||||||||||||||||||||
currentState: { | ||||||||||||||||||||||||||||||||||||||
selectedValues: values, | ||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||
[groupby, labelMap, setDataMask, selectedValues], | ||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
const eventHandlers: EventHandlers = { | ||||||||||||||||||||||||||||||||||||||
click: props => { | ||||||||||||||||||||||||||||||||||||||
const { name } = props; | ||||||||||||||||||||||||||||||||||||||
const values = Object.values(selectedValues); | ||||||||||||||||||||||||||||||||||||||
if (values.includes(name)) { | ||||||||||||||||||||||||||||||||||||||
handleChange(values.filter(v => v !== name)); | ||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||
handleChange([...values, name]); | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
return ( | ||||||||||||||||||||||||||||||||||||||
<Echart | ||||||||||||||||||||||||||||||||||||||
height={height} | ||||||||||||||||||||||||||||||||||||||
width={width} | ||||||||||||||||||||||||||||||||||||||
echartOptions={echartOptions} | ||||||||||||||||||||||||||||||||||||||
eventHandlers={eventHandlers} | ||||||||||||||||||||||||||||||||||||||
selectedValues={selectedValues} | ||||||||||||||||||||||||||||||||||||||
/> | ||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to check if
emitFilter
is enabled before calling the hook.