Up: Part IV: Syntax Previous: THE VERB: VOICES Next: THE PARTICIPLE
1. The Infinitive. 2. The Participle. 3. The Verbal Adjectives in -τός and -τέος.
The infinitive is in part a verb, in part a substantive.
a. Many substantives are closely related to verbs, but not all verbs can form substantives. All verbs can, however, form infinitives.
b. The word infinitive denotes a verbal form without any limitations (finis) of number and person.
The infinitive is like a verb herein:
a. It shows the distinctions of voice and tense (but not those of number and person). Having tenses, it can express different stages of action (action simply occurring, continuing, or finished); whereas the corresponding substantive sets forth the abstract idea without these distinctions. Contrast ποιεῖν, ποιήσειν, ποιῆσαι, πεποιηκέναι with ποίησις making.
b. It can have a subject before it and a predicate after it, and it can have an object in the genitive, dative, or accusative like the corresponding finite verb. Infinitives scarcely ever stand in the subjective genitive; and the object of an infinitive never stands in the objective genitive.
c. It is modified by adverbs, not by adjectives.
d. It may take ἄν and with that particle represent ἄν with the indicative (1784 ff.) or ἄν with the optative (1824).
e. It forms clauses of result with ὥστε, and temporal clauses with πρίν, etc.
The infinitive is like a substantive herein:
a. It may be the subject or object of a verb.
b. With the (neuter) article it shows all the case forms (except the vocative): τὸ (τοῦ, τῷ, τὸ) λύ̄ειν, λύ̄σειν, etc.
c. It may be governed by prepositions: πρὸ τοῦ λύ̄ειν.
The infinitive was originally a verbal noun in the dative (in part possibly also in the locative) case. The use to express purpose (2008) is a survival of the primitive meaning, from which all the other widely diverging uses were developed in a manner no longer always clear to us. But the to or for meaning seen in μανθάνειν ἥκομεν we have come to learn (for learning) can also be discerned in δύναμαι ἰδεῖν I have power for seeing, then I can see. Cp. 2000, 2006 a. As early as Homer, when the datival meaning had been in part obscured, the infinitive was employed as nominative (as subject) and accusative (as object). After Homer, the infinitive came to be used with the neuter article, the substantive idea thus gaining in definiteness. The article must be used when the infinitive stands as an object in the genitive or dative, and when it depends on prepositions.
The infinitive is used as subject, as predicate, and to supplement the meaning of words and clauses.
The negative of the infinitive is μή; but οὐ, used with a finite mood in direct discourse, is retained when that mood becomes infinitive in indirect discourse. Sometimes, however, μή is used in place of this οὐ (2723 ff.).
In general the subject of the infinitive, if expressed at all, stands in the accusative; when the subject of the infinitive is the same as the subject or object of the governing verb, or when it has already been made known in the sentence, it is not repeated with the infinitive.
When the subject of the infinitive is the same as that of the governing verb, it is omitted, and a predicate noun stands in the nominative case.
I think that I knowοἶμαι εἰδέναι
he said he was a PersianΠέρσης ἔφη εἶναι
I shall not admit that I have come uninvitedἐγὼ οὐχ ὁμολογήσω ἄκλητος ἥκειν
a. The nominative is used when the infinitive, expressing some action or state of the subject of the main verb, has the article in an oblique case. Thus, τούτων ἀξιωθεὶς διὰ τὸ πατρικὸς αὐτῷ φίλος εί̂ναι justifying these requests on the ground that he was his hereditary friend Aes. 3.52,
this he effected by reason of his being severeτοῦτο δ᾽ ἐποίει ἐκ τοῦ χαλεπὸς εἶναι
b. The nominative stands usually in sentences with δεῖν, χρῆναι etc., dependent on a verb of saying or thinking. Thus,
I thought I ought to surpass them and to show myself more magnificentἡγούμην . . . περιεῖναι δεῖν αὐτῶν καὶ μεγαλοψῡχότερος φαίνεσθαι
c. When the governing verb is a participle in an oblique case, a predicate noun usually agrees with the participle, and rarely stands in the nominative. Thus,
being rid of those who profess to be judgesἀπαλλαγεὶς τούτων τῶν φασκόντων δικαστῶν εἶναι
it dispenses the offices to those who always seem to be the most deservingτὰ̄ς ἀρχὰ̄ς δίδωσι . . . τοῖς ἀεὶ δόξᾱσιν ἀρίστοις εἶναι
A pronoun subject of the infinitive, if (wholly or partially) identical with the subject of the main verb, is generally expressed when emphatic, and stands in the accusative (cases of the nominative are rare and suspected); but the indirect reflexive σφεῖς stands in the nominative or accusative.
I think I have made more money than any two others togetherοἶμαι ἐμὲ πλείω χρήματα εἰργάσθαι ἢ ἄλλους σύνδυο
he thought the Thebans would let him have his own wayτοὺς δὲ Θηβαίους ἡγεῖτο . . . ἐά̄σειν ὅπως βούλεται πρά̄ττειν ἑαυτόν
a. After a preceding accusative with the infinitive, a second pronoun referring to a different person, and also subject of an infinitive, must also stand in the accusative whether or not it denotes the same person as the subject of the governing verb. Thus, ἀλλὰ νομίζεις ἡμᾶς μὲν ἀνέξεσθαί σου, αὐτὸς (see below) δὲ τυπήσειν; καὶ ἡμᾶς μὲν ἀποψηφιεῖσθαί σου, δὲ (not σὺ) δ᾽ ου᾽ παύσεσθαι but do you think that we are going to put up with you, while you strike us yourself? and that we are going to acquit you, while you will not cease your outrageous conduct? D. 21.204. αὐτός, above and in Κλέων οὐκ ἔφη αὐτός, ἀλλ᾽ ἐκεῖνον στρατηγεῖν Cleon said that not he himself, but that Nicias was in command T. 4.28, is not the expressed subject of the infinitive, but αὐτός of direct discourse (αὐτὸς τυπήσεις, αὐτὸς οὐ στρατηγῶ); hence αὐτός is not used here for σεαυτόν (ἑαυτόν).
When the subject of the infinitive is different from that of the governing verb, it stands in the accusative; and a predicate noun stands also in the accusative.
for I think you are to me both fatherland and friendsνομίζω γὰρ ὑ̄μᾶς ἐμοὶ εἶναι καὶ πατρίδα καὶ φίλους
for I maintain that the noble and good man is happyτὸν γὰρ καλὸν κἀ̄γαθὸν ἄνδρα εὐδαίμονα εἶναί φημι
A predicate noun takes the case of the subject of an infinitive itself dependent on a subjectless infinitive. Thus,
they manage it so that they seem to us to appear in various formsἡμῖν δὲ ποιοῦσι δοκεῖν σφᾶς παντοδαποὺς φαίνεσθαι
Several infinitives may be used in succession, one infinitive being the subject of another:
regarding it of great importance not to seem to any one to wish to behave outrageouslyπερὶ πολλοῦ ποιούμενος μηδενὶ δόξαι ὑβρίζειν βούλεσθαι
When the subject of the infinitive is the same as the object (in the genitive or dative) of the governing verb, it is often omitted, and a predicate noun is either attracted into the genitive or dative, or stands in the accusative in agreement with the omitted subject of the infinitive. See 1060-1062.
ἔξεστιν ἡμῖν ἀγαθοῖς εἶναι or ἔξεστιν ἡμῖν ἀγαθοὺς εἶναι it is in our power to be good (lit. to be good is possible for us). Thus, δεόμεθ᾽ οὖν ὑ̄μῶν . . . ἀκροά̄σασθαι τῶν λεγομένων, ἐνθῡμηθέντας ὅτι κτλ. we ask you therefore to listen to what is said, considering that, etc. 1. 14. 6. Cp. νῦν σοι ἔξεστιν ἀνδρὶ γενέσθαι quoted in 1062 with
it is in your power to become friends to the LacedaemoniansΛακεδαιμονίοις ἔξεστιν ὑ̄μῖν φίλους γενέσθαι
The subject of the infinitive is often retained when it is the same as the (omitted) oblique object of the governing verb. Thus,
he issued orders that the Greeks should get under armsπαρήγγειλε τὰ ὅπλα τίθεσθαι τοὺς Ἕλληνας
An indefinite or general subject of the infinitive (τινά, τινάς, ἀνθρώπους) is commonly omitted; and a predicate noun stands in the accusative. Thus, φιλάνθρωπον εἶναι δεῖ one (τινά) must be humane I. 2.15 (cp. 1984), ῥᾷον παραινεῖν ἢ παθόντα καρτερεῖν it is easier for a man to give advice than to endure suffering Men. Sent. 471,
for it is preferable to die in action rather than doing nothingδρῶντας γὰρ ἢ μὴ δρῶντας ἥδῑον θανεῖν
The construction of the accusative with the infinitive seems to have originated from the employment of the infinitive to complement the meaning of transitive verbs; as in κελεύω σε ἀπελθεῖν I command you to depart. Here the accusative was separated from the transitive verb and felt to be the independent subject of the infinitive (I command that you depart). Gradually the accusative with the infinitive was used even after verbs incapable of taking an object-accusative.
Instead of an impersonal passive verb with the accusative and infinitive as subject, Greek often uses the personal passive construction, the accusative becoming the nominative, subject to the leading verb.
Thus, Κῦρος ἠγγέλθη νῑκῆσαι Cyrus was reported to have conquered instead of ἠγγέλθη Κῦρον νῑκῆσαι it was reported that Cyrus had conquered, and δίκαιός εἰμι ἀπελθεῖν I am justified in going away instead of δίκαιόν ἐστιν ἐμὲ ἀπελθεῖν it is right for me to go away. English sometimes has to use the impersonal construction in place of the Greek personal construction (cp. 2107).
a. The personal construction is more common with λέγεται, ἀγγέλλεται, ὁμολογεῖται and other passive verbs of saying (regular with passive verbs of thinking); with συμβαίνει it happens; with ἀναγκαῖος necessary, ἄξιος worthy, δίκαιος just, δυνατός possible, ἐπιτήδειος fit, etc., followed by a form of εἶναι, instead of ἀναγκαῖον, ἄξιον, etc. Thus,
the Assyrian is reported to be about to make an incursion into his countryὁ Ἀσσύριος εἰς τὴν χώρᾱν αὐτοῦ ἐμβαλεῖν ἀγγέλλεται
much absurdity would resultπολλή τις ἀλογίᾱ ξυμβαίνει γίγνεσθαι
it is right for you to speakδίκαιος εἶ εἰπεῖν
it is right for him to bear the blameτὴν αἰτίᾱν οὗτός ἐστι δίκαιος ἔχειν
N.—δῆλός ἐστι and φανερός ἐστι take ὅτι or the participle (2107); δῆλόν ἐστι and φανερόν ἐστι take ὅτι, not the infinitive.
The personal constructions δοκῶ, ἔοικα (2089 c), δέω are regular instead of δοκεῖ, ἔοικε it seems, δεῖ it lacks (much or little). So with φαίνομαι for φαίνεται.
for I seem to be unableδοκῶ γάρ μοι ἄδυνατος εἶναι
it seems to me that we are encampedδοκοῦμέν μοι καθῆσθαι
now at least you seem to be our kingνῦν γε ἡμῶν ἔοικας βασιλεὺς εἶναι
I am far from speaking in my own defenceπολλοῦ δέω ἐγὼ ὑπὲρ ἐμαυτοῦ ἀπολογεῖσθαι
you seem to speak wellεὖ σὺ λέγειν φαίνει
a. δοκεῖ μοί τινα ἐλθεῖν for δοκεῖ τίς μοι ἐλθεῖν it seems to me that some one came is very rare. δοκεῖ meaning it seems good, it is decreed always takes the infinitive (1984, 1991). δοκῶ believe has the construction of 1992 c. Cp. 1998.
As Subject.—The infinitive may be used as subject, especially with quasi-impersonal verbs and expressions (933 a).
to learn to read is necessaryγράμματα μαθεῖν δεῖ
to perform this well is a creditκαλῶς τοῦτο δρᾶν
it seemed best to them to proceedἔδοξεν αὐτοῖς προϊέναι
it is for their interest to be friendsσυμφέρει αὐτοῖς φίλους εἶναι
Such quasi-impersonal verbs and expressions are δεῖ it is necessary, χρή (properly a substantive with ἐστί omitted, 793) it is necessary, δοκεῖ it seems good, ἔστι it is possible, ἔξεστι it is in one's power, οἷόν τέ ἐστι it is possible, πρέπει and προσήκει it is fitting, συμβαίνει it happens; and many expressions formed by ἐστί and a predicate noun, as ἄξιον it is right, δίκαιον it is just, ἀναγ- καῖον it is necessary, δυνατόν it is possible, ἀδύνατον (or ἀδύνατα) it is impossible, αἰσχρόν it is disgraceful, καλόν it is honourable, ὥρᾱ and καιρός it is time. With the last two expressions the old dative use of the infinitive is clear:
it is time for consideringὥρᾱ βουλεύεσθαι
a. On the personal ἄξιός εἰμι, δίκαιός εἰμι, δοκῶ, see 1982. For δεῖ με τοῦτο λέγειν we find the personal δέομαι τοῦτο λέγειν. Note the attraction in
the number of the things it is possible to mentionτὸ πλῆθος τῶν ἐνόντων εἰπεῖν
b. δεῖ and χρή regularly take the accusative and infinitive (cp. 1562); ἀνάγκη it is necessary takes the accusative or dative with the infinitive.
c. The subject of the infinitive is expressed or omitted according to the sense.
d. Homer shows only the beginnings of the use of the infinitive as a real subject, i.e. not a grammatical subject, as in 1984.
As Predicate.—In definitions the infinitive may be used as a predicate noun with ἐστί.
for to learn is to get knowledgeτὸ γὰρ γνῶναι ἐπιστήμην λαβεῖν ἐστιν
As an Appositive.—The infinitive may stand in apposition to a preceding substantive, pronoun, or adverb.
εἷς οἰωνὸς ἄριστος, ἀμύ̄νεσθαι περὶ πάτρης one omen is best, to fight for our country M 243, εἶπον . . . τοῦτο μόνον ὁρᾶν πάντας, τῷ πρόσθεν ἕπεσθαι I told all to pay heed to this only, viz., to follow their leader X. C. 2.2.8, καὶ ὑ̄μᾶς δὲ οὕτως, ὦ παῖδες, . . . ἐπαίδευον, τοὺς μὲν γεραιτέρους προτῑμᾶν, τῶν δὲ νεωτέρων προτετῑμῆσθαι and I have instructed you, too, my children (to this effect) to honour your elders in preference to yourselves and to receive honour from the younger in preference to them X. C. 8.7.10.
The infinitive not in indirect discourse, and in indirect discourse, is often used as the object of a verb.
The infinitive as object not in indirect discourse is used after almost any verb that requires another verb to complete its meaning. The tenses of this infinitive are timeless, and denote only stage of action.
The infinitive may be the only expressed object, or it may be one of two expressed objects, of the leading verb.
a good education teaches obedience to the lawsπαίδευσις καλὴ διδάσκει χρῆσθαι νόμοις
he taught you to distinguish the good and the badδιαγιγνώσκειν σε τοὺς ἀγαθοὺς καὶ τοὺς κακοὺς ἐδίδαξεν
a. Verbs signifying to ask, bid, forbid, permit, teach, etc., allow an infinitive as one of two objects.
b. Many verbal expressions, formed by a substantive and a verb, take the infinitive. Thus, τοὺς ἄλλους διδάσκειν τέχνην ἔχουσιν they possess the skill to teach (the) others I. 16.11. Cp. 2000.
Verbs of will or desire (and their opposites) are often followed by an infinitive. The infinitive with a subject accusative denotes that something should (may) be or be done. The negative is μή (see 2719-2721).
they were willing to listen to himἤθελον αὐτοῦ ἀκούειν
they planned to leave the cityἐβουλεύοντο ἐκλιπεῖν τὴν πόλιν
he seeks to do what he likes bestτὰ ἥδιστα . . . ζητεῖ ποιεῖν
the king asks that you sail awayβασιλεὺς ἀξιοῖ σὲ ἀποπλεῖν
it was decided that Alcibiades should sailἔδοξε πλεῖν τὸν Ἀλκιβιάδην
a. Verbs of will or desire with an accusative subject of the infinitive form one of the classes of substantive clauses introduced in English by that, though the infinitive in English is often more idiomatic.
Of verbs of will or desire that take the infinitive some have an object
a. In the accusative (or are intransitive), e.g.: αἱροῦμαι choose, αἰτῶ, αἰτοῦμαι ask, ἀξιῶ claim, ask, βουλεύομαι resolve, βούλομαι wish, will, δικαιῶ deem right, διανοοῦμαι intend, ἐθέλω (poet. θέλω ), wish, will, εἴωθα am wont to, ἐπιχειρῶ attempt, ἐῶ permit, ζητῶ seek, κελεύω command, suggest, invite, μέλλω delay, πειρῶμαι try, πέμπω send, προθῡμοῦμαι am zealous, προκαλοῦμαι invite, προτρέπω urge, σπεύδω hasten, am eager, σπουδάζω am eager, τολμῶ dare, φιλῶ am wont to, ψηφίζομαι vote.
b. In the genitive, e.g.: δέομαι ask, ἐπιθῡμῶ and ὀρέγομαι desire.
c. In the dative, e.g.: εὔχομαι pray, παραγγέλλω and προστάττω command, ἐπιβουλεύω purpose, συμβουλεύω advise, ἐπιτρέπω and συγχωρῶ permit, παραινῶ exhort, δοκῶ μοι I have a mind to; and λέγω, εἶπον, φωνῶ, φράζω tell (and βοῶ shout) in the sense of command.
N.—πείθω urge to a course of action, takes the infinitive, πείθω convince generally has ὡς, rarely the accusative with the infinitive. Thus,
he urged him to go by himselfἔπειθεν αὐτὸν καθ᾽ αὑτὸν πορεύεσθαι
for most people will not be convinced that of your own free will you did not desire to go awayοὐ γὰρ πείσονται οἱ πολλοί, ὡς σὺ αὐτὸς οὐκ ἠθέλησας ἀπιέναι
Verbs of will or desire not to do anything are e.g.: δέδοικα, φοβοῦμαι fear, φεύγω avoid, ὀκνῶ scruple, αἰσχύ̄νομαι, αἰδοῦμαι (2126) feel shame to, ἀπαγορεύω forbid, κωλύ̄ω hinder, ἀπέχομαι abstain from, εὐλαβοῦμαι, φυλάττομαι beware of. Thus,
I fear to refute youφοβοῦμαι διελέγχειν σε
I am ashamed to tell you the truthαἰσχύ̄νομαι ὑ̄μῖν εἰπεῖν τἀ̄ληθῆ
Under verbs of will or desire are included verbs expressing an activity to the end that something shall or shall not be done. Thus, δίδωμι offer, give, διαμάχομαι struggle against, ποιῶ, διαπρά̄ττομαι, κατεργάζομαι manage, effect, παρέχω offer (others in 1992, 1993).
Several verbs of will or desire take ὅπως with the future or the subjunctive (verbs of effort, 2211, 2214); or μή with the subjunctive (verbs of fear, 2225); some take the participle (2123 ff.).
The infinitive may be used with the
a. Genitive or dative when the expression of desire is addressed to a person and the genitive or dative depends on the leading verb. Here the sentence is simple. Thus,
I ask you to render a just verdictδέομαι ὑ̄μῶν . . . τὰ δίκαια ψηφίσασθαι
he ordered all the rest to arm themselvesτοῖς ἄλλοις πᾶσι παρήγγελλεν ἐξοπλίζεσθαι
b. Accusative when the action of a person is desired (example in 1979). Such sentences are complex.
N.—Verbs of commanding allow either a or b; but only κελεύω with the accusative permits either meaning: κελεύω σὲ ταῦτα μὴ ποιεῑν I tell you not to do this and I command that you shall not do this. Cp. 1981.
Several verbs signifying to say are also used as verbs of will and then mean command. The agent commanded usually stands in the accusative subject of the infinitive. So with λέγω, εἶπον, φράζω, φωνῶ. Thus
I say that thou shalt take Philoctetes by craftλέγω σ᾽ ἐγὼ δόλῳ Φιλοκτήτην λαβεῖν
I told them that they should sailτούτοις ἔλεγον πλεῖν
all said that the ringleaders should suffer punishmentπάντες ἔλεγον τοὺς τούτων ἄρξαντας δοῦναι δίκην
a. The agent may stand in the dative as
I bid thee let goχαλᾶν λέγω σοι
The present and aorist infinitive (both timeless) are the usual tenses of the infinitive after verbs of will or desire (see 1869). The perfect is rare; as εἶπον τὴν θύρᾱν κεκλεῖσθαι (1997). δοκῶ and δοκῶ μοι signifying I have a mind to or I am determined to take the present or aorist like
I have a mind to bring out the assδοκεῖ· τὸν ὄνον ἐξάγειν δοκῶ
but I am determined that I will not accept his opinionἀλλά μοι δοκῶ . . . οὐ πείσεσθαι αὐτῷ
a. Some verbs, as κελεύω, which might be held to introduce indirect discourse, are classed under ver<*>s of will or desire, because, like these verbs, they do not regularly take the future infinitive; and because, unlike verbs of saying and thinking (which admit all the tenses of the infinitive) they introduce infinitives which do not show differences of time. The future infinitive does not express a command. For a few cases of the future after verbs of will or desire, see 1869.
Verbs signifying to hope, expect, promise, threaten , and swear, when followed by the aorist (less often the present) infinitive (1868), have the construction of verbs of will or desire. When such verbs take the future infinitive they have the construction of indirect discourse.
The infinitive follows many verbs, especially such as denote ability, fitness, necessity, etc. (and their opposites).
he was no longer able to liveοὐκέτι ἐδύνατο . . . βιοτεύειν
knowing how to swimνεῖν ἐπιστάμενος
and all men are by nature prone to errπεφύ̄κᾱσί τε ἅπαντες . . . ἁμαρτάνειν
they learn how to govern and be governedμανθάνουσιν ἄρχειν τε καὶ ἄρχεσθαι
a. ἔχω I can is derived from the meaning I have especially with a verb of saying. Thus,
they can proclaim a stroke of ZeusΔιὸς πλᾱγὰ̄ν ἔχουσιν εἰπεῖν
The infinitive serves to define the meaning of adjectives, adverbs, and substantives, especially those denoting ability, fitness, capacity, etc. (and their opposites), and generally those analogous in meaning to verbs which take the infinitive (2000). Here the datival meaning (purpose, destination) is often apparent. Cp. 1969.
Adjectives and Adverbs.—
able to assist usἱκανοὶ ἡμᾶς ὠφελεῖν
skilled in speaking, evil in lifeδεινὸς λέγειν, κακὸς βιῶναι
able to loveοἷοι φιλεῖν
they are ready to fightἕτοιμοί εἰσι μάχεσθαι
most worthy to governἄρχειν ἀξιώτατος
quick to conceiveἐπινοῆσαι ὀξεῖς
most splendid to beholdκάλλιστα ἰδεῖν
a. Some of these adjectives take the infinitive by analogy to the related verbs, as πρόθῡμος zealous (προθῡμοῦμαι), ἐπιστήμων knowing how (ἐπίσταμαι).
οἷος fit, ὅσος sufficient take the infinitive like the fuller expressions τοιοῦτος οἷος, τοσοῦτος ὅσος. Thus,
for it was not the proper season to irrigate the plainοὐ γὰρ ἦν ὥρᾱ οἵᾱ τὸ πεδίον ἄρδειν
sufficient to live off ofὅσον ἀποζῆν
the kind of a man to be convincedτοιοῦτος οἷος . . . πείθεσθαι
Substantives.—As,
your children are almost of an age to be educatedοἱ παῖδες ὑ̄μῖν ὀλίγου ἡλικίᾱν ἔχουσι παιδεύεσθαι
we have leisure to learnσχολή γε ἡμῖν μανθάνειν
there is need to obeyἀνάγκη πείθεσθαι
it is high time to finishπεραίνειν ἤδη ὥρᾱ
The infinitive is added, like an accusative of respect (1601, 1602), to intransitive verbs (especially in poetry), to adjectives (more frequently in poetry), and to substantives (rarely). Thus, τοῖος ἰδεῖν such in aspect (lit. to look on) Theognis 216,
of a repulsive expressionὁρᾶν στυγνός
it is very fine to hearσαι παγκάλως ἔχει
a marvel even to hear ofθαῦμα καὶ ἀκοῦσαι
The infinitive limiting the meaning of an adjective is commonly active (or middle) in cases where the passive is more natural in English. Thus,
a speech capable of being understoodλόγος δυνατὸς κατανοῆσαι
worthy to be admiredἄξιος θαυμάσαι
a. The active use is due to the old datival function of the infinitive: δυνατὸς κατανοῆσαι capable for understanding.
The infinitive, with or without ὥστε or ὡς, may be used with ἤ than after comparatives, depending on an (implied) idea of ability or inability. ἢ ὥστε is more common than ἤ or ἢ ὡς. Cp. 2264.
for the disease is too great to be borneτὸ γὰρ νόσημα μεῖζον ἢ φέρειν
I fear lest some calamity befall the State greater than it can bearφοβοῦμαι μή τι μεῖζον ἢ ὥστε φέρειν δύνασθαι κακὸν τῇ πόλει συμβῇ
too short to reachβραχύτερα ἢ ὡς ἐξικνεῖσθαι
a. The force of ἢ ὥστε may be expressed by the genitive; as, κρεῖσσον λόγου (T. 2.50) = κρεῖσσον ἢ ὥστε λέγεσθαι. Cp. 1077.
b. Words implying a comparison may take the infinitive with ὥστε or ὡς (1063).
Infinitive of Purpose.—The infinitive may express purpose (usually only with verbs taking the accusative).
he gave this land over to the Greeks to plunderταύτην τὴν χώρᾱν ἐπέτρεψε διαρπάσαι τοῖς Ἕλλησιν
you granted a day to Aristarchus to make his defenceἈριστάρχῳ . . . ἔδοτε ἡμέρᾱν ἀπολογήσασθαι
I offer myself to be questionedπαρέχω ἐμαυτὸν ἐρωτᾶν
The infinitive of purpose is used in prose especially after verbs meaning to give, entrust, choose, appoint, take, receive. Verbs signifying to send, go, come usually take the future active participle (2065); but T. 6.50 has δέκα τῶν νεῶν προύπεμψαν ἐς τὸν μέγαν λιμένα πλεῦσαι they sent ahead ten ships to sail into the great harbour; and in poetry the infinitive often denotes purpose after these verbs, and after εἶναι in Homer ( Λ 20) and Hdt. (5. 25).
After verbs meaning to have (or be) at one's disposition:
the soldiers did not have money by means of which they could provision themselvesοἱ στρατιῶται ἀργύριον οὐκ εἶχον ἐπισῑτίζεσθαι
there is shade and grass to sit down inἐκεῖ σκιά̄ τ᾽ ἐστὶ καὶ πόᾱ καθίζεσθαι
Infinitive of Result.—The infinitive may be used with ὥστε (sometimes with ὡς) to denote a result, often an intended result. See 2260 ff.
a. Several verbs, substantives, and adjectives usually taking the infinitive also admit ὥστε with the infinitive (2271); and the infinitive is found where ὥστε with the infinitive might be expected: μνημονεύουσιν ἀφεθέντα τοῦτον ἐλεύθερον εἶναι they recall that he was emancipated (lit. released so as to be free) D. 29.25. Here the redundant infinitive expresses an intended result.
N.—This redundant use of εἶναι is common in Hom. and Hdt.
Certain idiomatic infinitives are used absolutely in parenthetical phrases to limit the application of a single expression or of the entire sentence.
a. Verbs of Saying.—ὡς ἔπος εἰπεῖν, ὡς εἰπεῖν so to speak, almost; (ὡς) ἁπλῶς εἰπεῖν, ὡς συνελόντι (1497) εἰπεῖν, ὡς (ἐν βραχεῖ or) συντόμως εἰπεῖν to speak briefly, concisely; ὡς ἐπὶ πᾶν εἰπεῖν, τὸ σύμπαν εἰπεῖν speaking generally; σχεδὸν εἰπεῖν so to say, almost (paene dixerim); σὺν θεῷ εἰπεῖν in God's name; and so ὡς with λέγειν, φράζειν, εἰρῆσθαι, as ὡς ἐν τύπῳ εἰρῆσθαι in general. Examples: ἀληθές γε ὡς ἔπος εἰπεῖν οὐδὲν εἰρήκᾱσιν not one word of truth, I may say, did they utter P. A. 17a, ἀγαθὸν μὲν ἁπλῶς εἰπεῖν οὐδὲν γέγονε τῇ πόλει in a word the State gained no advantage Dinarchus 1.33.
b. ὡς (ἔπος) εἰπεῖν is often used to limit too strict an application of a general statement, especially πᾶς or οὐδείς. Thus, πάντες ὡς ἔπος εἰπεῖν nearly every one, οὐδεὶς ὡς ἔπος εἰπεῖν almost no one. It is thus used like paene dixerim; rarely, like ut ita dicam, to soften the strength of a metaphor.
c. Especially common is the absolute εἶναι in ἑκὼν willingly, intentionally, if you can help it, usually in negative or quasi-negative statements (ἑκών may be inflected). Also in τὸ κατὰ τοῦτον (ἐπὶ τούτῳ) εἶναι as far as he is concerned, ὡς . . . εἶναι as far as . . . is concerned, τὸ νῦν εἶναι at present. Examples:
nor do you intentionally cause strangers to laughοὐδὲ ξένοις ἑκὼν εἶναι γέλωτα παρέχεις
it is not willingly separatedἑκοῦσα εἶναι οὐκ ἀπολείπεται
d. Other expressions: ἐμοὶ δοκεῖν, ὡς ἐμοὶ δοκεῖν, ὡς ἐμοὶ κρῖναι as it seems to me, in my opinion, (ὡς) εἰκάσαι to make a guess, (ὡς) συμβάλλειν to compare, (ὡς) ἀκοῦσαι to the ear, ὡς ὑμομνῆσαι to recall the matter, ὅσον γέ μ᾽ εἰδέναι as far as I know, etc.; ὀλίγου δεῖν, μῑκροῦ δεῖν almost, all but (δεῖν may be omitted, 1399). Examples: ὁ γὰρ Κτήσιππος ἔτυχε πόρρω καθεζόμενος τοῦ Κλεινίου, ἐμοὶ δοκεῖν for Ctesippus, it seems to me, happened to be sitting at a distance from Clinias P. Eu. 274b,
almost three talentsμῑκροῦ δεῖν τρία τάλαντα
e. Some of these absolute infinitives may be explained by reference to the idea of purpose (2008) or result. Thus, συνελόντι εἰπεῖν for one compressing the matter to speak (cp. ut paucis dicam), μῑκροῦ δεῖν so as to lack little. Others recall the adverbial accusative (1606); cp. ἐμοὶ δοκεῖν with γνώμην ἐμήν.
Infinitive in Commands.—The infinitive may be used for the second person of the imperative. The person addressed is regarded as the subject. This infinitive is commoner in poetry than in prose (where it has a solemn or formal force).
θαρσῶν νῦν, Διόμηδες, ἐπὶ Τρώεσσι μάχεσθαι with good courage now, Diomed, fight against the Trojans E 124, σὺ δέ, Κλεαρίδᾱ . . . τὰ̄ς πύλᾱς ἀνοίξᾱς ἐπεκθεῖν but do you, Clearidas, open the gates and sally forth T. 5.9.
a. This infinitive may be used in conjunction with an imperative:
hear ye, good people! drink the Pitchers as our sires drank!ἀκούετε λεῴ· κατὰ τὰ πάτρια τοὺς χόας πί̄νειν
b. The infinitive for the third person of the imperative often occurs in legal language (laws, treaties, etc.), and does not necessarily depend on the principal verb. Thus,
and the treaty shall continue for fifty yearsἔτη δὲ εἶναι τὰ̄ς σπονδὰ̄ς πεντήκοντα
c. The infinitive (with subject accusative) is rarely used for the third person of the imperative when there is an unconscious ellipsis of a word like δός grant, or εὔχομαι I pray. Thus, τεύχεα σῡλήσᾱς φερέτω κοίλᾱς ἐπὶ νῆας, σῶμα δὲ οἴκαδ᾽ ἐμὸν δόμεναι πάλιν let him strip off my arms and carry them to the hollow ships, but let him give back my body to my home H 78.
d. In negative commands (prohibitions) μή with the infinitive is poetic and Ionic: οἷς μὴ πελάζειν do not approach these ( = μὴ πέλαζε) A. Pr. 712,
and do not call him happy yetμηδὲ καλεῖν πω ὄλβιον
Infinitive in Wishes.—The infinitive with a subject accusative may be used in the sense of the optative of wish, usually with the same ellipsis as in 2013 c.
ye gods of my country, may bondage not be my lot!θεοὶ πολῖται, μή με δουλείᾱς τυχεῖν
the hunter should go forth in a light dressτὸν κυνηγέτην ἔχοντα ἐξιέναι . . . ἐλαφρὰ̄ν ἐσθῆτα
a. The nominative with the infinitive (instead of the optative) after αι᾽ γάρ occurs in Homer ( η 311, ω 376).
Infinitive in Exclamations.—The infinitive is often used in exclamations of surprise or indignation. The subject stands in the accusative.
that I should suffer this!ἐμὲ παθεῖν τάδε
to keep a dog like that!τοιουτονὶ̄ τρέφειν κύνα
On the infinitive with ἐφ᾽ ᾧ (ἐφ᾽ ᾧτε) see 2279; with πρίν, see 2453.
The infinitive is used as the object of verbs of saying and thinking. Such infinitives denote both time and stage of action (cp. 1866).
a. The finite verb of a sentence placed in dependence on a verb of saying or thinking that requires the infinitive, becomes infinitive, which infinitive stands in the relation of a substantive as subject or object of the leading verb. Commonly as object: thus, Κῦρος νῑκᾷ Cyrus is victorious, when made the object of φησί he says, becomes a part of a new sentence φησὶ Κῦρον νῑκᾶν, in which Κῦρον νικᾶν is the object of φησί. As subject, when the verb of saying is passive: thus, in λέγεται Κῦρον νῑκᾶν, the last two words form the subject of λέγεται.
Verbs of saying are e.g.: say φημί, φάσκω, λέγω; confess ὁμολογῶ; promise ὑπισχνοῦμαι, ὑποδέχομαι, ἐπαγγέλλομαι, ὑφίσταμαι; pretend προσποιοῦμαι; swear ὄμνῡμι; deny ἀπαρνοῦμαι; gainsay ἀντιλέγω; dispute ἀμφισβητῶ, etc.
Some verbs of saying admit other constructions than the infinitive, and especially ὅτι or ὡς (2579). λέγω, εἶπον, φράζω, φωνῶ with ὅτι or ὡς mean say, with the infinitive command (1997).
a. φημί say, assert, express the opinion that in classical Greek is almost always followed by the infinitive, but by ὅτι very often in the later language. φημὶ ὅτι occurs in X. A. 7.1.5 (φημὶ ὡς in L. 7.19, X. H. 6.3.7; D. 4.48, 27. 19 by anacoluthon).
b. λέγω state (impart a fact) takes either the infinitive or ὅτι or ὡς. The infinitive occurs usually with the passive (λέγεται, etc.) either in the personal or impersonal construction (1982 a). The active forms of λέγω with the infinitive mean command (1997).
c. εἶπον said usually takes ὅτι or ὡς; with the infinitive, it commonly means commanded (1997). Cp. the double use of told.
N.—εἶπον meaning said with the infinitive is rare, but occurs in good Attic prose: And. 1.57, 80; Thuc. 7. 35; Lys. 10. 6, 10. 9, 10. 12; Xen. H. 1. 6. 7, 2. 2. 15, C. 5. 5. 24, S. 2. 13; Is. 2.29; Lyc. 50; Aes. 3.37, 3. 59; Dem. 15. 18; Plato, G. 473 a, 503 d, Lach. 192 b, Charm. 174 a, Hipp. Maj. 291 b, Pol. 263 c, 290 b, L. 654 a, Clitoph. 409 a, 410 b. In poetry this use is frequent.
Verbs of thinking almost always take the infinitive. Such are: think ἡγοῦμαι, οἴομαι, δοκῶ, νομίζω; hope ἐλπίζω; suppose ὑπολαμβάνω; suspect ὑποπτεύω; guess εἰκάζω; feel confident πιστεύω; disbelieve ἀπιστῶ. The use of ὡς is rare, while ὅτι is very rare (2580).
a. Verbs of perceiving sometimes take the infinitive by analogy to verbs of thinking; as ἀκούω, αἰσθάνομαι, πυνθάνομαι (2144).
Each tense of direct discourse is retained (with its proper meaning as regards stage of action) when it becomes infinitive in indirect discourse; but an imperfect is represented by the present infinitive; a pluperfect, by the perfect infinitive. See 1866, 1867.
An original οὐ of direct discourse is generally, an original μή is always, retained in indirect discourse. But in some cases οὐ becomes μή (2723 ff.).
The infinitive is the subject of the passive of verbs of saying and thinking (1982 a). So with δοκεῖ it seems, φαίνεται it is plain, etc.
The infinitive represents a finite verb after verbs of saying and thinking.
a.
they assert that they are loyalεὖνοί φᾱσιν εἶναι
the guides say there is no other roadεἶναι ἄλλην ὁδόν
everybody in time to come will say that there is nothing more profitable than braveryπάντες ἐροῦσι τὸ λοιπὸν μηδὲν εἶναι κερδαλεώτερον τῆς ἀρετῆς
b. βασιλεὺς νῑκᾶν ἡγεῖται the king thinks he is victorious ( = νῑκῶ, cp. 1887) X. A. 2.1.11, οἴομαι βέλτιστον εἶναι I think it is best 5. 1. 8, ὑπώπτευον ἐπὶ βασιλέᾱ ἰέναι they suspected that they were to go against the king 1. 3. 1, (Σωκράτης)
Socrates was of the opinion that for a man not to know himself was very near to madnessτὸ ἀγνοεῖν ἑαυτὸν ἐγγυτάτω . . . μανίᾱς ἐλογίζετο εἶναι
c. When a word of saying is expressed or implied in what precedes, several infinitives may be used where the indicative is employed in translation. So in the narration in X. C. 1.3.5-6.
The infinitive with ἄν represents an indicative with ἄν or a potential optative with ἄν. See 1846, 1848, 1849, 2270.
Verbs signifying to hope, expect, promise, threaten , and swear take the future infinitive in indirect discourse, and the aorist (less often the present) infinitive not in indirect discourse (like verbs of will or desire, 1868, 1999). ἐλπίζω ταῦτα ποιήσειν I hope that I shall do this, ἐλπίζω ταῦτα ποιῆσαι or ποιεῖν I hope to do this.
The articular infinitive, while having the character of a substantive, retains the functions of a verb. In its older use the articular infinitive is a subject or object; the nearest approach to this use in Homer is
to watch is also troubleἀνί̄η καὶ τὸ φυλάσσειν
The articular infinitive admits the constructions of an ordinary substantive.
Nom. τὸ ποιεῖν making or to make, τὸ ποιήσειν, τὸ ποιῆσαι, τὸ πεποιηκέναι
Gen. τοῦ ποιεῖν of making, τοῦ ποιήσειν, τοῦ ποιῆσαι , etc.
Dat. τῷ ποιεῖν for making, by making, τῷ ποιήσειν, τῷ ποιῆσαι , etc.
Acc. τὸ ποιεῖν, τὸ ποιήσειν, τὸ ποιῆσαι , etc.
The articular infinitive is treated as subject, predicate noun, and object like the simple infinitive (1984-1986).
The negative of the articular infinitive is μή.
The articular infinitive may indicate time (after verbs of saying or thinking, 2034 g), or may be timeless.
The articular infinitive is in general used like the infinitive without the article, and may take ἄν; as regards its constructions it has the value of a substantive. The article is regularly used when the connection uniting the infinitive to another word has to be expressed by the genitive, the dative, or a preposition.
a. The articular infinitive is rarely used, like a true substantive, with the subjective genitive:
imitate at least their wisdomτό γ᾽ εὖ φρονεῖν αὐτῶν μῑμεῖσθε
Subject (1984):
in the young silence is better than speechνέοις τὸ σῑγᾶν κρεῖττόν ἐστι τοῦ λαλεῖν
the fact that the Peloponnesians did not come to their assistance enabled you to punish the Samiansτὸ Πελοποννησίους αὐτοῖς μὴ βοηθῆσαι παρέσχεν ὑ̄μῖν . . . Σαμίων κόλασιν
a. The genitive of the articular infinitive is used to limit the meaning of substantives, adjectives, and verbs.
b. Adnominal (1290):
from desire to drinkτοῦ πιεῖν ἐπιθῡμίᾳ
c. Partitive (1306):
having gained the greatest amount of courageτοῦ θαρσεῖν τὸ πλεῖστον εἰληφότες
d. After verbs:
we desisted from weepingἐπέσχομεν τοῦ δακρύ̄ειν
e. Purpose (cp. 1408), often a negative purpose:
in order not to do what was justτοῦ μὴ τὰ δίκαια ποιεῖν
Atalante was fortified to prevent pirates from ravaging Euboeaἐτειχίσθη Ἀταλάντη . . . τοῦ μὴ λῃστὰ̄ς . . . κακουργεῖν τὴν Εὔβοιαν
f. Genitive Absolute (2070): ἐπ᾽ ἐκείνοις δὲ ὄντος αἰεὶ τοῦ ἐπιχειρεῖν καὶ ἐφ᾽ ἡμῖν εἶναι δεῖ τὸ προαμύ̄νασθαι since the power of attack is always in their hands, so in our hands should lie the power of repelling it in advance T. 3.12.
g. After prepositions, e.g. ἀντὶ τοῦ ἐπὶ Κᾱρίᾱν ἰέναι . . . ἐπὶ Φρυγίᾱς ἐπορεύετο instead of going against Caria, he marched toward Phrygia X. H. 3.4.12,
without exercising self-controlἄνευ τοῦ σωφρονεῖν
he devotes his every effort that he may become master of theseὑπὲρ τοῦ τούτων γενέσθαι κύ̄ριος . . . πάντα πρᾱγματεύεται
a. With verbs, adjectives, and adverbs: thus,
that they may distrust my having been honoured by divine powersἵνα . . . ἀπιστῶσι τῷ ἐμὲ τετῑμῆσθαι ὑπὸ δαιμόνων
Philip has conquered us by nothing so much as by being beforehand in his operationsοὐδενὶ τῶν πάντων πλέον κεκράτηκε Φίλιππος ἢ τῷ πρότερος πρὸς τοῖς πρά̄γμασι γίγνεσθαι
equal to sorrowing beforehandἴσον δὲ τῷ προστένειν
b. After prepositions: e.g. οὐ γὰρ ἐπὶ τῷ δοῦλοι, ἀλλ᾽ ἐπὶ τῷ ὁμοῖοι τοῖς λειπομένοις εἶναι ἐκπέμπονται (ἄποικοι) for colonists are not sent out on the basis of being inferiors, but on the basis of being the equals of those who are left at home T. 1.34,
the one, in addition to gaining nothing from the embassy, ransomed the prisoners of warὁ μὲν πρὸς τῷ μηδὲν ἐκ τῆς πρεσβείᾱς λαβεῖν, τοὺς αἰχμαλώτους . . . ἐλύ̄σατο
for life is sweetest in being conscious of nothingἐν τῷ φρονεῖν γὰρ μηδὲν ἥδιστος βίος
a. Object (cp. 1989):
fearing to liveδείσᾱς τὸ ζῆν
we call doing wrong a greater evil, being wronged a lesserμεῖζον μέν φαμεν κακὸν τὸ ἀδικεῖν, ἔλᾱττον δὲ τὸ ἀδικεῖσθαι
b. After prepositions: e.g.
obedience appears to be an advantage of the greatest importance with regard to the successful accomplishment of excellent objectsμέγιστον ἀγαθὸν τὸ πειθαρχεῖν φαίνεται εἰς τὸ καταπρά̄ττειν τἀ̄γαθά
they are indifferent to everything in comparison with victoryτῶν ἁπάντων ἀπερίοπτοί εἰσι παρὰ τὸ νῑκᾶν
schooled to moderate needsπρὸς τὸ μετρίων δεῖσθαι πεπαιδευμένος
c. The accusative of the infinitive with τό appears after many verbs and verbal expressions which usually take only the simple infinitive. Such verbal expressions may be followed also by a genitive of a noun. Thus,
I commend speed to theeτὸ σπεύδειν δέ σοι παραινῶ
we trained her to show zeal in assisting to increase our estateτὸ προθῡμεῖσθαι δὲ συναύξειν τὸν οἶκον ἐπαιδεύομεν αὐτήν
you refuse to loveτὸ ἐρᾶν ἔξαρνος εἶ
d. So after adjectives. Thus, μακρὸς τὸ κρῖναι ταῦτα χὡ λοιπὸς χρόνος the future is long (i.e. time enough) to decide this S. El. 1030.
e. This object infinitive after verbs is often an internal accusative. The accusative after verbs and nouns is, in many cases, like an accusative of respect (1600); as
they refused to do itτὸ δρᾶν οὐκ ἠθέλησαν
they are ashamed to dareαἰσχύ̄νονται τὸ τολμᾶν
nor have I courage to remove theeοὐδ᾽ ἐμοί τοι τοὐξανιστάναι ἐστὶ θάρσος
they are able to make an inroad into our countryἐσβάλλειν . . . ἱκανοί εἰσι
f. Some verbs take the articular infinitive as an object when the simple infinitive could not be used:
taking heed only to strike any one he caughtμόνον ὁρῶν τὸ παίειν τὸν ἁλισκόμενον
g. Verbs of saying and thinking rarely take the articular infinitive (also with ἄν): ἐξομεῖ τὸ μὴ εἰδέναι; wilt thou swear thou didst not know? S. Ant. 535,
for I come with good grip on the hope that I can suffer nothing save what is my fateτῆς ἐλπίδος γὰρ ἔρχομαι δεδραγμένος, τὸ μὴ παθεῖν ἂν ἄλλο πλὴν τὸ μόρσιμον
h. On the use of the object infinitive with τὸ μή and τὸ μὴ οὐ, see 2744 and 2749.
i. The accusative with the infinitive may stand in the absolute construction: ἐπεί γε τὸ ἐλθεῖν τοῦτον, οἶμαι θεόν τινα αὐτὸν ἐπ᾽ αὐτὴν ἀγαγεῖν τὴν τῑμωρίᾱν as for his coming, I believe that some god brought him to his very punishment Lyc. 91.
Apposition (cp. 1987). The articular infinitive, in any case, is often used in apposition to a preceding word, especially a demonstrative.
injustice is this: to seek to have more than other peopleτοῦτό ἐστι τὸ ἀδικεῖν, τὸ πλέον τῶν ἄλλων ζητεῖν ἔχειν
man differs herein from other creatures that he aspires after honourδοκεῖ τούτῳ διαφέρειν ἀνὴρ τῶν ἄλλων ζῴων, τῷ τῑμῆς ὀρέγεσθαι
In Exclamation (cp. 2015).—Thus,
my ill-luck! that I should happen now to have been summoned hither!τῆς τύχης· τὸ ἐμὲ νῦν κληθέντα δεῦρο τυχεῖν
With Adjuncts.—The articular infinitive may take various adjuncts including dependent clauses, the whole forming one large substantival idea.
the fact that we have lost much in the warτὸ μὲν γὰρ πόλλ᾽ ἀπολωλεκέναι κατὰ τὸν πόλεμον
and in fact, since it is a serious business to provide for one's own necessities, it seems to me to be the part of an utter fool not to rest content with that, but in addition to take upon himself the burden of providing for the needs of the rest of the communityμὴ ἀρκεῖν τοῦτο, ἀλλὰ προσαναθέσθαι τὸ καὶ τοῖς ἄλλοις πολί̄ταις ὧν δέονται πορίζειν
Verbs signifying (or suggesting) to hinder take both the simple infinitive and the articular infinitive. Such verbs may take the strengthening but redundant negative μή (2739); and some, when themselves negatived or appearing in a question expecting a negative answer, admit the addition of the sympathetic οὐ (2742). Hence we have a variety of constructions (described in 2744 ff.)


Fairy Tales and Other Traditional Stories
by FCIT
“Why the Evergreen Trees Keep Their Leaves in Winter”
by Florence Holbrook
Additional Information
- Year Published: 0
- Language: English
- Country of Origin:
- Source: Sara Cone Bryant, ed., How to Tell Stories to Children, and Some Stories to Tell
-
Readability:
- Flesch–Kincaid Level: 3.4
- Word Count: 712
- Genre: Fairy Tale/Folk Tale
- Keywords: kindness
- ✎ Cite This
Downloads
One day, a long, long time ago, it was very cold; winter was coming. And all the birds flew away to the warm south, to wait for the spring. But one little bird had a broken wing and could not fly. He did not know what to do. He looked all round, to see if there was any place where he could keep warm. And he saw the trees of the great forest.
“Perhaps the trees will keep me warm through the winter,” he said.
So he went to the edge of the forest, hopping and fluttering with his broken wing. The first tree he came to was a slim silver birch.
“Beautiful birch-tree,” he said, “will you let me live in your warm branches until the springtime comes?”
“Dear me!” said the birch-tree, “what a thing to ask! I have to take care of my own leaves through the winter; that is enough for me. Go away.”
The little bird hopped and fluttered with his broken wing until he came to the next tree. It was a great, big oak-tree.
 If you stay in my branches all winter you will be eating my acorns. Go away.”
So the little bird hopped and fluttered with his broken wing till he came to the willow-tree by the edge of the brook.
 Go away.”
The poor little bird did not know where to go; but he hopped and fluttered along with his broken wing. Presently the spruce-tree saw him, and said, “Where are you going, little bird?”
“I do not know,” said the bird; “the trees will not let me live with them, and my wing is broken so that I cannot fly.”
“You may live on one of my branches,” said the spruce; “here is the warmest one of all.”
“But may I stay all winter?”
“Yes,” said the spruce; “I shall like to have you.”
The pine-tree stood beside the spruce, and when he saw the little bird hopping and fluttering with his broken wing, he said, “My branches are not very warm, but I can keep the wind off because I am big and strong.”
So the little bird fluttered up into the warm branch of the spruce, and the pine-tree kept the wind off his house; then the juniper-tree saw what was going on, and said that she would give the little bird his dinner all the winter, from her branches. Juniper berries are very good for little birds.
The little bird was very comfortable in his warm nest sheltered from the wind, with juniper berries to eat.
The trees at the edge of the forest remarked upon it to each other:
“I wouldn’t take care of a strange bird,” said the birch.
“I wouldn’t risk my acorns,” said the oak.
“I would not speak to strangers,” said the willow. And the three trees stood up very tall and proud.
That night the North Wind came to the woods to play. He puffed at the leaves with his icy breath, and every leaf he touched fell to the ground. He wanted to touch every leaf in the forest, for he loved to see the trees bare.
“May I touch every leaf?” he said to his father, the Frost King.
“No,” said the Frost King, “the trees which were kind to the bird with the broken wing may keep their leaves.”
So North Wind had to leave them alone, and the spruce, the pine, and the juniper-tree kept their leaves through all the winter. And they have done so ever since.


--- layout: post tags: [Productivity, Unit Testing] date: 2012-05-24 15:20:48 UTC title: "TDD test suites should run in 10 seconds or less" --- {% include JB/setup %}
Most guidance about Test-Driven Development (TDD) will tell you that unit tests should be fast. Examples of such guidance can be found in FIRST and xUnit Test Patterns. Rarely does it tell you how fast unit tests should be.
10 seconds for a unit test suite. Max.
Here's why.
When you follow the Red/Green/Refactor process, ideally you'd be running your unit test suite at least three times for each iteration:
Each time you run the unit test suite, you're essentially blocked. You have to wait until the test run has completed until you get the result.
During that wait time, it's important to keep focus. If the test run takes too long, your mind starts to wonder, and you'll suffer from context switching when you have to resume work.
When does your mind start to wonder? After about 10 seconds. That number just keeps popping up when the topic turns to focused attention. Obviously it's not a hard limit. Obviously there are individual and contextual variations. Still, it seems as though a 10 second short-term attention span is more or less hard-wired into the human brain.
Thus, a unit test suite used for TDD should run in less than 10 seconds. If it's slower, you'll be less productive because you'll constantly lose focus.
The test suite you work with when you do TDD should execute in less than 10 seconds on your machine. If you have hundreds of tests, each test should be faster than 100 milliseconds. If you have thousands, each test should be faster than 10 milliseconds. You get the picture.
That test suite doesn't need to be the same as is running on your CI server. It could be a subset of tests. That's OK. The TDD suite may just be part of your Test Pyramid.
Many people work around the Slow Tests anti-pattern by only running one test at a time, or perhaps one test class. In my experience, this is not an optimal solution because it slows you down. Instead of just going
you'd need to go
Obviously, that introduces friction into your process. Personally, I much prefer to have a fast test suite that I can run all the time at a key press.
Still, there are tools available that promises to do this analysis for you. One of them are Mighty Moose, with which I've had varying degrees of success. Another similar approach is NCrunch.
For a long time I've been wanting to write this article, but I've always felt held back by a lack of citations I could exhibit. While the Wikipedia link does provide a bit of information, it's not that convincing in itself (and it also cites the time span as 8 seconds).
However, that 10 second number just keeps popping up in all sorts of contexts, not all of them having anything to do with software development, so I decided to run with it. However, if some of my readers can provide me with better references, I'd be delighted.
Or perhaps I'm just suffering from confirmation bias...
Comments
Some of that can be alleviated with a DVCS, but rapid feedback just makes things a lot easier.
>> Mighty Moose, with which I've had varying degrees of success. Another similar approach is NCrunch.
I tried both the tools in a real VS solution (contained about 180 projects, 20 of them are test ones). Mighty Moose was continuously throwing exceptions and I didn't manage to get it work at all. NCrunch could not compile some of projects (it uses Mono compiler) but works with some success with the remained ones. Yes, feedback is rather fast (2-5 secs instead of 10-20 using ReSharper test runner), but it unstable and I've returned to ReSharper back.
TDD cannot be used for large applications.
I was doing some research myself. From what I understand, the Wikipedia article you link to talks mainly about attention span in the context of someone doing a certain task and being disturbed. However, while we wait for our unit tests to finish, we're not doing anything. This is more similar to waiting for a website to download and render.
The studies on "tolerable waiting time" are all over the map, but even old ones talk about 2 seconds. This paper mentions several studies, two of them from pre-internet days (scroll down to the graphics for a comparison table). This would mean that, ideally, we would need our tests to run in not 10 but 2 seconds! I say ideally, because this seams unrealistic to me at this moment (especially in projects where even compilation takes longer than 2 seconds). Maybe in the future, who knows.
Peter, thank you for writing. I recall reading about the 10 second rule some months before I wrote the article, but that, when writing the article, I had trouble finding public reference material. Thank you for making the effort of researching this and sharing your findings. I don't dispute what you wrote, but here are some further thoughts on the topic:
If the time limit really is two seconds, that's cause for some concern. I agree with you that it might be difficult to achieve that level of response time for a moderately-sized test suite. This does, however, heavily depend on various factors, the least of which isn't the language and platform.
For instance, when working with a 'warm' C# code base, compilation time can be fast enough that you might actually be able to compile and run hundreds of tests within two seconds. On the other hand, just compiling a moderately-sized Haskell code base takes longer than two seconds on my machine (but then, once Haskell compiles, you don't need a lot of tests to verify that it works correctly).
When working in interpreted languages, like SmallTalk (where TDD was originally rediscovered), Ruby, or JavaScript, there's no compilation step, so tests start running immediately. Being interpreted, the test code may run slower than compiled code, but my limited experience with JavaScript is that it can still be fast enough.


Life as a Little Penguin
Like all penguins, the Little Penguin is highly adapted for life in the sea. Its body is streamlined, its wings are modified as flippers and its feathers are densely distributed over its body. The upper parts, including the back of the Little Penguin are distinctly blue, which explains one of its alternative names (Blue Penguin) and the underbelly is white. Its bill is grey-black with a pinkish lower base, and its iris pale grey to white. One New Zealand population has broad white borders to the flippers, and considered by some as a separate species. Young penguins are bluer than adults. The Little Penguin is also known as the Fairy Penguin because of its small size.
The Little Penguin is the only species of penguin that breeds in Australia. Although the most famously occurring on Phillip Island in Victoria, dozens of colonies are scattered on islands from the NSW North Coast, south to Tasmania, and west to Carnac Island, off Fremantle. On land penguins are eaten by introduced predators and their burrows are trampled, and at sea they are susceptible to oil pollution, fish die-offs and entanglement in fishing nets. Despite this, the total population in Australia is stable at perhaps a million birds.


⇒
0
1
2
0
100
200
300
400
500
600
700
800
900
1,000
Why do we need visualizations?
Famous English adage
A picture is worth a thousand words
Illustration: Text
Planet / Star
~Radius (km)
Sun
695 500
Jupiter
69 900
Saturn
58 200
Uranus
25 300
Neptune
24 600
Earth
6 400
Venus
6 000
Mars
3 400
Mercury
2 400
Moon
1 700
Pluto
1 200
Comparison
Graphics
Digest information faster
Discover new information that wouldn't otherwise
be as obvious
Can take up less space
Generally more engaging
More memorable
Text
Shows exact numbers
More reusable
Can be used in further calculations
Can be used as input for visualizations
Conclusion
Visualization is an effective tool for communicating information
How do we build visualizations?
...
- Transform data into visual variables
- Render to the screen
...
Steps to build a visualization
Choose a type of visualization
Transform data into appropriate format
Associate data points with relevant visual information
Render visualization based on visual information
Optional . React to interactions by updating visualization
Can we achieve it using only native Web APIs ?
DIY charts
- Yes, of course, but is it worth our time?
- Simple static charts you could do yourself, and save some on the bundle size.
- But it can quickly get complicated when you want to do:
make the visualization dynamic, add animation, make smooth/rounded lines for a line chart, support complex interactions like pan and zoom, etc.
Minimal example using HTML and CSS
.axis {
position: absolute;
left: 0;
bottom: 0;
width: 3px;
height: 3px;
background-color: white;
transform: translate(-1.5px, 1.5px);
}
.axis-tick {
position: absolute;
bottom: 0;
width: 20px;
display: flex;
flex-direction: column;
text-align: center;
transform: translate(-10px, 54px);
}
.axis-tick::before {
content: '|';
}
.circle {
position: absolute;
width: 10px;
height: 10px;
background-color: white;
border-radius: 10px;
transform: translate(-5px, 5px);
}
Quickly becomes unmaintainable
What if we have a large amount of data points?
Do we want the visualization to be interactive?
How do we implement transitions/animations?
Will the data be dynamic?
Use a library
Some popular ones are:
Why talk about D3?
More interesting
Flexible
Tailored visualizations
Full control
Cutting-Edge
Use any browser-supported feature
No need to wait for library update
D3 - the library
Collection of utility functions
Manipulating data
Rendering visualizations
Grouped into various modules
How does D3 work
Data-Driven Documents (D3)
Manipulate data
Bind data to document
React to changes and actions
Reactive visualization
Mostly declarative
4 step process
Enrich data with visual information
Specify a selection of nodes to render
Join enriched data to selection
Render nodes with enriched data
Feels rather vague?
Let's see an example
Building a simple chart using D3
Step 1: Enrich data with spatial information
import * as d3 from 'd3';
const scale = d3.scaleLinear()
.domain([0, 100])
.range([0, 640]);
console.log(scale(0)); // Outputs: 0
console.log(scale(20)); // Outputs: 128
console.log(scale(50)); // Outputs: 320
console.log(scale(90)); // Outputs: 576
console.log(scale(100)); // Outputs: 640
0
20
50
90
100
Step 2: Specify a selection of nodes to render
Given the following HTML document:
The following code snippet will create a D3 selection
containing all of the circle elements:
import * as d3 from 'd3';
d3.select('svg')
.selectAll('circle');
Note : select
and selectAll
takes a CSS selector as parameter.
Step 3: Join enriched data to selection
Given the following HTML document:
We can bind our enriched data to the document as follows:
import * as d3 from 'd3';
const scale = d3.scaleLinear()
.domain([0, 100])
.range([0, 640]);
const data = [0, 20, 50, 90, 100];
const enrichedData = data.map(scale); // [0, 128, 320, 576, 640]
d3.select('svg')
.selectAll('circle')
.data(enrichedData);
Step 4: Render nodes with enriched data
Given a slightly modified version of the previous slide's
code:
import * as d3 from 'd3';
const scale = d3.scaleLinear()
.domain([0, 100])
.range([0, 640]);
const data = [0, 20, 50, 90, 100];
const enrichedData = data.map(scale); // [0, 128, 320, 576, 640]
const circles = d3.select('svg')
.selectAll('circle')
.data(enrichedData);
We can use the enter selection to append missing circles as follows:
circles.enter()
.append('circle')
.attr('cx', (d) => d)
.attr('cy', 0)
.attr('r', 5);
0
20
50
90
100
Mastering D3 require mastery of SVG
Like we mentioned before, one of the great things about D3 is that it does not abstract away the underlying Web Technologies
provided by the browser.
D3 simply allows you to effectively manipulate the DOM directly and do so in a data-driven fashion.
When we are working with D3 the aim is, in 99% of cases, to build an SVG. It is therefore very important to have a good grasp on
SVG. Without it you will not be very effective with D3. So lets dive in.
Two types of computer graphics
Raster graphics
Vector graphics
- Vector graphics and Raster graphics (Bitmaps) are two canonical categories of computer graphics.
Raster graphics
Bitmaps / grid of pixels
Eg. PNG and JPEG
Great for photo realism
Space efficiency
Not very scalable
RASTER GRAPHICS
- Raster graphics you are all familiar with. Raster graphics are bitmaps, usually a rectangular grid of pixels.
Where a pixel is a point with color.
- Png and jpeg are fileformats that fall under the category of raster graphics.
- Raster graphics are great for photo-realism, but because a raster image must somehow describe the color of every pixel it consists of, it
is not very space efficient when containing only simple shapes.
- Due to a raster graphic consists of a fixed amount of pixels it is also not very scalable.
Vector graphics
Defined with math
Vector graphics = points and the lines/curves between them
Source code define shapes
Circle with center of (x,y) and radius r
Rectangle with width and height etc.
Stroke and fill
Infinitly scalable
Can be very space efficient
Lack the detail posible in a raster graphic
Suitable for simple drawings, not photo realism
VECTOR GRAPHICS
- Vector graphics is defined by using mathematical equations to describe an image.
- At the lowest level, vector graphics are computer graphics images defined in terms of coordinates/points on a cartesian plane,
connected by lines or curves to form polygons and other shapes.
- The source code of a vector graphic describe the shapes it consists of and their attributes.
- Like a circle with center coordinates X and Y and radius r
- Or a rectangle with coordinates X and Y and width W and hight H
- The resulting shapes become visible on the screen by giving color to the storke (the line forming the shape) and fill (the inside of the shape).
- The points, the lines and their relative position contain all the information you need to draw the vector graphic at any resolution,
and is therefor infinitly scalable.
- Considerable space savings can be achieved when all the shapes of an image are defined with simple parameters instead of pixels.
- Because vector graphics consists of coordinates/points with lines and curves between them, the file size of the
representation does not depend on the dimensions of the object. The same graphic can be served to both mobile and 8K displays
- Vector graphics images will lack the detail compared to a real photo.
- And are more suited for simple or drawings.
Scalable Vector Graphics (SVG)
SVG is a web standard for vector graphics
XML based markup language
Support styling with CSS
But does not support the same attributes as HTML (more on this later)
SVGs are part of the DOM
Programmatically manipulating SVG documents is just like manipulating HTML documents
- SVG is a web standard for vector graphics
- SVG is XML based just like HTML
- SVG support CSS, so you style your SVGs much like you would your HTML, with some important differences we will come back to.
- SVGs and their content are part of the DOM and you work with these elements just like you would normal HTML elements
- Programmatically manipulating SVG documents is just like HTML documents
Use cases for SVG
Adding complex shapes and backgrounds to your webpage
Icons
Vector based images and illustrations
Micro interactions
Animations
Flare
Data visulazation
Understanding SVG
Treated much like an image
Creates an infinitly large plane
Origo in the top left corner
Positive x towards the right
Positive y downward
Four imporatant attributes
xmlns
viewBox
width
hight
The viewBox
Defines the position adn dimension, in user space, of an SVG viewport
The telescope through which we look at the SVG
ViewBox example
Styling content of SVGs
Much like HTML, but not entierly
No box model
No document flow
Only "absolute" positioning relative to the SVG element
No z-index
Uses "the painters model"
...
SVG uses the "painters model", which means that what you draw first to the SVG is at the back, while what you draw later is to the front.
You therefore need to be cognizant of the order you add elements to you SVG.
The renderable elements
SVG element reference
Lets explore the elements supported by SVG!
- Different types of elements
- THIS IS THE PRIMITIVES YOU WILL BE THINKING IN WHEN AUTHORING SVG, WHICH IS WHAT YOU DO WHEN BUILDING DATA VISUALIZATION USING D3!
- Renderable elements to take not of: circle, ellipse, image, line, path, polygon, polyline, rect, text, a
The group element
The div of SVG (kind of)
MDN Web Docs > SVG > Element > g
There is another very important element to know about
- Container element to group SVG elements together
- Is not rendered to the screen
- Children inherit attributes from group elements
- Transformations applied to the group is applied to all children (very useful)
How we build a bar chart with SVG and D3
Visual guide to buildinging a bar chart
With our new knowledge of Vector graphics and SVG lets walk through step by step
how we use D3 to construct a data visualizaiton.
Tin has already walked us through the general steps, but lets get into the details.
Go through building a data visualization
- The SVG element
- Group axis and data in group elements
- Positioning axis
- Positioning data
Walk through everything while illustrating with high charts
D3 with React
Two approaches
Use React to render nodes
Manipulates data using D3
Benefits from Virtual DOM
Use D3 to render nodes
Mutates DOM directly
Avoids overhead from Virtual DOM
Two separate concerns
Data manipulation
Rendering
Alright, let's get back to D3. Now we've seen how to use D3 to render SVGs,
but how do we use D3 in a project with React? Since most of use are working
in React project nowadays, we thought that it'd be nice to give you examples
that show how D3 can be integrated with React.
To use D3 with React, you have to choose between two approaches concerning
rendering:
- Either you let React do the rendering, which gives you the benefits that a
Virtual DOM comes with.
- Or you bypass React's Virtual DOM and let D3 do the rendering by mutating
the DOM directly.
Either way, one thing that becomes quite apparent when usind D3 with React is
that there are two separate concerns that need to be addressed:
- Data manipulation, which you'll always use D3 for
- And rendering, where you have the two possible approaches above
You dont have to use D3 for rendering if you don't want/need to.
This is an important distinction because it means that the data manipulation
logic can live outside of React's lifecycle and thus be reused more easily,
if you happen to want that.
Approach: React rendering D3 manipulated data
Let's take a closer look at the first approach: to let React handle the
rendering. The code block that you see here does exactly that, but let's
dissect it so that it's easier to digest.
First, we start by importing React and the React hooks that we need. Then we
import D3 as usual - this is the same as always.
Finally, we look at the actual juice of this example. Here, we create a React
component that takes in our data as a prop.
Then we do our usual business by creating a linear scale and storing the
visual properties in a new variable. Only this time, we've wrapped the logic
into a `useMemo` hook to make sure that the logic is ran only once - unless
the data changes of course, then we'd want to recreate the scale and
recalculate the visual properties.
Finally, we render the SVG and circle elements using JSX by iterating over
our enriched data.
Simple enough!
Approach: D3 rendering nodes in React
So how do we let D3 handle the rendering instead?
Here's a modified version of the React component from the previous slide.
Notice that, this time, we do not render the circles using JSX. Instead we
store a reference to the SVG element rendered by React using the `useRef`
hook and let D3 handle the rendering in a `useEffect` hook.
To render in React using D3, we first need to make sure that the SVG element
has been rendered by React - it must exist before we can proceed. Then, we do
our usual stuff: specify the selection of nodes that we want to render, bind
our data to it, and finally use the enter selection to append elements.
Notice that we can use our reference the React rendered SVG element directly
as a parameter to `select`, which will create a selection containing only the
SVG element, if it exists.
D3 with TypeScript
There will be plenty of type issues
But it's nice to have type-completion*
import * as d3 from 'd3';
const data = [10, 20, 50, 90, 100];
const scale = d3.scaleLinear()
.domain(d3.extent(data) as [number, number])
.range([0, 640]),
const enrichedData = data.map(scale);
d3.select(svgRef.current)
.selectAll('circle')
.data(enrichedData)
.enter()
.append('circle')
.attr('cx', (d) => d as number)
.attr('cy', 0)
.attr('r', 5);
D3 has types, but the types are not allways as permissive as the JavaScript it describes.
For example a D3 function can in reality handle both numbers and strings, but the types only
allow one of them requiering you to opt out of the Type system or cast the data to the required type.
Sometimes the types are downright wrong.
The solution is to allow the types to help you as much as possible, and sprinkle in some explicit type casting or
just opt out by using "any" or @ts-ignore.
More advanced D3
Now, lets look at some more advanced capabilities of D3.
Transitions with D3
D3 transitions makes it easy to animate DOM changes
Transitions is a limited form of keyframe animation
Transitions interpolate values over time
D3 supports interpolation for several types
Numbers, colors, geometric transforms, strings with embeded numbers (paths and fonts for example)
Lets start with transitions. selection.transition makes it easy to animate transitions when changing the DOM.
The ease of applying transitions to your data visualizations is one of the reasons why D3 is so popular. And
transisions are something you do not get when rendering with React. Which is why you usually do the rendering with
D3 also in the context of a React app.
D3s transition interface mirrors the selection interface which makes it really easy to add smooth
animations to previsouly static visualizations.
Transitions are a limited form of key frame animation with only two key frames: start and end. Where the
start is the current state of the DOM and the end is the desired state of DOM, which you define with
.attr() and .style() to your selection.
D3 is able to interpolate several types of values, not just numbers, but also colors and string values like a path or
fonts and even geometric transforms.
Transitions example
d3
.selectAll("rect")
.data(data)
.join(
enter =>
enter
.append("rect")
.attr("fill", "red")
.attr("opacity", 0)
.call(enter => enter
.transition()
.delay(100)
.duration(200)
.ease(d3.easeLinear)
.attr("opacity", 1)
),
update =>
update
.transition()
.attr("fill", "blue"),
exit =>
exit
.transition()
.attr("opacity", 0)
.remove()
)
Example - Transition between stacked and grouped bar chart
- Create a selection and bind data to it
- We join the data to some rect elements
- Setup the start state for entering elements
- Call transition(), duration(), delay() and easing() (duration and easing have good defaults) to get a transition and configure it
- These methods can also take a function which is given the datum for each element of the transition. This enables
control of duration, delay and easing for each element seperately. You can do many compext things with just these methods.
- Define the new desired state with .attr() or .style() calls
- Handle how you want to transition entering, updating and exiting elements seperately
- D3 handles the interpolation of values and applying updates to the DOM
- Rebinding your selection to new data will now result in an animated trasition.
What you think about is how to i transition in the entering nodes, how to i transition nodes allready in the DOM to their new state
and how to I transition out elements that we no longer have any data binding for.
Interaction with D3
Responding to user iteraction
We are only limited by what is possible with the DOM
We can hook into events like: click, drag, focus, mouseenter, scroll etc.
Only limitd by our imagination
Tooltip example comming up later
d3.selectAll(".bar").on(eventName, callback);
When it comes to interactivity we are refering to making our data visualization repond to user input and interaction.
For exmaple
- adding a click handler which render some additional information about what you clicked at
- Adding a tooltip which is shown when hovering over an element
- Adding pan and zoom gestures (more about that later)
In 99% of cases we are using D3 to render an SVG, or perhaps we are using HTML. Regardless, we are using the DOM.
Which means we have the ability to register event listeners for all sorts of events and do whatever we want in
response. Just like we normally do.
We are only limited by our imagination.
Examples of events we could use
- Click
- Drag
- Focus
- Mouseender, mouseleave
- Scroll etc.
to update the data visualization.
D3 makes it easy to register event listeners on elements in a selection using the .on(eventName, callback) method.
Later we will see an example of how we can add a tooltip to a plot
Pan and zoom with D3
Popular interaction techniques
Implemented with CSS transforms
Updating the scale factor => zooming
Updating x and y translate => panning
function zoomHandler({ transform }) {
div.style(
"transform",
"translate(" + transform.x + "px," + transform.y + "px) scale(" + transform.k + ")"
);
}
Wellify.ai Map View
Zoomable scatterplot example
Panning and zooming are popular interaction techniques which allows the user to focus on a region of interest.
We are all very used to click and drag to move around and scroll/pinch to zoom in and out, but how can we implement
this with D3?
Basically what D3 does is simply to apply CSS transforms to all the elements in the svg. Meaning to zoom, D3
applies scaling and to pan; D3 applies a translation.
- Talk about Map View (Note creating ZoomBehaviour, adding zoom behaviour to SVG and handling zoom events)
D3 zoom in designed to work with d3-scale and d3-axis. In order to make it easy to update the scale and axis
when zooming and panning around.
What about rendering with HTML5 canvas?
The DOM has some limitations. When the DOM of the active page becomes too large and highly nested
the browser will have difficulty keeping up and frames start dropping. Lighthouse start triggering
warnings when the DOM exceeds 1500 elements, have a depth greater than 32 nodes or have a parent node
with more than 60 child nodes. The DOM is of course capable of handling a lot more on powerfull devices,
but these are still the recommendations of browser engeneers.
Its is said that SVGs should not exceed having more than 1000 elements. 2000 and 3000 and maybe more will
still work in devices with decent hardware, but if you for some reason need the ability to put several
thousand shapes on the screen, HTML5 canvas is what you will need to reach for.
Number of shapes on the screen does not need to be the deciding factor for you. Drawing shapes to a Canvas is
in general a lot cheaper than using the DOM. If performance is a concern, canvas can be the solution.
A general rule I have come accross is that Canvas can handle drawing of an order or magnitue more shapes than
SVG and sill maintain the framerate. This of course depends a lot on what and how you are drawing in adition to
any additional program logic your are running.
The decision of starting to use Canvas should not be taken lightly. Your codebase will grow in complexity,
there will be more lines of code to achive the same result you did with SVG.
The browser is not aware of the shapes you have drawn to the canvas or their boundaries. Hit detection you will have to
code yourself, so adding interactivity is a challange, and accessibility of your site will go down as the browser
wont help you in that department ether.
Introduction to HTML5 Canvas
This will be a quite shallow introduction, but I hope to help you start building your mental model of Canvas and canvas programming
as well as placing it in the landscape of other rendering technologeis on the web.
The Canvas API provides a means for drawing graphics via JavaScript on a HTML canvas element.
Among other things, canvas can be used for animation, game graphics, photo manipulation, real-time video processing and data visualization.
The Canvas API largely focuses on 2D graphics. But the WebGL API, which also uses the canvas element, can draws hardware-accelerated
2D and 3D graphics.
const canvas = document.getElementById("chart");
const ctx = canvas.getContext("2d");
ctx.beginPath();
ctx.rect(20, 20, 150, 100);
ctx.stroke();
The canvas element operates much like an image in the DOM, but you have the ability to programmatically
control its content. The canvas element itself can be styled like an image using CSS. Apply margin, border,
background as you normally would. In addition, the base attributes any HTML element has, like id and class,
the canvas element also has. The canvas element also have width and height attributes, but you don’t have to use these;
you can also set width and height with CSS.
- Fallback content is placed inside the canvas element. For this reason it is required to have a closing tag
(canvas).
The canvas element creates a fixed-size drawing surface that expose one or more “rendering contexts”.
A rendering context is an object we can use to manipulate the content shown in the canvas.
The rendering context we fill focus on today is the 2D rendering context, but there is also a 3D context
which WebGL uses.
Some facts about HTML5 canvas
Same coordinate system as SVG
Only support two primitve shapes
The canvas coordinate system works the same way as the SVG coordinate system with respect to the
location of the origin and direction of the axis. So you are allready familier with that
The canvas, actually, only supports two primitive shapes: rectangles and paths, where paths are lists of points
connected by lines or curves.
All other shapes you want to create must be created by combining one or more paths.
On order to author a path you use methods exposed on the 2D context to create and add together multiple subpaths,
which combined can become shapes of arbitrary complexity.
Drawing rectangles
var ctx = canvas.getContext('2d');
ctx.fillRect(x, y, width, height);
ctx.clearRect(x, y, width, height);
ctx.strokeRect(x, y, width, height);
Continuing with how to draw rectangles. Here we have three methods.
The first create a rect and fill it, all in one call.
The second create a rect and strokes it, all in one call.
The third clears a rect (removing any color of the affected pixels)
Drawing paths
const ctx = canvas.getContext("2d");
ctx.beginPath();
ctx.moveTo(x, y);
ctx.lineTo(x, y);
ctx.quadraticCurveTo(cpx, cpy, x, y);
ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
ctx.arc(x, y, radius, startAngle, endAngle [, anticlockwise]);
ctx.arcTo(x1, y1, x2, y2, radius);
ctx.ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle [, anticlockwise]);
ctx.rect(x, y, width, height);
// ctx.closePath()
As mentioned, a path is a list of points connected by lines.
To make a shape using a path you go through the following steps:
1. Create the path: ctx.beginPath()
2. Issue draw commands do draw the path (specify the points and lines). There is no limit to the
number of draw commands or the combination of them you can issue to create your shapes.
Go through code on the screen
3. Finally, you stroke and/or fill the path to make is visible (render it)
a. Ctx.fill()
b. Ctx.stroke()
A path or sub path can be “closed” or “open”. When filling a path it is closed automatically. Closing a path
means to draw a line from the current position of the path to the start position, completing the path, closing the remaining gap.
Becoming effective in using canvas involves becoming comfortable with these methods and how to compose them
together to create the shapes you want. The methods on the screen is pretty much it (you do have some more tools but..),
those are all you have at your disposal. Take a second to take in the simplicity of the API.
Drawing text
const ctx = canvas.getContext("2d");
ctx.fillText(text, x, y [, maxWidth]);
ctx.strokeText(text, x, y [, maxWidth]);
Adding text to the canvas is easy. You use one of the following two methods to render text to the canvas:
1. fillText(text, x, y [, maxWidth])
2. strokeText(text, x, y [, maxWidth])
There are styling options to further control how the text is rendered to the canvas, but we will skip over that.
Styling and colors
Stroke and fill
Configure the context before stroking/filling
const ctx = canvas.getContext("2d");
// Configure styles
ctx.fillStyle = 'rgba(250, 130, 0, 0.7)';
ctx.strokeStyle = 'blue'
ctx.lineWidth = 5;
ctx.lineCap = 'round'
...
// Create path
ctx.beginPath();
ctx.moveTo(x, y);
ctx.lineTo(x, y);
...
// Stroke and/or fill the path
ctx.stroke();
ctx.fill();
There are only two things you can do to style a shape. Style the stroke and the fill.
Styles are defiened by configuring the context with the styles you want before stroking or filling the shape you are drawing.
You do have a few options when it comes to styling:
Color:
- Defined the color using the same conventions supported by CSS
o Ctx.fillStyle = “rgba(255, 160, 0, 1) etc.
- Set the alpha for everything about to be storked or filled with ctx.globalAlpha
Line styles
- LineWidth
- lineCap: appearance of the end of lines
- lineJoin: appearance of the corners where lines meet
- setLineDash(segments)
- lineDathOffset
Gradients
It is possible to fill and stroke shapes using linear, radial and conic gradients.
This works is done by creating a CanvasGradient object and then assign it to the
fillStyle or strokeStyle.
Other tools to style your shapes are
- Patterns
- Shadows
There are several other tools at your disposal, but the key takeaway here is:
- Shapes are styled with stroke and fill
- Configure the styles before stroking/filling
Managing canvas state
...
ctx.fill();
// Push canvas state to a stack
ctx.save();
// Change styles
ctx.fillStyle = 'rgba(0, 0, 250, 0.5)';
...
// Draw shapes
ctx.beginPath();
ctx.rect(x, y, width, height);
ctx.fill();
// Pop canvas state from a stack
ctx.restore();
Managing the state of the context, meaning the styling configuration can be cumbersome, but you have a tool
to make it a bit more manageable. You can save the context state to a stack and later restore it after having modified
it.
Explain code
Animation
No CSS no DOM
Redraw everything every frame
One class per type of object
Scene graph
You cannot use CSS, and moving a shape does not involve updating an attribute on a DOM element,
but rather to redraw the whole canvas and every shape within it.
You as a programmer have to take responsibility to recalculate the position and modifications to
all the shapes in the scene and redraw everything.
There are many techniques to optimize this process by reducing the amount of shapes you need to
redraw every frame. For example, put all the static shapes
Since you have to keep track of all the shapes in memory and manage how they all relate to eachother.
Which are inside others, which are drawn on top and which are behind. In compex use cases you end up
creating dedicated classes for the different types of objects you have in the scene (scene objects). Such a class then
contains positioning and sizing information and so on. It is also common to put the render logic on those
clases. To the objects know how to draw them selves.
These scene objects can then be organized in a scene graph expressing the relationships of the objects.
Interaction
The canvas is just a bitmap
Add event handlers to the canvas element
Based on the "scene graph" you can calculate what object the user interacted with
The canvas element is just a bitmap and does not provide any information about its content to the
outside world. All the build in features you get when using HTML or SVG elements, like the ability
to add event handlers or use CSS to dynamically change styles on hover, focus etc, does not work
with object drawn in the canvas. You have to add all these capabilities on your own.
To add interaction you would noramlly
- Add mouse events handleres etc. to the canvas element itself
- Based on the “scene graph” of your application you can calculate what the user is hovering over,
for example, and update the canvas accordingly.
D3 with HTML5 Canvas
D3 is tightly coupled with the DOM
D3 as a library of utility functions
Easiest approach
D3 manipulates the DOM inside a custom element
Iterate over the nodes and draw them to the canvas
Now we know a bit about Canvas, how can we leverage D3 when drawing to a canvas.
D3 is a library to manipulate the DOM, not arbitrary object in memory. You cannot use d3-selection and
data-biding on an array of JavaScript objects.
D3 has a lot of utility fuctions which you can use to aid in the developent of your own system to handle
updates to data, transitions and so on, but you would need to take on a lot of the responsibility that
D3 normally has.
The easiest way to move rendering from SVG or HTML to canvas is in fact to use D3 to manipulate the DOM,
just like normal, but put all the nodes inside a custom element. The browser will ignore the custom element
and not spend any resources on rendering the stuff you put inside.
You still use resources to manipulate the DOM, but the browser saves on rendering.
In order to draw to the canvas you simply iterate over all the DOM nodes D3 controlls and use their element type
and attributes as arguments in the drawing process.
Checking the DOM for changes 30 times a second and redrawing the canvas will result in smooth animations,
and D3 still does all the heavy lifting.
Canvas Demo
Lets look at a couple of examples
D3 with canvas demos
- Show animation
- Explain code
- Show scatter plot
- Explain code


Project
GitHub
Collaborators:
Description:
Tools used:
published
This webpage is all about Isaac Heist, that's me, and all the projects I have done. Feel free to look around or checkout my social links to get to know me better.
Hello! My name is Isaac Heist. Thanks for visiting my portfolio page. Here's a little bit about me. I am a husband, father, worship pastor, a student at Code Fellows, and a full-stack JavaScript developer. I also once built some pretty sweet kitchen cabinets. I speak Spanish fluently as a second language and really love the country of Mexico.
The size of my family including myself, my wife and kids, my parents and all my siblings and their spouses and kids: