Skip to content
This repository has been archived by the owner on Jun 25, 2020. It is now read-only.

Commit

Permalink
fix: line chart does not handle temporal field correctly (#68)
Browse files Browse the repository at this point in the history
* fix: fallback to default margin when margin is partially set

* feat: can disable axis title

* feat: adjust margin according to axis title visibility

* feat: include margin in formData

* feat: add buildQuery

* fix: address kyle comments

* fix: remove string false

* fix: line chart temporal scale

* fix: format
  • Loading branch information
kristw authored and xtinec committed Apr 23, 2019
1 parent 9c9dd9d commit 79ff3e1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default [
x: {
field: 'x',
type: 'temporal',
format: '%Y',
format: '%Y-%m',
scale: {
type: 'time',
},
Expand Down
20 changes: 11 additions & 9 deletions packages/superset-ui-preset-chart-xy/src/Line/Line.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class LineChart extends PureComponent<Props> {
const { width, height } = dim;
const { data, encoding, margin, theme } = this.props;

const { channels } = this.encoder;

const fieldNames = data.keys
.filter(k => k !== encoding.x.field && k !== encoding.y.field)
.sort((a, b) => a.localeCompare(b));
Expand All @@ -94,15 +96,15 @@ class LineChart extends PureComponent<Props> {

const series: Series = {
key: fieldNames.map(f => firstDatum[f]).join(','),
color: this.encoder.channels.color.encode(firstDatum),
fill: this.encoder.channels.fill.encode(firstDatum, false),
strokeDasharray: this.encoder.channels.strokeDasharray.encode(firstDatum),
color: channels.color.encode(firstDatum),
fill: channels.fill.encode(firstDatum, false),
strokeDasharray: channels.strokeDasharray.encode(firstDatum),
values: [],
};

series.values = seriesData.map(v => ({
x: this.encoder.channels.x.encode(v),
y: this.encoder.channels.y.encode(v),
x: channels.x.get(v),
y: channels.y.get(v),
data: v,
parent: series,
}));
Expand Down Expand Up @@ -157,8 +159,8 @@ class LineChart extends PureComponent<Props> {
height,
margin: { ...DEFAULT_MARGIN, ...margin },
theme,
xEncoder: this.encoder.channels.x,
yEncoder: this.encoder.channels.y,
xEncoder: channels.x,
yEncoder: channels.y,
children,
});

Expand Down Expand Up @@ -186,8 +188,8 @@ class LineChart extends PureComponent<Props> {
snapTooltipToDataX
theme={theme}
tooltipData={tooltipData}
xScale={this.encoder.channels.x.definition.scale}
yScale={this.encoder.channels.y.definition.scale}
xScale={channels.x.definition.scale}
yScale={channels.y.definition.scale}
>
{children}
{layout.renderXAxis()}
Expand Down

0 comments on commit 79ff3e1

Please sign in to comment.