diff --git a/eos/graph/__init__.py b/eos/graph/__init__.py
index 55b6ec0e4..8ac11a9c5 100644
--- a/eos/graph/__init__.py
+++ b/eos/graph/__init__.py
@@ -16,61 +16,3 @@
# You should have received a copy of the GNU Lesser General Public License
# along with eos. If not, see .
# ===============================================================================
-
-
-import math
-from abc import ABCMeta, abstractmethod
-
-
-class Graph(metaclass=ABCMeta):
-
- def __init__(self):
- self._cache = {}
-
- @abstractmethod
- def getPlotPoints(self, fit, extraData, xRange, xAmount):
- raise NotImplementedError
-
- def getYForX(self, fit, extraData, x):
- raise NotImplementedError
-
- def _xIter(self, fit, extraData, xRange, xAmount):
- rangeLow, rangeHigh = self._limitXRange(xRange, fit, extraData)
- # Amount is amount of ranges between points here, not amount of points
- step = (rangeHigh - rangeLow) / xAmount
- if step == 0:
- yield xRange[0]
- else:
- current = rangeLow
- # Take extra half step to make sure end of range is always included
- # despite any possible float errors
- while current <= (rangeHigh + step / 2):
- yield current
- current += step
-
- def _limitXRange(self, xRange, fit, extraData):
- rangeLow, rangeHigh = sorted(xRange)
- limitLow, limitHigh = self._getXLimits(fit, extraData)
- rangeLow = max(limitLow, rangeLow)
- rangeHigh = min(limitHigh, rangeHigh)
- return rangeLow, rangeHigh
-
- def _getXLimits(self, fit, extraData):
- return -math.inf, math.inf
-
- def clearCache(self, key=None):
- if key is None:
- self._cache.clear()
- elif key in self._cache:
- del self._cache[key]
-
-
-class SmoothGraph(Graph, metaclass=ABCMeta):
-
- def getPlotPoints(self, fit, extraData, xRange, xAmount):
- xs = []
- ys = []
- for x in self._xIter(fit, extraData, xRange, xAmount):
- xs.append(x)
- ys.append(self.getYForX(fit, extraData, x))
- return xs, ys
diff --git a/eos/graph/base.py b/eos/graph/base.py
new file mode 100644
index 000000000..fc2daab5d
--- /dev/null
+++ b/eos/graph/base.py
@@ -0,0 +1,76 @@
+# ===============================================================================
+# Copyright (C) 2010 Diego Duclos
+#
+# This file is part of eos.
+#
+# eos is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+#
+# eos is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with eos. If not, see .
+# ===============================================================================
+
+
+import math
+from abc import ABCMeta, abstractmethod
+
+
+class Graph(metaclass=ABCMeta):
+
+ def __init__(self):
+ self._cache = {}
+
+ @abstractmethod
+ def getPlotPoints(self, mainInput, miscInputs, xSpec, ySpec, fit, tgt):
+ raise NotImplementedError
+
+ def getYForX(self, x, miscInputs, xSpec, ySpec, fit, tgt):
+ raise NotImplementedError
+
+ def _xIter(self, fit, extraData, xRange, xAmount):
+ rangeLow, rangeHigh = self._limitXRange(xRange, fit, extraData)
+ # Amount is amount of ranges between points here, not amount of points
+ step = (rangeHigh - rangeLow) / xAmount
+ if step == 0:
+ yield xRange[0]
+ else:
+ current = rangeLow
+ # Take extra half step to make sure end of range is always included
+ # despite any possible float errors
+ while current <= (rangeHigh + step / 2):
+ yield current
+ current += step
+
+ def _limitXRange(self, xRange, fit, extraData):
+ rangeLow, rangeHigh = sorted(xRange)
+ limitLow, limitHigh = self._getXLimits(fit, extraData)
+ rangeLow = max(limitLow, rangeLow)
+ rangeHigh = min(limitHigh, rangeHigh)
+ return rangeLow, rangeHigh
+
+ def _getInputLimits(self, inputHandle, inputUnit, fit):
+ return -math.inf, math.inf
+
+ def clearCache(self, key=None):
+ if key is None:
+ self._cache.clear()
+ elif key in self._cache:
+ del self._cache[key]
+
+
+class SmoothGraph(Graph, metaclass=ABCMeta):
+
+ def getPlotPoints(self, mainInput, miscInputs, xSpec, ySpec, fit, tgt):
+ xs = []
+ ys = []
+ for x in self._xIter(fit, extraData, xRange, xAmount):
+ xs.append(x)
+ ys.append(self.getYForX(fit, extraData, x))
+ return xs, ys
diff --git a/eos/graph/fitCapAmountVsTime.py b/eos/graph/fitCapAmountVsTime.py
index 16627617d..e0a9069a0 100644
--- a/eos/graph/fitCapAmountVsTime.py
+++ b/eos/graph/fitCapAmountVsTime.py
@@ -1,6 +1,6 @@
import math
-from eos.graph import SmoothGraph
+from .base import SmoothGraph
class FitCapAmountVsTimeGraph(SmoothGraph):
diff --git a/eos/graph/fitCapRegenVsCapPerc.py b/eos/graph/fitCapRegenVsCapPerc.py
index ff686abea..d4a01f7c7 100644
--- a/eos/graph/fitCapRegenVsCapPerc.py
+++ b/eos/graph/fitCapRegenVsCapPerc.py
@@ -1,6 +1,6 @@
import math
-from eos.graph import SmoothGraph
+from .base import SmoothGraph
class FitCapRegenVsCapPercGraph(SmoothGraph):
diff --git a/eos/graph/fitDistanceVsTime.py b/eos/graph/fitDistanceVsTime.py
index dcc5ce506..f1762b18a 100644
--- a/eos/graph/fitDistanceVsTime.py
+++ b/eos/graph/fitDistanceVsTime.py
@@ -1,6 +1,6 @@
import math
-from eos.graph import SmoothGraph
+from .base import SmoothGraph
class FitDistanceVsTimeGraph(SmoothGraph):
diff --git a/eos/graph/fitDmgVsTime.py b/eos/graph/fitDmgVsTime.py
index 49912ec90..95db4b253 100644
--- a/eos/graph/fitDmgVsTime.py
+++ b/eos/graph/fitDmgVsTime.py
@@ -18,9 +18,9 @@
# ===============================================================================
-from eos.graph import Graph
from eos.utils.spoolSupport import SpoolType, SpoolOptions
from gui.utils.numberFormatter import roundToPrec
+from .base import Graph
class FitDmgVsTimeGraph(Graph):
diff --git a/eos/graph/fitDpsVsRange.py b/eos/graph/fitDpsVsRange.py
index 31d0de723..741a7d2d8 100644
--- a/eos/graph/fitDpsVsRange.py
+++ b/eos/graph/fitDpsVsRange.py
@@ -24,8 +24,8 @@ from logbook import Logger
import eos.config
from eos.const import FittingHardpoint, FittingModuleState
-from eos.graph import SmoothGraph
from eos.utils.spoolSupport import SpoolType, SpoolOptions
+from .base import SmoothGraph
pyfalog = Logger(__name__)
diff --git a/eos/graph/fitDpsVsTime.py b/eos/graph/fitDpsVsTime.py
index b1c4ab58e..e93e8a731 100644
--- a/eos/graph/fitDpsVsTime.py
+++ b/eos/graph/fitDpsVsTime.py
@@ -20,9 +20,9 @@
from itertools import chain
-from eos.graph import Graph
from eos.utils.spoolSupport import SpoolType, SpoolOptions
from gui.utils.numberFormatter import roundToPrec
+from .base import Graph
class FitDpsVsTimeGraph(Graph):
diff --git a/eos/graph/fitShieldAmountVsTime.py b/eos/graph/fitShieldAmountVsTime.py
index 387e80dee..443e1ea1c 100644
--- a/eos/graph/fitShieldAmountVsTime.py
+++ b/eos/graph/fitShieldAmountVsTime.py
@@ -1,7 +1,7 @@
import math
from logbook import Logger
-from eos.graph import SmoothGraph
+from .base import SmoothGraph
pyfalog = Logger(__name__)
diff --git a/eos/graph/fitShieldRegenVsShieldPerc.py b/eos/graph/fitShieldRegenVsShieldPerc.py
index 27902e428..3793d6727 100644
--- a/eos/graph/fitShieldRegenVsShieldPerc.py
+++ b/eos/graph/fitShieldRegenVsShieldPerc.py
@@ -1,6 +1,6 @@
import math
-from eos.graph import SmoothGraph
+from .base import SmoothGraph
class FitShieldRegenVsShieldPercGraph(SmoothGraph):
diff --git a/eos/graph/fitSpeedVsTime.py b/eos/graph/fitSpeedVsTime.py
index ea19a310a..2aa021adb 100644
--- a/eos/graph/fitSpeedVsTime.py
+++ b/eos/graph/fitSpeedVsTime.py
@@ -1,6 +1,6 @@
import math
-from eos.graph import SmoothGraph
+from .base import SmoothGraph
class FitSpeedVsTimeGraph(SmoothGraph):
diff --git a/eos/graph/fitWarpTimeVsDistance.py b/eos/graph/fitWarpTime.py
similarity index 97%
rename from eos/graph/fitWarpTimeVsDistance.py
rename to eos/graph/fitWarpTime.py
index a16a63ec9..1ddca2ae4 100644
--- a/eos/graph/fitWarpTimeVsDistance.py
+++ b/eos/graph/fitWarpTime.py
@@ -1,13 +1,13 @@
import math
from eos.const import FittingModuleState
-from eos.graph import SmoothGraph
+from .base import SmoothGraph
AU_METERS = 149597870700
-class FitWarpTimeVsDistanceGraph(SmoothGraph):
+class FitWarpTimeGraph(SmoothGraph):
def __init__(self):
super().__init__()
diff --git a/gui/builtinGraphs/__init__.py b/gui/builtinGraphs/__init__.py
index 5cf1cd831..ea8b49783 100644
--- a/gui/builtinGraphs/__init__.py
+++ b/gui/builtinGraphs/__init__.py
@@ -1,11 +1,11 @@
# noinspection PyUnresolvedReferences
from gui.builtinGraphs import ( # noqa: E402,F401
- fitDamageStats,
+ # fitDamageStats,
# fitDmgVsTime,
# fitShieldRegenVsShieldPerc,
# fitShieldAmountVsTime,
# fitCapRegenVsCapPerc,
# fitCapAmountVsTime,
# fitMobilityVsTime,
- fitWarpTimeVsDistance
+ fitWarpTime
)
diff --git a/gui/builtinGraphs/base.py b/gui/builtinGraphs/base.py
index 935e65ce4..21eb0f1c1 100644
--- a/gui/builtinGraphs/base.py
+++ b/gui/builtinGraphs/base.py
@@ -18,7 +18,6 @@
# =============================================================================
-import re
from abc import ABCMeta, abstractmethod
from collections import OrderedDict, namedtuple
@@ -32,7 +31,8 @@ class Graph(metaclass=ABCMeta):
def register(cls):
Graph.views.append(cls)
- def __init__(self):
+ def __init__(self, eosGraph):
+ self._eosGraph = eosGraph
self._cache = {}
@property
@@ -84,13 +84,11 @@ class Graph(metaclass=ABCMeta):
def getPlotPoints(self, mainInput, miscInputs, xSpec, ySpec, fit, tgt=None):
try:
- plotData = self._cache[fit.ID][ySpec]
+ plotData = self._cache[fit.ID][(ySpec, xSpec)]
except KeyError:
- extraData = {k: float(v) if v else None for k, v in extraData.items()}
- graph = getattr(self, self.yDefs[yType].eosGraph, None)
- plotData = graph.getPlotPoints(fit, extraData, xRange, xAmount)
+ plotData = self._eosGraph.getPlotPoints(mainInput, miscInputs, xSpec, ySpec, fit, tgt)
fitCache = self._cache.setdefault(fit.ID, {})
- fitCache[yType] = plotData
+ fitCache[(ySpec, xSpec)] = plotData
return plotData
def clearCache(self, key=None):
@@ -102,7 +100,7 @@ class Graph(metaclass=ABCMeta):
getattr(self, yDef.eosGraph).clearCache(key=key)
-YDef = namedtuple('YDef', ('handle', 'unit', 'label', 'eosGraph'))
+YDef = namedtuple('YDef', ('handle', 'unit', 'label'))
XDef = namedtuple('XDef', ('handle', 'unit', 'label', 'mainInput'))
Input = namedtuple('Input', ('handle', 'unit', 'label', 'iconID', 'defaultValue', 'defaultRange', 'mainOnly'))
VectorDef = namedtuple('VectorDef', ('lengthHandle', 'lengthUnit', 'angleHandle', 'angleUnit', 'label'))
diff --git a/gui/builtinGraphs/fitDamageStats.py b/gui/builtinGraphs/fitDamageStats.py
index fcceff5b9..a836c007c 100644
--- a/gui/builtinGraphs/fitDamageStats.py
+++ b/gui/builtinGraphs/fitDamageStats.py
@@ -29,8 +29,7 @@ class FitDamageStatsGraph(Graph):
name = 'Damage Stats'
def __init__(self):
- super().__init__()
- self.eosGraph = EosGraph()
+ super().__init__(EosGraph())
@property
def xDefs(self):
@@ -45,9 +44,9 @@ class FitDamageStatsGraph(Graph):
@property
def yDefs(self):
return [
- YDef(handle='dps', unit=None, label='DPS', eosGraph='eosGraph'),
- YDef(handle='volley', unit=None, label='Volley', eosGraph='eosGraph'),
- YDef(handle='damage', unit=None, label='Damage inflicted', eosGraph='eosGraph')]
+ YDef(handle='dps', unit=None, label='DPS'),
+ YDef(handle='volley', unit=None, label='Volley'),
+ YDef(handle='damage', unit=None, label='Damage inflicted')]
@property
def inputs(self):
diff --git a/gui/builtinGraphs/fitWarpTimeVsDistance.py b/gui/builtinGraphs/fitWarpTime.py
similarity index 83%
rename from gui/builtinGraphs/fitWarpTimeVsDistance.py
rename to gui/builtinGraphs/fitWarpTime.py
index b54015dff..468c246b3 100644
--- a/gui/builtinGraphs/fitWarpTimeVsDistance.py
+++ b/gui/builtinGraphs/fitWarpTime.py
@@ -18,17 +18,16 @@
# =============================================================================
-from eos.graph.fitWarpTimeVsDistance import FitWarpTimeVsDistanceGraph as EosGraph
+from eos.graph.fitWarpTime import FitWarpTimeGraph as EosGraph
from .base import Graph, XDef, YDef, Input
-class FitWarpTimeVsDistanceGraph(Graph):
+class FitWarpTimeGraph(Graph):
name = 'Warp Time'
def __init__(self):
- super().__init__()
- self.eosGraph = EosGraph()
+ super().__init__(EosGraph())
@property
def xDefs(self):
@@ -38,7 +37,7 @@ class FitWarpTimeVsDistanceGraph(Graph):
@property
def yDefs(self):
- return [YDef(handle='time', unit='s', label='Warp time', eosGraph='eosGraph')]
+ return [YDef(handle='time', unit='s', label='Warp time')]
@property
def inputs(self):
@@ -47,4 +46,4 @@ class FitWarpTimeVsDistanceGraph(Graph):
Input(handle='distance', unit='km', label='Distance', iconID=1391, defaultValue=10000, defaultRange=(150, 5000), mainOnly=False)]
-FitWarpTimeVsDistanceGraph.register()
+FitWarpTimeGraph.register()