MCPcopy Create free account
hub / github.com/LUX-Core/lux / keyPixelOffset

Method keyPixelOffset

src/qt/qcustomplot.cpp:23333–23387  ·  view source on GitHub ↗

! \internal Returns the pixel offset in the key dimension the specified \a bars plottable should have at the given key coordinate \a keyCoord. The offset is relative to the pixel position of the key coordinate \a keyCoord. */

Source from the content-addressed store, hash-verified

23331 coordinate \a keyCoord.
23332*/
23333double QCPBarsGroup::keyPixelOffset(const QCPBars *bars, double keyCoord)
23334{
23335 // find list of all base bars in case some mBars are stacked:
23336 QList<const QCPBars*> baseBars;
23337 Q_FOREACH (const QCPBars *b, mBars)
23338 {
23339 while (b->barBelow())
23340 b = b->barBelow();
23341 if (!baseBars.contains(b))
23342 baseBars.append(b);
23343 }
23344 // find base bar this "bars" is stacked on:
23345 const QCPBars *thisBase = bars;
23346 while (thisBase->barBelow())
23347 thisBase = thisBase->barBelow();
23348
23349 // determine key pixel offset of this base bars considering all other base bars in this barsgroup:
23350 double result = 0;
23351 int index = baseBars.indexOf(thisBase);
23352 if (index >= 0)
23353 {
23354 if (baseBars.size() % 2 == 1 && index == (baseBars.size()-1)/2) // is center bar (int division on purpose)
23355 {
23356 return result;
23357 } else
23358 {
23359 double lowerPixelWidth, upperPixelWidth;
23360 int startIndex;
23361 int dir = (index <= (baseBars.size()-1)/2) ? -1 : 1; // if bar is to lower keys of center, dir is negative
23362 if (baseBars.size() % 2 == 0) // even number of bars
23363 {
23364 startIndex = baseBars.size()/2 + (dir < 0 ? -1 : 0);
23365 result += getPixelSpacing(baseBars.at(startIndex), keyCoord)*0.5; // half of middle spacing
23366 } else // uneven number of bars
23367 {
23368 startIndex = (baseBars.size()-1)/2+dir;
23369 baseBars.at((baseBars.size()-1)/2)->getPixelWidth(keyCoord, lowerPixelWidth, upperPixelWidth);
23370 result += qAbs(upperPixelWidth-lowerPixelWidth)*0.5; // half of center bar
23371 result += getPixelSpacing(baseBars.at((baseBars.size()-1)/2), keyCoord); // center bar spacing
23372 }
23373 for (int i = startIndex; i != index; i += dir) // add widths and spacings of bars in between center and our bars
23374 {
23375 baseBars.at(i)->getPixelWidth(keyCoord, lowerPixelWidth, upperPixelWidth);
23376 result += qAbs(upperPixelWidth-lowerPixelWidth);
23377 result += getPixelSpacing(baseBars.at(i), keyCoord);
23378 }
23379 // finally half of our bars width:
23380 baseBars.at(index)->getPixelWidth(keyCoord, lowerPixelWidth, upperPixelWidth);
23381 result += qAbs(upperPixelWidth-lowerPixelWidth)*0.5;
23382 // correct sign of result depending on orientation and direction of key axis:
23383 result *= dir*thisBase->keyAxis()->pixelOrientation();
23384 }
23385 }
23386 return result;
23387}
23388
23389/*! \internal
23390

Callers 3

getKeyRangeMethod · 0.80
dataPixelPositionMethod · 0.80
getBarRectMethod · 0.80

Calls 3

getPixelWidthMethod · 0.80
sizeMethod · 0.45
atMethod · 0.45

Tested by

no test coverage detected