<commit_before>"""
* Copyright 2007,2008,2009 <NAME>
* Copyright (C) 2009 <NAME> <<EMAIL>>
*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
*  http:#www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*
"""

import math

import GChart
import Double
from Point import Point
from Symbol import Symbol

from GChartConsts import Y2_AXIS
from GChartConsts import N_PRE_SYSTEM_CURVES


"""*
* Represents a curve on a chart, which includes
* information such as the x,y coordinates of each point,
* the symbol used to represent points on the curve, etc.
* <p>
* To create a curve, use the <tt>GChart.addCurve</tt>
* method.
*
* @see GChart#addCurve() addCurve()
*
"""

EXTRA_BANDS = 2;   # far left, right (top, bottom) bands

class Curve:

    def isValidated(self):
        return self.validated
    
    """
    * TestGChart14d revealed that curves.indexOf(curve) could, due to its
    * sequential search, create a performance bug if the chart had
    * over 100 curves (e.g. the 160 pie chart slices/curves of TestGChart14d)
    * <p>
    *
    * With a little extra bookkeeping during add/remove curve to call these
    * methods (and the extra int) this problem was corrected.
    *
    *
    """
    def incrementIndex(self):
        self.indexOf += 1
    
    def decrementIndex(self):
        self.indexOf -= 1
    
    def clearIndex(self):
        self.indexOf = GChart.NAI
    
    def getIndexOf(self):
        return self.indexOf
    
    """
    def assertCurveNotRemoved(self):
        if self.indexOf == GChart.NAI:
            raise IllegalStateException(
            "Removed curves should not be modified. " +
            "You removed a curve, but retained a reference " +
            "to that curve, and then tried to modify one of " +
            "its properties after you removed it.")
        
    
    """
    """
    * No constructor because curves are always
    * contained within, and managed by, their containing
    * GChart via its addCurve, removeCurve, and related
    * methods.
    *
    """
    def __init__(self, chart, indexOf=GChart.NAI):
        self.chart = chart
        self.wasCanvasRendered = False
        self.visible = True
        self.legendHTML = None
        self.points = []
        # symbol defines how every point on this curve is rendered
        self.symbol = Symbol(self)
        
        self.yAxisId = GChart.Y_AXIS
        self.validated = False
        self.indexOf = indexOf
    
        self.bandList = None # index of first point in each band
        self.bandThickness = Double.NaN

    """*
    * Adds a point at the specified position in the point
    * sequence, increasing the indexes of existing points at or after
    * the specified position by 1.
    *
    * @param iPoint the position that the point will occupy
    * @param x the x-coordinate of the point (model units)
    * @param y the y-coordinate of the point (model units)
    *
    * @see #getPoint getPoint
    * @see #addPoint(double, double) addPoint(double,double)
    * @see #removePoint removePoint
    * @see #clearPoints clearPoints
    * @see #getNPoints getNPoints
    """
    def addPoint(self, arg1, arg2, arg3=None):
        self.invalidate()
        if arg3 is None:
            x = arg1
            y = arg2
            self.points.append(Point(self, x, y))
        else:
            iPoint = arg1
            x = arg2
            y = arg3
            self.points.insert(iPoint, Point(self, x, y))
    
    
    """*
    * Removes every point this curve contains.
    *
    * @see Point Point
    * @see #getPoint getPoint
    * @see #addPoint(double, double) addPoint(double,double)
    * @see #addPoint(int,double,double) addPoint(int,double,double)
    * @see #removePoint removePoint
    * @see #getNPoints getNPoints
    """
    def clearPoints(self):
        if self == self.getParent().getTouchedCurve():
            plotPanel.touch(None)
        
        self.invalidate()
        del self.points
        self.points = []
    
    
    
    """
    * Locates index of vertical or horizontal hit-testing band
    * that the given point appears in. The first and last
    * "pseudo-bands" are devoted to holding all points that fall
    * either to the left of or to the right of (or above or below
    * for horizontal banding) the first or last "normal" band
    * covering the decorated chart's containing "box".
    * <p>
    *
    * Note that some points just slightly off the right or bottom edge
    * may not end up in a pseudo-band, due to the fact that the chart
    * width (or height) need not be an even multiple of the (fixed) band
    * thickness (the "last band sticking out a bit" effect).
    *
    """
    def getBand(self, iPoint, bandThickness):
        result = GChart.NAI
        symType = getSymbol().getSymbolType()
        xPx = symType.getCenterX(plotPanel, getSymbol(), iPoint)
        if xPx!=xPx:
            return result; # NaN points not in any band
        
        yPx = symType.getCenterY( plotPanel, getSymbol(), iPoint, onY2())
        if yPx!=yPx:
            return result; # NaN points not in any band
        
        # now, we've got a point with x,y values in some sort of band
        
        if getSymbol().isHorizontallyBanded():
            if yPx < 0:
                result = 0; # off-chart point above chart
            
            elif yPx >= (len(self.bandList)-EXTRA_BANDS)*bandThickness:
                result = len(self.bandList)-1; # off-chart point below chart
            
            else:
                # inside a normal, chart-covering, band
                result = 1 + int ( floor(yPx/bandThickness) )
            
        
        else:
            # vertically banded
            if xPx < 0:
                result = 0;  # off-chart point to the left
            
            elif xPx >= (len(self.bandList)-EXTRA_BANDS)*bandThickness:
                result = len(self.bandList)-1; # off-chart point to the right
            
            else:
                # within one of the real bands covering the chart
                result = 1 + int ( floor(xPx/bandThickness) )<commit_msg>more gchart update<commit_after>"""
* Copyright 2007,2008,2009 <NAME>
* Copyright (C) 2009 <NAME> <<EMAIL>>
*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
*  http:#www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*
"""

import math

import GChart
import Double
from Point import Point
from Symbol import Symbol

from GChartConsts import Y2_AXIS
from GChartConsts import N_PRE_SYSTEM_CURVES


"""*
* Represents a curve on a chart, which includes
* information such as the x,y coordinates of each point,
* the symbol used to represent points on the curve, etc.
* <p>
* To create a curve, use the <tt>GChart.addCurve</tt>
* method.
*
* @see GChart#addCurve() addCurve()
*
"""

EXTRA_BANDS = 2;   # far left, right (top, bottom) bands

class Curve:

    def isValidated(self):
        return self.validated
    
    """
    * TestGChart14d revealed that curves.indexOf(curve) could, due to its
    * sequential search, create a performance bug if the chart had
    * over 100 curves (e.g. the 160 pie chart slices/curves of TestGChart14d)
    * <p>
    *
    * With a little extra bookkeeping during add/remove curve to call these
    * methods (and the extra int) this problem was corrected.
    *
    *
    """
    def incrementIndex(self):
        self.indexOf += 1
    
    def decrementIndex(self):
        self.indexOf -= 1
    
    def clearIndex(self):
        self.indexOf = GChart.NAI
    
    def getIndexOf(self):
        return self.indexOf
    
    """
    def assertCurveNotRemoved(self):
        if self.indexOf == GChart.NAI:
            raise IllegalStateException(
            "Removed curves should not be modified. " +
            "You removed a curve, but retained a reference " +
            "to that curve, and then tried to modify one of " +
            "its properties after you removed it.")
        
    
    """
    """
    * No constructor because curves are always
    * contained within, and managed by, their containing
    * GChart via its addCurve, removeCurve, and related
    * methods.
    *
    """
    def __init__(self, chart, indexOf=GChart.NAI):
        self.chart = chart
        self.wasCanvasRendered = False
        self.visible = True
        self.legendHTML = None
        self.points = []
        # symbol defines how every point on this curve is rendered
        self.symbol = Symbol(self)
        
        self.yAxisId = GChart.Y_AXIS
        self.validated = False
        self.indexOf = indexOf
    
        self.bandList = None # index of first point in each band
        self.bandThickness = Double.NaN

    """*
    * Adds a point at the specified position in the point
    * sequence, increasing the indexes of existing points at or after
    * the specified position by 1.
    *
    * @param iPoint the position that the point will occupy
    * @param x the x-coordinate of the point (model units)
    * @param y the y-coordinate of the point (model units)
    *
    * @see #getPoint getPoint
    * @see #addPoint(double, double) addPoint(double,double)
    * @see #removePoint removePoint
    * @see #clearPoints clearPoints
    * @see #getNPoints getNPoints
    """
    def addPoint(self, arg1, arg2, arg3=None):
        self.invalidate()
        if arg3 is None:
            x = arg1
            y = arg2
            self.points.append(Point(self, x, y))
        else:
            iPoint = arg1
            x = arg2
            y = arg3
            self.points.insert(iPoint, Point(self, x, y))
    
    
    """*
    * Removes every point this curve contains.
    *
    * @see Point Point
    * @see #getPoint getPoint
    * @see #addPoint(double, double) addPoint(double,double)
    * @see #addPoint(int,double,double) addPoint(int,double,double)
    * @see #removePoint removePoint
    * @see #getNPoints getNPoints
    """
    def clearPoints(self):
        if self == self.getParent().getTouchedCurve():
            plotPanel.touch(None)
        
        self.invalidate()
        del self.points
        self.points = []
    
    
    
    """
    * Locates index of vertical or horizontal hit-testing band
    * that the given point appears in. The first and last
    * "pseudo-bands" are devoted to holding all points that fall
    * either to the left of or to the right of (or above or below
    * for horizontal banding) the first or last "normal" band
    * covering the decorated chart's containing "box".
    * <p>
    *
    * Note that some points just slightly off the right or bottom edge
    * may not end up in a pseudo-band, due to the fact that the chart
    * width (or height) need not be an even multiple of the (fixed) band
    * thickness (the "last band sticking out a bit" effect).
    *
    """
    def getBand(self, iPoint, bandThickness):
        result = GChart.NAI
        symType = self.getSymbol().getSymbolType()
        xPx = symType.getCenterX(plotPanel, self.getSymbol(), iPoint)
        if xPx!=xPx:
            return result; # NaN points not in any band
        
        yPx = symType.getCenterY( plotPanel, self.getSymbol(), iPoint, onY2())
        if yPx!=yPx:
            return result; # NaN points not in any band
        
        # now, we've got a point with x,y values in some sort of band
        
        if self.getSymbol().isHorizontallyBanded():
            if yPx < 0:
                result = 0; # off-chart point above chart
            
            elif yPx >= (len(self.bandList)-EXTRA_BANDS)*bandThickness:
                result = len(self.bandList)-1; # off-chart point below chart
            
            else:
                # inside a normal, chart-covering, band
                result = 1 + int ( floor(yPx/bandThickness) )
            
        
        else:
            # vertically banded
            if xPx < 0:
                result = 0;  # off-chart point to the left
            
            elif xPx >= (len(self.bandList)-EXTRA_BANDS)*bandThickness:
                result = len(self.bandList)-1; # off-chart point to the right
            
            else:
                # within one of the real bands covering the chart
                result = 1 + int ( floor(xPx/bandThickness) )
{'fraction_non_alphanumeric': 0.08578188201175303, 'fraction_numerical': 0.008089750438830801, 'mean_word_length': 2.16751269035533, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6588349', 'n_tokens_mistral': 3840, 'n_tokens_neox': 3723, 'n_words': 1366}