Fork of Bowl of Fruit - General Update Pattern Special Cases
This example illustrates a color legend using a categorical color scale from D3 v5, displaying two fruit categories, "apple" and "lemon," as colored circles with text labels. The visualization uses an SVG rendering and applies the general update pattern, where entering groups are appended and exiting groups are removed, as seen in the `colorlegend.js` module. The legend's position and styling are set via attribute transforms, with the color scale mapping categories to specific hex colors. The code leverages the D3 selection API, including `select`, `append`, `merge`, and the `scaleOrdinal` function to manage the dynamic creation and update of legend elements.