Skip to content

Conversation

@d2fong
Copy link
Member

@d2fong d2fong commented Aug 25, 2025

This pull request introduces several improvements and new features related to custom graphics rendering in the Vizmapper, especially for pie and ring charts. Key changes include refactoring and extending utility functions, updating how custom graphics properties are handled, and adding new color palettes for custom graphics. Additionally, new components for rendering pie and ring chart previews are implemented. Below are the most important changes grouped by theme:

Custom Graphics Rendering and Preview Components

  • Added new React components PieChartRender and RingChartRender for rendering preview images of pie and ring charts based on custom graphics properties. These components display the chart with correct slice colors and support empty states and labels. (src/components/Vizmapper/VisualPropertyRender/CustomGraphics/PieChartRender.tsx, [1]; src/components/Vizmapper/VisualPropertyRender/CustomGraphics/RingChartRender.tsx, [2]
  • Removed the old CustomGraphic.tsx file and replaced its logic with the new, more modular CustomGraphics components. (src/components/Vizmapper/VisualPropertyRender/CustomGraphic.tsx, src/components/Vizmapper/VisualPropertyRender/CustomGraphic.tsxL1-L66)

Utility and Property Handling Improvements

  • Refactored pie and ring chart property mapping in cyjs-util.ts to use new utility functions and constants for property names and valid index ranges, improving maintainability and correctness. (src/components/NetworkPanel/CyjsRenderer/cyjs-util.ts, [1] [2] [3] [4]
  • Improved the logic in updateCyElements to ensure custom graphics properties are properly removed from Cytoscape.js objects when not present in the view model, preventing stale data. (src/components/NetworkPanel/CyjsRenderer/cyjs-util.ts, src/components/NetworkPanel/CyjsRenderer/cyjs-util.tsR449-R467)

Palette and Color Support

Form and Value Rendering Updates

  • Updated imports and logic in VisualPropertyValueForm.tsx to use the new CustomGraphics types and components. Added handling for rendering empty views when no custom graphic is selected. (src/components/Vizmapper/Forms/VisualPropertyValueForm.tsx, [1] [2]

These changes collectively improve the flexibility, visual quality, and maintainability of custom graphics rendering in the Vizmapper.

yihangx and others added 7 commits July 31, 2025 01:10
- Introduced utility functions to retrieve pie chart background color and size properties based on slice index.
- Updated the `createCyjsDataMapper` function to utilize these new utilities for better maintainability.
- Refactored pie chart property mappings to use constants from `SpecialPropertyName`.
- Added validation for slice indices in new utility functions to ensure robustness.
- Improved the handling of custom graphics properties in the update cycle.
- Sync cy objects by necessarily removing custom graphics keys that would exist in the view model if custom graphics properties are removed
- Moved `CustomGraphic.tsx` to a new directory structure under `CustomGraphics/` for better organization.
- Updated import paths in `VisualPropertyValueForm.tsx` to reflect the new location of `CustomGraphic`.
- Introduced new components for rendering pie and ring charts (`PieChartRender.tsx` and `RingChartRender.tsx`) to enhance modularity and maintainability.
- Added margin and background color to the StyledAccordion for better visual separation.
- Updated Typography in StyledAccordion to increase font weight for emphasis.
- Introduced handling for 'nodeImageChart' visual properties in VisualPropertyValueRender.
- Refactored ChartGraphicForm layout for better responsiveness and clarity.
- Implemented step overview in CustomGraphicDialog to guide users through the configuration process.
- Adjusted rendering order in PieChartRender and RingChartRender to align with Cytoscape.js expectations.
@d2fong d2fong requested a review from Copilot August 25, 2025 22:40

This comment was marked as outdated.

d2fong added 5 commits August 26, 2025 11:21
- Adjusted padding and margin in StyledAccordion for better spacing.
- Updated Typography font weight for improved readability.
- Simplified handling of custom graphic properties in ChartGraphicForm.
- Introduced random color generation for chart slices to enhance visual diversity.
- Enhanced user guidance in ChartGraphicForm with clearer instructions and layout adjustments.
- Streamlined rendering logic in CustomGraphicDialog for better user experience.
…t configuration

- Removed the monolithic `CustomGraphic.tsx` and replaced it with modular components for better maintainability.
- Added `CustomGraphicDialog`, `CustomGraphicPicker`, and `CustomGraphicRender` for enhanced user interaction and rendering of pie and ring charts.
- Implemented forms for attributes, palette selection, and properties configuration to streamline the chart setup process.
- Updated import paths in `VisualPropertyValueForm.tsx` to reflect the new component structure.
- Introduced utility functions for color management and chart properties handling to improve code organization and reusability.
- Replaced `ChartPreview` with `CustomGraphicPreview`
- Updated `SelectTypeStep` to include a warning for missing numeric properties, enhancing user guidance.
- Introduced `hasNumericProperties` state to manage step navigation and button states based on available data.
- Refactored `StepProgress` to disable steps when numeric properties are not available, improving user experience.
- Removed unused random color generation function and associated tests to streamline codebase.
…passes

- Updated property names in CustomGraphicsPositionType to uppercase constants for improved clarity and consistency.
- Adjusted DEFAULT_CUSTOM_GRAPHICS_POSITION to reflect the new property naming convention.
- Enhanced exportNetworkToCx2 function by creating separate lists for custom graphic node visual properties based on their usage (defaults, mappings, bypasses), improving code organization and readability.
- Updated VisualPropertyValueRender to handle null custom graphic types, improving error handling.
- Enhanced CustomGraphicDialog with new props for better user interaction, including disabling escape key and handling backdrop clicks.
- Refactored README.md to reflect the new structure and features of custom graphics components, including detailed descriptions of new components and validation features.
- Improved AttributesForm and PaletteForm for better user experience, including layout adjustments and enhanced palette selection with tabs and popover functionality.
@d2fong d2fong requested a review from Copilot August 26, 2025 18:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request introduces significant improvements and new features for custom graphics rendering in the Vizmapper, with a focus on pie and ring charts. The changes replace the old monolithic CustomGraphic.tsx with a comprehensive, modular component system that includes enhanced color palettes, improved visual property handling, and better user experience through a step-by-step wizard interface.

Key Changes:

  • Refactored custom graphics system with modular React components for pie and ring chart rendering
  • Added extensive color palette support with Sequential, Diverging, and Viridis color schemes
  • Improved visual property mapping and CX export functionality with separate handling for defaults, mappings, and bypasses
  • Enhanced Vizmapper UI with accordion-style organization and better visual property grouping

Reviewed Changes

Copilot reviewed 29 out of 29 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
src/store/io/exportCX.ts Separates custom graphic properties into distinct lists for defaults, mappings, and bypasses in CX export
src/models/VisualStyleModel/impl/cyJsVisualPropertyConverter.ts Adds utility functions for generating pie chart property names with validation
src/models/VisualStyleModel/impl/DefaultVisualStyle.ts Updates custom graphics position property names to use uppercase constants
src/models/VisualStyleModel/impl/CyjsProperties/CyjsVisualPropertyName.ts Converts pie chart property types to use template literals for indexed properties
src/models/VisualStyleModel/impl/CyjsProperties/CyjsStyleModels/DirectMappingSelector.ts Adds comprehensive pie chart property constants for all 16 slices
src/models/VisualStyleModel/impl/CustomGraphicsImpl.ts Major refactor with new utility functions, property validation, and improved chart computation
src/models/VisualStyleModel/impl/CustomColor.ts Adds 340+ lines of new color palettes for custom graphics
src/models/VisualStyleModel/VisualPropertyValue/CustomGraphicsType.ts Updates position type property names to uppercase constants
src/components/Vizmapper/index.tsx Complete UI overhaul with accordion organization and improved property grouping
Multiple new custom graphics components Implements modular component system with wizard interface, form components, and rendering utilities

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +36 to +37
const DEFAULT_COLOR = '#000000' as ColorType

Copy link

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

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

Consider moving DEFAULT_COLOR to a constants file or importing from existing constants to maintain consistency across the codebase.

Suggested change
const DEFAULT_COLOR = '#000000' as ColorType

Copilot uses AI. Check for mistakes.
Comment on lines +186 to +188
const { PALETTES } = require('../utils/palettes')
const { pickEvenly } = require('../utils/colorUtils')

Copy link

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

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

Use ES6 import syntax instead of require() for consistency with the rest of the TypeScript codebase.

Suggested change
const { PALETTES } = require('../utils/palettes')
const { pickEvenly } = require('../utils/colorUtils')

Copilot uses AI. Check for mistakes.
Comment on lines +186 to +188
const { PALETTES } = require('../utils/palettes')
const { pickEvenly } = require('../utils/colorUtils')

Copy link

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

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

Use ES6 import syntax instead of require() for consistency with the rest of the TypeScript codebase.

Suggested change
const { PALETTES } = require('../utils/palettes')
const { pickEvenly } = require('../utils/colorUtils')

Copilot uses AI. Check for mistakes.
const x2 = radius * Math.cos(endAngle)
const y2 = radius * Math.sin(endAngle)

const largeArcFlag = sliceAngle > 180 ? 1 : 0
Copy link

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider extracting magic number 180 to a named constant (e.g., LARGE_ARC_THRESHOLD) to improve code readability and maintainability.

Suggested change
const largeArcFlag = sliceAngle > 180 ? 1 : 0
const largeArcFlag = sliceAngle > LARGE_ARC_THRESHOLD ? 1 : 0

Copilot uses AI. Check for mistakes.
const x4 = innerRadius * Math.cos(startAngle)
const y4 = innerRadius * Math.sin(startAngle)

const largeArcFlag = sliceAngle > 180 ? 1 : 0
Copy link

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider extracting magic number 180 to a named constant (e.g., LARGE_ARC_THRESHOLD) to improve code readability and maintainability. This duplicates the same logic from PieChartRender.tsx.

Suggested change
const largeArcFlag = sliceAngle > 180 ? 1 : 0
const largeArcFlag = sliceAngle > LARGE_ARC_THRESHOLD ? 1 : 0

Copilot uses AI. Check for mistakes.
Comment on lines +140 to +142
maxWidth: 500,
width: 500,
height: 800,
Copy link

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider extracting modal dimensions (500, 800) to named constants to improve maintainability and allow for easier theme customization.

Suggested change
maxWidth: 500,
width: 500,
height: 800,
maxWidth: PALETTE_MODAL_WIDTH,
width: PALETTE_MODAL_WIDTH,
height: PALETTE_MODAL_HEIGHT,

Copilot uses AI. Check for mistakes.
const width = computeCustomGraphicSizeProperties(id, widthVp, mappers, row)

const height = computeCustomGraphicSizeProperties(id, heightVp, mappers, row)
const padding = 4 // padding between pie chart and node border, this is an attempt to render things similarly to Cytoscape Desktop
Copy link

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

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

Consider extracting the magic number 4 to a named constant (e.g., PIE_CHART_PADDING) to improve maintainability.

Suggested change
const padding = 4 // padding between pie chart and node border, this is an attempt to render things similarly to Cytoscape Desktop
const padding = PIE_CHART_PADDING

Copilot uses AI. Check for mistakes.
const width = computeCustomGraphicSizeProperties(id, widthVp, mappers, row)

const height = computeCustomGraphicSizeProperties(id, heightVp, mappers, row)
const padding = 4 // padding between pie chart and node border, this is an attempt to render things similarly to Cytoscape Desktop
Copy link

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

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

This duplicates the same padding logic from computePieChartProperties. Consider extracting to a shared constant or utility function.

Suggested change
const padding = 4 // padding between pie chart and node border, this is an attempt to render things similarly to Cytoscape Desktop
const padding = PIE_CHART_NODE_BORDER_PADDING // padding between pie chart and node border, this is an attempt to render things similarly to Cytoscape Desktop

Copilot uses AI. Check for mistakes.

<FormControl
size="small"
sx={{ '& .MuiInputBase-root': { height: 32, width: 340 } }}
Copy link

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider extracting magic numbers (32, 340) to named constants or theme variables to improve maintainability and consistency.

Suggested change
sx={{ '& .MuiInputBase-root': { height: 32, width: 340 } }}
sx={{ '& .MuiInputBase-root': { height: INPUT_HEIGHT, width: INPUT_WIDTH } }}

Copilot uses AI. Check for mistakes.
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.

3 participants