Skip to content

add format option for slider widget and return texts for display values#154

Merged
dcaminos merged 5 commits intostreamlit:developfrom
dcaminos:issue1100/slider_formatting_function
Sep 24, 2019
Merged

add format option for slider widget and return texts for display values#154
dcaminos merged 5 commits intostreamlit:developfrom
dcaminos:issue1100/slider_formatting_function

Conversation

@dcaminos
Copy link
Copy Markdown
Contributor

@dcaminos dcaminos commented Sep 20, 2019

https://github.com/streamlit/streamlit-old-private/issues/1100

*Added new field to Slider proto definition:
-string format = 7;
*Overridden ThumbValue and Tick subcomponents from UISlider component


Screen Shot 2019-09-20 at 3 59 18 PM
Screen Shot 2019-09-20 at 3 59 27 PM (2)

  • By checking this box, I agree that all contributions to this project are made under the Apache 2.0 license.

@dcaminos dcaminos requested review from jrhone, kantuni and tvst September 20, 2019 19:18
color: $disabled ? gray : primary,
top: "-22px",
position: "absolute" as "absolute",
whiteSpace: "nowrap" as "nowrap",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is the as "nowrap" required? Seems quite odd.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, is required, but the right way is: whiteSpace: "nowrap",

Copy link
Copy Markdown
Contributor

@tvst tvst left a comment

Choose a reason for hiding this comment

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

Approved after comments are addressed.

If you feel like you were unable to satisfactorily address a comment, ping me on Slack and let's chat about solutions.

import { debounce } from "lib/utils"
import { WidgetStateManager } from "lib/WidgetStateManager"
import { sliderOverrides } from "lib/widgetTheme"
var sprintf = require("sprintf-js").sprintf
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please change to a normal import. If not possible, add comment explaining why.

overrides={sliderOverrides}
overrides={{
...sliderOverrides,
// @Dani:here is doc about how override subcomponents: https://baseweb.design/components/slider/
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This comment is not necessary, please remove.

(What I was asking for before was to put a comment saying where you took the code from, but after reading that page I see your code is different enough from the source that this isn't needed.)

position: "absolute" as "absolute",
whiteSpace: "nowrap",
backgroundColor: "transparent",
lineHeight: 1.6,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Use lineHeightBase instead. Same below.

paddingBottom: smallTextMargin,
color: $disabled ? gray : primary,
top: "-22px",
position: "absolute" as "absolute",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Continuing the conversation from here: why is the as "absolute" needed? What kind of error do you get if this isn't included? I'm having a hard time understanding what's happening behind the scenes in the TS compiler...

Copy link
Copy Markdown
Contributor Author

@dcaminos dcaminos Sep 24, 2019

Choose a reason for hiding this comment

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

It's a TS problem, I don't know exactly why. I solved it casting the object:
const tickBarItemStyle = sliderOverrides.TickBarItem.style as React.CSSProperties

"react-virtualized": "^9.21.0",
"reactstrap": "^8.0.1",
"recharts": "^1.6.2",
"sprintf-js": "^1.1.2",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Don't forget to regenerated the NOTICES file:

make notices

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the make notices command is wrong, I will update the make file, the right command is 'yarn licenses`.

Do you want to change the make verb? : make licenses maybe?

step : int/float
The stepping interval.
Defaults to 1 if the value is an int, 0.01 otherwise.
format : str
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Change to str or None.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

And, actually, please change the other arguments above that accept None.

if all_ints:
format = "%d"
else:
format = "%0.2f"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add a comment here saying something like:

It would be great if we could guess the number of decimal places from the step`argument, but this would only be meaningful if step were a decimal. As a possible improvement we could make this function accept decimals and/or use some heuristics for floats.

@dcaminos dcaminos merged commit d3e7dda into streamlit:develop Sep 24, 2019
@dcaminos dcaminos deleted the issue1100/slider_formatting_function branch September 24, 2019 20:44
tconkling added a commit to tconkling/streamlit that referenced this pull request Sep 25, 2019
# By Jonathan Rhone (3) and others
# Via GitHub
* develop:
  Text changes in ☰ menu and several CLI prompts (streamlit#180)
  add format option for slider widget and return texts for display values (streamlit#154)
  Merge ForwardMsg caching into develop  (streamlit#178)
  e2e test for magic (streamlit#172)
  Bart example update (streamlit#179)
  Pedantic CircleCI cleanup (streamlit#174)
  Fix overwriting elements in the sidebar (streamlit#181)
  update vega lite chart snapshot (streamlit#183)
  Stop react-markdown from converting "[foo]" to a link. (streamlit#151)
  Issue 1204: Graphs using Vega-Lite (streamlit#56)
  Removing uber demo from streamlit repo (streamlit#159)

# Conflicts:
#	lib/streamlit/DeltaGenerator.py
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.

2 participants