08 August 2015

CombinedChart


public class CombinedChartData: BarLineScatterCandleChartData
{
    private var lineData: LineChartData!
    private var barData: BarChartData!
    private var scatterData: ScatterChartData!
    private var candleData: CandleChartData!
    private var _bubbleData: BubbleChartData!

<span class="kd">public</span> <span class="k">override</span> <span class="nf">init</span><span class="p">()</span>
<span class="p">{</span>
    <span class="k">super</span><span class="o">.</span><span class="nf">init</span><span class="p">()</span>
<span class="p">}</span>

<span class="kd">public</span> <span class="k">override</span> <span class="nf">init</span><span class="p">(</span><span class="nv">xVals</span><span class="p">:</span> <span class="p">[</span><span class="kt">String</span><span class="p">?]?,</span> <span class="nv">dataSets</span><span class="p">:</span> <span class="p">[</span><span class="kt">ChartDataSet</span><span class="p">]?)</span>
<span class="p">{</span>
    <span class="k">super</span><span class="o">.</span><span class="nf">init</span><span class="p">(</span><span class="nv">xVals</span><span class="p">:</span> <span class="n">xVals</span><span class="p">,</span> <span class="nv">dataSets</span><span class="p">:</span> <span class="n">dataSets</span><span class="p">)</span>
<span class="p">}</span>

<span class="kd">public</span> <span class="k">override</span> <span class="nf">init</span><span class="p">(</span><span class="nv">xVals</span><span class="p">:</span> <span class="p">[</span><span class="kt">NSObject</span><span class="p">]?,</span> <span class="nv">dataSets</span><span class="p">:</span> <span class="p">[</span><span class="kt">ChartDataSet</span><span class="p">]?)</span>
<span class="p">{</span>
    <span class="k">super</span><span class="o">.</span><span class="nf">init</span><span class="p">(</span><span class="nv">xVals</span><span class="p">:</span> <span class="n">xVals</span><span class="p">,</span> <span class="nv">dataSets</span><span class="p">:</span> <span class="n">dataSets</span><span class="p">)</span>
<span class="p">}</span>

<span class="kd">public</span> <span class="k">var</span> <span class="nv">lineData</span><span class="p">:</span> <span class="kt">LineChartData</span><span class="o">!</span>
<span class="p">{</span>
    <span class="k">get</span>
    <span class="p">{</span>
        <span class="k">return</span> <span class="n">_lineData</span>
    <span class="p">}</span>
    <span class="k">set</span>
    <span class="p">{</span>
        <span class="n">_lineData</span> <span class="o">=</span> <span class="n">newValue</span>
        <span class="k">for</span> <span class="n">dataSet</span> <span class="k">in</span> <span class="n">newValue</span><span class="o">.</span><span class="n">dataSets</span>
        <span class="p">{</span>
            <span class="n">_dataSets</span><span class="o">.</span><span class="nf">append</span><span class="p">(</span><span class="n">dataSet</span><span class="p">)</span>
        <span class="p">}</span>

        <span class="nf">checkIsLegal</span><span class="p">(</span><span class="n">newValue</span><span class="o">.</span><span class="n">dataSets</span><span class="p">)</span>

        <span class="nf">calcMinMax</span><span class="p">(</span><span class="nv">start</span><span class="p">:</span> <span class="n">_lastStart</span><span class="p">,</span> <span class="nv">end</span><span class="p">:</span> <span class="n">_lastEnd</span><span class="p">)</span>
        <span class="nf">calcYValueSum</span><span class="p">()</span>
        <span class="nf">calcYValueCount</span><span class="p">()</span>

        <span class="nf">calcXValAverageLength</span><span class="p">()</span>
    <span class="p">}</span>
<span class="p">}</span>

<span class="kd">public</span> <span class="k">var</span> <span class="nv">barData</span><span class="p">:</span> <span class="kt">BarChartData</span><span class="o">!</span>
<span class="p">{</span>
    <span class="k">get</span>
    <span class="p">{</span>
        <span class="k">return</span> <span class="n">_barData</span>
    <span class="p">}</span>
    <span class="k">set</span>
    <span class="p">{</span>
        <span class="n">_barData</span> <span class="o">=</span> <span class="n">newValue</span>
        <span class="k">for</span> <span class="n">dataSet</span> <span class="k">in</span> <span class="n">newValue</span><span class="o">.</span><span class="n">dataSets</span>
        <span class="p">{</span>
            <span class="n">_dataSets</span><span class="o">.</span><span class="nf">append</span><span class="p">(</span><span class="n">dataSet</span><span class="p">)</span>
        <span class="p">}</span>

        <span class="nf">checkIsLegal</span><span class="p">(</span><span class="n">newValue</span><span class="o">.</span><span class="n">dataSets</span><span class="p">)</span>

        <span class="nf">calcMinMax</span><span class="p">(</span><span class="nv">start</span><span class="p">:</span> <span class="n">_lastStart</span><span class="p">,</span> <span class="nv">end</span><span class="p">:</span> <span class="n">_lastEnd</span><span class="p">)</span>
        <span class="nf">calcYValueSum</span><span class="p">()</span>
        <span class="nf">calcYValueCount</span><span class="p">()</span>

        <span class="nf">calcXValAverageLength</span><span class="p">()</span>
    <span class="p">}</span>
<span class="p">}</span>

<span class="kd">public</span> <span class="k">var</span> <span class="nv">scatterData</span><span class="p">:</span> <span class="kt">ScatterChartData</span><span class="o">!</span>
<span class="p">{</span>
    <span class="k">get</span>
    <span class="p">{</span>
        <span class="k">return</span> <span class="n">_scatterData</span>
    <span class="p">}</span>
    <span class="k">set</span>
    <span class="p">{</span>
        <span class="n">_scatterData</span> <span class="o">=</span> <span class="n">newValue</span>
        <span class="k">for</span> <span class="n">dataSet</span> <span class="k">in</span> <span class="n">newValue</span><span class="o">.</span><span class="n">dataSets</span>
        <span class="p">{</span>
            <span class="n">_dataSets</span><span class="o">.</span><span class="nf">append</span><span class="p">(</span><span class="n">dataSet</span><span class="p">)</span>
        <span class="p">}</span>

        <span class="nf">checkIsLegal</span><span class="p">(</span><span class="n">newValue</span><span class="o">.</span><span class="n">dataSets</span><span class="p">)</span>

        <span class="nf">calcMinMax</span><span class="p">(</span><span class="nv">start</span><span class="p">:</span> <span class="n">_lastStart</span><span class="p">,</span> <span class="nv">end</span><span class="p">:</span> <span class="n">_lastEnd</span><span class="p">)</span>
        <span class="nf">calcYValueSum</span><span class="p">()</span>
        <span class="nf">calcYValueCount</span><span class="p">()</span>

        <span class="nf">calcXValAverageLength</span><span class="p">()</span>
    <span class="p">}</span>
<span class="p">}</span>

<span class="kd">public</span> <span class="k">var</span> <span class="nv">candleData</span><span class="p">:</span> <span class="kt">CandleChartData</span><span class="o">!</span>
<span class="p">{</span>
    <span class="k">get</span>
    <span class="p">{</span>
        <span class="k">return</span> <span class="n">_candleData</span>
    <span class="p">}</span>
    <span class="k">set</span>
    <span class="p">{</span>
        <span class="n">_candleData</span> <span class="o">=</span> <span class="n">newValue</span>
        <span class="k">for</span> <span class="n">dataSet</span> <span class="k">in</span> <span class="n">newValue</span><span class="o">.</span><span class="n">dataSets</span>
        <span class="p">{</span>
            <span class="n">_dataSets</span><span class="o">.</span><span class="nf">append</span><span class="p">(</span><span class="n">dataSet</span><span class="p">)</span>
        <span class="p">}</span>

        <span class="nf">checkIsLegal</span><span class="p">(</span><span class="n">newValue</span><span class="o">.</span><span class="n">dataSets</span><span class="p">)</span>

        <span class="nf">calcMinMax</span><span class="p">(</span><span class="nv">start</span><span class="p">:</span> <span class="n">_lastStart</span><span class="p">,</span> <span class="nv">end</span><span class="p">:</span> <span class="n">_lastEnd</span><span class="p">)</span>
        <span class="nf">calcYValueSum</span><span class="p">()</span>
        <span class="nf">calcYValueCount</span><span class="p">()</span>

        <span class="nf">calcXValAverageLength</span><span class="p">()</span>
    <span class="p">}</span>
<span class="p">}</span>

<span class="kd">public</span> <span class="k">var</span> <span class="nv">bubbleData</span><span class="p">:</span> <span class="kt">BubbleChartData</span><span class="o">!</span>
<span class="p">{</span>
    <span class="k">get</span>
    <span class="p">{</span>
        <span class="k">return</span> <span class="n">_bubbleData</span>
    <span class="p">}</span>
    <span class="k">set</span>
    <span class="p">{</span>
        <span class="n">_bubbleData</span> <span class="o">=</span> <span class="n">newValue</span>
        <span class="k">for</span> <span class="n">dataSet</span> <span class="k">in</span> <span class="n">newValue</span><span class="o">.</span><span class="n">dataSets</span>
        <span class="p">{</span>
            <span class="n">_dataSets</span><span class="o">.</span><span class="nf">append</span><span class="p">(</span><span class="n">dataSet</span><span class="p">)</span>
        <span class="p">}</span>

        <span class="nf">checkIsLegal</span><span class="p">(</span><span class="n">newValue</span><span class="o">.</span><span class="n">dataSets</span><span class="p">)</span>

        <span class="nf">calcMinMax</span><span class="p">(</span><span class="nv">start</span><span class="p">:</span> <span class="n">_lastStart</span><span class="p">,</span> <span class="nv">end</span><span class="p">:</span> <span class="n">_lastEnd</span><span class="p">)</span>
        <span class="nf">calcYValueSum</span><span class="p">()</span>
        <span class="nf">calcYValueCount</span><span class="p">()</span>

        <span class="nf">calcXValAverageLength</span><span class="p">()</span>
    <span class="p">}</span>
<span class="p">}</span>

<span class="kd">public</span> <span class="k">override</span> <span class="kd">func</span> <span class="nf">notifyDataChanged</span><span class="p">()</span>
<span class="p">{</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">_lineData</span> <span class="o">!==</span> <span class="kc">nil</span><span class="p">)</span>
    <span class="p">{</span>
        <span class="n">_lineData</span><span class="o">.</span><span class="nf">notifyDataChanged</span><span class="p">()</span>
    <span class="p">}</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">_barData</span> <span class="o">!==</span> <span class="kc">nil</span><span class="p">)</span>
    <span class="p">{</span>
        <span class="n">_barData</span><span class="o">.</span><span class="nf">notifyDataChanged</span><span class="p">()</span>
    <span class="p">}</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">_scatterData</span> <span class="o">!==</span> <span class="kc">nil</span><span class="p">)</span>
    <span class="p">{</span>
        <span class="n">_scatterData</span><span class="o">.</span><span class="nf">notifyDataChanged</span><span class="p">()</span>
    <span class="p">}</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">_candleData</span> <span class="o">!==</span> <span class="kc">nil</span><span class="p">)</span>
    <span class="p">{</span>
        <span class="n">_candleData</span><span class="o">.</span><span class="nf">notifyDataChanged</span><span class="p">()</span>
    <span class="p">}</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">_bubbleData</span> <span class="o">!==</span> <span class="kc">nil</span><span class="p">)</span>
    <span class="p">{</span>
        <span class="n">_bubbleData</span><span class="o">.</span><span class="nf">notifyDataChanged</span><span class="p">()</span>
    <span class="p">}</span>
<span class="p">}</span>

}



blog comments powered by Disqus