Skip to content
Merged
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
47 changes: 45 additions & 2 deletions docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '''
<graph type="indicator" string="Total Sales">
<field name="total" type="float" operator="sum"/>
</graph>
'''
indicator = parse_graph(xml)

# Indicator with progress bar
xml = '''
<graph type="indicator" string="Completion" progressbar="1">
<field name="completed" type="integer" operator="sum"/>
</graph>
'''
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 = '''
<graph type="indicator" string="Success Rate" showPercent="1" suffix="%">
<field name="success" type="integer" operator="sum"/>
</graph>
'''
indicator = parse_graph(xml)
result = indicator.process(85, 100)
# result: {'value': 85, 'total': 100, 'type': 'indicator', 'percent': 85.0, 'suffix': '%', 'showPercent': True}
```

### GraphIndicatorField Class
Expand Down
35 changes: 35 additions & 0 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '''
<graph type="indicator" string="Project Completion" progressbar="1">
<field name="completed_tasks" type="integer" operator="sum"/>
</graph>
'''

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 = '''
<graph type="indicator" string="Success Rate" showPercent="1" suffix="%">
<field name="successful" type="integer" operator="sum"/>
</graph>
'''

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
Expand Down
30 changes: 29 additions & 1 deletion docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,45 @@ 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 = '''
<graph type="indicator" string="Total Sales">
<field name="total_sales" type="float" operator="sum"/>
</graph>
'''

indicator = parse_graph(indicator_xml)

# Indicator with progress bar
progress_xml = '''
<graph type="indicator" string="Task Completion" progressbar="1">
<field name="completed" type="integer" operator="sum"/>
</graph>
'''
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 = '''
<graph type="indicator" string="Success Rate" showPercent="1" suffix="%">
<field name="success" type="integer" operator="sum"/>
</graph>
'''
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.
Expand Down