I am trying to sketch a composite pattern diagram for the plot linked below.
It is a 2D curve that contains multiple curves, a title, labels for X & Y axes, labels for individual curves, and a dashed-line grid. Some features of the plot will include ability to draw the curves in specified colors and also display a legend of symbols. Also, the application should allow for multiple plots and automatically relabel the plot when it is resized and provide a capability to zoom into portions of the curve.
These are the components I was able to come up with:
Leaves:
Curve {String curveLabel; String color; setColor()}
Axes {String X_Label, Y_Label;}
DashedLine {int x, y;}
Composites:
Interface:
Here, I have 3 leaves and one node. The curve leaf will have a unique label for each curve (e.g. v3(t)) with a method to set the desired color. The Axes leaf will have an X-Axis Label and a Y-Axis Label. The DashedLine leaf will have x and y coordinates for placement of the grid. The Plot node will have a title along with a collection of components including plots and leaves plus methods to display a legend, zoom into the plot and relabel the plot when resized. All the leaves and the node implement the PlotInterface and hence all provide concrete implementations of the draw() method.
That's all I have so far but I'm still learning design patterns so wanted to see if I am approaching it correctly or if there is a better way to use composite design pattern to tackle this problem. Any suggestions or guidance will be hugely appreciated! Thanks in advance.
I would recommend design mentioned here You can have a base graph which will have axes and dashed lines. You can create as many graphs as you want by decorating this base graph. This is easy to implement and extendable. Let me know if you need assistance.