1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415
|
/**
*
* This file is part of Tulip (www.tulip-software.org)
*
* Authors: David Auber and the Tulip development Team
* from LaBRI, University of Bordeaux
*
* Tulip 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 3
* of the License, or (at your option) any later version.
*
* Tulip 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 General Public License for more details.
*
*/
#include "QuantitativeParallelAxis.h"
#include "AxisConfigDialogs.h"
#include <tulip/IntegerProperty.h>
#include <tulip/DoubleProperty.h>
#include <tulip/ForEach.h>
using namespace std;
namespace tlp {
QuantitativeParallelAxis::QuantitativeParallelAxis(const Coord &baseCoord, const float height, const float axisAreaWidth, ParallelCoordinatesGraphProxy *graphProxy,
const string &graphPropertyName, const bool ascendingOrder, const Color &axisColor, const float rotationAngle, const GlAxis::CaptionLabelPosition captionPosition) :
ParallelAxis(new GlQuantitativeAxis(graphPropertyName, baseCoord, height, GlAxis::VERTICAL_AXIS, axisColor, true, ascendingOrder), axisAreaWidth, rotationAngle, captionPosition),
nbAxisGrad(DEFAULT_NB_AXIS_GRAD), axisMinValue(DBL_MAX), axisMaxValue(-DBL_MAX), graphProxy(graphProxy), log10Scale(false), integerScale(false) {
glQuantitativeAxis = dynamic_cast<GlQuantitativeAxis *>(glAxis);
boxPlotValuesCoord.resize(5);
boxPlotStringValues.resize(5);
redraw();
}
void QuantitativeParallelAxis::setAxisLabels() {
double propertyMin = getAssociatedPropertyMinValue();
double propertyMax = getAssociatedPropertyMaxValue();
bool realScale = false;
if (propertyMin >= INT_MIN && propertyMax <= INT_MAX) {
if (getAxisDataTypeName() == "double") {
unsigned int n;
forEach(n, graphProxy->getDataIterator()) {
double val = graphProxy->getPropertyValueForData<DoubleProperty, DoubleType>(getAxisName(), n);
double intpart, fracpart;
fracpart = modf(val, &intpart);
realScale = realScale || (fracpart != 0);
}
}
}
else {
realScale = true;
}
if (axisMinValue > propertyMin || propertyMin == propertyMax) {
axisMinValue = propertyMin;
}
if (axisMaxValue < propertyMax || propertyMin == propertyMax) {
axisMaxValue = propertyMax;
}
if (getAxisDataTypeName() == "double" && realScale) {
glQuantitativeAxis->setAxisParameters(axisMinValue, axisMaxValue, nbAxisGrad, GlAxis::RIGHT_OR_ABOVE, true);
integerScale = false;
}
else {
long long min = static_cast<long long>(axisMinValue);
long long max = static_cast<long long>(axisMaxValue);
unsigned long long incrementStep = (max - min) / DEFAULT_NB_AXIS_GRAD;
if (incrementStep < 1) incrementStep = 1;
glQuantitativeAxis->setAxisParameters(min, max, incrementStep, GlAxis::RIGHT_OR_ABOVE, true);
integerScale = true;
}
glQuantitativeAxis->setLogScale(log10Scale);
}
void QuantitativeParallelAxis::computeBoxPlotCoords() {
set<double> propertyValuesSet;
Iterator<unsigned int> *dataIt = graphProxy->getDataIterator();
while (dataIt->hasNext()) {
unsigned int dataId = dataIt->next();
double value;
if (getAxisDataTypeName() == "double") {
value = graphProxy->getPropertyValueForData<DoubleProperty, DoubleType> (getAxisName(), dataId);
}
else {
value = static_cast<double>(graphProxy->getPropertyValueForData<IntegerProperty, IntegerType> (getAxisName(), dataId));
}
propertyValuesSet.insert(value);
}
delete dataIt;
vector<double> propertyValuesVector(propertyValuesSet.begin(), propertyValuesSet.end());
unsigned int vectorSize = propertyValuesVector.size();
if (vectorSize < 4) {
boxPlotValuesCoord[BOTTOM_OUTLIER] = Coord(-1.0f, -1.0f, -1.0f);
boxPlotValuesCoord[FIRST_QUARTILE] = Coord(-1.0f, -1.0f, -1.0f);
boxPlotValuesCoord[MEDIAN] = Coord(-1.0f, -1.0f, -1.0f);
boxPlotValuesCoord[THIRD_QUARTILE] = Coord(-1.0f, -1.0f, -1.0f);
boxPlotValuesCoord[TOP_OUTLIER] = Coord(-1.0f, -1.0f, -1.0f);
boxPlotStringValues[BOTTOM_OUTLIER] = "KO";
boxPlotStringValues[FIRST_QUARTILE] = "KO";
boxPlotStringValues[MEDIAN] = "KO";
boxPlotStringValues[THIRD_QUARTILE] = "KO";
boxPlotStringValues[TOP_OUTLIER] = "KO";
}
else {
double median;
if (vectorSize % 2 == 1) {
median = propertyValuesVector[vectorSize / 2.];
}
else {
median = (propertyValuesVector[(vectorSize / 2.) - 1] + propertyValuesVector[vectorSize / 2.]) / 2.;
}
double firstQuartile;
if (vectorSize % 2 == 1) {
firstQuartile = propertyValuesVector[vectorSize / 4.];
}
else {
firstQuartile = (propertyValuesVector[(vectorSize / 4.) - 1] + propertyValuesVector[vectorSize / 4.]) / 2;
}
double thirdQuartile;
if (vectorSize % 2 == 1) {
thirdQuartile = propertyValuesVector[3 *(vectorSize / 4.)];
}
else {
thirdQuartile = (propertyValuesVector[3 *(vectorSize / 4.) - 1] + propertyValuesVector[3 *(vectorSize / 4.)]) / 2.;
}
double lowBorder = (firstQuartile - (1.5 * (thirdQuartile - firstQuartile)));
double bottomOutlier = 0.0;
vector<double>::iterator it;
for (it = propertyValuesVector.begin() ; it != propertyValuesVector.end() ; ++it) {
if (*it > lowBorder) {
bottomOutlier = *it;
break;
}
}
double highBorder = (thirdQuartile + (1.5 * (thirdQuartile - firstQuartile)));
double topOutlier = 0;
vector<double>::reverse_iterator itr;
for (itr = propertyValuesVector.rbegin() ; itr != propertyValuesVector.rend() ; ++itr) {
if (*itr < highBorder) {
topOutlier = *itr;
break;
}
}
boxPlotValuesCoord[BOTTOM_OUTLIER] = getAxisCoordForValue(bottomOutlier);
boxPlotValuesCoord[FIRST_QUARTILE] = getAxisCoordForValue(firstQuartile);
boxPlotValuesCoord[MEDIAN] = getAxisCoordForValue(median);
boxPlotValuesCoord[THIRD_QUARTILE] = getAxisCoordForValue(thirdQuartile);
boxPlotValuesCoord[TOP_OUTLIER] = getAxisCoordForValue(topOutlier);
boxPlotStringValues[BOTTOM_OUTLIER] = getStringFromNumber(bottomOutlier);
boxPlotStringValues[FIRST_QUARTILE] = getStringFromNumber(firstQuartile);
boxPlotStringValues[MEDIAN] = getStringFromNumber(median);
boxPlotStringValues[THIRD_QUARTILE] = getStringFromNumber(thirdQuartile);
boxPlotStringValues[TOP_OUTLIER] = getStringFromNumber(topOutlier);
}
}
double QuantitativeParallelAxis::getAssociatedPropertyMinValue() {
if (graphProxy->getGraph()->getRoot() == graphProxy->getGraph()) {
if (getAxisDataTypeName() == "double") {
return graphProxy->getPropertyMinValue<DoubleProperty, DoubleType>(getAxisName());
}
else {
return (double) graphProxy->getPropertyMinValue<IntegerProperty, IntegerType>(getAxisName());
}
}
else {
Iterator<unsigned int> *dataIt = graphProxy->getDataIterator();
unsigned int dataId = dataIt->next();
double min;
if (getAxisDataTypeName() == "double") {
min = graphProxy->getPropertyValueForData<DoubleProperty, DoubleType>(getAxisName(),dataId);
}
else {
min = graphProxy->getPropertyValueForData<IntegerProperty, IntegerType>(getAxisName(),dataId);
}
while (dataIt->hasNext()) {
dataId = dataIt->next();
double propertyValue;
if (getAxisDataTypeName() == "double") {
propertyValue = graphProxy->getPropertyValueForData<DoubleProperty, DoubleType>(getAxisName(),dataId);
}
else {
propertyValue = graphProxy->getPropertyValueForData<IntegerProperty, IntegerType>(getAxisName(),dataId);
}
if (propertyValue < min) {
min = propertyValue;
}
}
delete dataIt;
return min;
}
}
double QuantitativeParallelAxis::getAssociatedPropertyMaxValue() {
if (getAxisDataTypeName() == "double") {
return graphProxy->getPropertyMaxValue<DoubleProperty, DoubleType>(getAxisName());
}
else {
return (double) graphProxy->getPropertyMaxValue<IntegerProperty, IntegerType>(getAxisName());
}
}
void QuantitativeParallelAxis::translate(const Coord &c) {
ParallelAxis::translate(c);
boxPlotValuesCoord[BOTTOM_OUTLIER] += c;
boxPlotValuesCoord[FIRST_QUARTILE] += c;
boxPlotValuesCoord[MEDIAN] += c;
boxPlotValuesCoord[THIRD_QUARTILE] += c;
boxPlotValuesCoord[TOP_OUTLIER] += c;
}
Coord QuantitativeParallelAxis::getPointCoordOnAxisForData(const unsigned int dataIdx) {
double value = 0;
if (getAxisDataTypeName() == "double") {
value = graphProxy->getPropertyValueForData<DoubleProperty, DoubleType>(getAxisName(), dataIdx);
}
else if (getAxisDataTypeName() == "int") {
value = static_cast<double>(graphProxy->getPropertyValueForData<IntegerProperty, IntegerType>(getAxisName(), dataIdx));
}
Coord axisPointCoord(glQuantitativeAxis->getAxisPointCoordForValue(value));
if (rotationAngle != 0.0f) {
rotateVector(axisPointCoord, rotationAngle, Z_ROT);
}
return axisPointCoord;
}
Coord QuantitativeParallelAxis::getAxisCoordForValue(double value) {
return glQuantitativeAxis->getAxisPointCoordForValue(value);
}
void QuantitativeParallelAxis::redraw() {
setAxisLabels();
ParallelAxis::redraw();
computeBoxPlotCoords();
}
void QuantitativeParallelAxis::showConfigDialog() {
QuantitativeAxisConfigDialog dialog(this);
dialog.exec();
updateSlidersWithDataSubset(graphProxy->getHighlightedElts());
}
string QuantitativeParallelAxis::getAxisDataTypeName() const {
return graphProxy->getProperty(getAxisName())->getTypename();
}
double QuantitativeParallelAxis::getValueForAxisCoord(const Coord &axisCoord) {
return glQuantitativeAxis->getValueForAxisPoint(axisCoord);
}
std::string QuantitativeParallelAxis::getTopSliderTextValue() {
if (getAxisDataTypeName() == "int" || integerScale) {
int val = (int) getValueForAxisCoord(topSliderCoord);
if (glQuantitativeAxis->hasAscendingOrder()) {
return getStringFromNumber(val == glQuantitativeAxis->getAxisMaxValue() ? val : val - 1);
}
else {
return getStringFromNumber(val);
}
}
else if (getAxisDataTypeName() == "double") {
return getStringFromNumber(getValueForAxisCoord(topSliderCoord));
}
else {
return "";
}
}
std::string QuantitativeParallelAxis::getBottomSliderTextValue() {
if (getAxisDataTypeName() == "int" || integerScale) {
int val = (int) getValueForAxisCoord(bottomSliderCoord);
if (!glQuantitativeAxis->hasAscendingOrder()) {
return getStringFromNumber(val == glQuantitativeAxis->getAxisMaxValue() ? val : val - 1);
}
else {
return getStringFromNumber(val);
}
return getStringFromNumber(getValueForAxisCoord(bottomSliderCoord));
}
else if (getAxisDataTypeName() == "double") {
return getStringFromNumber(getValueForAxisCoord(bottomSliderCoord));
}
else {
return "";
}
}
const set<unsigned int> &QuantitativeParallelAxis::getDataInRange(float yLowBound, float yHighBound) {
dataSubset.clear();
float rotAngleBak = rotationAngle;
rotationAngle = 0.0f;
Iterator<unsigned int> *dataIt = graphProxy->getDataIterator();
while (dataIt->hasNext()) {
unsigned int dataId = dataIt->next();
Coord dataCoord(getPointCoordOnAxisForData(dataId));
if (dataCoord.getY() <= yHighBound && dataCoord.getY() >= yLowBound) {
dataSubset.insert(dataId);
}
}
delete dataIt;
rotationAngle = rotAngleBak;
return dataSubset;
}
const set<unsigned int> &QuantitativeParallelAxis::getDataInSlidersRange() {
return getDataInRange(bottomSliderCoord.getY(), topSliderCoord.getY());
}
const set<unsigned int> &QuantitativeParallelAxis::getDataBetweenBoxPlotBounds() {
if (boxPlotLowBound != NO_VALUE && boxPlotHighBound != NO_VALUE) {
return getDataInRange(boxPlotValuesCoord[boxPlotLowBound].getY(), boxPlotValuesCoord[boxPlotHighBound].getY());
}
else {
dataSubset.clear();
return dataSubset;
}
}
void QuantitativeParallelAxis::updateSlidersWithDataSubset(const set<unsigned int> &dataSubset) {
float rotAngleBak = rotationAngle;
rotationAngle = 0.0f;
set<unsigned int>::iterator it;
Coord max(getBaseCoord());
Coord min(getBaseCoord() + Coord(0.0f, getAxisHeight()));
for (it = dataSubset.begin() ; it != dataSubset.end() ; ++it) {
Coord dataCoord(getPointCoordOnAxisForData(*it));
if (dataCoord.getY() < min.getY()) {
min = dataCoord;
}
if (dataCoord.getY() > max.getY()) {
max = dataCoord;
}
}
bottomSliderCoord = min;
topSliderCoord = max;
rotationAngle = rotAngleBak;
}
void QuantitativeParallelAxis::setAscendingOrder(const bool ascendingOrder) {
Coord baseCoord(getBaseCoord());
float axisHeight = getAxisHeight();
if (ascendingOrder != hasAscendingOrder()) {
float spaceBetweenSlider = topSliderCoord.getY() - bottomSliderCoord.getY();
float axisCenterTopSliderDist = topSliderCoord.getY() - (baseCoord.getY() + axisHeight / 2.0f);
topSliderCoord.setY((baseCoord.getY() + axisHeight / 2.0f) - axisCenterTopSliderDist + spaceBetweenSlider);
float axisCenterBottomSliderDist = bottomSliderCoord.getY() - (baseCoord.getY() + axisHeight / 2.0f);
bottomSliderCoord.setY((baseCoord.getY() + axisHeight / 2.0f) - axisCenterBottomSliderDist - spaceBetweenSlider);
}
glQuantitativeAxis->setAscendingOrder(ascendingOrder);
}
}
|