-
Notifications
You must be signed in to change notification settings - Fork 77
feat: line chart with revised encodeable utilities #26
Conversation
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.
Looking great overall, thanks for all the effort here! 💛 💜
packages/superset-ui-plugins-demo/storybook/stories/preset-chart-xy/Line/data/data.js
Show resolved
Hide resolved
type: 'time', | ||
}, | ||
axis: { | ||
orientation: 'bottom', |
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.
could abstract these into knob
s for easy debugging and demo-ing what it does.
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.
I converted it to tsx
then add knobs. Then it starts complaining for missing types definition for external module. I renamed it back to jsx
and will take care of the tsx
and external type def issue in a follow-up pr.
packages/superset-ui-plugins-demo/storybook/stories/preset-chart-xy/Line/index.js
Outdated
Show resolved
Hide resolved
packages/superset-ui-plugins-demo/storybook/stories/preset-chart-xy/Line/stories/basic.jsx
Show resolved
Hide resolved
packages/superset-ui-preset-chart-xy/src/utils/XYChartLayout.tsx
Outdated
Show resolved
Hide resolved
packages/superset-ui-preset-chart-xy/src/utils/XYChartLayout.tsx
Outdated
Show resolved
Hide resolved
packages/superset-ui-preset-chart-xy/src/utils/XYChartLayout.tsx
Outdated
Show resolved
Hide resolved
packages/superset-ui-preset-chart-xy/src/utils/createTickComponent.tsx
Outdated
Show resolved
Hide resolved
packages/superset-ui-preset-chart-xy/types/@vx/legend/index.d.ts
Outdated
Show resolved
Hide resolved
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.
Awesome work!! Just left some comments on
-
Customizability issue'
-
the style Props and defaultProps.
Both are nit :)
parent: Series; | ||
} | ||
|
||
const CIRCLE_STYLE = { strokeWidth: 1.5 }; |
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.
does it mean users cannot customize the style? If the chart is tailored specially for superset, I won't see it will be an issue. But just was thinking of the customization part.
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.
This is only for the highlighted circle when using crosshair. May have to think more carefully about how to expose customization.
return ( | ||
<div key={field} style={LEGEND_CONTAINER_STYLE}> | ||
<LegendOrdinal scale={scale} labelFormat={channelEncoder.formatValue}> | ||
{(labels: Label[]) => ( |
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.
Have we done the test with extremely large number of legends here? So far, there are a lot of chart in Superset that has more than I'd say 20 legends. At least we need to make sure the chart can be rendered.
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.
LEGEND_CONTAINER_STYLE
caps the legend with maxHeight
.
@@ -29,34 +11,32 @@ type Props = { | |||
legendJustifyContent: 'center' | 'flex-start' | 'flex-end'; | |||
position: 'top' | 'left' | 'bottom' | 'right'; | |||
renderChart: (dim: { width: number; height: number }) => ReactNode; | |||
renderLegend: (params: { direction: string }) => ReactNode; | |||
hideLegend: boolean; | |||
renderLegend?: (params: { direction: string }) => ReactNode; |
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.
I saw we have two different ways to define Props with defaultProps. Can we make the styles consistent? I do like the way you defined before, with & typeof defaultProps
.
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.
Yes, fixed.
packages/superset-ui-preset-chart-xy/src/encodeable/parsers/extractScale.ts
Show resolved
Hide resolved
* feat: line chart * feat: implement scale extraction * refactor: no error * fix: handle null * fix: nicing and demo * fix: legend and demo * fix: remove commented code * fix: clean * fix: reviewer comments * fix: legend and series * docs: make demos tsx * fix: reactnode * fix: label angle * fix: resolve labelxxx field names * docs: try knobs * feat: improve axis * refactor: combine computelayout into axisagent * refactor: cleaner use of scale * fix: proptypes
tl;dr. This PR add the first working version of the new Line Chart.
🌕Code Overview
This PR adds two new
LineChart
plugins under thepreset-chart-xy
package. Both plugins point to the sameChart
component but has differentChartMetadata
andtransformProps
. The legacy-compatible plugin will have the sameChartMetadata
with theuseLegacyApi
field set totrue
. ThetransformProps
is the key difference as the legacy-compatible plugin converts legacyformData
to the newformData
while the new plugin'stransformProps
does very little.📈 Line Chart
In
Line.tsx
, which is the main chart component.Line
usesXYChartLayout
, which is a cross-chart utility, to compute necessary margins and labelling strategy for the axes. It also usesChartLegend
to display legend. In addition, it has two chart-specific subcomponents.Encoder
The
Encoder
captures it visual encoding channels (x
,y
,color
,fill
,strokeDasharray
). Each channel has aChannelType
(X
|Y
|XBand
|YBand
|Color
,Category
|Text
) andOutput
(string | boolean | number | null
). These two type parameters are used to generateEncoding
type, which is a vega-lite-ish encoding grammar.Once the
Encoder
is initialized and passed in the actualencoding
config, it can provide utility functions for getting value fromdatum
, encoding values, as well as things we usually want fromscale
oraxis
.Tooltip
This simply renders chart-specific tooltip.
📐 Chart Layout
A chart has multiple wrappers. At the top level
<WithLegend />
attaches legend to one side of the chart, splitting the container into two parts: legend andChartFrame
. Legend will take only necessary space and give the rest toChartFrame
. The actual chart is contained within theChartFrame
and usually has the same size. However, in some case when the chart has to guarantee minimum width and/or height to be usable and theChartFrame
is too small for that, the chart will be given the specified minimum width and/or height, making theChartFrame
scrollable instead.📘 Documentation
Update the storybook for line chart in
packages/superset-ui-plugins-demo/storybook/stories/preset-chart-xy
🔮 Future Work
There are still work remaining after this PR. This PR is a major milestone but not completion.
Encoder
only when necessary.Encoder
class more convenient.computeXAxisLayout()
andcomputeYAxisLayout()
intoAxisAgent
.AxisAgent
derive config type (XAxis | YAxis
) from channel type.tsx
work with knobs without complaining about types