diff --git a/docs/api-reference.md b/docs/api-reference.md index ea29cd6..b26ac3a 100644 --- a/docs/api-reference.md +++ b/docs/api-reference.md @@ -114,21 +114,64 @@ Single-value indicator graphs. - `field`: Main field configuration - `compare_field`: Optional comparison field +- `progressbar`: Whether to display as a progress bar (boolean) +- `show_percent`: Whether to display the percentage value (boolean) +- `suffix`: Optional suffix to append to the value (e.g., '%', 'kW') +- `color`: Conditional color expression +- `icon`: Conditional icon expression +- `total_domain`: Domain for calculating the total value #### Methods -##### get_indicator_value(values, fields) +##### process(value, total=0) -Calculate the indicator value. +Process indicator data and return formatted result. + +**Parameters:** +- `value`: The indicator value +- `total` (optional): The total value for percentage calculation + +**Returns:** +- Dictionary containing: + - `value`: The indicator value + - `total`: The total value (if provided) + - `type`: Graph type ('indicator') + - `percent`: Calculated percentage (if progressbar or show_percent is True) + - `progressbar`: True if progressbar attribute is set + - `showPercent`: True if showPercent attribute is set + - `suffix`: Value suffix (if set) + - `color`: Evaluated color (if color condition is set) + - `icon`: Evaluated icon (if icon condition is set) **Example:** ```python +# Basic indicator xml = ''' ''' indicator = parse_graph(xml) + +# Indicator with progress bar +xml = ''' + + + +''' +indicator = parse_graph(xml) +result = indicator.process(75, 100) +# result: {'value': 75, 'total': 100, 'type': 'indicator', 'percent': 75.0, 'progressbar': True} + +# Indicator with percentage display +xml = ''' + + + +''' +indicator = parse_graph(xml) +result = indicator.process(85, 100) +# result: {'value': 85, 'total': 100, 'type': 'indicator', 'percent': 85.0, 'suffix': '%', 'showPercent': True} ``` ### GraphIndicatorField Class diff --git a/docs/examples.md b/docs/examples.md index f309347..a29e12a 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -122,6 +122,41 @@ kpi_result = kpi_graph.process(revenue_data, {'revenue': {'type': 'float'}}) print(f"Total Revenue: {kpi_result}") ``` +### Indicator with Progress Bar + +```python +# Indicator with progress bar showing completion percentage +progress_xml = ''' + + + +''' + +progress_graph = parse_graph(progress_xml) + +# Process with value and total +result = progress_graph.process(75, 100) +print(f"Progress: {result}") +# Output: {'value': 75, 'total': 100, 'type': 'indicator', 'percent': 75.0, 'progressbar': True} +``` + +### Indicator with Percentage Display + +```python +# Indicator showing percentage without progress bar +percent_xml = ''' + + + +''' + +percent_graph = parse_graph(percent_xml) + +result = percent_graph.process(85, 100) +print(f"Success Rate: {result}") +# Output: {'value': 85, 'total': 100, 'type': 'indicator', 'percent': 85.0, 'suffix': '%', 'showPercent': True} +``` + ## Tree View Examples ### Basic Employee List diff --git a/docs/usage.md b/docs/usage.md index 93ea032..2ebaf99 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -67,6 +67,8 @@ print(result) # Processed graph data ready for visualization ### Indicator Graphs +Indicators display single KPI values and support several display modes: + ```python # Simple indicator indicator_xml = ''' @@ -74,10 +76,36 @@ indicator_xml = ''' ''' - indicator = parse_graph(indicator_xml) + +# Indicator with progress bar +progress_xml = ''' + + + +''' +progress_indicator = parse_graph(progress_xml) +result = progress_indicator.process(75, 100) +# result: {'value': 75, 'total': 100, 'percent': 75.0, 'progressbar': True} + +# Indicator with percentage display +percent_xml = ''' + + + +''' +percent_indicator = parse_graph(percent_xml) +result = percent_indicator.process(85, 100) +# result: {'value': 85, 'total': 100, 'percent': 85.0, 'showPercent': True, 'suffix': '%'} ``` +**Indicator Attributes:** +- `progressbar`: Display as a progress bar with percentage (set to "1" or "true") +- `showPercent`: Display the percentage value as text (set to "1" or "true") +- `suffix`: Add a suffix to the value (e.g., "%", "kW", "users") +- `color`: Conditional color expression (e.g., "red:value<50;green:value>=50") +- `icon`: Conditional icon expression + ## Tree Views Tree views handle structured data displays with filtering capabilities.