void DataCurve::setLabelsColumnName(const QString& name) { if (!validCurveType()) return; if (d_labels_column == name && !d_labels_list.isEmpty()) return; d_labels_column = name; loadLabels(); }
void ActionConstant::loadConstant(const DLabel & labels) { loadLabels(*this, labels); A_FIRST = SHIFT + 1; A_END = A_FIRST + LabelCount; SH_FIRST = A_END; SH_END = SH_FIRST + m_nSuperTagCount + 1; }
void QwtHistogram::loadDataFromMatrix() { if (!d_matrix) return; int size = d_matrix->numRows()*d_matrix->numCols(); const double *data = d_matrix->matrixModel()->dataVector(); int n; gsl_histogram *h; if (d_autoBin){ double min, max; d_matrix->range(&min, &max); d_begin = floor(min); d_end = ceil(max); d_bin_size = 1.0; n = qRound((d_end - d_begin)/d_bin_size); if (!n) return; h = gsl_histogram_alloc (n); if (!h) return; gsl_histogram_set_ranges_uniform (h, floor(min), ceil(max)); } else { n = int((d_end - d_begin)/d_bin_size + 1); if (!n) return; h = gsl_histogram_alloc (n); if (!h) return; double *range = new double[n+2]; for (int i = 0; i<= n+1; i++ ) range[i] = d_begin + i*d_bin_size; gsl_histogram_set_ranges (h, range, n+1); delete[] range; } for (int i = 0; i<size; i++ ) gsl_histogram_increment (h, data[i]); double X[n], Y[n]; //stores ranges (x) and bins (y) for (int i = 0; i<n; i++ ){ Y[i] = gsl_histogram_get (h, i); double lower, upper; gsl_histogram_get_range (h, i, &lower, &upper); X[i] = lower; } setData(X, Y, n); d_mean = gsl_histogram_mean(h); d_standard_deviation = gsl_histogram_sigma(h); d_min = gsl_histogram_min_val(h); d_max = gsl_histogram_max_val(h); gsl_histogram_free (h); if (d_show_labels) loadLabels(); }
void QwtHistogram::loadData() { if (d_matrix){ loadDataFromMatrix(); return; } int r = abs(d_end_row - d_start_row) + 1; QVarLengthArray<double> Y(r); int ycol = d_table->colIndex(title().text()); int size = 0; for (int i = 0; i<r; i++ ){ QString yval = d_table->text(i, ycol); if (!yval.isEmpty()){ bool valid_data = true; Y[size] = ((Graph *)plot())->locale().toDouble(yval, &valid_data); if (valid_data) size++; } } if(size < 2 || (size==2 && Y[0] == Y[1])){//non valid histogram double X[2]; Y.resize(2); for (int i = 0; i<2; i++ ){ Y[i] = 0; X[i] = 0; } setData(X, Y.data(), 2); return; } int n; gsl_histogram *h; if (d_autoBin){ n = 10; h = gsl_histogram_alloc (n); if (!h) return; gsl_vector *v = gsl_vector_alloc (size); for (int i = 0; i<size; i++ ) gsl_vector_set (v, i, Y[i]); double min, max; gsl_vector_minmax (v, &min, &max); gsl_vector_free (v); d_begin = floor(min); d_end = ceil(max); if (d_end == max) d_end += 1.0; d_bin_size = (d_end - d_begin)/(double)n; gsl_histogram_set_ranges_uniform (h, d_begin, d_end); } else { n = int((d_end - d_begin)/d_bin_size + 1); h = gsl_histogram_alloc (n); if (!h) return; double *range = new double[n+2]; for (int i = 0; i<= n+1; i++ ) range[i] = d_begin + i*d_bin_size; gsl_histogram_set_ranges (h, range, n+1); delete[] range; } for (int i = 0; i<size; i++ ) gsl_histogram_increment (h, Y[i]); double X[n]; //stores ranges (x) and bins (y) Y.resize(n); for (int i = 0; i<n; i++ ){ Y[i] = gsl_histogram_get (h, i); double lower, upper; gsl_histogram_get_range (h, i, &lower, &upper); X[i] = lower; } setData(X, Y.data(), n); d_mean = gsl_histogram_mean(h); d_standard_deviation = gsl_histogram_sigma(h); d_min = gsl_histogram_min_val(h); d_max = gsl_histogram_max_val(h); gsl_histogram_free (h); if (d_show_labels) loadLabels(); }
void DataCurve::loadData() { Plot *plot = static_cast<Plot *>(this->plot()); Graph *g = static_cast<Graph *>(plot->parent()); if (!g) return; int xcol = d_table->colIndex(d_x_column); int ycol = d_table->colIndex(title().text()); if (xcol < 0 || ycol < 0){ remove(); return; } int r = abs(d_end_row - d_start_row) + 1; QVarLengthArray<double> X(r), Y(r); int xColType = d_table->columnType(xcol); int yColType = d_table->columnType(ycol); QStringList xLabels, yLabels;// store text labels // int xAxis = QwtPlot::xBottom; // if (d_type == Graph::HorizontalBars) // xAxis = QwtPlot::yLeft; QTime time0; QDateTime date0; QString date_time_fmt = d_table->columnFormat(xcol); if (xColType == Table::Time){ for (int i = d_start_row; i <= d_end_row; i++ ){ QString xval=d_table->text(i,xcol); if (!xval.isEmpty()){ time0 = QTime::fromString (xval, date_time_fmt); if (time0.isValid()) break; } } } else if (xColType == Table::Date){ for (int i = d_start_row; i <= d_end_row; i++ ){ QString xval=d_table->text(i,xcol); if (!xval.isEmpty()){ date0 = QDateTime::fromString (xval, date_time_fmt); if (date0.isValid()) break; } } } int size = 0; for (int i = d_start_row; i <= d_end_row; i++ ){ QString xval = d_table->text(i,xcol); QString yval = d_table->text(i,ycol); if (!xval.isEmpty() && !yval.isEmpty()){ bool valid_data = true; if (xColType == Table::Text){ xLabels << xval; X[size] = (double)(size + 1); } else if (xColType == Table::Time){ QTime time = QTime::fromString (xval, date_time_fmt); if (time.isValid()) X[size]= time0.msecsTo (time); } else if (xColType == Table::Date){ QDateTime d = QDateTime::fromString (xval, date_time_fmt); if (d.isValid()) X[size] = (double) date0.secsTo(d); } else X[size] = plot->locale().toDouble(xval, &valid_data); if (yColType == Table::Text){ yLabels << yval; Y[size] = (double)(size + 1); } else Y[size] = plot->locale().toDouble(yval, &valid_data); if (valid_data) size++; } } X.resize(size); Y.resize(size); // The code for calculating the waterfall offsets, that is here in QtiPlot, has been moved up to // PlotCurve so that MantidCurve can access it as well. if (g->isWaterfallPlot()) { // Calculate the offsets computeWaterfallOffsets(); } // End re-jigged waterfall offset code if (!size){ remove(); return; } else { if (d_type == Graph::HorizontalBars){ setData(Y.data(), X.data(), size); foreach(DataCurve *c, d_error_bars) c->setData(Y.data(), X.data(), size); } else { setData(X.data(), Y.data(), size); foreach(DataCurve *c, d_error_bars) c->setData(X.data(), Y.data(), size); } if (xColType == Table::Text){ if (d_type == Graph::HorizontalBars) g->setLabelsTextFormat(QwtPlot::yLeft, ScaleDraw::Text, d_x_column, xLabels); else g->setLabelsTextFormat(QwtPlot::xBottom, ScaleDraw::Text, d_x_column, xLabels); } else if (xColType == Table::Time || xColType == Table::Date){ int axis = QwtPlot::xBottom; if (d_type == Graph::HorizontalBars) axis = QwtPlot::yLeft; ScaleDraw *old_sd = static_cast<ScaleDraw *>(plot->axisScaleDraw(axis)); ScaleDraw *sd = new ScaleDraw(plot, old_sd); if (xColType == Table::Date) sd->setDateTimeOrigin(date0); else sd->setDateTimeOrigin(QDateTime(QDate::currentDate(), time0)); plot->setAxisScaleDraw(axis, sd); } if (yColType == Table::Text) g->setLabelsTextFormat(QwtPlot::yLeft, ScaleDraw::Text, title().text(), yLabels); } if (!d_labels_list.isEmpty()){ (static_cast<Graph*>(plot->parent()))->updatePlot(); loadLabels(); } }
void DataCurve::loadData() { Graph *g = (Graph *)plot(); if (!g) return; int xcol = d_x_table->colIndex(d_x_column); int ycol = d_table->colIndex(title().text()); if (xcol < 0 || ycol < 0) { remove(); return; } int rows = d_table->numRows(); if (d_end_row < 0 || d_end_row >= rows) d_end_row = rows - 1; int xColType = d_x_table->columnType(xcol); int yColType = d_table->columnType(ycol); int r = abs(d_end_row - d_start_row) + 1; QPolygonF data; data.reserve(r); QStringList xLabels, yLabels;// store text labels int xAxis = QwtPlot::xBottom; if (d_type == Graph::HorizontalBars) xAxis = QwtPlot::yLeft; QString date_time_fmt = d_table->columnFormat(xcol); int size = 0, from = 0; d_data_ranges.clear(); for (int i = d_start_row; i <= d_end_row; i++ ) { QString xval = d_x_table->text(i, xcol); QString yval = d_table->text(i, ycol); if (!xval.isEmpty() && !yval.isEmpty()) { bool valid_data = true; QPointF p; if (xColType == Table::Text) { xLabels << xval; p.setX((double)(size + 1)); } else if (xColType == Table::Time) p.setX(Table::fromTime(QTime::fromString(xval.trimmed(), date_time_fmt))); else if (xColType == Table::Date) p.setX(Table::fromDateTime(QDateTime::fromString(xval.trimmed(), date_time_fmt))); else p.setX(g->locale().toDouble(xval, &valid_data)); if (yColType == Table::Text) { yLabels << yval; p.setY((double)(size + 1)); } else p.setY(g->locale().toDouble(yval, &valid_data)); if (valid_data) { data << p; size++; } } else if (from < size) { DataRange range; range.from = from; range.to = size - 1; d_data_ranges.push_back(range); from = size; } } if (d_data_ranges.size() && from < size) { DataRange range; range.from = from; range.to = size - 1; d_data_ranges.push_back(range); } if (!size) { remove(); return; } data.resize(size); if (g->isWaterfallPlot()) { int index = g->curveIndex(this); int curves = g->curveCount(); DataCurve *c = g->dataCurve(0); if (index > 0 && c) { double xmin = c->minXValue(); double dx = index*g->waterfallXOffset()*0.01*g->canvas()->width()/(double)(curves - 1); d_x_offset = g->invTransform(xAxis, g->transform(xAxis, xmin) + dx) - xmin; double ymin = c->minYValue(); double dy = index*g->waterfallYOffset()*0.01*g->canvas()->height()/(double)(curves - 1); d_y_offset = ymin - g->invTransform(yAxis(), g->transform(yAxis(), ymin) + dy); setZ(-index); setBaseline(d_y_offset); data.translate(d_x_offset, d_y_offset); } else { setZ(0); setBaseline(0.0); } if (g->grid()) g->grid()->setZ(-g->curveCount() - 1); } double speedTol = g->getDouglasPeukerTolerance(); if (speedTol != 0.0 && size >= g->speedModeMaxPoints()) { QwtWeedingCurveFitter *fitter = new QwtWeedingCurveFitter(speedTol); data = fitter->fitCurve(data); delete fitter; } if (d_type == Graph::HorizontalBars) { size = data.size(); for (int i = 0; i < size; i++) { QPointF p = data.at(i); data[i] = QPointF(p.y(), p.x()); } } setData(data); foreach(ErrorBarsCurve *c, d_error_bars) c->setData(data); if (xColType == Table::Text) g->setLabelsTextFormat(xAxis, ScaleDraw::Text, d_x_column, xLabels); if (yColType == Table::Text) g->setLabelsTextFormat(QwtPlot::yLeft, ScaleDraw::Text, title().text(), yLabels); setRenderHint(QwtPlotItem::RenderAntialiased, g->isCurveAntialiasingEnabled(this)); if (!d_labels_list.isEmpty()) { ((Graph*)plot())->updatePlot(); loadLabels(); } }
void DataCurve::loadData() { Graph *g = (Graph *)plot(); if (!g) return; int xcol = d_table->colIndex(d_x_column); int ycol = d_table->colIndex(title().text()); if (xcol < 0 || ycol < 0){ remove(); return; } int r = abs(d_end_row - d_start_row) + 1; QVarLengthArray<double> X(r), Y(r); int xColType = d_table->columnType(xcol); int yColType = d_table->columnType(ycol); QStringList xLabels, yLabels;// store text labels QTime time0; QDateTime date0; QString date_time_fmt = d_table->columnFormat(xcol); if (xColType == Table::Time){ for (int i = d_start_row; i <= d_end_row; i++ ){ QString xval=d_table->text(i,xcol); if (!xval.isEmpty()){ time0 = QTime::fromString (xval, date_time_fmt); if (time0.isValid()) break; } } } else if (xColType == Table::Date){ for (int i = d_start_row; i <= d_end_row; i++ ){ QString xval=d_table->text(i,xcol); if (!xval.isEmpty()){ date0 = QDateTime::fromString (xval, date_time_fmt); if (date0.isValid()) break; } } } int size = 0; for (int i = d_start_row; i <= d_end_row; i++ ){ QString xval = d_table->text(i,xcol); QString yval = d_table->text(i,ycol); if (!xval.isEmpty() && !yval.isEmpty()){ bool valid_data = true; if (xColType == Table::Text){ xLabels << xval; X[size] = (double)(size + 1); } else if (xColType == Table::Time){ QTime time = QTime::fromString (xval, date_time_fmt); if (time.isValid()) X[size]= time0.msecsTo (time); } else if (xColType == Table::Date){ QDateTime d = QDateTime::fromString (xval, date_time_fmt); if (d.isValid()) X[size] = (double) date0.secsTo(d); } else X[size] = g->locale().toDouble(xval, &valid_data); if (yColType == Table::Text){ yLabels << yval; Y[size] = (double)(size + 1); } else Y[size] = g->locale().toDouble(yval, &valid_data); if (valid_data) size++; } } X.resize(size); Y.resize(size); if (!size){ remove(); return; } else { if (d_type == Graph::HorizontalBars){ setData(Y.data(), X.data(), size); foreach(DataCurve *c, d_error_bars) c->setData(Y.data(), X.data(), size); } else { setData(X.data(), Y.data(), size); foreach(DataCurve *c, d_error_bars) c->setData(X.data(), Y.data(), size); } if (xColType == Table::Text){ if (d_type == Graph::HorizontalBars) g->setLabelsTextFormat(QwtPlot::yLeft, ScaleDraw::Text, d_x_column, xLabels); else g->setLabelsTextFormat(QwtPlot::xBottom, ScaleDraw::Text, d_x_column, xLabels); } else if (xColType == Table::Time || xColType == Table::Date){ int axis = QwtPlot::xBottom; if (d_type == Graph::HorizontalBars) axis = QwtPlot::yLeft; ScaleDraw *old_sd = (ScaleDraw *)g->axisScaleDraw(axis); ScaleDraw *sd = new ScaleDraw(g, old_sd); if (xColType == Table::Date) sd->setDateTimeOrigin(date0); else sd->setDateTimeOrigin(QDateTime(QDate::currentDate(), time0)); g->setAxisScaleDraw(axis, sd); } if (yColType == Table::Text) g->setLabelsTextFormat(QwtPlot::yLeft, ScaleDraw::Text, title().text(), yLabels); } if (!d_labels_list.isEmpty()){ ((Graph*)plot())->updatePlot(); loadLabels(); } }