From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id aCqAFTR31l6wfQAA0tVLHw (envelope-from ) for ; Tue, 02 Jun 2020 15:58:44 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id eINmETR31l6uPAAA1q6Kng (envelope-from ) for ; Tue, 02 Jun 2020 15:58:44 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 96332940982 for ; Tue, 2 Jun 2020 15:58:43 +0000 (UTC) Received: from localhost ([::1]:33268 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jg9JK-0002dM-IG for larch@yhetil.org; Tue, 02 Jun 2020 11:58:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57672) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jg9IF-0002av-RY for emacs-orgmode@gnu.org; Tue, 02 Jun 2020 11:57:35 -0400 Received: from latitanza.investici.org ([82.94.249.234]:52931) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jg9ID-0001X4-Mt for emacs-orgmode@gnu.org; Tue, 02 Jun 2020 11:57:35 -0400 Received: from mx3.investici.org (unknown [127.0.0.1]) by latitanza.investici.org (Postfix) with ESMTP id B41B912096B; Tue, 2 Jun 2020 15:57:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anche.no; s=stigmate; t=1591113448; bh=n8g6mBOvHbFNDyDK1UaSR10Lzybif25RsCASDLEhKlI=; h=To:From:Subject:Date:From; b=pXQsSRbjP8LNT3oM+4pNDI+1maQhJJg1qIUQWkQky9pIK263sf4D5uEGOlxY+u6Rc otaw8BAQmupI0It6Sq5mFbPRSH2kkYsj807Uchs0RTUMKGN10H94uyZwhhXFHAbJ1J 4tBONWKT6BBezlyy0S9xss4KEGrAr0trr8kXk7IA= Received: from [82.94.249.234] (mx3.investici.org [82.94.249.234]) (Authenticated sender: mariotomo@inventati.org) by localhost (Postfix) with ESMTPSA id C47B7120278; Tue, 2 Jun 2020 15:57:27 +0000 (UTC) To: emacs-orgmode@gnu.org From: Mario Frasca Subject: [PATCH] implementing `with' as a list, and respecting `deps' order. Message-ID: <43f4eda9-627d-4b36-7226-37b5458193e8@anche.no> Date: Tue, 2 Jun 2020 10:57:07 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Received-SPF: pass client-ip=82.94.249.234; envelope-from=mario@anche.no; helo=latitanza.investici.org X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/02 11:57:29 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=fail (body hash did not verify) header.d=anche.no header.s=stigmate header.b=pXQsSRbj; dmarc=none; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Spam-Score: -0.01 X-TUID: 6+KHCPOdsapD From 436bfd0b9fd656f52ea9d7e6a6a665a32564ae93 Mon Sep 17 00:00:00 2001 From: Mario Frasca Date: Tue, 2 Jun 2020 15:46:20 +0000 Subject: [PATCH] implementing `with' as a list, and respecting `deps' order. ---  doc/org-manual.org            |  7 ++--  lisp/org-plot.el              | 66 +++++++++++++++++++++--------------  testing/lisp/test-org-plot.el | 64 +++++++++++++++++++++++++++++++++  3 files changed, 108 insertions(+), 29 deletions(-)  create mode 100644 testing/lisp/test-org-plot.el diff --git a/doc/org-manual.org b/doc/org-manual.org index 92252179b..40cb3c2f2 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -2845,9 +2845,10 @@ For more information and examples see the [[https://orgmode.org/worg/org-tutoria  - =with= :: -  Specify a =with= option to be inserted for every column being -  plotted, e.g., =lines=, =points=, =boxes=, =impulses=. Defaults to -  =lines=. +  Specify a =with= option to be inserted for the columns being +  plotted, e.g., =lines=, =points=, =boxes=, =impulses=. You can specify +  a single value, to be applied to all columns, or a list of different +  values, one for each column in the =deps= property. Defaults to =lines=.  - =file= :: diff --git a/lisp/org-plot.el b/lisp/org-plot.el index a23195d2a..073075037 100644 --- a/lisp/org-plot.el +++ b/lisp/org-plot.el @@ -179,6 +179,24 @@ and dependent variables."        (setf back-edge "") (setf front-edge ""))))      row-vals)) +(defun org-plot/zip-deps-with (num-cols ind deps with) +  "Describe each column to be plotted as (col . with). +Loops over DEPS and WITH in order to cons their elements. +If the DEPS list of columns is not given, use all columns from 1 +to NUM-COLS, excluding IND. +If WITH is given as a string, use the given value for all columns. +If WITH is given as a list, and it's shorter than DEPS, expand it +with the global default value." +  (unless deps +    (setq deps (remove ind (number-sequence 1 num-cols)))) +  (setq with +    (if (listp with) +        (append with +            (make-list (max 0 (- (length deps) (length with))) +                   "lines")) +      (make-list (length deps) with))) +  (cl-mapcar #'cons deps with)) +  (defun org-plot/gnuplot-script (data-file num-cols params &optional preface)    "Write a gnuplot script to DATA-FILE respecting the options set in PARAMS.  NUM-COLS controls the number of columns plotted in a 2-d plot. @@ -239,32 +257,27 @@ manner suitable for prepending to a user-specified script."                 (or timefmt    ; timefmt passed to gnuplot                     "%Y-%m-%d-%H:%M:%S") "\"")))      (unless preface -      (pcase type            ; plot command -    (`2d (dotimes (col num-cols) -           (unless (and (eq type '2d) -                (or (and ind (equal (1+ col) ind)) -                (and deps (not (member (1+ col) deps))))) -         (setf plot-lines -               (cons -            (format plot-str data-file -                (or (and ind (> ind 0) -                     (not text-ind) -                     (format "%d:" ind)) "") -                (1+ col) -                (if text-ind (format ":xticlabel(%d)" ind) "") -                with -                (or (nth col col-labels) -                    (format "%d" (1+ col)))) -            plot-lines))))) -    (`3d -     (setq plot-lines (list (format "'%s' matrix with %s title ''" -                    data-file with)))) -    (`grid -     (setq plot-lines (list (format "'%s' with %s title ''" -                    data-file with))))) +      (setq plot-lines +        (pcase type            ; plot command +          (`2d (cl-loop +            for (col . with) +            in (org-plot/zip-deps-with num-cols ind deps with) +            collect (format plot-str data-file +                    (or (and ind (> ind 0) +                         (not text-ind) +                         (format "%d:" ind)) "") +                    col +                    (if text-ind (format ":xticlabel(%d)" ind) "") +                    with +                    (or (nth (1- col) col-labels) +                    (format "%d" col))))) +          (`3d (list (format "'%s' matrix with %s title ''" +                 data-file with))) +          (`grid (list (format "'%s' with %s title ''" +                   data-file with)))))        (funcall ats             (concat plot-cmd " " (mapconcat #'identity -                           (reverse plot-lines) +                           plot-lines                             ",\\\n    "))))      script)) @@ -310,7 +323,8 @@ line directly before or after the table."                  table data-file params)))           (when y-labels (plist-put params :ylabels y-labels)))))        ;; Check for timestamp ind column. -      (let ((ind (1- (plist-get params :ind)))) +      (let ((ind (1- (plist-get params :ind))) +        (with (plist-get params :with)))      (when (and (>= ind 0) (eq '2d (plist-get params :plot-type)))        (if (= (length            (delq 0 (mapcar @@ -320,7 +334,7 @@ line directly before or after the table."           0)            (plist-put params :timeind t)          ;; Check for text ind column. -        (if (or (string= (plist-get params :with) "hist") +        (if (or (equal with "hist")              (> (length              (delq 0 (mapcar                   (lambda (el) diff --git a/testing/lisp/test-org-plot.el b/testing/lisp/test-org-plot.el new file mode 100644 index 000000000..2bf153400 --- /dev/null +++ b/testing/lisp/test-org-plot.el @@ -0,0 +1,64 @@ +;;; test-org-plot.el --- Tests for Org Plot library    -*- lexical-binding: t; -*- + +;; Copyright (C) 2020  Mario Frasca + +;; Author: Mario Frasca + +;; This file is not part of GNU Emacs. + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program 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. + +;; You should have received a copy of the GNU General Public License +;; along with this program.  If not, see . + +;;; Code: + +(require 'org-test) +(require 'org-plot) + + +;; General auxiliaries + +(ert-deftest test-org-plot/zip-deps-with () +  "Test `org-plot/zip-deps-with' specifications." +  ;; no deps, no with. defaults to all except ind, and "lines" +  (should +   (equal (org-plot/zip-deps-with 3 1 nil nil) +      '((2 . "lines") (3 . "lines")))) +  ;; no deps, single with. defaults to all except ind, and repeated with +  (should +   (equal (org-plot/zip-deps-with 3 1 nil "hist") +      '((2 . "hist") (3 . "hist")))) +  ;; no deps, explicit with +  (should +   (equal (org-plot/zip-deps-with 3 1 nil '("points" "hist")) +      '((2 . "points") (3 . "hist")))) +  ;; explicit with, same length as deps +  (should +   (equal (org-plot/zip-deps-with 5 1 '(2 4) '("points" "hist")) +      '((2 . "points") (4 . "hist")))) +  ;; same as above, but different order +  (should +   (equal (org-plot/zip-deps-with 5 1 '(4 2) '("points" "hist")) +      '((4 . "points") (2 . "hist")))) +  ;; if with exceeds deps, trailing elements are discarded +  (should +   (equal (org-plot/zip-deps-with 5 1 '(4 2) '("points" "hist" "lines")) +      '((4 . "points") (2 . "hist")))) +  ;; fills in with "lines" +  (should +   (equal (org-plot/zip-deps-with 5 1 '(4 2 3) '("points")) +      '((4 . "points") (2 . "lines") (3 . "lines"))))) + + + +(provide 'test-org-plot) +;;; test-org-plot.el end here -- 2.20.1