-
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'snehilvj:master' into add-type-simplegrid
- Loading branch information
Showing
10 changed files
with
202 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
from .theme import DEFAULT_THEME | ||
import plotly.graph_objects as go | ||
import plotly.io as pio | ||
import copy | ||
|
||
|
||
def add_figure_templates(default=None): | ||
|
||
""" | ||
Create and register Plotly figure templates styled to match the Mantine default theme. | ||
This function generates two custom Plotly templates: | ||
- "mantine_light" for light mode | ||
- "mantine_dark" for dark mode | ||
Templates are registered with `plotly.io.templates`, allowing you to apply them to Plotly figures | ||
using the template names "mantine_light" or "mantine_dark". These templates include Mantine-inspired | ||
color palettes, background colors, and other layout customizations. | ||
Parameters: | ||
- default (str): The default template to apply globally. Must be either "mantine_light" or "mantine_dark". | ||
If not set, the default Plotly template remains unchanged. | ||
Returns: | ||
- None: The templates are registered and optionally set as the default, but no value is returned. | ||
""" | ||
|
||
colors = DEFAULT_THEME["colors"] | ||
font_family = DEFAULT_THEME["fontFamily"] | ||
# pallet generated from https://www.learnui.design/tools/data-color-picker.html#palette | ||
custom_colorscale = [ | ||
"#1864ab", # blue[9] | ||
"#7065b9", | ||
"#af61b7", | ||
"#e35ea5", | ||
"#ff6587", | ||
"#ff7c63", | ||
"#ff9e3d", | ||
"#fcc419", # yellow[5] | ||
] | ||
|
||
# Default theme configurations | ||
default_themes = { | ||
"light": { | ||
"colorway": [ | ||
colors[color][6] | ||
for color in ["blue", "red", "green", "violet", "orange", "cyan", "pink", "yellow"] | ||
], | ||
"paper_bgcolor": "#ffffff", # mantine background color | ||
"plot_bgcolor": "#ffffff", | ||
"gridcolor": "#dee2e6", | ||
}, | ||
"dark": { | ||
"colorway": [ | ||
colors[color][8] | ||
for color in ["blue", "red", "green", "violet", "orange", "cyan", "pink", "yellow"] | ||
], | ||
"paper_bgcolor": colors["dark"][7], # mantine background color | ||
"plot_bgcolor": colors["dark"][7], | ||
"gridcolor": "#343a40", | ||
} | ||
} | ||
|
||
def make_template(name): | ||
#Start with either a light or dark Plotly template | ||
base = "plotly_white" if name == "light" else "plotly_dark" | ||
template = copy.deepcopy(pio.templates[base]) | ||
|
||
layout = template.layout | ||
theme_config = default_themes[name] | ||
|
||
# Apply theme settings | ||
layout.colorway = theme_config["colorway"] | ||
layout.colorscale.sequential = custom_colorscale | ||
layout.piecolorway = theme_config["colorway"] | ||
layout.paper_bgcolor = theme_config["paper_bgcolor"] | ||
layout.plot_bgcolor = theme_config["plot_bgcolor"] | ||
layout.font.family = font_family | ||
|
||
# Grid settings | ||
for axis in (layout.xaxis, layout.yaxis): | ||
axis.gridcolor = theme_config["gridcolor"] | ||
axis.gridwidth = 0.5 | ||
axis.zerolinecolor = theme_config["gridcolor"] | ||
|
||
# Geo settings | ||
layout.geo.bgcolor = theme_config["plot_bgcolor"] | ||
layout.geo.lakecolor = theme_config["plot_bgcolor"] | ||
layout.geo.landcolor = theme_config["plot_bgcolor"] | ||
|
||
# Hover label settings | ||
layout.hoverlabel.font.family = font_family | ||
|
||
# Scatter plot settings | ||
template.data.scatter = (go.Scatter(marker_line_color=theme_config["plot_bgcolor"]),) | ||
template.data.scattergl = (go.Scattergl(marker_line_color=theme_config["plot_bgcolor"]),) | ||
|
||
return template | ||
|
||
|
||
# #register templates | ||
pio.templates["mantine_light"] = make_template("light") | ||
pio.templates["mantine_dark"] = make_template("dark") | ||
|
||
# set the default | ||
if default in ["mantine_light", "mantine_dark"]: | ||
pio.templates.default = default | ||
elif default: | ||
raise ValueError(f"unrecognized {default=}, allowed values are 'mantine_light' and 'mantine_dark'") | ||
|
||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { | ||
MantineColor, | ||
SemiCircleProgress as MantineSemiCircleProgess, | ||
} from "@mantine/core"; | ||
import { BoxProps } from "props/box"; | ||
import { DashBaseProps } from "props/dash"; | ||
import { StylesApiProps } from "props/styles"; | ||
import React from "react"; | ||
|
||
interface Props extends BoxProps, StylesApiProps, DashBaseProps { | ||
/** Progress value from `0` to `100` */ | ||
value: number; | ||
|
||
/** Diameter of the svg in px, `200` by default */ | ||
size?: number; | ||
|
||
/** Circle thickness in px, `12` by default */ | ||
thickness?: number; | ||
|
||
/** Orientation of the circle, `'up'` by default */ | ||
orientation?: 'up' | 'down'; | ||
|
||
/** Direction from which the circle is filled, `'left-to-right'` by default */ | ||
fillDirection?: 'right-to-left' | 'left-to-right'; | ||
|
||
/** Key of `theme.colors` or any valid CSS color value, `theme.primaryColor` by default */ | ||
filledSegmentColor?: MantineColor; | ||
|
||
/** Key of `theme.colors` or any valid CSS color value, by default the value is determined based on the color scheme value */ | ||
emptySegmentColor?: MantineColor; | ||
|
||
/** Transition duration of filled section styles changes in ms, `0` by default */ | ||
transitionDuration?: number; | ||
|
||
/** Label rendered inside the circle */ | ||
label?: React.ReactNode; | ||
|
||
/** Label position relative to the circle center, `'bottom'` by default */ | ||
labelPosition?: 'center' | 'bottom'; | ||
} | ||
|
||
/** Use to represent progress with semi circle diagram */ | ||
const SemiCircleProgress = (props: Props) => { | ||
const { setProps, loading_state, ...others } = props; | ||
|
||
return ( | ||
<MantineSemiCircleProgess | ||
{...others} | ||
/> | ||
); | ||
}; | ||
|
||
SemiCircleProgress.defaultProps = {}; | ||
|
||
export default SemiCircleProgress; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters