#include "PlotNode.h"

#include "PlotCaptionNode.h"
#include "PlotSeriesNode.h"

#include "LineNode.h"
#include "EquationNode.h"
#include "TextNode.h"


PlotNode::PlotNode(const Transform& transform)
    : AbstractVisualNode(transform)
{

}

void PlotNode::setContent(Plot* content)
{
    mContent = content;
    mContentDirty = true;
}

void PlotNode::update(SceneInfo* sceneInfo)
{
    if (mContentDirty)
    {
        createOrUpdateGeometry(sceneInfo);
        mContentDirty = false;
    }
}

void PlotNode::setAxisEndStyle(LineEndNode::Style style)
{
    if (mAxisEndStyle != style)
    {
        mAxisEndStyle = style;
        mContentDirty = true;
    }
}

void PlotNode::createOrUpdateGeometry(SceneInfo*)
{
    const double height = 100.0;
    const double width = 100.0;

    Point x_axis_start{ 0.0, height };
    std::vector<Point> x_axis_points = { Point(width, 0.0) };
    mXAxis = std::make_unique<LineNode>(Transform(x_axis_start), x_axis_points);
    mXAxis->setEndEndStyle(mAxisEndStyle);

    addChild(mXAxis.get());

    Point y_axis_start{ 0.0, height };
    std::vector<Point> y_axis_points = { Point(0.0, -height) };
    mYAxis = std::make_unique<LineNode>(Transform(y_axis_start), y_axis_points);
    mYAxis->setEndEndStyle(mAxisEndStyle);

    addChild(mYAxis.get());

}


