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

Use line tile in place page #2734

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

shifucun
Copy link
Contributor

@shifucun shifucun commented May 23, 2023

  • Move explore url computation to frontend and added an optional child component in line tile to hold that.
  • Remove line chart data calculation on the server side.
  • This sets up an example to move other charts as tile.

This revealed a bug when denominator is present (note the value is much smaller due to wrong scaling"
image

@shifucun shifucun requested a review from chejennifer May 23, 2023 18:33
Copy link
Contributor

@chejennifer chejennifer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is cool!

@@ -51,6 +51,10 @@ interface LineTilePropType {
apiRoot?: string;
// Whether or not to render the data version of this tile
isDataTile?: boolean;
// The link of the stat var legend
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: mention that it's a map where key is the stat var dcid and value is the link to use for that stat var

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

></Chart>
);
}
const id = randDomId();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this chart used to only be added to the page if there is trend data, but now it's always added to the page? I don't think we want to show empty charts on the place page?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now Flask still fetches the place page cache (for bar data) and trim spec if no data is available. So only valid spec are returned, thus the line chart always have data.

A related issue is when line chart has single dot. I added a callback function to LineLine, which set "display: false" so the line tile is removed if there is only single dot.

};
})}
svgChartHeight={CHART_HEIGHT}
className={"ranking-class"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious what this class is for & what ranking has to do with this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be removed.

// TODO(datcom): handle i18n for scaled numbers
const scaling = this.props.scaling ? this.props.scaling : 1;
const sv = !_.isEmpty(this.props.statsVars) ? this.props.statsVars[0] : "";
switch (this.props.chartType) {
case chartTypeEnum.LINE:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you also need to update the drawChart function & componentDidUpdate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the drawLine() in drawChart

Copy link
Contributor Author

@shifucun shifucun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for review!

@@ -51,6 +51,10 @@ interface LineTilePropType {
apiRoot?: string;
// Whether or not to render the data version of this tile
isDataTile?: boolean;
// The link of the stat var legend
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

};
})}
svgChartHeight={CHART_HEIGHT}
className={"ranking-class"}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be removed.

// TODO(datcom): handle i18n for scaled numbers
const scaling = this.props.scaling ? this.props.scaling : 1;
const sv = !_.isEmpty(this.props.statsVars) ? this.props.statsVars[0] : "";
switch (this.props.chartType) {
case chartTypeEnum.LINE:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the drawLine() in drawChart

></Chart>
);
}
const id = randDomId();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now Flask still fetches the place page cache (for bar data) and trim spec if no data is available. So only valid spec are returned, thus the line chart always have data.

A related issue is when line chart has single dot. I added a callback function to LineLine, which set "display: false" so the line tile is removed if there is only single dot.

@shifucun shifucun requested a review from chejennifer May 24, 2023 16:38
Copy link
Contributor

@chejennifer chejennifer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the updates!

@@ -152,8 +169,7 @@ export function draw(
chartData.unit
);
if (!isCompleteLine) {
svgContainer.querySelectorAll(".dotted-warning")[0].className +=
" d-inline";
elem.querySelectorAll(".dotted-warning")[0].className += " d-inline";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe should check that querySelectorAll returns a non-empty list before accessing the first element? & maybe should also iterate through the list and add the class name to all selected elements?

// Optional callback function when source link is clicked.
clickFn?: ClickFnType;
// Optional callback function to hide the tile when it only has single dot.
hideTileFn?: () => void;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: if I'm understanding this correctly, it looks like this callback is really a callback to handle when there is a single dot. Place page handles this by hiding the tile, but other callers of this tile could technically handle it differently. Maybe update the name of the prop and the description?

sources: Set<string>;
handleEmbed?: () => void;
exploreJsx?: JSX.Element;
// Optional callback function when source link is clicked.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not just for source link right? also used for export?

// set of full urls of sources of the data in the chart
sources: Set<string>;
handleEmbed?: () => void;
export interface ClickFnType {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: since this is an exported interface, can we make the name more informative. Maybe something about ChartFooter like ChartFooterClickFns or something of that sort.

Also add a comment describing this type?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants