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

[WIP] Add the textfield to write X legend of chart #61

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions src/lib/Chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ export default class Chart {
layout.barmode = "stack";
layout.barnorm = "percent";
}
if (
this.params.xLegend &&
(this.params.type === "line" || this.params.type === "bar" || this.params.type === "area")
) {
layout.xaxis = {
title: this.params.xLegend
};
}

return layout;
}
Expand Down
10 changes: 10 additions & 0 deletions src/renderer/components/QueryResultChart/QueryResultChart.css
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,13 @@
flex: 1;
width: 0;
}

.QueryResultChart-textField {
width: 100%;
font-size: 14px;
line-height: 34px;
padding-left: 10px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
33 changes: 30 additions & 3 deletions src/renderer/components/QueryResultChart/QueryResultChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,22 @@ import React from "react";
import Select from "react-select";
import Chart from "../../../lib/Chart";

export default class QueryResultChart extends React.Component<any, any> {
type State = {
readonly xLegend: string;
};

export default class QueryResultChart extends React.Component<any, State> {
chartElement: HTMLDivElement | null;

shouldComponentUpdate(nextProps) {
constructor(props) {
super(props);
this.state = {
xLegend: ""
};
this.handleChangeXLegend = this.handleChangeXLegend.bind(this);
}

shouldComponentUpdate(nextProps, nextState: State) {
const query = nextProps.query;
const chart = nextProps.chart;

Expand All @@ -15,6 +27,7 @@ export default class QueryResultChart extends React.Component<any, any> {
if (this.props.query.id !== query.id) return true;
if (this.props.query.runAt !== query.runAt) return true;
if (this.props.chart.updatedAt !== chart.updatedAt) return true;
if (this.state.xLegend !== nextState.xLegend) return true;

return false;
}
Expand All @@ -31,7 +44,8 @@ export default class QueryResultChart extends React.Component<any, any> {
stacking: chart.stacking,
groupBy: chart.groupColumn,
rows: query.rows,
fields: query.fields
fields: query.fields,
xLegend: this.state.xLegend.length > 0 ? this.state.xLegend : null
};

new Chart(params).drawTo(this.chartElement);
Expand All @@ -57,6 +71,10 @@ export default class QueryResultChart extends React.Component<any, any> {
this.update({ xColumn: option ? option.value : null });
}

handleChangeXLegend(e: React.ChangeEvent<HTMLInputElement>) {
this.setState({ xLegend: e.target.value });
}

handleChangeY(options) {
this.update({ yColumns: options.map(o => o.value) });
}
Expand Down Expand Up @@ -116,6 +134,15 @@ export default class QueryResultChart extends React.Component<any, any> {
<div className="QueryResultChart-label">{chart.type === "pie" ? "Label Column" : "X Column"}</div>
<Select options={fieldOptions} value={chart.xColumn} onChange={o => this.handleChangeX(o)} />
</div>
<div className="QueryResultChart-item" hidden={chart.type === "pie"}>
<div className="QueryResultChart-label">X Legend</div>
<input
className="QueryResultChart-textField"
type="text"
value={this.state.xLegend}
onChange={this.handleChangeXLegend}
/>
</div>
<div className="QueryResultChart-item">
<div className="QueryResultChart-label">{chart.type === "pie" ? "Value Column" : "Y Column"}</div>
<Select multi={true} options={fieldOptions} value={chart.yColumns} onChange={o => this.handleChangeY(o)} />
Expand Down