mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[escher] Palette: factorize data color iteration
This commit is contained in:
@@ -168,6 +168,7 @@ void CalculationController::willDisplayCellAtLocation(HighlightCell * cell, int
|
||||
myCell->setFirstText(buffer);
|
||||
buffer[0] = 'Y';
|
||||
myCell->setSecondText(buffer);
|
||||
assert(seriesNumber < Palette::numberOfDataColors());
|
||||
myCell->setColor(Palette::DataColor[seriesNumber]);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -407,6 +407,7 @@ void GraphController::setRoundCrossCursorView() {
|
||||
bool round = *m_selectedDotIndex < 0;
|
||||
if (round) {
|
||||
// Set the color although the cursor view stays round
|
||||
assert(*m_selectedSeriesIndex < Palette::numberOfDataColors());
|
||||
m_roundCursorView.setColor(Palette::DataColor[*m_selectedSeriesIndex]);
|
||||
}
|
||||
CursorView * nextCursorView = round ? static_cast<Shared::CursorView *>(&m_roundCursorView) : static_cast<Shared::CursorView *>(&m_crossCursorView);
|
||||
|
||||
@@ -22,6 +22,7 @@ void GraphView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
Poincare::Context * globContext = AppsContainer::sharedAppsContainer()->globalContext();
|
||||
for (int series = 0; series < Store::k_numberOfSeries; series++) {
|
||||
if (!m_store->seriesIsEmpty(series)) {
|
||||
assert(series < Palette::numberOfDataColors());
|
||||
KDColor color = Palette::DataColor[series];
|
||||
Model * seriesModel = m_store->modelForSeries(series);
|
||||
drawCartesianCurve(ctx, rect, -INFINITY, INFINITY, [](float abscissa, void * model, void * context) {
|
||||
|
||||
@@ -31,6 +31,7 @@ Ion::Storage::Record::ErrorStatus SequenceStore::addEmptyModel() {
|
||||
const char * name = firstAvailableName(&nameIndex);
|
||||
assert(name);
|
||||
// Choose the corresponding color
|
||||
assert(nameIndex < Palette::numberOfDataColors());
|
||||
KDColor color = Palette::DataColor[nameIndex];
|
||||
Sequence::RecordDataBuffer data(color);
|
||||
// m_sequences
|
||||
|
||||
@@ -57,8 +57,7 @@ ContinuousFunction ContinuousFunction::NewModel(Ion::Storage::Record::ErrorStatu
|
||||
static int s_colorIndex = 0;
|
||||
// Create the record
|
||||
char nameBuffer[SymbolAbstract::k_maxNameSize];
|
||||
int numberOfColors = sizeof(Palette::DataColor)/sizeof(KDColor);
|
||||
RecordDataBuffer data(Palette::DataColor[s_colorIndex++ % numberOfColors]);
|
||||
RecordDataBuffer data(Palette::nextDataColor(&s_colorIndex));
|
||||
if (baseName == nullptr) {
|
||||
DefaultName(nameBuffer, SymbolAbstract::k_maxNameSize);
|
||||
baseName = nameBuffer;
|
||||
|
||||
@@ -55,10 +55,12 @@ public:
|
||||
// Colors
|
||||
static KDColor colorOfSeriesAtIndex(int i) {
|
||||
assert(i >= 0 && i < k_numberOfSeries);
|
||||
assert(i < Palette::numberOfDataColors());
|
||||
return Palette::DataColor[i];
|
||||
}
|
||||
static KDColor colorLightOfSeriesAtIndex(int i) {
|
||||
assert(i >= 0 && i < k_numberOfSeries);
|
||||
assert(i < Palette::numberOfLightDataColors());
|
||||
return Palette::DataColorLight[i];
|
||||
}
|
||||
protected:
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define ESCHER_PALETTE_H
|
||||
|
||||
#include <kandinsky/color.h>
|
||||
#include <stddef.h>
|
||||
|
||||
class Palette {
|
||||
public:
|
||||
@@ -34,6 +35,10 @@ public:
|
||||
constexpr static KDColor Purple = KDColor::RGB24(0x6e2d79);
|
||||
constexpr static KDColor DataColor[] = {Red, Blue, Green, YellowDark, Magenta, Turquoise, Pink, Orange};
|
||||
constexpr static KDColor DataColorLight[] = {RedLight, BlueLight, GreenLight, YellowLight};
|
||||
|
||||
constexpr static size_t numberOfDataColors() { return sizeof(DataColor)/sizeof(KDColor); }
|
||||
constexpr static size_t numberOfLightDataColors() { return sizeof(DataColorLight)/sizeof(KDColor); }
|
||||
static KDColor nextDataColor(int * colorIndex);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <escher/palette.h>
|
||||
#include <assert.h>
|
||||
|
||||
constexpr KDColor Palette::YellowDark;
|
||||
constexpr KDColor Palette::YellowLight;
|
||||
@@ -29,3 +30,11 @@ constexpr KDColor Palette::Brown;
|
||||
constexpr KDColor Palette::Purple;
|
||||
constexpr KDColor Palette::DataColor[];
|
||||
constexpr KDColor Palette::DataColorLight[];
|
||||
|
||||
KDColor Palette::nextDataColor(int * colorIndex) {
|
||||
size_t nbOfColors = numberOfDataColors();
|
||||
assert(*colorIndex < nbOfColors);
|
||||
KDColor c = DataColor[*colorIndex];
|
||||
*colorIndex = (*colorIndex + 1) % nbOfColors;
|
||||
return c;
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ mp_obj_t modpyplot_arrow(size_t n_args, const mp_obj_t *args) {
|
||||
assert(n_args == 4);
|
||||
assert(sPlotStore != nullptr);
|
||||
|
||||
KDColor color = Palette::DataColor[paletteIndex++]; // FIXME: Share overflow routine
|
||||
KDColor color = Palette::nextDataColor(&paletteIndex);
|
||||
sPlotStore->addSegment(args[0], args[1], mp_obj_new_float(mp_obj_get_float(args[0])+mp_obj_get_float(args[2])), mp_obj_new_float(mp_obj_get_float(args[1])+mp_obj_get_float(args[3])), color, true);
|
||||
|
||||
return mp_const_none;
|
||||
@@ -93,7 +93,7 @@ mp_obj_t modpyplot_bar(mp_obj_t x, mp_obj_t height) {
|
||||
size_t length = extractAndValidatePlotInput(x, height, &xItems, &hItems);
|
||||
mp_float_t w = 0.8; // TODO: w should be an optional parameter
|
||||
|
||||
KDColor color = Palette::DataColor[paletteIndex++]; // FIXME: Share overflow routine
|
||||
KDColor color = Palette::nextDataColor(&paletteIndex);
|
||||
for (size_t i=0; i<length; i++) {
|
||||
mp_float_t rectX = mp_obj_get_float(xItems[i])-w/2.0;
|
||||
mp_float_t h = mp_obj_get_float(hItems[i]);
|
||||
@@ -188,7 +188,7 @@ mp_obj_t modpyplot_hist(mp_obj_t x) {
|
||||
binIndex++;
|
||||
}
|
||||
|
||||
KDColor color = Palette::DataColor[paletteIndex++]; // FIXME: Share overflow routine
|
||||
KDColor color = Palette::nextDataColor(&paletteIndex);
|
||||
for (size_t i=0; i<nBins; i++) {
|
||||
mp_float_t width = mp_obj_get_float(edgeItems[i+1]) - mp_obj_get_float(edgeItems[i]);
|
||||
sPlotStore->addRect(edgeItems[i], binItems[i], mp_obj_new_float(width), binItems[i], color);
|
||||
@@ -203,7 +203,7 @@ mp_obj_t modpyplot_scatter(mp_obj_t x, mp_obj_t y) {
|
||||
mp_obj_t * xItems, * yItems;
|
||||
size_t length = extractAndValidatePlotInput(x, y, &xItems, &yItems);
|
||||
|
||||
KDColor color = Palette::DataColor[paletteIndex++]; // FIXME: Share overflow routine
|
||||
KDColor color = Palette::nextDataColor(&paletteIndex);
|
||||
for (size_t i=0; i<length; i++) {
|
||||
sPlotStore->addDot(xItems[i], yItems[i], color);
|
||||
}
|
||||
@@ -218,7 +218,7 @@ mp_obj_t modpyplot_plot(mp_obj_t x, mp_obj_t y) {
|
||||
mp_obj_t * xItems, * yItems;
|
||||
size_t length = extractAndValidatePlotInput(x, y, &xItems, &yItems);
|
||||
|
||||
KDColor color = Palette::DataColor[paletteIndex++]; // FIXME: Share overflow routine
|
||||
KDColor color = Palette::nextDataColor(&paletteIndex);
|
||||
for (size_t i=0; i<length-1; i++) {
|
||||
sPlotStore->addSegment(xItems[i], yItems[i], xItems[i+1], yItems[i+1], color, false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user